de.cau.cs.kieler.sim.kiem
Class KiemPlugin

java.lang.Object
  extended by org.eclipse.core.runtime.Plugin
      extended by org.eclipse.ui.plugin.AbstractUIPlugin
          extended by de.cau.cs.kieler.sim.kiem.KiemPlugin
All Implemented Interfaces:
org.osgi.framework.BundleActivator

public class KiemPlugin
extends AbstractUIPlugin

This activator class controls the life cycle of the KiemPlugin. It also provides the access to the one and only instance of this class and hence a way to access the execution thread. For the execution thread it allows to access the KiemView for updating or refreshing the table or the step information text field.

Rating yellow
(2009-01-15)

Field Summary
static int AIMED_STEP_DURATION_DEFAULT
          The Constant AIMED_STEP_DURATION_DEFAULT.
static String AIMED_STEP_DURATION_ID
          The identifier for the aimed step duration.
static int AIMED_STEP_DURATION_MAX
          The Constant AIMED_STEP_DURATION_MAX.
static int AIMED_STEP_DURATION_MIN
          The Constant AIMED_STEP_DURATION_MIN.
static String PLUGIN_ID
          The Constant PLUGIN_ID.
static String TIMEOUT_ID
          The identifier for the timeout.
 
Fields inherited from class org.eclipse.core.runtime.Plugin
PLUGIN_PREFERENCE_SCOPE, PREFERENCES_DEFAULT_OVERRIDE_BASE_NAME, PREFERENCES_DEFAULT_OVERRIDE_FILE_NAME
 
Constructor Summary
KiemPlugin()
          The constructor if the KIEM plug-in.
 
Method Summary
 DataComponentWrapper addTodataComponentWrapperList(AbstractDataComponent component)
          Add a DataComponent instance to the dataComponentWrapperList.
 void clearDataComponentWrapperList()
          Safely clear DataComponentWrapperList and call DataComponent destructors.
 int getAimedStepDuration()
          Gets the currently set aimed step duration.
 Boolean getBooleanValueFromProviders(String propertyId)
          Get a new property value from one of the configuration providers.
 List<DataComponentWrapper> getDataComponentWrapperList()
          Returns the current DataComponentWrapper-List that is held by the KIEM plug-in directly.
static KiemPlugin getDefault()
          Returns the shared instance of the KIEM plug-in.
 List<DataComponentWrapper> getDefaultComponentWrapperList()
          Returns the default ComponentWrapperList.
 EventManager getEventManager()
          Gets the single EventManager that handles notification of DataComponents when KiemEvents occur.
 Execution getExecution()
          Gets the execution.
 Integer getIntegerValueFromProviders(String propertyId)
          Get a new property value from one of the configuration providers.
 KiemView getKIEMViewInstance()
          Gets the KiemView instance.
 String getPropertyValueFromProviders(String propertyId)
          Get a new property value from one of the configuration providers.
 List<AbstractDataComponent> getRegisteredDataComponentList()
          This initializes the DataComponentList with all registered and loaded plug-ins that extend the following two extension points:
- JSONObjectDataComponent
- JSONStringDataComponent
If a DataComponent is registered but cannot be instantiated because of an error this will result in a warning only so that all other fully functional DataComponents are still loaded.
static void handleComponentError(AbstractDataComponent dataComponent, Exception exception)
          This method handles errors or warnings within the execution of DataComponents.
 boolean initExecution()
          Initializes the Execution.
 void notifyConfigurationProviders(String propertyId, String value)
          Notify all configuration providers that a property in the currently loaded configuration has changed.
 void openFile(IEditorInput editorInput)
          Opens an Execution File (*.execution) and tries to update the dataComponentWrapperList according to this file.
 void openFile(IPath executionFile, boolean readOnly)
          Opens an Execution File (*.execution) and tries to update the dataComponentWrapperList according to this file.
 void setAimedStepDuration(int aimedStepDurationi)
          Sets the aimed step duration.
 void setExecution(Execution executionParam)
          Sets the execution.
 void setKIEMViewInstance(KiemView kIEMViewInstanceParam)
          Sets the KIEM view instance.
 void setViewFocus()
          Sets the view focus to the KiemView instance.
 void showError(String textMessage, String pluginID, Exception exception, boolean silent)
          Shows an error dialog using the StatusAdapter.
 void showWarning(String textMessage, String pluginID, Exception exception, boolean silent)
          Shows a warning dialog using the StatusAdapter.
 void start(org.osgi.framework.BundleContext context)
           
 void stop(org.osgi.framework.BundleContext context)
           
 void updateEventManager()
          Update event manager's DataComponentWrapper list.
 void updateStepsAsync()
          Updates the steps in the Step text field asynchronously.
 void updateViewAsync()
          Updates the view of the KiemView table asynchronously.
 
