close

Filter

loading table of contents...

Studio Developer Manual / Version 2101

Table Of Contents

7.13.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.blueprint.studio {

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 ext.Component;
import ext.Plugin;
import ext.StringUtil;
import ext.container.Container;

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 = 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 ");
  }
}
}

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.