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 boolean DEBUG
          The Constant DEBUG.
static String PLUGIN_ID
          The Constant PLUGIN_ID.
static int SLEEPTIME
          The Constant SLEEPTIME for a sync method spinlock.
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 cancelInitialization()
          Cancel the initialization.
 void checkForSingleEnabledMaster(boolean silent)
          Check for single enabled master.
 void checkForSingleEnabledMaster(boolean silent, DataComponentWrapper dataComponentWrapper)
          Check the current selection (enabled DataComponentWrappers) for a just a single enabled master.
 void clearDataComponentWrapperList()
          Safely clear DataComponentWrapperList and call DataComponent destructors.
 void doSave(IProgressMonitor monitor, Shell parentShellParam)
          Do save method that can be called from outside (e.g., a user interface view).
 void doSaveAs(Shell parentShellParam)
          Do save as method that can be called from outside (e.g., a user interface view).
 String getActiveProjectName()
          Gets the file name (without possible extension) of the currently opened file, if any, or "noname" otherwise.
 int getAimedStepDuration()
          Gets the currently set aimed step duration.
 Boolean getBooleanValueFromProviders(String propertyId)
          Get a new property value from one of the configuration providers.
 IPath getCurrentFile()
          Gets the current file.
 DataComponentWrapper getCurrentMaster()
          Gets the current master.
 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.
 InitializeExecution getInitializeExecution()
          Gets the initialize execution.
 Integer getIntegerValueFromProviders(String propertyId)
          Get a new property value from one of the configuration providers.
 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.
 boolean isDirty()
          Checks whether dirty flag is true.
 boolean isInitializingExecution()
          Checks whether the execution is currently initializing.
 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 openFile(IPath executionFile, String pluginID, boolean readOnly)
          Opens an Execution File (*.execution) and tries to update the dataComponentWrapperList according to this file.
 int promptToSaveOnClose(Shell parentShellParam)
          Prompt to save on close if the current file was modified (is dirty).
 void setAimedStepDuration(int aimedStepDurationi)
          Sets the aimed step duration.
 void setCurrentFile(IPath currentFileParam)
          Sets the current file.
 void setDirty(boolean isDirtyParam)
          Sets the dirty flag.
 void setExecution(Execution executionParam)
          Sets the execution.
 void setShell(Shell parentShellParam)
          Sets the parent shell that KIEM shoudl use to display user dialogs.
 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 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

DEBUG

public static final boolean DEBUG
The Constant DEBUG.


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

SLEEPTIME

public static final int SLEEPTIME
The Constant SLEEPTIME for a sync method spinlock.

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

setShell

public void setShell(Shell parentShellParam)
Sets the parent shell that KIEM shoudl use to display user dialogs.

Parameters:
parentShellParam - the new shell

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(IPath executionFile,
                     String pluginID,
                     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
pluginID - the id of the plugin where the file is located
readOnly - the readonly flag indicates that the file is locked for writing
Throws:
IOException - if the file was not found

openFile

public void openFile(IEditorInput editorInput)
              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 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
Throws:
IOException

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

getActiveProjectName

public String getActiveProjectName()
Gets the file name (without possible extension) of the currently opened file, if any, or "noname" otherwise.

Returns:
the active project name

setCurrentFile

public void setCurrentFile(IPath currentFileParam)
Sets the current file.

Parameters:
currentFileParam - the new currently opened file

promptToSaveOnClose

public int promptToSaveOnClose(Shell parentShellParam)
Prompt to save on close if the current file was modified (is dirty).

Parameters:
parentShellParam - the parent shell
Returns:
an int value indicating the users decision

getCurrentFile

public IPath getCurrentFile()
Gets the current file.

Returns:
the current file

getCurrentMaster

public DataComponentWrapper getCurrentMaster()
Gets the current master.

Returns:
the current file

checkForSingleEnabledMaster

public void checkForSingleEnabledMaster(boolean silent)
Check for single enabled master. This is just a wrapper for the method checkForSingleEnabledMaster(boolean, DataComponentWrapper).

Parameters:
silent - if true, the warning dialog will be suppressed

checkForSingleEnabledMaster

public void checkForSingleEnabledMaster(boolean silent,
                                        DataComponentWrapper dataComponentWrapper)
Check the current selection (enabled DataComponentWrappers) for a just a single enabled master. If any second enabled master is found it will be disabled and the user is notified with a warning dialog - depending on the silent-flag.

Parameters:
silent - if true, the warning dialog will be suppressed
dataComponentWrapper - the DataComponentWrapper that is allowed to be the master or null

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.


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

doSave

public void doSave(IProgressMonitor monitor,
                   Shell parentShellParam)
Do save method that can be called from outside (e.g., a user interface view).

Parameters:
monitor - the monitor
parentShellParam - the parent shell

doSaveAs

public void doSaveAs(Shell parentShellParam)
Do save as method that can be called from outside (e.g., a user interface view).

Parameters:
parentShellParam - the parent shell to open the save dialog in

isDirty

public boolean isDirty()
Checks whether dirty flag is true. Dirty means that the currentFile has been modified since the last save/load action.

Returns:
true, if is dirty

setDirty

public void setDirty(boolean isDirtyParam)
Sets the dirty flag. Dirty means that the currentFile has been modified since the last save/load action.

Parameters:
isDirtyParam - the new dirty

cancelInitialization

public void cancelInitialization()
Cancel the initialization.


isInitializingExecution

public boolean isInitializingExecution()
Checks whether the execution is currently initializing.

Returns:
true, if is initializing execution

getInitializeExecution

public InitializeExecution getInitializeExecution()
Gets the initialize execution.

Returns:
the initialize execution

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