edu.cmu.sei.osate.ui.actions
Class AbstractAaxlAction

java.lang.Object
  extended by edu.cmu.sei.osate.ui.actions.AbstractAaxlAction
All Implemented Interfaces:
org.eclipse.ui.IActionDelegate, org.eclipse.ui.IObjectActionDelegate, org.eclipse.ui.IWorkbenchWindowActionDelegate
Direct Known Subclasses:
AaxlReadOnlyAction, AaxlReadOnlyActionAsJob

public abstract class AbstractAaxlAction
extends java.lang.Object
implements org.eclipse.ui.IWorkbenchWindowActionDelegate, org.eclipse.ui.IObjectActionDelegate

Abstract superclass for AaxlReadOnlyAction and AaxlReadOnlyActionAsJob. Contains all the utility methods lookupPropertyDefinition(String, String), lookupPropertyType(String, String), etc. Abstracts the Eclipse job creation process. Calls createJob(AObject) to get the job to run. It is expected that the job invoke actionBody(IProgressMonitor, AObject). This method initializes the OSATE action by creating the error reporter manager, calling initPropertyReferences(), etc., and finally invokes doAaxlAction(IProgressMonitor, AObject) to run the specific analysis action body.

Users should not extend this class directly, but should extend AaxlReadOnlyActionAsJob.

Author:
aarong

Constructor Summary
AbstractAaxlAction()
          The constructor.
 
Method Summary
protected  void actionBody(org.eclipse.core.runtime.IProgressMonitor monitor, AObject root)
           
protected abstract  org.eclipse.core.runtime.jobs.Job createJob(AObject root)
           
 void dispose()
          We can use this method to dispose of any system resources we previously allocated.
protected abstract  void doAaxlAction(org.eclipse.core.runtime.IProgressMonitor monitor, AObject root)
          This method will be defined by the ultimate subclass, and implements the true body of the action.
protected  void error(AObject obj, java.lang.String msg)
          Report error message on object as result of action.
protected  AnalysisErrorReporterFactory getAnalysisErrorReporterFactory()
          Get the factory to be used to generate error reporters for this action.
protected  org.osgi.framework.Bundle getBundle()
          Get the bundle ("plug-in") to attribute internal errors to.
protected  AnalysisErrorReporterFactory getDefaultAnalysisErrorReporterFactory()
          Generate an error reporter factory that creates the default error reporters used by the analysis.
protected  AnalysisErrorReporterManager getErrorManager()
          Get the error mananger used by the action.
protected  java.lang.String getMarkerType()
          Get the type of the markers that the action might create.
protected  java.util.List getPropertyLookupErrors()
          Get the property lookup errors.
protected  org.eclipse.swt.widgets.Shell getShell()
           
protected  org.eclipse.ui.IWorkbenchWindow getWindow()
           
protected  boolean hasPropertyLookupErrors()
          Find out if there were any errors initializing the property references.
protected  void info(AObject obj, java.lang.String msg)
          Report an informative message on object as result of action.
 void init(org.eclipse.ui.IWorkbenchWindow window)
          We will cache window object in order to be able to provide parent shell for the message dialog.
protected  void initPropertyReferences()
          Plug-ins override this to initialize references to property definitions and constants that they use.
protected  void internalError(java.lang.Exception e)
          Report an internal error in the operation of the action.
protected  void internalError(java.lang.String msg)
          Report an internal error in the operation of the action.
protected  EnumLiteral lookupEnumerationLiteral(java.lang.String enumType, java.lang.String literalName)
          Lookup a particular enumeration literal from a predeclared property type, updating the error list if it or its declaring enumeration type is not found.
protected  EnumLiteral lookupEnumerationLiteral(java.lang.String ps, java.lang.String enumType, java.lang.String literalName)
          Lookup a particular enumeration literal, updating the error list if it or its declaring enumeration type is not found.
protected  PropertyConstant lookupOptionalPropertyConstant(java.lang.String ps, java.lang.String name)
          Lookup a particular optional property constant definition.
protected  PropertyDefinition lookupOptionalPropertyDefinition(java.lang.String ps, java.lang.String name)
          Lookup a particular optional property definition.
protected  PropertyType lookupOptionalPropertyType(java.lang.String ps, java.lang.String name)
          Lookup a particular optional property type definition.
