com.ibm.commons.swt.data.editors.api
Class PropertyEditor

java.lang.Object
  extended by com.ibm.commons.swt.data.editors.api.PropertyEditor
All Implemented Interfaces:
IPropertyEditor
Direct Known Subclasses:
AbstractCheckBoxEditor, AbstractCLabelEditor, AbstractComboEditor, AbstractLabelEditor, AbstractObjectEditor, AbstractTableEditor, AbstractTextEditor, PrimitiveCollectionEditor, TreeComboEditor

public abstract class PropertyEditor
extends java.lang.Object
implements IPropertyEditor

An abstract class that provides a framework for creating controls that act together to modify an attribute in the associated model.


Constructor Summary
PropertyEditor()
          Constructs a new instance of this class.
PropertyEditor(IValidator validator)
          Creates a new PropertyEditor instance with an associated IValidator which is used for validating the input of the PropertyEditor.
 
Method Summary
 void addPropertyEditorUpdateListener(PropertyEditorUpdateListener listener)
          Allows interested parties to register an event listener to this PropertyEditor.
 void addValidator(IValidator validator)
          Adds a validator to the list of validators associated with this editor.
 java.lang.String callDialog(CompositeEditor parent, java.lang.String value)
          Open a dialog to edit this property.
abstract  org.eclipse.swt.widgets.Control createControl(CompositeEditor parent)
          This method is called by the PropertyEditor during initialization.
 java.lang.Object getContextAttribute()
          Returns the attribute associated with this editor.
 java.lang.Object getContextObject()
          Returns the element in the model that this editor is associated with.
static PropertyEditor getDefaultEditor(int type)
          Given a predefinted integer value this utility method will return the associated predefined PropertyEditor.
 java.lang.String getDialogButtonAltText(CompositeEditor parent)
          Return the alternate text to place on the dialog button if there is one to edit this property.
 org.eclipse.swt.graphics.Image getDialogButtonImage(CompositeEditor parent)
          Optionally return an image to place on the dialog button if there is one to edit this property.
 java.lang.String getDialogButtonText(CompositeEditor parent)
          Return the text to place on the dialog button if there is one to edit this property.
static PropertyEditor getEditor(IMember member)
          This static utility method returns a property editor for the given member variable.
 java.lang.String getRenderedValue(java.lang.String value)
          Returns the 'UI Value' based on the value stored in the model.
 java.lang.String getScriptMode()
          Returns the modes that can be used to edit the value of the attribute.
 IValidator getTextValidator()
          Returns the validator associated with the editor.
 IValidator getValidator()
          Returns the validator associated with this editor, as set using setValidator(IValidator).
 org.eclipse.ui.IWorkbenchPart getWorkBenchPart()
          Returns the IWorkbenchPart that this editor is operating on.
 boolean hasDialogButton(CompositeEditor parent)
          Return true if this property may be edited via a dialog button.
abstract  void initControlValue(CompositeEditor parent, java.lang.String value)
          Set the given value into the control created for this property editor.
 boolean isScriptModeFixed()
          Returns whether or not multiple modes are allowed when editing scripts.
protected  void postModelUpdate()
          Property editors are responsible for calling this method AFTER they update the model outside of using parent.updateValue
protected  void preModelUpdate()
          Property editors are responsible for calling this method *BEFORE* they update the model outside of using parent.updateValue
 void removePropertyEditorUpdateListener(PropertyEditorUpdateListener listener)
          Allows interested parties to remove an event listener from this PropertyEditor.
 void setContextAttribute(java.lang.Object attr)
          Sets the attribute associated with this editor.
 void setContextObject(java.lang.Object element)
          Sets the element in the model that this editor is associated with.
abstract  void setId(java.lang.String id)
          Allows the implementor to associate an ID attribute with this control.
 void setScriptMode(java.lang.String mode)
          Sets the modes that can be used to edit the value of the attribute.
 void setValidator(IValidator validator)
          Sets the validator to use with this editor.
 void setWorkBenchPart(org.eclipse.ui.IWorkbenchPart wbPart)
          Sets the IWorkbenchPart associated with this editor.
abstract  boolean stopEdit(CompositeEditor parent)
          Called to tell the current editor to stop editing the associated attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyEditor

