validateSettings

Checks the user settings passed in the read-only NodeSettings object. Make sure that all required values are available in the NodeSettings. Make sure they are in the valid range, they are consistent to each other, but do not modify any members in the NodeModel here. If you need to keep a value (e.g. to compare it with another user value), store it in a local temporary variable. If settings are incomplete or invalid, throw an InvalidSettingsException with a useful error message (it is shown to the user). The getter methods of the NodeSettings object throw an exception, if a specified key does not exist. It is advisable to catch this exception and to create a new one with a better user message.

Example #1:

  	protected void validateSettings(final NodeSettingsRO settings)              throws InvalidSettingsException {          // simply checks if the keys are available          settings.getInt(CFG_PERCENTAGE);          settings.getBoolean(CFG_REPLACE);      }  

Consider that a node was already released and in the next release a new field is added to the dialog and therefore also to the settings. Then every existing workflow will fail while loading, since the new field cannot be found in the settings. To avoid this you could also in the model provide some default values if the key cannot be found. See below:

Example #2:

  	protected void validateSettings(final NodeSettingsRO settings)              throws InvalidSettingsException {          // simply checks if the keys are available          settings.getInt(CFG_PERCENTAGE);          settings.getBoolean(CFG_REPLACE);          settings.getBoolean(CFG_NEW_FIELD, true);      }  

Of course, in the loadValidatedSettings method the same default value has to be used. If DefaultComponents with their SettingsModels are used, the method would look as in Example #2.

Example #3:

  	protected void validateSettings(final NodeSettingsRO settings)              throws InvalidSettingsException {          // simply checks if the keys are available            m_settingsModel.validateSettings(settings);      }  

If there are dependencies to check between two settings values, the validateSettings method becomes a bit more complicated: If a settings model validates a value, it does not store that value, thus you have no access to that value you are supposed to validate. If you need to check some values against each other (like, to ensure that the new minimum is smaller than the specified maximum, for example), you need to create new temporary settings models, load the new values in, read and verify them, and release the settings models at the end. Here is a code example:

Example #4:

  	protected void validateSettings(final NodeSettingsRO settings)              throws InvalidSettingsException {            // create new (temp) settings models          // (if m_min and m_max are fields of the NodeModel)          SettingsModelInteger min =                     m_min.createCloneWithValidatedValue(MIN, settings);          SettingsModelInteger max =                     m_max.createCloneWithValidatedValue(MAX, settings);            if (min.getIntValue() >= max.getIntValue()) {              throw new InvalidSettingsException("The specified minimum "                     + "must be smaller than the maximum value.");          }  }