Methods inherited from class org.eclipse.ui.plugin.AbstractUIPlugin
createImageRegistry, getDialogSettings, getImageRegistry, getPreferenceStore, getWorkbench, imageDescriptorFromPlugin, initializeDefaultPluginPreferences, initializeDefaultPreferences, initializeImageRegistry, loadDialogSettings, loadPreferenceStore, refreshPluginActions, saveDialogSettings, savePreferenceStore, shutdown, startup
 
Methods inherited from class org.eclipse.core.runtime.Plugin
find, find, getBundle, getDescriptor, getLog, getPluginPreferences, getStateLocation, internalInitializeDefaultPluginPreferences, isDebugging, openStream, openStream, savePluginPreferences, setDebugging, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

AIMED_STEP_DURATION_DEFAULT

public static final int AIMED_STEP_DURATION_DEFAULT
The Constant AIMED_STEP_DURATION_DEFAULT. Default value of the AimedStepDuration text field in ms.

See Also:
Constant Field Values

AIMED_STEP_DURATION_MIN

public static final int AIMED_STEP_DURATION_MIN
The Constant AIMED_STEP_DURATION_MIN. Minimum value of the AimedStepDuration text field in ms.

See Also:
Constant Field Values

AIMED_STEP_DURATION_MAX

public static final int AIMED_STEP_DURATION_MAX
The Constant AIMED_STEP_DURATION_MAX. Maximum value of the AimedStepDuration text field in ms.

See Also:
Constant Field Values

PLUGIN_ID

public static final String PLUGIN_ID
The Constant PLUGIN_ID.

See Also:
Constant Field Values

AIMED_STEP_DURATION_ID

public static final String AIMED_STEP_DURATION_ID
The identifier for the aimed step duration.

See Also:
Constant Field Values

TIMEOUT_ID

public static final String TIMEOUT_ID
The identifier for the timeout.

See Also:
Constant Field Values
Constructor Detail

KiemPlugin

public KiemPlugin()
The constructor if the KIEM plug-in. A default DataComponentWrapperList is created. It contains all DataComponents in the default order ( getDefaultComponentWrapperList() ). The execution is null by default. The KIEMViewInstance is set, in the constructor of the.

See Also:
KiemView
Method Detail

updateEventManager

public void updateEventManager()
Update event manager's DataComponentWrapper list.


getExecution

public Execution getExecution()
Gets the execution. The use of this method is only recommended for remote controlling KIEM.

Returns:
the execution

setExecution

public void setExecution(Execution executionParam)
Sets the execution. The use of this method is only recommended for remote controlling KIEM.

Parameters:
executionParam - the execution param

start

public void start(org.osgi.framework.BundleContext context)
           throws Exception
Specified by:
start in interface org.osgi.framework.BundleActivator
Overrides:
start in class AbstractUIPlugin
Throws:
Exception

stop

public void stop(org.osgi.framework.BundleContext context)
          throws Exception
Specified by:
stop in interface org.osgi.framework.BundleActivator
Overrides:
stop in class AbstractUIPlugin
Throws:
Exception

getDefault

public static KiemPlugin getDefault()
Returns the shared instance of the KIEM plug-in. This is mainly used by the execution thread to access the view of the KIELER Execution Manager or the other way round.