public PropertyEditor()
Constructs a new instance of this class.


PropertyEditor

public PropertyEditor(IValidator validator)
Creates a new PropertyEditor instance with an associated IValidator which is used for validating the input of the PropertyEditor. Values which do not conform with the criteria laid out by the validator will not be accepted for input by the editor.

Parameters:
validator - - com.ibm.commons.iloader.node.IValidator The validator which is used to validate the PropertyEditor's input.
See Also:
com.ibm.commons.iloader.node.validators.IValidator}
Method Detail

getDefaultEditor

public static PropertyEditor getDefaultEditor(int type)
Given a predefinted integer value this utility method will return the associated predefined PropertyEditor. The predefined integer values are:
  • TYPE_STRING = 0;
  • TYPE_INTEGER = 1;
  • TYPE_NUMBER = 2;
  • TYPE_BOOLEAN = 3;
  • TYPE_OBJECT = 4;


  • The associated editors are:

  • com.ibm.commons.swt.data.editors.StringEditor
  • com.ibm.commons.swt.data.editors.IntegerEditor
  • com.ibm.commons.swt.data.editors.DoubleEditor
  • com.ibm.commons.swt.data.editors.BooleanEditor


  • Parameters:
    type - - int
    Returns:
    PropertyEditor

    getEditor

    public static PropertyEditor getEditor(IMember member)
    This static utility method returns a property editor for the given member variable. The member variable represents an attribute in the model associated with the PropertyEditor. This method will first query the member to calculate if a PropertyEditor has been preassigned with this member (by calling the member.getEditor() method). If a PropertyEditor has not been preassigned then the member variable is queried for its type and the default PropertyEditor for the given type is returned.

    Parameters:
    member - - com.ibm.commons.iloader.node.IMember
    Returns:
    com.ibm.commons.swt.data.editors.api.PropertyEditor
    See Also:
    com.ibm.commons.swt.data.editors.api.PropertyEditor#getDefaultEditor(int)}, com.ibm.commons.iloader.node.IMember}

    addValidator

    public void addValidator(IValidator validator)
    Adds a validator to the list of validators associated with this editor. Each validator is queried when the user inputs information into the PropertyEditor, if the validator determines the information being entered by the user is invalid then the user is notified.

    Parameters:
    validator - - com.ibm.commons.iloader.node.IValidator A validator which is used to validate the PropertyEditor's input.

    getTextValidator

    public IValidator getTextValidator()
    Returns the validator associated with the editor.

    Returns:
    See Also:
    IValidator

    callDialog

    public java.lang.String callDialog(CompositeEditor parent,
                                       java.lang.String value)
    Open a dialog to edit this property. It is at the discretion of the PropertyEditor implementor to override this method in order to actually invoke the dialog, and return the appropriate string value to the PropertyEditor once the dialog is dismissed (via OK or Cancel).

    Parameters:
    parent - - The parent composite editor
    value - - The current value being edited
    Returns:
    the new property value after the dialog has been dismissed

    createControl

    public abstract org.eclipse.swt.widgets.Control createControl(CompositeEditor parent)
    This method is called by the PropertyEditor during initialization. This method creates the control that is used by the PropertyEditor to edit the associated property.

    Parameters:
    parent - - The parent of the control
    Returns:
    Control - The 'control' used to edit this property (control is used liberally here as a composite of controls could be returned).

    setId

    public abstract void setId(java.lang.String id)
    Allows the implementor to associate an ID attribute with this control. This may be of use later when trying to identify the control.

    Parameters:
    id -

    getContextAttribute

    public java.lang.Object getContextAttribute()
    Returns the attribute associated with this editor.

    Returns:
    Object
    See Also:
    IMember

    getContextObject

    public java.lang.Object getContextObject()
    Returns the element in the model that this editor is associated with.

    Returns:
    Object

    getDialogButtonAltText

    public java.lang.String getDialogButtonAltText(CompositeEditor parent)
    Return the alternate text to place on the dialog button if there is one to edit this property.

    Parameters:
    parent - - the CompositeEditor that is the parent of this editor, may be null.
    Returns:
    String - the alt text to appear on the dialog button
    See Also:
    CompositeEditor

    getDialogButtonText

    public java.lang.String getDialogButtonText(CompositeEditor parent)
    Return the text to place on the dialog button if there is one to edit this property.

    Parameters:
    parent - - the CompositeEditor that is the parent of this editor, may be null.
    Returns:
    String - the text to place on the dialog button

    getDialogButtonImage

    public org.eclipse.swt.graphics.Image getDialogButtonImage(CompositeEditor parent)
    Optionally return an image to place on the dialog button if there is one to edit this property.

    Parameters:
    parent - - the CompositeEditor that is the parent of this editor, may be null.
    Returns:
    Image - the image to place on the dialog button

    getRenderedValue

    public java.lang.String getRenderedValue(java.lang.String value)
    Returns the 'UI Value' based on the value stored in the model.

    Parameters:
    value - - the String value stored in the associated model.
    Returns:
    String

    getValidator

    public IValidator getValidator()
    Returns the validator associated with this editor, as set using setValidator(IValidator).

    Returns:

    getWorkBenchPart

    public org.eclipse.ui.IWorkbenchPart getWorkBenchPart()
    Returns the IWorkbenchPart that this editor is operating on.

    Returns:

    hasDialogButton

    public boolean hasDialogButton(CompositeEditor parent)
    Return true if this property may be edited via a dialog button.

    Returns:
    boolean

    initControlValue

    public abstract void initControlValue(CompositeEditor parent,
                                          java.lang.String value)
    Set the given value into the control created for this property editor.

    Parameters:
    CompositeEditor - - the parent CompositeEditor
    String - - the value to set in the editor
    See Also:
    CompositeEditor

    setContextAttribute

    public void setContextAttribute(java.lang.Object attr)
    Sets the attribute associated with this editor.

    Parameters:
    attr -
    See Also:
    IMember

    setContextObject

    public void setContextObject(java.lang.Object element)
    Sets the element in the model that this editor is associated with.

    Parameters:
    element -

    setValidator

    public void setValidator(IValidator validator)
    Sets the validator to use with this editor. Only values allowed by the validator will be allowed by the editor.

    Parameters:
    validator -

    setWorkBenchPart

    public void setWorkBenchPart(org.eclipse.ui.IWorkbenchPart wbPart)
    Sets the IWorkbenchPart associated with this editor.

    Parameters:
    wbPart -

    stopEdit

    public abstract boolean stopEdit(CompositeEditor parent)
    Called to tell the current editor to stop editing the associated attribute. Typically this will be called when the current CompositeEditor has lost focus.

    Parameters:
    parent - - CompositeEditor
    Returns:
    boolean - returns true if the operation succeeded, otherwise returns false.

    isScriptModeFixed

    public boolean isScriptModeFixed()
    Returns whether or not multiple modes are allowed when editing scripts.

    Returns:

    setScriptMode

    public void setScriptMode(java.lang.String mode)
    Sets the modes that can be used to edit the value of the attribute.

    Parameters:
    mode -

    getScriptMode

    public java.lang.String getScriptMode()
    Returns the modes that can be used to edit the value of the attribute.

    Returns:
    String

    addPropertyEditorUpdateListener

    public void addPropertyEditorUpdateListener(PropertyEditorUpdateListener listener)
    Allows interested parties to register an event listener to this PropertyEditor. The even listener will be notified when this PropertyEditor before and after each model update event.

    Parameters:
    listener - - com.ibm.commons.swt.data.editors.PropertyEditorUpdateListener
    See Also:
    com.ibm.commons.swt.data.editors.support.PropertyEditorUpdateListener}

    removePropertyEditorUpdateListener

    public void removePropertyEditorUpdateListener(PropertyEditorUpdateListener listener)
    Allows interested parties to remove an event listener from this PropertyEditor.

    Parameters:
    listener - - com.ibm.commons.swt.data.editors.PropertyEditorUpdateListener
    See Also:
    com.ibm.commons.swt.data.editors.support.PropertyEditorUpdateListener}

    preModelUpdate

    protected void preModelUpdate()
    Property editors are responsible for calling this method *BEFORE* they update the model outside of using parent.updateValue


    postModelUpdate

    protected void postModelUpdate()
    Property editors are responsible for calling this method AFTER they update the model outside of using parent.updateValue