loading table of contents...

7.12.5. Customizing the Start up Behavior

After successful login, Studio restores the tabs of the last session. This default behavior can be disabled by calling the setDefaultTabStateManagerEnabled(enable) method of IEditorContext class.

When you set this value to false, Studio will start with a blank working area (that is, no documents or other tabs are open). This might be handy if you want to customize the startup behavior. When, for example, you want to open all documents that a given search query finds on startup, you can do that with code like the following:

package com.coremedia.ui.examples.openCheckedOutDocuments {
import com.coremedia.cap.common.session;
import com.coremedia.cap.content.search.SearchParameters;
import com.coremedia.cap.user.User;
import com.coremedia.cms.editor.EditorErrors_properties;
import com.coremedia.cms.editor.sdk.editorContext;
import com.coremedia.cms.editor.sdk.util.MessageBoxUtil;
import com.coremedia.ui.data.Bean;
import com.coremedia.ui.data.PropertyChangeEvent;
import com.coremedia.ui.examples.openCheckedOutDocuments.config.openCheckedOutDocumentsPlugin;

import ext.Component;
import ext.Container;
import ext.Plugin;
import ext.util.StringUtil;

public class OpenCheckedOutDocumentsPlugin implements Plugin{

  private const MAX_OPEN_TABS:int = 10;

  public function OpenCheckedOutDocumentsPlugin(config:openCheckedOutDocumentsPlugin = null) {
  }

  public function init(component:Component):void {
    //get the top level container
    var mainView:Container = component.findParentBy(function(container:Container){
      return !container.ownerCt;
    });

    mainView.addListener('afterrender', openDocuments, null, {
      single: true
    });

  }

  private function openDocuments():void {
    // Perform query to determine documents checked out by me.
    var searchParameters:SearchParameters = createSearchParameters();
    var searchResult:Bean = session.getConnection().getContentRepository().getSearchService().search(searchParameters);
    // When the query result is loaded ...
    searchResult.addPropertyChangeListener(SearchParameters.HITS, function openInTabs(event:PropertyChangeEvent):void {
      // ... open all documents in tabs.
      var searchResult:Array = event.newValue;
      if (searchResult && searchResult.length > 0) {
        editorContext.getContentTabManager().openDocuments(searchResult.slice(0, MAX_OPEN_TABS));
        if (searchResult.length > MAX_OPEN_TABS) {
          MessageBoxUtil.showInfo(EditorErrors_properties.INSTANCE.editorStart_tooManyDocuments_title,
                  EditorErrors_properties.INSTANCE.editorStart_tooManyDocuments_message);
        }
      }
    });
    searchResult.get(SearchParameters.HITS);
  }

  private function createSearchParameters():SearchParameters {
    var searchParameters:SearchParameters = new SearchParameters();
    searchParameters.filterQuery = [ getQueryFilterString()];

    //searchParameters.contentType = ['Document_'];
    searchParameters.orderBy = ['freshness asc'];

    return searchParameters;
  }

  private function getQueryFilterString():String {
    var filterQueries:Array = [];

    // retrieve user URI for parametrized filter expressions:
    var user:User = session.getUser();
    var userUri:String = "<" + user.getUriPath() + ">";

    // filter documents checked out by me
    filterQueries.push("ischeckedout:true");
    filterQueries.push(StringUtil.format("editor:{0}", userUri));

    return filterQueries.join(" AND ");
  }
}
}