Advanced Topics

Synchronizing Multiple Editors

The Model-Delegate pattern that is applied by the settings framework allows multiple editors (i.e., multiple views) concurrent access to the model. In order to have each compound editor with its set of embedded item editors display the current values and state from the model, it is necessary these are propagated in time.

Interface ItemEditor provides the following methods to support implicit synchronization of values and state whenever they are changed in the model, i.e., whenever an option item's value or its state is modified:

boolean isAutoAdopt()
boolean isAutoCommit()

void setAutoAdopt(boolean autoAdopt)
void setAutoCommit(boolean autoCommit)
Description Methods to control implicit synchronization of an item editor.

As mentioned in the section called “Synchronizing Editors and Option Items” a compound editor that is created by class TableEditorFactory by default supports both "push" and "pull" semantics with value and state change propagation. To achieve implicit synchronization for other compound editors also, code similar to that presented in Example 10.12, “Setting embedded editors to auto-adopt state” can be used. It sets each embedded item editor of a given compound editor to auto-adopt state, so that it automatically "pulls" the current value and state of its respective option item whenever it has been modified.

Example 10.12. Setting embedded editors to auto-adopt state

public void setAutoAdopt(Editor editor, boolean autoAdopt)
{
  if (editor instanceof CompoundEditor)
  {
    // Iterate over all embedded editors of this compound editor. 
    for (Iterator it = ((CompoundEditor)editor).editors(); it.hasNext(); )
      // Recurse. 
      setAutoAdopt((Editor)it.next(), autoAdopt);
  }
  else if (editor instanceof ItemEditor)
  {
    // Set the autoAdopt property on this item editor. 
    ((ItemEditor)editor).setAutoAdopt(autoAdopt);
  }
}

Tutorial Demo Code

OptionHandlerDemo.java is an extensive tutorial demo application that shows multiple editors and their synchronization.