Returns:
the one and only shared instance of this KIEM plug-in

openFile

public void openFile(IEditorInput editorInput)
Opens an Execution File (*.execution) and tries to update the dataComponentWrapperList according to this file. If the components or properties loaded do not exist in the environment (e.g., the according plug-ins where not loaded) then an error message will bring this to the user's attention.

This method is called from the KiemProxyEditor that acts as a proxy for passing the editoInput from the Workbench to the KiemView.

Parameters:
editorInput - the file editor input to open

openFile

public void openFile(IPath executionFile,
                     boolean readOnly)
              throws IOException
Opens an Execution File (*.execution) and tries to update the dataComponentWrapperList according to this file. If the components or properties loaded do not exist in the environment (e.g., the according plug-ins where not loaded) then an error message will bring this to the user's attention.

This method can be called from another plug-in and is part of the KIEM API.

Parameters:
executionFile - the execution file to open
readOnly - the readonly flag indicates that the file is locked for writing
Throws:
IOException - if the file was not found

notifyConfigurationProviders

public void notifyConfigurationProviders(String propertyId,
                                         String value)
Notify all configuration providers that a property in the currently loaded configuration has changed. author: soh

Parameters:
propertyId - the id of the property.
value - the value of the property.

getPropertyValueFromProviders

public String getPropertyValueFromProviders(String propertyId)
Get a new property value from one of the configuration providers. Will get the first value of any provider that doesn't throw an exception when the request is made. author: soh

Parameters:
propertyId - the id of the property to look for
Returns:
the new value of the property

getIntegerValueFromProviders

public Integer getIntegerValueFromProviders(String propertyId)
Get a new property value from one of the configuration providers. Will get the first value of any provider that doesn't throw an exception when the request is made. author: soh

Parameters:
propertyId - the id of the property to look for
Returns:
the new value of the property

getBooleanValueFromProviders

public Boolean getBooleanValueFromProviders(String propertyId)
Get a new property value from one of the configuration providers. Will get the first value of any provider that doesn't throw an exception when the request is made. author: soh

Parameters:
propertyId - the id of the property to look for
Returns:
the new value of the property

updateViewAsync

public void updateViewAsync()
Updates the view of the KiemView table asynchronously. This method is used to update the KiemView table from within the execution thread.


updateStepsAsync

public void updateStepsAsync()
Updates the steps in the Step text field asynchronously. This method is used to update the KiemView steps from within the execution thread.


setViewFocus

public void setViewFocus()
Sets the view focus to the KiemView instance. This method is called by the AimedStepDuration text field if the used wants to leave its focus by pressing [ENTER].


getKIEMViewInstance

public KiemView getKIEMViewInstance()
Gets the KiemView instance.

Returns:
the KiemView instance

setKIEMViewInstance

public void setKIEMViewInstance(KiemView kIEMViewInstanceParam)
Sets the KIEM view instance. This method is called by the constructor of the Class KiemView so that this plug-in (or the execution thread) is able to trigger updates on the view.

Parameters:
kIEMViewInstanceParam - the one and only KiemView instance

getAimedStepDuration

public int getAimedStepDuration()
Gets the currently set aimed step duration. author: soh

Returns:
the aimed step duration

setAimedStepDuration

public void setAimedStepDuration(int aimedStepDurationi)
Sets the aimed step duration. This method sets the aimed step duration and also passes-on the value to the execution thread if that exists. author: soh

Parameters:
aimedStepDurationi - the new aimed step duration

getRegisteredDataComponentList

public List<AbstractDataComponent> getRegisteredDataComponentList()
This initializes the DataComponentList with all registered and loaded plug-ins that extend the following two extension points:
- JSONObjectDataComponent
- JSONStringDataComponent
If a DataComponent is registered but cannot be instantiated because of an error this will result in a warning only so that all other fully functional DataComponents are still loaded. This method remembers its list thru the whole life-cycle of this plug-in and always returns the same list. All DataComponents that cannot be instantiated due to errors will not occur in the list.

