|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectARoad0.Gui1.SimplePropertyEditor
public class SimplePropertyEditor
This class is responsible for displaying and editing the more simple properties in the gBase classes, by the mean of panels. The getCustomEditor() method is used then. This class is selected by the numerous XXXBeanInfo classes in gBase, in their property descriptors. It is used by Gui1.BeamerManager.addPropertyEditor().
The possible property types are boolean, int, String, ARoad0.gBase.ImmutableName and any ARoad0.gBase.BaseObject. Object is not an allowed type. This class is a PropertyEditor that gets, updates and listens the property in the relevant gBase instance. It has several subclasses. It is also a custom editor that provides getCustomEditor(), and specifies the prefered size of the panel to be displayed.
This instance listens actions from the JComponent property when the user enters data, and from gBase objects when the program updates the property. When the user updates make changes in the data base, this instance updates the base, then these changes are fired to this instance to update the JComponent in the GUI. So, the GUI always DISPLAYS THE RIGHT DATA which is in the base. After an user update, the sequence of calls is: - actionPerformed() from the JComponent, - setAsText() or setValue(), which updates the data base object, - propertyChange() from the object, with firing to the JComponent and before, unregisters this PropertyEditor as a JComponent listener, to avoid a loop. The updating handles all the exceptions in the same way. A message is displayed to the user from the exception, and the editor data is reset through the call to the current value. So, the called gBase class for the updating method may choose how the exception impacts the current value. Caution: the property sourceBeanInfo_ is initialized only when the property values are constrained.
As a PropertyEditor, it must be able to register PropertyChangeListeners but this is not a feature to use so far. Use only registration on gBase BoundBeans, that handle PropertyChangeListeners. In the same way, do not use the ActionEvents handling - add/removeActionListener() - in the JComponent property.
An instance is constructed through the factory method 'valueOf()'. This static constructor has to be called by all the subclasses, which have to be build up by an overriding version of this method. It is possible to get a reusable empty instance. java.beans.PropertyEditorManager is not used. When a String is entered in a JTextField, its length is limited to 200, to prevent any unauthorized input. A space is always added to the end of the string. For a boolean property, the editor may be a combobox with a specified text, or a checkbox to select to select yes/no simply. The right editor is get from the property descriptor in the BeanInfo class.
Field Summary | |
---|---|
protected javax.swing.JComponent |
boundComponent_
The component that displays a bound property in the beamer. |
protected java.lang.String |
displayName_
It is not the display name of the property, given by the property descriptor. |
static SimplePropertyEditor |
EMPTY_INSTANCE
A reusable empty instance for initialization, to avoid the use of 'new' for temporary values. |
protected static java.lang.Object |
EMPTY_OBJECT
An empty object for initialization |
protected static int |
INITIAL_CAPACITY
|
protected boolean |
isRestrictedArgument_
Is true if it is a constrained property that is not in the constructor. |
protected java.util.Vector |
listeners_
The listeners for property updates |
protected java.beans.PropertyDescriptor |
propertyDescriptor_
The property descriptor |
protected java.lang.Class |
propertyType_
The type of the property. |
protected java.lang.reflect.Method |
readMethod_
The read method if it exists, for the property |
protected BaseObject |
source_
The instance owning the property |
protected BeanInfoPattern |
sourceBeanInfo_
The BeanInfo instance associated to the source_. |
protected java.lang.reflect.Method |
writeMethod_
The write method if it exists, for the property |
Constructor Summary | |
---|---|
SimplePropertyEditor()
Constructor FOR USE ONLY through the valueOf() method, EMPTY_INSTANCE and the subclasses. |
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent _evt)
Manages the events fired by the components in the JPanel displayed in the beamer, returned by getCustomEditor(). |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener _listener)
Register a listener for the PropertyChange event - NO USE SO FAR. |
void |
finalizeForProcess()
Finalizes the instance. |
private void |
firePropertyChange()
Reports that we have been modified to any interested listeners - NOT USED SO FAR. |
java.lang.String |
getAsText()
Gets the property value as a string suitable for presentation to a human to edit. |
private javax.swing.JPanel |
getBooleanEditor()
Gets the boolean editor with the property name. |
protected boolean[] |
getButtonsDisplaying()
Gets the status of buttons: to display or not in the property editor, through a reading of the property descriptor. |
java.awt.Component |
getCustomEditor()
Returns a full custom Component that edits its property value, with the relevant buttons following the property descriptor. |
java.lang.String |
getDisplayName()
Gets the value of the display property name (not the true name, given by the property descriptor). |
private javax.swing.JPanel |
getGeneralEditor(java.lang.String _displayName,
java.lang.String _text,
boolean _withWriteMethod,
boolean _isBound,
boolean _isBaseObject)
Gets the editor with the property name when the property type is not boolean: int, String, ImmutableName or BaseObject. |
java.lang.String |
getJavaInitializationString()
This method is intended for use when generating Java code to set the value of the property. |
protected java.lang.Object[] |
getKnownValuesForNewElement()
Some constructor/add/copy arguments may be set as mandatory by the BeanInfo, and this method returns an array of these known values, at the right position for the arguments array to use. |
protected ImmutableName |
getNameFromDetailledName(java.lang.String _detailledName)
Uses the property source_ to get the name of an ACSObject from its detailled name. |
java.awt.Dimension |
getPreferedSizeForEditing()
Get the prefered size for the rectangle into which the value is displayed, in the component returned by getCustomEditor(). |
java.beans.PropertyDescriptor |
getPropertyDescriptor()
Gets the descriptor of the property. |
java.lang.Class |
getPropertyType()
Gets the value of the property type, that is the Class of the returned object in getValue(): boolean (not Boolean here), String, ImmutableName,. |
protected java.lang.String[] |
getRestrictedValues(ACS _acs)
Gets the restricted String values for the argument or the key. |
BaseObject |
getSource()
Gets the value of the property source. |
java.lang.String[] |
getTags()
When the value is a boolean, the tags are empty to indicate that a checkbox is required, excepted if a couple of tags is set in the property descriptor with the key 'tags', to indicate that a combobox with the tags is required. |
java.lang.Object |
getValue()
Gets the value of the property, from the gBase instance, through the property descriptor in the relevant BeanInfo class. |
java.lang.reflect.Method |
getWriteMethod()
Gets the method on the source for updates. |
void |
handleNewBaseObject(BaseObject _obj)
NO USE SO FAR. |
void |
handleSelectionDialog(java.util.Map _validatedObjectsSetMap)
Called by DialogBox.showExplorerSelectionDialogt() for actionPerformed(), when the property is a BaseObject which has been selected in the explorer. |
boolean |
isPaintable()
Determines whether the class will honor the paintValue method. |
void |
paintValue(java.awt.Graphics gfx,
java.awt.Rectangle box)
Paint a representation of the value into a given area of screen real estate. |
void |
propertyChange(java.beans.PropertyChangeEvent _evt)
Manages the events fired by the base object source_ displayed in the beamer, if it is a bound property and when the property value changes. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener _listener)
Remove a listener for the PropertyChange event - NO USE SO FAR. |
private void |
resetUpdate(java.lang.String _text)
Resets the update when the user enter is not correct, and display an error message. |
void |
setAsText(java.lang.String _text)
Sets the property value by parsing a given String. |
protected void |
setListPanelDimension(int _listSize,
javax.swing.JScrollPane _component,
boolean _largeWidth,
boolean _buttonPanel,
boolean _namePanel)
Called by RightMapPropertyEditor, CollectionPropertyEditor, StringMapPropertyEditor, AssociationMapPropertyEditor, to set the dimension of the list. |
void |
setValue(java.lang.Object _value)
Sets a new value. |
protected javax.swing.JPanel |
setVerticalButtonsInEditor(boolean[] _l_buttons,
boolean _forMapKey,
boolean _forMapValue)
Creates a vertical panel with the relevant buttons. |
boolean |
supportsCustomEditor()
Determines whether the propertyEditor can provide a custom editor. |
java.lang.String |
toString()
Get the values of variables for the instance. |
static CommonPropertyEditor |
valueOf(BaseObject _source,
java.beans.PropertyDescriptor _propertyDescriptor)
Factory method to use when a CommonPropertyEditor is delegating to us. |
protected void |
viewOneElement(java.lang.Object _toView)
Called when the user clicks on the button 'See'. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final int INITIAL_CAPACITY
protected java.lang.Class propertyType_
protected java.lang.String displayName_
protected BaseObject source_
protected java.beans.PropertyDescriptor propertyDescriptor_
protected javax.swing.JComponent boundComponent_
protected java.lang.reflect.Method readMethod_
protected java.lang.reflect.Method writeMethod_
protected java.util.Vector listeners_
protected boolean isRestrictedArgument_
protected BeanInfoPattern sourceBeanInfo_
protected static final java.lang.Object EMPTY_OBJECT
public static final SimplePropertyEditor EMPTY_INSTANCE
Constructor Detail |
---|
SimplePropertyEditor()
Method Detail |
---|
public static CommonPropertyEditor valueOf(BaseObject _source, java.beans.PropertyDescriptor _propertyDescriptor) throws java.lang.NullPointerException, ProcessError
_source
- owning the property, to update through setValue()
and to use for any events we fire._propertyDescriptor
- is the descriptor of the property
java.lang.NullPointerException
- if _source or _displayName is null
ProcessError
- if BeanInfo and PropertyDecriptor calls failpublic void setValue(java.lang.Object _value)
setValue
in interface java.beans.PropertyEditor
_value
- object to be edited. This
object is not modified by the PropertyEditor. May be null.public java.lang.Object getValue()
getValue
in interface java.beans.PropertyEditor
public java.lang.String getAsText()
getAsText
in interface java.beans.PropertyEditor
Returns "
public void setAsText(java.lang.String _text) throws java.lang.IllegalArgumentException
setAsText
in interface java.beans.PropertyEditor
_text
- is the string to be parsed.
if
- the argument is null, empty or not well matched.
java.lang.IllegalArgumentException
public BaseObject getSource()
getSource
in interface NewBaseObjectListener
public java.lang.String getDisplayName()
getDisplayName
in interface CommonPropertyEditor
public java.lang.Class getPropertyType()
getPropertyType
in interface CommonPropertyEditor
public java.beans.PropertyDescriptor getPropertyDescriptor()
getPropertyDescriptor
in interface CommonPropertyEditor
public java.lang.reflect.Method getWriteMethod()
getWriteMethod
in interface CommonPropertyEditor
public java.lang.String[] getTags()
getTags
in interface java.beans.PropertyEditor
public boolean supportsCustomEditor()
supportsCustomEditor
in interface java.beans.PropertyEditor
public java.awt.Component getCustomEditor()
getCustomEditor
in interface CommonPropertyEditor
getCustomEditor
in interface java.beans.PropertyEditor
PropertyEditor.getCustomEditor()
public java.lang.String getJavaInitializationString()
Example results are "2", "new Color(127,127,34)", "Color.orange", etc.
getJavaInitializationString
in interface java.beans.PropertyEditor
public java.awt.Dimension getPreferedSizeForEditing()
getPreferedSizeForEditing
in interface CommonPropertyEditor
public boolean isPaintable()
isPaintable
in interface java.beans.PropertyEditor
public void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box)
paintValue
in interface java.beans.PropertyEditor
gfx
- Graphics object to paint into.box
- Rectangle within graphics object into which we should paint.public void addPropertyChangeListener(java.beans.PropertyChangeListener _listener)
addPropertyChangeListener
in interface java.beans.PropertyEditor
_listener
- An object to be invoked when a PropertyChange
event is fired.public void removePropertyChangeListener(java.beans.PropertyChangeListener _listener)
removePropertyChangeListener
in interface java.beans.PropertyEditor
_listener
- The PropertyChange listener to be removed.public void actionPerformed(java.awt.event.ActionEvent _evt)
When a string is entered in a JTextField, its length is limited to 200. Then, after the user text, a space is added to the end of the string. When an integer is entered in a JTextField, its length is limited to 50. When a name is entered, this method checks its format and if it is wrong, it displays an error message and returns.
actionPerformed
in interface java.awt.event.ActionListener
_evt
- is the event fired by a JComboBox, a JCheckBox, a JTextField
or a JButton classpublic void propertyChange(java.beans.PropertyChangeEvent _evt)
propertyChange
in interface java.beans.PropertyChangeListener
_evt
- only source and property name in _evt are used in this methodpublic java.lang.String toString()
toString
in class java.lang.Object
public void handleSelectionDialog(java.util.Map _validatedObjectsSetMap)
handleSelectionDialog
in interface SelectionDialogListener
_validatedObjectsSetMap
- with one element, where
- the key is propertyType_,
- the value is a List of one selected object.
May be null or empty if the user cancels the operation.public void handleNewBaseObject(BaseObject _obj)
handleNewBaseObject
in interface NewBaseObjectListener
_obj
- is the BaseObject instance to set for this propertypublic void finalizeForProcess()
finalizeForProcess
in interface CommonPropertyEditor
protected java.lang.String[] getRestrictedValues(ACS _acs)
- 2 - uses the 'choiceMethodForNew' to call a method which returns a String array, a List or a Set of Strings, and this method is from a specified objet or from the source,
- 3 - from BaseUtilityImpl.getL_AcsRestrictedTypes() if there is a matching key.
For the subclasses of this class where the property is a map, this method is used only for the map keys, not for the map values. Called by actionPerformed() when the value has been entered by the user, CollectionPropertyEditor.addOneStringOrNameElements() and StringMapPropertyEditor.addKeyElement(). Calls BaseUtilityImpl.getL_AcsRestrictedStrings().
_acs
- is the new object ACS. Not null only for the third case with
BaseUtilityImpl.getL_AcsRestrictedTypes().
protected boolean[] getButtonsDisplaying()
setVerticalButtonsInEditor(boolean[], boolean, boolean)
protected javax.swing.JPanel setVerticalButtonsInEditor(boolean[] _l_buttons, boolean _forMapKey, boolean _forMapValue)
- _forMapKey and _forMapValue are not both true
- for collections, Select/Remove or New/Delete, but not together
- only New and Delete for map keys
- for map values, Select/Remove or NewV/DeletV, but not together
The returned value is sometimes used only to test if it is null. Called by CollectionPropertyEditor, StringMapPropertyEditor, RightMapPropertyEditor.
_l_buttons
- is an array of 9 booleans from getButtonsDisplaying()_forMapKey
- is true when the panel is for the buttons of the key
in a MapPropertyEditor. Only 'New' and 'Delete' buttons are relevant then._forMapValue
- is true when the panel is for the buttons of the value
in a MapPropertyEditor. 'New' and 'Delete' buttons are never relevant then.
getButtonsDisplaying()
protected void viewOneElement(java.lang.Object _toView)
_toView
- BaseObject to view, or ImmutableName of the BaseObject to view,
or String of DetailledName for an AclEntry or Privilege to view in the beamerprotected java.lang.Object[] getKnownValuesForNewElement()
In the property descritor, 'withKnownArgumentsForNew' allows to define the constructor arguments which has to be fixed - with 'choiceMethodForNew' or not, add method or not - when a new instance is created through the 'New' button.
First case for the fixed argument: the string 'this' is used to point to the object in the beamer; but this object is NOT get as argument if the 'this' index in the array is after the last specified argument for the constructor or the add method. Second case: search the right property descriptor in the beamer, and call the read method to initialize a l_fixedValue from this object. Third case for the fixed argument: the string 'thisname' is used to point to the value returned from getName() by the object in the beamer. Fourth case: the string 'true' or 'false' is used to define a boolean value. Fifth case, if none of the previous cases matches: takes directly the fixed argument if it is a String.
When the value of an argument is not determined, the returned array sets 'null'. The returned array may be shorter than the argument arrays for the new object. Called by actionPerformed() and CollectionPropertyEditor.addElements().
protected void setListPanelDimension(int _listSize, javax.swing.JScrollPane _component, boolean _largeWidth, boolean _buttonPanel, boolean _namePanel)
_listSize
- height of the list in _component_component
- is the scrollpane which contains the JList to display_largeWidth
- true to have a width equal to the beamer width,
as for CollectionPropertyEditor_buttonPanel
- true if there is a vertical panel for buttons,
for which the width is from CommonPropertyEditor.BUTTON_DIMENSION_2._namePanel
- false if the name of the property is not displayed,
and the panel is then larger.protected ImmutableName getNameFromDetailledName(java.lang.String _detailledName)
_detailledName
-
DetailledName
private javax.swing.JPanel getBooleanEditor()
private javax.swing.JPanel getGeneralEditor(java.lang.String _displayName, java.lang.String _text, boolean _withWriteMethod, boolean _isBound, boolean _isBaseObject)
_displayName
- of the property_text
- is the current value of the property, in a textual form_withWriteMethod
- true if the property may be updated through this editor_isBound
- true if the property may change (even if _withWriteMethod
is false)_isBaseObject
- true if the property type is a BaseObject. The 'View' button
is then displayed.
private void firePropertyChange()
private void resetUpdate(java.lang.String _text)
_text
- message that explains the error to the user
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |