Class GUIVariable
- java.lang.Object
-
- net.ssehub.easy.producer.ui.confModel.GUIVariable
-
- All Implemented Interfaces:
java.lang.Comparable<GUIVariable>,IGUIConfigurableElement
- Direct Known Subclasses:
AbstractExpandableGUIVariable,BasisGUIVariable,ComboboxGUIVariable,ConfigurationTableEditorFactory.DelegatingGuiVariable
public abstract class GUIVariable extends java.lang.Object implements IGUIConfigurableElement, java.lang.Comparable<GUIVariable>
AIDecisionVariablewith functionality needed by the Eclipse UI.- Author:
- El-Sharkawy
-
-
Field Summary
Fields Modifier and Type Field Description private org.eclipse.swt.widgets.Compositecompositeprivate java.lang.StringerrorMsgprivate GUIHistoryhistoryprivate GUIVariableparentThe parent holding this variable.private GUIConfigurationparentConfigprivate java.lang.Stringtooltipprivate IDecisionVariablevariable
-
Constructor Summary
Constructors Modifier Constructor Description protectedGUIVariable(IDecisionVariable variable, GUIConfiguration parentConfig, GUIVariable parent, org.eclipse.swt.widgets.Composite composite)Sole constructor for this class.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) voidaddErrorMessage(ContainableModelElement conflictingElement, java.lang.String userMessage)Adds a new error message to thisGUIVariable.intcompareTo(GUIVariable other)GUIVariableextend()Creates a new empty nested value/variable if supported.voidfreeze()Causes to freeze the current value.private voidfreezeNested(GUIVariable nestedVar)Recursive part offreeze()to freeze also all nested elements.IAssignmentStategetAssignmentState()The currentIAssignmentStateof the wrappedIDecisionVariable.abstract org.eclipse.jface.viewers.CellEditorgetCellEditor(org.eclipse.swt.widgets.Composite parent)Returns aCellEditorfor a table.java.lang.StringgetComment()Returns the comment of the model element.org.eclipse.swt.widgets.CompositegetComposite()Returns the GUI component where this variable and its editors are displayed.GUIConfigurationgetConfiguration()Getter for the configuration which holds this variable.abstract GUIEditorgetEditor()Returns the (non-cell) editor for this variable.java.lang.StringgetErrorMessages()Returns the stored error messages as a string.GUIHistorygetHistory()Getter for the history of the variable.java.lang.StringgetName()Returns the name of theIDecisionVariable.intgetNestedDepth()Returns how many parentIDecisionVariables exist for this variable.GUIVariablegetNestedElement(int index)Returns a nested element specified by the given index.intgetNestedElementsCount()Returns the number of nested elements.java.lang.StringgetNullLabel()Returns the label for an IVML null value to be used in this GUI variable.GUIVariablegetParent()Returns the parent Variable holding this variable.java.lang.StringgetTooltip()Returns a tooltip which can be displayed inside the GUI.GUIVariablegetTopLevelParent()Returns the TopLevelParent Variable holding this variable or the variable itself if it is a top level variable.protected IDatatypegetType()Returns the type of the underlying IVML variable.abstract java.lang.ObjectgetValue()Returns the value of the givenIDecisionVariableso that it can be used as return value for theEditingSupport.getValue(Object)method.protected abstract ValuegetValueAssignment(java.lang.Object value)Converts the given object into aValue.abstract java.lang.StringgetValueText()Returns a string representation of the current value.IDecisionVariablegetVariable()Returns the wrappedIDecisionVariable.booleanhasErrors()Checks whether error messages are stored to thisGUIVariable.booleanhasNullValue()Checks whether the variable has aNullValue.booleanhasValue()Checks whether the variable has a configuredValue.booleanisAnnotated()Returns whether the variable has any annotations.booleanisEditable()Returns whether the wrappedIDecisionVariablecan be edited.booleanisExpandable()Returns whether is variable can be expanded.booleanisExtendable()Returns whether is variable can be extended (insert new empty values).booleanisFreezable()Returns whether this variable can be frozen.booleanisFrozen()Returns whether the current variable is already frozen.(package private) booleanisTopLevelDeclaration()Check for TopLevelDeclaration.voidremove(GUIVariable nestedVariable)Deletes a nestedGUIVariablefrom this variable.(package private) voidremoveErrorMessages()Removes the stored error message.protected GUIVariablereplace(GUIVariable nestedVariable, Value value)Replaces a variable to reflect the new value (of a more or less specific type).(package private) static voidreplaceValue(IDecisionVariable decVar, Value value)Replaces the value indecVarbyvalue.voidsetEmptyValue()Removes the currentValue.voidsetNULLValue()Sets aNullValue.voidsetValue(java.lang.Object value)Sets the value of the wrappedIDecisionVariable.voidsetVariable(IDecisionVariable variable)Setter for the wrappedIDecisionVariable.java.lang.StringtoString()voidunfreeze(IAssignmentState state)Unfreezes the current variable.
-
-
-
Field Detail
-
parentConfig
private GUIConfiguration parentConfig
-
variable
private IDecisionVariable variable
-
tooltip
private java.lang.String tooltip
-
errorMsg
private java.lang.String errorMsg
-
history
private GUIHistory history
-
composite
private org.eclipse.swt.widgets.Composite composite
-
parent
private GUIVariable parent
The parent holding this variable. Can be null in case of top level elements.
-
-
Constructor Detail
-
GUIVariable
protected GUIVariable(IDecisionVariable variable, GUIConfiguration parentConfig, GUIVariable parent, org.eclipse.swt.widgets.Composite composite)
Sole constructor for this class.- Parameters:
variable- TheIDecisionVariablerepresented by this GUIVariableparentConfig- TheGUIConfigurationholding this GUIVariableparent- The parent GUIVariable holding this variable. Can be null if and only if this variable is a top level variable stored inside the configuration.composite- The controlling composite, needed for the creation of editors.
-
-
Method Detail
-
getComposite
public final org.eclipse.swt.widgets.Composite getComposite()
Returns the GUI component where this variable and its editors are displayed.- Returns:
- The holding GUI component.
-
getVariable
public IDecisionVariable getVariable()
Returns the wrappedIDecisionVariable.- Returns:
- The wrapped
IDecisionVariable
-
getParent
public GUIVariable getParent()
Returns the parent Variable holding this variable.- Returns:
- The parent or null if this variable is a top level variable nested directly inside the configuration.
-
getTopLevelParent
public GUIVariable getTopLevelParent()
Returns the TopLevelParent Variable holding this variable or the variable itself if it is a top level variable.- Returns:
- The TopLevelParent or this if this variable is a top level variable.
-
setVariable
public void setVariable(IDecisionVariable variable)
Setter for the wrappedIDecisionVariable.- Parameters:
variable- The newIDecisionVariable
-
getNestedDepth
public final int getNestedDepth()
Returns how many parentIDecisionVariables exist for this variable.- Returns:
- 0 if the Configuration is the direct parent of this
IDecisionVariable, otherwise a number greater than 0 indicating how manyIDecisionVariables between the Configuration and this variable exist.
-
getCellEditor
public abstract org.eclipse.jface.viewers.CellEditor getCellEditor(org.eclipse.swt.widgets.Composite parent)
Returns aCellEditorfor a table.- Parameters:
parent- The GUI component where thisGUIVariableand, thus, its editor are displayed.- Returns:
CellEditorto configure the enclosedIDecisionVariable
-
getEditor
public abstract GUIEditor getEditor()
Returns the (non-cell) editor for this variable. The editor shall be ready to use, i.e., properly initialized.- Returns:
- the editor, may be null if the variable shall not be displayed / being edited
-
getValue
public abstract java.lang.Object getValue()
Returns the value of the givenIDecisionVariableso that it can be used as return value for theEditingSupport.getValue(Object)method.- Returns:
- A value as needed by the Eclipse UI.
-
setValue
public void setValue(java.lang.Object value)
Sets the value of the wrappedIDecisionVariable.- Parameters:
value- The value to be set.
-
getValueAssignment
protected abstract Value getValueAssignment(java.lang.Object value) throws ValueDoesNotMatchTypeException
Converts the given object into aValue.- Parameters:
value- An object given by the Eclipse GUI.- Returns:
- A
Valuerepresentation of the object, maybe null. - Throws:
ValueDoesNotMatchTypeException- in case ofvaluecannot be converted to the related data type of the wrappedIDecisionVariable.
-
getName
public java.lang.String getName()
Returns the name of theIDecisionVariable.- Returns:
- The name of the
IDecisionVariable, must not be null.
-
getAssignmentState
public IAssignmentState getAssignmentState()
The currentIAssignmentStateof the wrappedIDecisionVariable.- Returns:
- The
IAssignmentStateof the wrappedIDecisionVariable.
-
isEditable
public boolean isEditable()
Returns whether the wrappedIDecisionVariablecan be edited.- Returns:
- true if the variable can be edited, otherwise false.
-
getValueText
public abstract java.lang.String getValueText()
Returns a string representation of the current value. This is used when no cursor is inside the cell (if the user is not editing the variable).- Returns:
- A string representation of the current value or null.
-
isExpandable
public boolean isExpandable()
Returns whether is variable can be expanded. Subclasses may override this method.- Returns:
- true if this variable is expandable, otherwise false.
-
isExtendable
public boolean isExtendable()
Returns whether is variable can be extended (insert new empty values). Subclasses may override this method.- Returns:
- true if this variable is extendable, otherwise false.
- See Also:
extend()
-
extend
public GUIVariable extend()
Creates a new empty nested value/variable if supported. This method shall only be called by the set and sequence variables.- Returns:
- the new empty variable or null if nothing happened, e.g., not
isExtendable().
-
remove
public void remove(GUIVariable nestedVariable)
Deletes a nestedGUIVariablefrom this variable. This is only supported inContainerGUIVariableclass.- Parameters:
nestedVariable- The nested variable which shall be removed.
-
replace
protected GUIVariable replace(GUIVariable nestedVariable, Value value) throws ConfigurationException
Replaces a variable to reflect the new value (of a more or less specific type).- Parameters:
nestedVariable- the variable to be replaced (may affect top-level GUI variables)value- the new value carrying the type- Returns:
- the new variable or
nestedVariable - Throws:
ConfigurationException- in case that configuring the variable is not possible
-
replaceValue
static void replaceValue(IDecisionVariable decVar, Value value) throws ConfigurationException
Replaces the value indecVarbyvalue.- Parameters:
decVar- the decision variable to changevalue- the new value- Throws:
ConfigurationException- in case that the original value cannot be cleared or the new value cannot be set
-
getComment
public java.lang.String getComment()
Returns the comment of the model element.- Returns:
- Comment of this model element.
-
getNestedElementsCount
public int getNestedElementsCount()
Returns the number of nested elements. The return value should be 0 unless thisIDecisionVariableis anAbstractExpandableGUIVariable.- Returns:
- An integer value greater or equal to 0.
-
getNestedElement
public GUIVariable getNestedElement(int index)
Returns a nested element specified by the given index.- Parameters:
index- The 0-based index of the nested element.- Returns:
- The specified nestedvariable.
- Throws:
java.lang.ArrayIndexOutOfBoundsException- if this variable has no nested elements, is not expanded, or if the index is out of range (index < 0 || index >= size())
-
getConfiguration
public final GUIConfiguration getConfiguration()
Getter for the configuration which holds this variable.- Specified by:
getConfigurationin interfaceIGUIConfigurableElement- Returns:
- The configuration bearing this variable.
-
isFrozen
public boolean isFrozen()
Returns whether the current variable is already frozen.- Returns:
- true if the variable is frozen, otherwise false.
-
isFreezable
public final boolean isFreezable()
Returns whether this variable can be frozen. In case of some nested variables it is not possible to freeze only the nested variable (e.g. a nested set variable).- Returns:
- true if the nested variable can be frozen, otherwise false.
-
freeze
public void freeze()
Causes to freeze the current value.
-
freezeNested
private void freezeNested(GUIVariable nestedVar)
Recursive part offreeze()to freeze also all nested elements. This is especially needed to store nested states for the undo function.- Parameters:
nestedVar- The nested element to freeze.
-
unfreeze
public void unfreeze(IAssignmentState state)
Unfreezes the current variable.- Parameters:
state- the state after unfreezing (do not useAssignmentState.FROZEN)
-
getTooltip
public final java.lang.String getTooltip()
Returns a tooltip which can be displayed inside the GUI.- Returns:
- The datatype of the variable (must not be null).
-
hasErrors
public final boolean hasErrors()
Checks whether error messages are stored to thisGUIVariable.- Returns:
- true if this variable has stored error messages, false otherwise.
- See Also:
getErrorMessages()
-
getErrorMessages
public final java.lang.String getErrorMessages()
Returns the stored error messages as a string.- Returns:
- The error messages stored at this variable or null if no errors are stored.
- See Also:
hasErrors()
-
removeErrorMessages
final void removeErrorMessages()
Removes the stored error message.
-
addErrorMessage
final void addErrorMessage(ContainableModelElement conflictingElement, java.lang.String userMessage)
Adds a new error message to thisGUIVariable.- Parameters:
conflictingElement- AContainableModelElementwhich lead to the conflict and wheregetVariable()is included.userMessage- Optional: A error message which can be ready by a normal user. If null, the constraint will be used for displaying an error message.
-
compareTo
public final int compareTo(GUIVariable other)
- Specified by:
compareToin interfacejava.lang.Comparable<GUIVariable>
-
isTopLevelDeclaration
boolean isTopLevelDeclaration()
Check for TopLevelDeclaration. Can be null in case of top level elements.- Returns:
- true if Element is a TopLevelDeclaration.
-
getHistory
public GUIHistory getHistory()
Getter for the history of the variable.- Returns:
- The history of the variable.
-
hasValue
public boolean hasValue()
Checks whether the variable has a configuredValue.- Returns:
- true if the variable has a value, false otherwise.
-
hasNullValue
public boolean hasNullValue()
Checks whether the variable has aNullValue. Note: this method does not check whether the variable has a value.- Returns:
- true if the variable has a
NullValue, false otherwise.
-
setEmptyValue
public void setEmptyValue()
Removes the currentValue.
-
setNULLValue
public void setNULLValue()
Sets aNullValue.
-
getNullLabel
public java.lang.String getNullLabel()
Returns the label for an IVML null value to be used in this GUI variable.- Returns:
- the label for an IVML null value
-
getType
protected IDatatype getType()
Returns the type of the underlying IVML variable. In case of derived variables, it returns the innermost type.- Returns:
- the type
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isAnnotated
public boolean isAnnotated()
Returns whether the variable has any annotations.- Returns:
- true The variable has at least one annotation, false the variable has no annotations.
-
-