Returns:
the DataComponentList

initExecution

public boolean initExecution()
Initializes the Execution. This is one of the heart-methods of this plug-in. It does the following tasks:

(1) Check if there are any (enabled) DataProducers or DataConsumers.
(2) Check if all DataComponent's properties are set correctly
(3) Grab all interface variables provided by the DataComponents.
(4) Distribute the union of all the variables to all DataComponents.
(5) Initialize the DataComponents
(6) Create an run the Execution thread

This method returns true if the execution is successfully initialized or if the execution thread already exists, hence the execution is not null.

Returns:
true, if successful

addTodataComponentWrapperList

public DataComponentWrapper addTodataComponentWrapperList(AbstractDataComponent component)
Add a DataComponent instance to the dataComponentWrapperList. This will clone the DataComponent and add an executable extension. It then creates a new DataComponentWrapper instance that encapsulates the just created DataComponent (and offers additional information and methods). The latter will be added then to the DataComponentList.

Parameters:
component - the component
Returns:
the added dataComponentWrapper component

getDefaultComponentWrapperList

public List<DataComponentWrapper> getDefaultComponentWrapperList()
Returns the default ComponentWrapperList. This will contain all registered DataComponents that extend one the following extension points:
- JSONObjectDataComponent
- JSONStringDataComponent
They will be ordered in the "natural" way, meaning that the (pure) data producers are scheduled before the data observer & producers which are themselves scheduled before the (pure) data observers. Although DataComponents may be multiple instantiable, by default, there will be exactly one instance per DataComponent in the list.

Returns:
the default DataComponentWrapperList

clearDataComponentWrapperList

public void clearDataComponentWrapperList()
Safely clear DataComponentWrapperList and call DataComponent destructors.


getDataComponentWrapperList

public List<DataComponentWrapper> getDataComponentWrapperList()
Returns the current DataComponentWrapper-List that is held by the KIEM plug-in directly. Any modification on this list is persistent in this one and only plug-in instance. The DataComponentWrapperList holds a list of DataComponents, selected from all registered (and loaded) plug-ins that extend the following extension points:
- JSONObjectDataComponent
- JSONStringDataComponent

Returns:
the DataComponentWrapperList

handleComponentError

public static void handleComponentError(AbstractDataComponent dataComponent,
                                        Exception exception)
This method handles errors or warnings within the execution of DataComponents. It specifically handles the following two types or errors:
- KiemExecutionException
- KiemExecutionException
If the mustStop flag is set, then the execution is immediately stopped. Note that all threads will be advised to stop in the Execution.errorTerminate() method. But there is no guarantee that they really stop. The links to these threads will be cut down, so that there is the possibility of zombie threads.

Parameters:
dataComponent - the DataComponent that caused the error or warning
exception - the Exception if any, or null

getEventManager

public EventManager getEventManager()
Gets the single EventManager that handles notification of DataComponents when KiemEvents occur.

Returns:
the event manager

showWarning

public void showWarning(String textMessage,
                        String pluginID,
                        Exception exception,
                        boolean silent)
Shows a warning dialog using the StatusAdapter. This dialog will *NOT* be modal, so that the user is notified but the current work is not interrupted.
Additionally the information will be logged in the error log so that the user has the opportunity to e.g., access the error stack trace. The plug-in id is required, textMessage and exception are optional.

Parameters:
textMessage - the text message
pluginID - the plug-in id
exception - the exception
silent - the silent tag indicates that only logging occurs, no message dialog is displayed

showError

public void showError(String textMessage,
                      String pluginID,
                      Exception exception,
                      boolean silent)
Shows an error dialog using the StatusAdapter. This dialog will be modal, so that the user has to click OK to end it. Additionally the information will be logged in the error log so that the user has the opportunity to e.g., access the error stack trace. The plug-in id is required, textMessage and exception are optional.

Parameters:
textMessage - the optional text message
pluginID - the plug-in id
exception - the exception if any, null otherwise
silent - the silent tag indicates that only logging occurs, no message dialog is displayed