org.knime.core.node.defaultnodesettings
Class DialogComponent

java.lang.Object
  extended by org.knime.core.node.defaultnodesettings.DialogComponent
Direct Known Subclasses:
AggregationColumnDialogComponent, DialogComponentBoolean, DialogComponentButton, DialogComponentButtonGroup, DialogComponentButtonLabel, DialogComponentChoiceConfig, DialogComponentColumnFilter, DialogComponentColumnNameSelection, DialogComponentDoubleRange, DialogComponentFileChooser, DialogComponentLabel, DialogComponentMultiLineString, DialogComponentNumber, DialogComponentNumberEdit, DialogComponentPasswordField, DialogComponentString, DialogComponentStringListSelection, DialogComponentStringSelection

public abstract class DialogComponent
extends Object

Abstract implementation of a component handling a standard type in a NodeDialog. Actual implementations will make sure the label and editable components are placed nicely in the underlying JPanel and their models will handle save/load to and from config objects. Using the DefaultNodeSettingsPane it is easy to add such Component to quickly assemble a dialog dealing with typical parameters.
Each component has a DialogComponent.EmptySettingsModel associated with it, which stores the current value of the component and handles all value related operations, like loading, saving, etc.

Author:
M. Berthold, University of Konstanz
See Also:
DefaultNodeSettingsPane, DialogComponent.EmptySettingsModel

Nested Class Summary
protected static class DialogComponent.EmptySettingsModel
          ------------------------------------------------------------------------- Components deriving from DialogComponent can use this model if they don't need or want to store any value (but are only displaying stuff).
 
Field Summary
protected static Color DEFAULT_BG
          default background color for editable components.
protected static Color DEFAULT_FG
          default foreground color for editable components.
 
Constructor Summary
DialogComponent(SettingsModel model)
          Abstract constructor expecting the model for this component.
 
Method Summary
protected abstract  void checkConfigurabilityBeforeLoad(PortObjectSpec[] specs)
          Will be called before the new values are loaded from the NodeSettings object.
protected  void clearError(JTextField field)
          Sets the foreground and background colors of the specified component back to the normal default colors.
 JPanel getComponentPanel()
           
protected  PortObjectSpec getLastTableSpec(int portID)
           
protected  PortObjectSpec[] getLastTableSpecs()
           
 SettingsModel getModel()
           
 void loadSettingsFrom(NodeSettingsRO settings, PortObjectSpec[] specs)
          Read value(s) of this dialog component from the configuration object.
 void saveSettingsTo(NodeSettingsWO settings)
          Write value(s) of this dialog component to the configuration object.
 void setEnabled(boolean enabled)
          Deprecated. rather use the component's DialogComponent.EmptySettingsModel to enable/disable the component.
protected abstract  void setEnabledComponents(boolean enabled)
          This method is called by the above (final) setEnabled(boolean) method.
abstract  void setToolTipText(String text)
          Implement this so it sets the tooltip on your component(s).
protected  void showError(JTextField field)
          Colors the component red, and registers a listener to the edit field that sets the colors back to the default as soon as the user edits something in the field.
protected abstract  void updateComponent()
          Read the value from the DialogComponent.EmptySettingsModel and set/display it in the component.
protected abstract  void validateSettingsBeforeSave()
          Will be called before the value of the component is saved into the NodeSettings object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FG

protected static final Color DEFAULT_FG
default foreground color for editable components.


DEFAULT_BG

protected static final Color DEFAULT_BG
default background color for editable components.

Constructor Detail

DialogComponent

public DialogComponent(SettingsModel model)
Abstract constructor expecting the model for this component.

Parameters:
model - the value model for this component
Method Detail

getComponentPanel

public JPanel getComponentPanel()
Returns:
the panel in which all sub-components of this component are arranged. This panel can be added to the dialog pane.

getModel

public final SettingsModel getModel()
Returns:
the Settings model associated with this component.

getLastTableSpec

protected final PortObjectSpec getLastTableSpec(int portID)
Parameters:
portID - the id of the port the spec should be returned for
Returns:
the spec for the specified port that came in through the last call to loadSettings. Could be null!
See Also:
loadSettingsFrom(NodeSettingsRO, PortObjectSpec[])

getLastTableSpecs

protected final PortObjectSpec[] getLastTableSpecs()
Returns:
the specs that came in through the last call to loadSettings. Could be null!
See Also:
loadSettingsFrom(NodeSettingsRO, PortObjectSpec[])

loadSettingsFrom

public final void loadSettingsFrom(NodeSettingsRO settings,
                                   PortObjectSpec[] specs)
                            throws NotConfigurableException
Read value(s) of this dialog component from the configuration object. This method will be called by the dialog pane only.

Parameters:
settings - the NodeSettings to read from
specs - the input specs
Throws:
NotConfigurableException - If there is no chance for the dialog component to be valid (i.e. the settings are valid), e.g. if the given specs lack some important columns or column types.

updateComponent

protected abstract void updateComponent()
Read the value from the DialogComponent.EmptySettingsModel and set/display it in the component. (Called after loading new values in the model to ensure they are transfered into the component.) Implementations should set the new value(s) in the components, should clear any possible error indications, and should also take over the enable state.


saveSettingsTo

public final void saveSettingsTo(NodeSettingsWO settings)
                          throws InvalidSettingsException
Write value(s) of this dialog component to the configuration object. This method will be called by the dialog pane only. (Is not called if the component is disabled.)

Parameters:
settings - the NodeSettings to read from
Throws:
InvalidSettingsException - if the user has entered wrong values.

validateSettingsBeforeSave

protected abstract void validateSettingsBeforeSave()
                                            throws InvalidSettingsException
Will be called before the value of the component is saved into the NodeSettings object. Can be used to commit values, to update the model and must be used to validate the entered value. NOTE: it will be called even if the model is disabled.

Throws:
InvalidSettingsException - if the entered values are invalid

checkConfigurabilityBeforeLoad

protected abstract void checkConfigurabilityBeforeLoad(PortObjectSpec[] specs)
                                                throws NotConfigurableException
Will be called before the new values are loaded from the NodeSettings object. Can be used to avoid loading due to missing, invalid, or inappropriate incoming table specs.
Note: This is called even if the component is disabled. Don't reject specs that might be handled by other components

Parameters:
specs - the specs from the input ports.
Throws:
NotConfigurableException - if the component can't be used due to inappropriate table specs. (Prevents the dialog from being opened.)

setEnabled

@Deprecated
public final void setEnabled(boolean enabled)
Deprecated. rather use the component's DialogComponent.EmptySettingsModel to enable/disable the component.

Sets the enabled status of the component. Disabled components don't take user input. Retrieving the value from a disabled model (SettingsModel) could lead to unexpected results.

Parameters:
enabled - if true the contained components will be enabled
See Also:
Component.setEnabled(boolean)

setEnabledComponents

protected abstract void setEnabledComponents(boolean enabled)
This method is called by the above (final) setEnabled(boolean) method. Derived classes should disable all the contained components in here.

Parameters:
enabled - the new status of the component
See Also:
setEnabled(boolean)

showError

protected void showError(JTextField field)
Colors the component red, and registers a listener to the edit field that sets the colors back to the default as soon as the user edits something in the field.

Parameters:
field - the component to set the color in

clearError

protected void clearError(JTextField field)
Sets the foreground and background colors of the specified component back to the normal default colors.

Parameters:
field - the textfield to clear the error for

setToolTipText

public abstract void setToolTipText(String text)
Implement this so it sets the tooltip on your component(s).

Parameters:
text - the tool tip text to set.
See Also:
JComponent.setToolTipText(java.lang.String)


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.