Class EmfDialogBuilder

java.lang.Object
com.amalgamasimulation.desktop.ui.editor.dialogs.EmfDialogBuilder

public class EmfDialogBuilder extends Object
Builder of a dialog with one field per feature of an EMF object, created by Dialogues.emf(Shell, String, EObject). The field kind depends on the attribute type: int and Integer give an integer field, double and Double a double field, String a text field.

The fields show the values of the object when the dialog opens. After OK one CompoundCommand of SetCommands sets all the features on the command stack of CommandsManager.getEditingDomain(), so one Undo restores them. Cancel changes neither the object nor the command stack.

Author:
Ionov Ivan
  • Method Details

    • feature

      public EmfDialogBuilder feature(org.eclipse.emf.ecore.EStructuralFeature feature, String label)
      Parameters:
      feature - single-valued int, Integer, double, Double or String attribute of the class of the object; not null
      label - label of the field; not null
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the feature is of another type or not of the class of the object; the message names the feature
    • file

      public EmfDialogBuilder file(org.eclipse.emf.ecore.EStructuralFeature feature, String label)
      Adds a file path field with the Buttons.openFile() button for a String feature. The default strategy is ValidationStrategies.stringIsNotEmpty().
      Parameters:
      feature - single-valued String attribute of the class of the object; not null
      label - label of the field; not null
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the feature is not a String attribute of the class of the object
    • folder

      public EmfDialogBuilder folder(org.eclipse.emf.ecore.EStructuralFeature feature, String label)
      Adds a folder path field with the Buttons.openDirectory() button for a String feature. The default strategy is ValidationStrategies.stringIsNotEmpty().
      Parameters:
      feature - single-valued String attribute of the class of the object; not null
      label - label of the field; not null
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the feature is not a String attribute of the class of the object
    • strategy

      public EmfDialogBuilder strategy(org.eclipse.emf.ecore.EStructuralFeature feature, ValidationStrategy<?,String> strategy)
      Replaces the validation strategy of the field of the feature. The strategy must take and return the type of the feature, and not return null for an int or double feature. A strategy of another type throws ClassCastException when the dialog opens or on OK; the object and the command stack stay the same.
      Parameters:
      feature - the feature of an added field
      strategy - checks and converts the text of the field
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if no field was added for the feature
    • button

      public EmfDialogBuilder button(org.eclipse.emf.ecore.EStructuralFeature feature, ISimpleButtonProperties button)
      Sets the button of the field of the feature. For a file or folder field it replaces the default button, for example with Buttons.openFile().extensions(...).
      Parameters:
      feature - the feature of an added field
      button - the button; one instance belongs to one field
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if no field was added for the feature
    • message

      public EmfDialogBuilder message(String message)
      Sets the message under the title.
      Parameters:
      message - the message; null shows no message
      Returns:
      this builder
    • open

      public boolean open()
      Opens the dialog and waits until it is closed.
      Returns:
      true after OK, when the features have got the new values; false after Cancel