The documentation for this example class is included here as a reference. The complete documentation for all of the classes can be found in the API Reference.
The source for this sample class is included with the plug-in and it is shipped as a text file that can be loaded into any file viewer. This class does not include any code and it is intended to be used as a template for creating new observers.
Before discussing the structure of this class, it is important to state that this class definition actually performs two distinct functions. It will register itself as an enhancement to an existing event (Data file build). It will also register itself as a contributed tool. This section will discuss the portion of the class that deals with the contributed tool logic.
The getDescription$() method must be modified to set a description for the new class.
The getEventNotification() method may need to be changed to return the setting of the event notification flag. The setting of this flag will determine when this observer is notified that an event has been triggered. It will also add a preference to the "Contributed Extensions / Tools" preference page to allow the user to enable use of the extension.
Normally, for a contributed tool this will be set to _pvxConstants'_ideNone which will disable event notification (and also not add to the preference page). A contributed tool is configured this way since the user will be initiating the action by selection from the list of contributed tools.
This class is a special case in that it actually does double duty and acts as a simple event observer as well as a contributed tool. For this reason, the event notification is set to identify when to notify this class of the triggering of an event.
The actionPerformed() method must be modified to add the logic that will be executed when the event has been triggered. The following section of code taken from the source for this observer shows the code that was added to the template.
if resource<>0 { /* Add logic for this observer */ resPath$=resManager'getPathToSelectedResourceInNavigator$() if resource'getType()<>resource'FOLDER { _TMP$="", \ _TMP=0; open input(hfn,isz=1,err=*next)resPath$; _TMP=lfo; read record (_TMP,ind=0,siz=8,err=*next)_TMP$ if _TMP>0 \ then close (_TMP) if pos(_TMP$="[Pvxkey][Pvxky2]",8)>0 { _obj'data2xml(resPath$) } else { _obj'xml2data(resPath$) } /* Force a refresh of Navigation view (DEPTH_ONE, DEPTH_INFINITE, DEPTH_ZERO) */ resource'refreshLocal(resource'DEPTH_ONE,*-1) } }
This logic checks the file header to determine if the file is a ProvideX keyed file. If the file is a ProvideX keyed file it is converted to XML. Otherwise, an attempt will be made to convert the file from XML to a ProvideX keyed file.
When completed, the resource manager is asked to refresh the folder which will tell Eclipse that a modification has occurred.
The source file can be viewed to see the details of this process and how the external programs were used.