de.cau.cs.kieler.sim.kiem.config.managers
Class ConfigurationManager

java.lang.Object
  extended by de.cau.cs.kieler.sim.kiem.config.managers.AbstractManager
      extended by de.cau.cs.kieler.sim.kiem.config.managers.ConfigurationManager

public final class ConfigurationManager
extends AbstractManager

Handles the default and currently running configuration.

Rating proposed yellow
(2010-01-27)

Method Summary
 void addProperty(KiemProperty prop)
          Add a new property to the default configuration.
 String findProperty(String propertyKey)
          Try to find a specific property value.
 String findPropertyValue(KiemPropertyKeyWrapper key, String defaultValue)
          Try to find a specific property value.
 List<KiemPropertyKeyWrapper> getAllKeys()
          Get all keys in the default configuration.
 ConfigDataComponent getCurrentConfig()
          Returns the configuration of the currently running schedule.
 ConfigDataComponent getDefaultConfig()
          Get the default configuration.
 KiemProperty[] getExternalDefaultProperties()
          Get all default properties that were created by the user.
static ConfigurationManager getInstance()
          Returns the singleton instance of this manager.
 KiemProperty[] getInternalDefaultProperties()
          Get all default properties that are used by the KIEM itself and that can be changed through more convenient means than a table.
 void initWithDefaults(AbstractDataComponent dataComponent)
          Initialize a data component with the default values.
 void load()
          Load the saved data from the plugin's preference store.
 void removeProperty(KiemPropertyKeyWrapper key)
          Removes properties with the specified key.
 void restoreDefaultEditorDefaults()
          Restore the default editor to the coded defaults.
 void restoreDefaults()
          Restore the default settings.
 void save()
          Save the default configuration to the eclipse preferences.
 void updateCurrentProperty(KiemPropertyKeyWrapper propertyId, String value)
          Updates the property in the currently loaded configuration.
 void updateCurrentProperty(String key, String value)
          Update a property in the current configuration.
 void updateDefaultProperty(String key, String value)
          Update a property in the default configuration.
 
Methods inherited from class de.cau.cs.kieler.sim.kiem.config.managers.AbstractManager
addEventListener, load, notifyListeners, remove, removeEventListener, save, saveAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ConfigurationManager getInstance()
Returns the singleton instance of this manager.

Returns:
the instance

getAllKeys

public List<KiemPropertyKeyWrapper> getAllKeys()
Get all keys in the default configuration. Mainly used for building the list selection dialog where the default usage of properties can be set up.

Returns:
the list of all available properties

getCurrentConfig

public ConfigDataComponent getCurrentConfig()
Returns the configuration of the currently running schedule.

Returns:
The currently running configuration.

getDefaultConfig

public ConfigDataComponent getDefaultConfig()
Get the default configuration. If no default configuration has been loaded yet try to load it from the eclipse preference store through the super class. If there is no configuration available create a new one.

Returns:
the default configuration.

getExternalDefaultProperties

public KiemProperty[] getExternalDefaultProperties()
Get all default properties that were created by the user.

Returns:
the array of properties.

getInternalDefaultProperties

public KiemProperty[] getInternalDefaultProperties()
Get all default properties that are used by the KIEM itself and that can be changed through more convenient means than a table.

This does not include the default editor name and key as that can be modified through another dialog by selection from list.

Returns:
the array of properties.

addProperty

public void addProperty(KiemProperty prop)
Add a new property to the default configuration.

Parameters:
prop - The property to be added.

findProperty

public String findProperty(String propertyKey)
                    throws KiemPropertyException
Try to find a specific property value.

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

One place to add values that can be retrieved by this method is the User Defined Properties page in the KIEM preference pages.

Parameters:
propertyKey - the key of the property
Returns:
the value of the property
Throws:
KiemPropertyException - if the value could not be found

findPropertyValue

public String findPropertyValue(KiemPropertyKeyWrapper key,
                                String defaultValue)
                         throws KiemPropertyException
Try to find a specific property value.

First the method tries to look for the key in the currently loaded configuration unless the key is in the list of keys where the default configuration should be used anyway. If finding the key in the current configuration fails the method continues to look for it in the default configuration. If the property is found it is added to the currently running configuration and returned.

If the property is not and a non-null default value is supplied the property is added to the default and currently running configuration. If no default value is supplied an exception is thrown.

Parameters:
key - The key to look for.
defaultValue - the default value to assign if the property is not found, not used if it is null
Returns:
The returned value.
Throws:
KiemPropertyException - if no property could be found. Can not happen if defaultValue is not null.

removeProperty

public void removeProperty(KiemPropertyKeyWrapper key)
Removes properties with the specified key.

Parameters:
key - the key of the properties that will be removed.

updateCurrentProperty

public void updateCurrentProperty(KiemPropertyKeyWrapper propertyId,
                                  String value)
Updates the property in the currently loaded configuration.

Parameters:
propertyId - the key of the property to change
value - the new value of the property

updateCurrentProperty

public void updateCurrentProperty(String key,
                                  String value)
Update a property in the current configuration.

If the key doesn't exist a new property is created. If the key already exists the value in the existing property is updated with the new value.

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

These saved properties can be accessed by findProperty(String)

Parameters:
key - a unique non-null key for the added property
value - the value for the added property

updateDefaultProperty

public void updateDefaultProperty(String key,
                                  String value)
Update a property in the default configuration.

If the key doesn't exist a new property is created. If the key already exists the value in the existing property is updated with the new value.

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

These saved properties can be accessed by findProperty(String)

Parameters:
key - a unique non-null key for the added property
value - the value for the added property

initWithDefaults

public void initWithDefaults(AbstractDataComponent dataComponent)
Initialize a data component with the default values.

Parameters:
dataComponent - the data component

restoreDefaultEditorDefaults

public void restoreDefaultEditorDefaults()
Restore the default editor to the coded defaults.


restoreDefaults

public void restoreDefaults()
Restore the default settings.


load

public void load()
Load the saved data from the plugin's preference store. Usually not necessary as data is loaded on demand.

Specified by:
load in class AbstractManager

save

public void save()
Save the default configuration to the eclipse preferences.

Specified by:
save in class AbstractManager