Edit online

Configuring a State Listener for Author Mode

The ro.sync.ecss.extensions.api.AuthorExtensionStateListener implementation is notified when the Author mode extension (where the listener is defined) is activated or deactivated in the document type detection process.

import ro.sync.ecss.extensions.api.AuthorAccess;
import ro.sync.ecss.extensions.api.AuthorExtensionStateListener;

public class SDFAuthorExtensionStateListener implements
  AuthorExtensionStateListener {
  private AuthorListener sdfAuthorDocumentListener;
  private AuthorMouseListener sdfMouseListener;
  private AuthorCaretListener sdfCaretListener;
  private OptionListener sdfOptionListener;

When the association rules of the framework (document type) configuration match that of a document open in the Author editing mode, the activation event received by this listener should be used to perform custom initializations and to register listeners such as ro.sync.ecss.extensions.api.AuthorListener, ro.sync.ecss.extensions.api.AuthorMouseListener, or ro.sync.ecss.extensions.api.AuthorCaretListener.

public void activated(AuthorAccess authorAccess) {
  // Get the value of the option.
  String option = authorAccess.getOptionsStorage().getOption(
               "sdf.custom.option.key", "");
  // Use the option for some initializations...
  
  // Add an OptionListener.
  authorAccess.getOptionsStorage().addOptionListener(sdfOptionListener);
  
  // Add author DocumentListeners.
  sdfAuthorDocumentListener = new SDFAuthorListener();
  authorAccess.getDocumentController().addAuthorListener(
               sdfAuthorDocumentListener);

  // Add MouseListener.
  sdfMouseListener = new SDFAuthorMouseListener();
  authorAccess.getEditorAccess().addAuthorMouseListener(sdfMouseListener);

  // Add CaretListener.
  sdfCaretListener = new SDFAuthorCaretListener();
  authorAccess.getEditorAccess().addAuthorCaretListener(sdfCaretListener);

  // Other custom initializations...

}

The authorAccess parameter received by the activated method can be used to gain access to specific Author mode actions and informations related to components such as the editor, document, workspace, tables, or the change tracking manager.

If options specific to the custom developed Author Extension need to be stored or retrieved, a reference to the ro.sync.ecss.extensions.api.OptionsStorage can be obtained by calling the getOptionsStorage method from the authorAccess. The same object can be used to register ro.sync.ecss.extensions.api.OptionListener listeners. An option listener is registered in relation with an option key and will be notified about the value changes of that option.

An AuthorListener can be used if events related to the Author mode document modifications are of interest. The listener can be added to the ro.sync.ecss.extensions.api.AuthorDocumentController. A reference to the document controller is returned by the getDocumentController method from the authorAccess. The document controller can also be used to perform operations involving document modifications.

To provide access to the Author mode component-related functionality and information, the authorAccess has a reference to the ro.sync.ecss.extensions.api.access.AuthorEditorAccess that can be obtained when calling the getEditorAccess method. At this level, AuthorMouseListener and AuthorCaretListener can be added to provide notification of mouse and cursor events that occur in the Author editor mode.

The deactivation event is received when another framework is activated for the same document, the user switches to another editor mode or the editor is closed. The deactivate method is typically used to unregister the listeners previously added on the activate method and to perform other actions. For example, options related to the deactivated Author Extension can be saved at this point.

public void deactivated(AuthorAccess authorAccess) {
  // Store the option.
  authorAccess.getOptionsStorage().setOption(
               "sdf.custom.option.key", optionValue);
  
  // Remove the OptionListener.
  authorAccess.getOptionsStorage().removeOptionListener(sdfOptionListener);
    
  // Remove DocumentListeners.
  authorAccess.getDocumentController().removeAuthorListener(
               sdfAuthorDocumentListener);
    
  // Remove MouseListener.
  authorAccess.getEditorAccess().removeAuthorMouseListener(sdfMouseListener);

  // Remove CaretListener.
  authorAccess.getEditorAccess().removeAuthorCaretListener(sdfCaretListener);
    
  // Other actions...
    
}
Note: The complete source code for framework customization examples can be found in the oxygen-sample-framework module of the Oxygen SDK, available as a Maven archetype on the Oxygen XML Editor Eclipse plugin website.