protected  PropertyConstant lookupPropertyConstant(java.lang.String name)
          Lookup a particular property constant, updating the error list if it is not found.
protected  PropertyConstant lookupPropertyConstant(java.lang.String ps, java.lang.String name)
          Lookup a particular predeclared property constant, updating the error list if it is not found.
protected  PropertyDefinition lookupPropertyDefinition(java.lang.String name)
          Lookup a particular predeclared property definition, updating the error list if it is not found.
protected  PropertyDefinition lookupPropertyDefinition(java.lang.String ps, java.lang.String name)
          Lookup a particular property definition, updating the error list if it is not found.
protected  PropertyType lookupPropertyType(java.lang.String name)
          Lookup a particular predeclared property type, updating the error list if it is not found.
protected  PropertyType lookupPropertyType(java.lang.String ps, java.lang.String name)
          Lookup a particular property type, updating the error list if it is not found.
protected  UnitLiteral lookupUnitLiteral(java.lang.String unitType, java.lang.String literalName)
          Lookup a particular unit literal from a predeclared property type, updating the error list if it or its declaring unit type is not found.
protected  UnitLiteral lookupUnitLiteral(java.lang.String ps, java.lang.String unitType, java.lang.String literalName)
          Lookup a particular unit literal, updating the error list if it or its declaring unit type is not found.
protected  boolean reportPropertyLookupErrors()
          Check if there were property lookup errors and put up an error dialog box if there were.
 void run(org.eclipse.jface.action.IAction action)
          The action has been activated.
 void selectionChanged(org.eclipse.jface.action.IAction action, org.eclipse.jface.viewers.ISelection selection)
          Selection in the workbench has been changed.
 void setActivePart(org.eclipse.jface.action.IAction action, org.eclipse.ui.IWorkbenchPart targetPart)
           
protected  boolean suppressErrorMessages()
          Override this to return true if the default error reporting mechanism should not be used.
protected  void warning(AObject obj, java.lang.String msg)
          Report warning message on object as result of action.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractAaxlAction

public AbstractAaxlAction()
The constructor.

Method Detail

setActivePart

public void setActivePart(org.eclipse.jface.action.IAction action,
                          org.eclipse.ui.IWorkbenchPart targetPart)
Specified by:
setActivePart in interface org.eclipse.ui.IObjectActionDelegate
See Also:
IObjectActionDelegate.setActivePart(IAction, IWorkbenchPart)

run

public final void run(org.eclipse.jface.action.IAction action)
The action has been activated. The argument of the method represents the 'real' action sitting in the workbench UI. Indirectly invokes the body of the action, doAaxlAction(IProgressMonitor, AObject), by setting up a UIJob that invokes (default visibility method) processAaxlAction.

Specified by:
run in interface org.eclipse.ui.IActionDelegate

actionBody

protected final void actionBody(org.eclipse.core.runtime.IProgressMonitor monitor,
                                AObject root)

createJob

protected abstract org.eclipse.core.runtime.jobs.Job createJob(AObject root)

initPropertyReferences

protected void initPropertyReferences()
Plug-ins override this to initialize references to property definitions and constants that they use. The default implementation does nothing


lookupPropertyDefinition

protected final PropertyDefinition lookupPropertyDefinition(java.lang.String ps,
                                                            java.lang.String name)
Lookup a particular property definition, updating the error list if it is not found.

Returns:
The property defintion, or null if it is not found.

lookupOptionalPropertyDefinition

protected final PropertyDefinition lookupOptionalPropertyDefinition(java.lang.String ps,
                                                                    java.lang.String name)
Lookup a particular optional property definition. Does not update the error list if the definition is not found. It is assumed the plug-in is written in such a way that it works correctly even when the definition is absent.

Returns:
The property definition or null if it is not found.

lookupPropertyDefinition

protected final PropertyDefinition lookupPropertyDefinition(java.lang.String name)
Lookup a particular predeclared property definition, updating the error list if it is not found.

Returns:
The property defintion, or null if it is not found.

lookupPropertyType

protected final PropertyType lookupPropertyType(java.lang.String ps,
                                                java.lang.String name)
Lookup a particular property type, updating the error list if it is not found.

