Implementing an Author Extension State Listener

The ro.sync.ecss.extensions.api.AuthorExtensionStateListener implementation is notified when the Author extension where the listener is defined is activated or deactivated in the Document Type detection process.

Note: The Javadoc documentation of the Author API used in the example files is available on the Oxygen XML Author website. Also it can be downloaded as a zip archive from the website.
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;

The activation event received by this listener when the rules of the Document Type Association match a document opened in the Author editor mode, should be used to perform custom initializations and to register listeners like 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 option listener.
	  authorAccess.getOptionsStorage().addOptionListener(sdfOptionListener);
	  
	  // Add author document listeners.
	  sdfAuthorDocumentListener = new SDFAuthorListener();
	  authorAccess.getDocumentController().addAuthorListener(
               sdfAuthorDocumentListener);
	
	  // Add mouse listener.
	  sdfMouseListener = new SDFAuthorMouseListener();
	  authorAccess.getEditorAccess().addAuthorMouseListener(sdfMouseListener);
	
	  // Add caret listener.
	  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 Author specific actions and informations related to components like 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 author access. 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 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 author access. The document controller can also be used to perform operations involving document modifications.

To provide access to Author editor component related functionality and information, the author access 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 which will be notified about mouse and caret events occurring 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 option listener.
	  authorAccess.getOptionsStorage().removeOptionListener(sdfOptionListener);
    
	  // Remove document listeners.
	  authorAccess.getDocumentController().removeAuthorListener(
               sdfAuthorDocumentListener);
    
	  // Remove mouse listener.
	  authorAccess.getEditorAccess().removeAuthorMouseListener(sdfMouseListener);

	  // Remove caret listener.
	  authorAccess.getEditorAccess().removeAuthorCaretListener(sdfCaretListener);
    
	  // Other actions...
    
	}