public class PropertyEnv extends Object
PropertySheet
or PropertyPanel
component. An instance of
PropertyEnv is passed to the attachEnv()
method of property editors implementing ExPropertyEditor.
Such property editors may then call
env.getFeatureDescriptor().get("someHintString")
to retrieve hints that affect their behavior from the
Node.Property object whose properties they are displaying.
The other purpose of the of this interface is to
enable communication between the PropertyEditor
and
the PropertySheet
or PropertyPanel
.
The custom property editor can get into a state when the visual state
does not represent valid value and in such case needs to disable OK button.
To handle that the property editor has to keep reference to its associated
PropertyEnv
and switch it into invalid state by calling
setState(
as soon as the content of the custom property editor is invalid and then
back by
PropertyEnv.STATE_INVALID
)setState(
when the custom property editor becomes valid once again. As a reaction
to these calls the displayer of the custom property editor (for example
dialog with OK button) is supposed to disable and re-enable the button.
PropertyEnv.STATE_VALID
)
Also it can happen that the property editor is complex and cannot decide whether
the value is valid quickly. Just knows that it needs to be validated.
For that purpose it wants to be informed when user presses the OK button and
do the complex validation then. For that purpose there is the PropertyEnv.STATE_NEEDS_VALIDATION
state. The property editor needs to use it and attach a listener to
be notified when the user presses the OK button:
class Validate implements VetoableChangeListener { public void vetoableChange(VetoableChangeEvent ev) throws PropertyVetoException { if (PROP_STATE.equals(ev.getPropertyName())) { if (!doTheComplexValidationOk()) { throw new PropertyVetoException(...); } } // otherwise allow the switch to ok state } } Validate v = new Validate(); env.setState(STATE_NEEDS_VALIDATION); env.addVetoableChangeListener(v);When the state is
PropertyEnv.STATE_NEEDS_VALIDATION
the OK button
of the surrounding dialog shall be enabled and when pressed the vetoable
listener notified about the expected change from
PropertyEnv.STATE_NEEDS_VALIDATION
to PropertyEnv.STATE_VALID
which can either be accepted or vetoed.Modifier and Type | Field and Description |
---|---|
static String |
PROP_STATE
Name of the state property.
|
static Object |
STATE_INVALID
One possible value for the setState/getState methods.
|
static Object |
STATE_NEEDS_VALIDATION
One possible value for the setState/getState methods.
|
static Object |
STATE_VALID
One possible value for the setState/getState methods.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener l)
Property change listener: listenning here you will be notified
when the state of the environment is has been changed.
|
void |
addVetoableChangeListener(VetoableChangeListener l)
Vetoable change listener: listenning here you will be notified
when the state of the environment is being changed (when the setState
method is being called).
|
static PropertyEnv |
create(FeatureDescriptor fd,
Object... beans)
Creates a PropertyEnv instance for given feature descriptor (property)
and beans (nodes).
|
Object[] |
getBeans()
Array of beans that the edited property belongs to.
|
FeatureDescriptor |
getFeatureDescriptor()
Feature descritor that describes the property.
|
Object |
getState()
A getter for the current state of the environment.
|
void |
registerInplaceEditorFactory(InplaceEditor.Factory factory)
Register a factory for InplaceEditor instances that the property
sheet should use as an inline editor for the property.
|
void |
removePropertyChangeListener(PropertyChangeListener l)
Removes Property change listener.
|
void |
removeVetoableChangeListener(VetoableChangeListener l)
Vetoable change listener removal.
|
void |
setState(Object newState)
A setter that should be used by the property editor
to change the state of the environment.
|
String |
toString() |
public static final String PROP_STATE
public static final Object STATE_VALID
public static final Object STATE_NEEDS_VALIDATION
public static final Object STATE_INVALID
public static PropertyEnv create(FeatureDescriptor fd, Object... beans)
fd
- Feature descritor that describes the property.beans
- Objects that the edited property belongs to (typically its node).public Object[] getBeans()
public FeatureDescriptor getFeatureDescriptor()
public void setState(Object newState)
public Object getState()
public void addVetoableChangeListener(VetoableChangeListener l)
public void addPropertyChangeListener(PropertyChangeListener l)
public void removeVetoableChangeListener(VetoableChangeListener l)
public void removePropertyChangeListener(PropertyChangeListener l)
public void registerInplaceEditorFactory(InplaceEditor.Factory factory)
getValue(String)
.Node.Property
,
InplaceEditor