Returns:
The property type, or null if it is not found.

lookupUnitLiteral

protected final UnitLiteral lookupUnitLiteral(java.lang.String ps,
                                              java.lang.String unitType,
                                              java.lang.String literalName)
Lookup a particular unit literal, updating the error list if it or its declaring unit type is not found.

Returns:
The unit literal, or null if it or it's declaring unit type is not found.

lookupEnumerationLiteral

protected final EnumLiteral lookupEnumerationLiteral(java.lang.String ps,
                                                     java.lang.String enumType,
                                                     java.lang.String literalName)
Lookup a particular enumeration literal, updating the error list if it or its declaring enumeration type is not found.

Returns:
The enumeration literal, or null if it or it's declaring enumeration type is not found.

lookupOptionalPropertyType

protected final PropertyType lookupOptionalPropertyType(java.lang.String ps,
                                                        java.lang.String name)
Lookup a particular optional property type definition. Does not update the error list if the type is not found. It is assumed the plug-in is written in such a way that it works correctly even when the type is absent.

Returns:
The property type or null if it is not found.

lookupPropertyType

protected final PropertyType lookupPropertyType(java.lang.String name)
Lookup a particular predeclared property type, updating the error list if it is not found.

Returns:
The property type or null if it is not found.

lookupUnitLiteral

protected final UnitLiteral lookupUnitLiteral(java.lang.String unitType,
                                              java.lang.String literalName)
Lookup a particular unit literal from a predeclared property type, updating the error list if it or its declaring unit type is not found.

Returns:
The unit literal, or null if it or it's declaring unit type is not found.

lookupEnumerationLiteral

protected final EnumLiteral lookupEnumerationLiteral(java.lang.String enumType,
                                                     java.lang.String literalName)
Lookup a particular enumeration literal from a predeclared property type, updating the error list if it or its declaring enumeration type is not found.

Returns:
The enumeration literal, or null if it or it's declaring enumeration type is not found.

lookupPropertyConstant

protected final PropertyConstant lookupPropertyConstant(java.lang.String name)
Lookup a particular property constant, updating the error list if it is not found.

Returns:
The property constant or null if it is not found.

lookupPropertyConstant

protected final PropertyConstant lookupPropertyConstant(java.lang.String ps,
                                                        java.lang.String name)
Lookup a particular predeclared property constant, updating the error list if it is not found.

Returns:
The property constant or null if it is not found.

lookupOptionalPropertyConstant

protected final PropertyConstant lookupOptionalPropertyConstant(java.lang.String ps,
                                                                java.lang.String name)
Lookup a particular optional property constant definition. Does not update the error list if the type is not found. It is assumed the plug-in is written in such a way that it works correctly even when the constant is absent.

Returns:
The property constant or null if it is not found.

hasPropertyLookupErrors

protected final boolean hasPropertyLookupErrors()
Find out if there were any errors initializing the property references.


getPropertyLookupErrors

protected final java.util.List getPropertyLookupErrors()
Get the property lookup errors.

Returns:
A List of strings, where each string names the property refernece or property constant that could not be found. Meant to be used to construct a larger error message.

suppressErrorMessages

protected boolean suppressErrorMessages()
Override this to return true if the default error reporting mechanism should not be used. By default the action will report those property references that could not be found and avoids invoking doAaxlAction(IProgressMonitor, AObject). If this method returns true then the error reporting will be suppressed and doAaxlAction(IProgressMonitor, AObject)will be invoked. The intent here, however, is that the implementation of doAaxlAction(IProgressMonitor, AObject)will check whether there were errors and report them in its own way. This is useful if the plug-in has a more sophisticated initialziation process and could have additional start up errors that it needs to report. The lookup errors are available to the body of the action via getPropertyLookupErrors().

Returns:
The default implementation returns false.

reportPropertyLookupErrors

protected final boolean reportPropertyLookupErrors()
Check if there were property lookup errors and put up an error dialog box if there were.

Returns:
Whether there any lookup errors to be reported.

doAaxlAction

protected abstract void doAaxlAction(org.eclipse.core.runtime.IProgressMonitor monitor,
                                     AObject root)
This method will be defined by the ultimate subclass, and implements the true body of the action. It is invoked along a call chain from the run(IAction) method, which first makes sure the OSATE environment is loaded and other house cleaning things.

It is a good idea, although not required, for the action to check to see if the action has been cancelled. If cancellation is detected, this method should throw the unchecked exception OperationCanceledException.

Parameters:
monitor - The progress monitor to use to provide feedback about the action and to check for cancellation.
root - The currently selected AObject in the workspace.
Throws:
org.eclipse.core.runtime.OperationCanceledException - Thrown if the method detected that the action has been cancelled.

selectionChanged

public final void selectionChanged(org.eclipse.jface.action.IAction action,
                                   org.eclipse.jface.viewers.ISelection selection)
Selection in the workbench has been changed. We can change the state of the 'real' action here if we want, but this can only happen after the delegate has been created.

Specified by:
selectionChanged in interface org.eclipse.ui.IActionDelegate

dispose

public void dispose()
We can use this method to dispose of any system resources we previously allocated.

Specified by:
dispose in interface org.eclipse.ui.IWorkbenchWindowActionDelegate
See Also:
IWorkbenchWindowActionDelegate.dispose()

init

public void init(org.eclipse.ui.IWorkbenchWindow window)
We will cache window object in order to be able to provide parent shell for the message dialog.

Specified by:
init in interface org.eclipse.ui.IWorkbenchWindowActionDelegate
See Also:
IWorkbenchWindowActionDelegate.init(org.eclipse.ui.IWorkbenchWindow)

getWindow

protected final org.eclipse.ui.IWorkbenchWindow getWindow()

getShell

protected final org.eclipse.swt.widgets.Shell getShell()

getMarkerType

protected java.lang.String getMarkerType()
Get the type of the markers that the action might create. This is used to create a new MarkerAnalysisErrorReporterfor that marker type for the resource being analyzed. Any existing markers of that type on the resource will be removed.

Subclasses should override this method to change the marker type used by the action. The initial implementation returns the generic "AadlObjectMarker" marker type, and will therefore cause all existing OSATE markers to be removed from the resource.

Returns:
The marker type to use for the action's results. This initial implementation specifically returns "AadlObjectMarker".
See Also:
getDefaultAnalysisErrorReporterFactory(), getAnalysisErrorReporterFactory()

getDefaultAnalysisErrorReporterFactory

protected final AnalysisErrorReporterFactory getDefaultAnalysisErrorReporterFactory()
Generate an error reporter factory that creates the default error reporters used by the analysis. The default error reporter is a MarkerAnalysisErrorReporter that generates markers with the marker type determined by getMarkerType().

This method exists so that subclasses can override getAnalysisErrorReporterFactory() to create factories that return instances of ChainedAnalysisErrorReporter where one of the delegate error reporters is the default error reporter.

See Also:
getMarkerType(), getAnalysisErrorReporterFactory()

getAnalysisErrorReporterFactory

protected AnalysisErrorReporterFactory getAnalysisErrorReporterFactory()
Get the factory to be used to generate error reporters for this action.

See Also:
getMarkerType(), getDefaultAnalysisErrorReporterFactory()

getBundle

protected org.osgi.framework.Bundle getBundle()
Get the bundle ("plug-in") to attribute internal errors to.

Subclasses should override this method to return the bundle in which they are located. The default value is to return the bundle associated with edu.cmu.sei.osate.ui.

Returns:
The bundle to blame internal errors on.

getErrorManager

protected final AnalysisErrorReporterManager getErrorManager()
Get the error mananger used by the action.

Returns:
Error Reporter

error

protected final void error(AObject obj,
                           java.lang.String msg)
Report error message on object as result of action.

Parameters:
obj - Aobject that has been processed by the action
msg - The error message

warning

protected final void warning(AObject obj,
                             java.lang.String msg)
Report warning message on object as result of action.

Parameters:
obj - Aobject that has been processed by the action
msg - The warning message

info

protected final void info(AObject obj,
                          java.lang.String msg)
Report an informative message on object as result of action.

Parameters:
obj - Aobject that has been processed by the action
msg - The informative message

internalError

protected final void internalError(java.lang.String msg)
Report an internal error in the operation of the action.


internalError

protected final void internalError(java.lang.Exception e)
Report an internal error in the operation of the action.