|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectARoad0.Gui1.SimplePropertyEditor
ARoad0.Gui1.CollectionPropertyEditor
public class CollectionPropertyEditor
This class is responsible for displaying and editing, by the mean of panels, one property of a gBase BaseObject for which the type is an array, a map or a collection.
It completes SimplePropertyEditor, which handles simple types, RightMapPropertyEditor for StringRight maps and StringRightPropertyEditor for unmodifiable String maps. It is not overridden. valueOf() is the only factory method to build up an instance. It is possible to get a reusable empty instance.
getCustomEditor() is used to display the property editor. The updating is done through a setValue() or an adding method. setAsText() throws an exception, and getAsText() returns a null value. This class handles the reading method, and for the updatings, it tries the 'ChoiceMethodForNew', first, 'add' and 'remove' methods, second, then the set method for the property. This class is returned by the XXXBeanInfo classes in gBase, in their property descriptors. It is used by Gui1.BeamerManager.addPropertyEditor(). The possible property types are String[], BaseObject[], ImmutableName[], StringRight[], java.util.Collection and java.util.Map, where the values of the Map or the Collection are BaseObjects, DetailledNames, Strings or Names. There are functionnal restrictions when the type is a Collection:
- StringRight is a forbidden type for the values,
and there are also functionnal restrictions with Map:
- only BaseObject is allowed as type for the values,
- the map is not displayed; only the values are,
- the 'add/select' and 'remove/delete' buttons are not workable.
When the type is String, it cannot use the remove method, only the write one. When the type is a subclass of BaseObject without being a DetailledName, the displayed list contains the names of the BaseObjects. This class extends the SimplePropertyEditor class which handles the types Boolean, String, ARoad0.gBase.ImmutableName and ARoad0.gBase.BaseObject. This class listens actions in two cases:
- from a JButton in the JComponent when the user enters data,
- from gBase objects (typically the source) when the program updates the property, through a PropertyChangeEvent about all the property or only ONE element.
To allow the user updating to make changes in the data base, this class instance edits the base object, then these changes are fired to the class instance to update the JComponent in the GUI. If the new value is an array or a collection, the GUI shows always the true data in the base. Otherwise, the new value is an array or a collection item, and the GUI is updated whitout any call to the base.
After an user click on a button in the JComponent, the sequence of calls is:
- actionPerformed() from the JButton,
- addElements(), addOneStringElement(), addRestrictedStringElements() or removeElements(), which calls to the data base object,
- propertyChange() from the object,
- updating of the JList in the JComponent.
After an InvocationTargetException, this class does not restore the true value in the editor. As a PropertyEditor, it registers PropertyChangeListeners but this is not recommanded so far - use rather registration on gBase PropertyChangeListeners.
SimplePropertyEditor
,
StringMapPropertyEditor
Field Summary | |
---|---|
protected java.lang.reflect.Method |
addMethod_
The add method if it exists, for the property. |
static CollectionPropertyEditor |
EMPTY_INSTANCE
A reusable empty instance for initialization, to avoid the use of 'new' for temporary values. |
(package private) javax.swing.DefaultListModel |
listModel_
The listModel_ of ImmutableNames for BaseObjects not being DetailledName, or Strings otherwise, in the JList which displays the collection |
protected int |
maxSize_
The maximal size which is allowed for this collection. |
protected boolean |
propertyIsArray_
True if the property is an array, false if it is a collection or a map |
protected java.lang.Class |
propertyTypeInGroup_
When the property type is a Collection or a Map, propertyTypeInGroup_ is set following the 'valueTypeInGroup' value in the BeanInfo. |
protected java.lang.reflect.Method |
removeMethod_
The remove method if it exists, for the property If it is non null, the writeMethod in 'super' may be still non null. |
protected javax.swing.JScrollPane |
scrollPane_
the scrollpane of the list |
Fields inherited from class ARoad0.Gui1.SimplePropertyEditor |
---|
boundComponent_, displayName_, EMPTY_OBJECT, INITIAL_CAPACITY, isRestrictedArgument_, listeners_, propertyDescriptor_, propertyType_, readMethod_, source_, sourceBeanInfo_, writeMethod_ |
Constructor Summary | |
---|---|
CollectionPropertyEditor()
Constructor for using only through the super.valueOf() method and EMPTY_INSTANCE. |
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent _evt)
Manages the events fired by the buttons 'See', 'New', 'Select', 'Remove', 'Delete', 'Previous' in the JPanel displayed in the beamer. |
private void |
addElement()
Called by actionPerformed() when the user clicks on the button 'New'. |
void |
addOneBaseObject(java.lang.Object[] _l_obj)
Called by BaseObjectHandler for addElement(), to add a BaseObject by the mean of the calling to a specific method on the right instance in the data base. |
private void |
addOneStringOrNameElements()
Called by addElement() when the user clicks on the button 'New' for adding one String or a Name value for a BaseObject. |
private void |
addRestrictedStringElements(java.lang.String[] _l_ACSlimitedValues)
This method displays to the user a list of allowed values which are not still selected. |
void |
finalizeForProcess()
Finalize the instance; the call is reserved to BeamerManager. |
java.lang.String |
getAsText()
Gets the property value as a string suitable for presentation to a human to edit. |
private javax.swing.JPanel |
getCollectionEditor()
This is the main method of this class, which gets the array, collection or map editor with the property name and the relevant buttons. |
java.awt.Component |
getCustomEditor()
Makes a full custom JPanel that edits the property value. |
java.awt.Dimension |
getPreferedSizeForEditing()
Get the prefered size for the rectangle into which the value is displayed, in the component returned by getCustomEditor(). |
java.lang.String[] |
getTags()
Overridden method. |
java.lang.Object |
getValue()
Gets the true values of the property, from the gBase instance, through the property descriptor in the relevant BeanInfo class. |
void |
handleNewBaseObject(java.lang.Object _obj)
Called by BaseObjectHandler for addElement(), when there is a new BaseObject instance which has been created by BaseObjectHandler, and which has to be added to the collection property. |
void |
handleSelectionDialog(java.util.Map _validatedObjectsSetMap)
Called by DialogBox.showExplorerSelectionDialog() for actionPerformed(), when the property is a Collection, a Map or an array, and the property type is a BaseObject which has to be selected in the explorer through the button 'Select'. |
private void |
handleSelectionUpdate(java.util.List _list)
Called by handleSelectionDialog() for actionPerformed() and directly by actionPerformed() for restricted values, when the property is a Collection, a Map or an array, and the property type is a BaseObject which has to be selected in the explorer through the button 'Select'. |
private void |
initializeListModel()
Called by getCollectionEditor() and getCustomEditor() to initialize the list model. |
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 has changed. |
private void |
removeElements(java.lang.Object[] _l_objectsToRemove,
java.lang.String _type)
This method calls the remove/delete method of the property. |
void |
removeOneBaseObject(java.lang.Object[] _l_obj)
NO USE. |
(package private) void |
removeWithSpecificMethod(BaseObject _objectToRemove)
Removes a BaseObject when writeMethod_ and finalizeForUser() do not exist. |
void |
setAsText(java.lang.String _text)
Sets the property value by parsing a given String. |
void |
setValue(java.lang.Object _value)
Set the object in the base through the write method. |
private boolean |
setValueControl(java.lang.Object _value)
Called by setValue() to control the parameter and the global variables. |
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 CollectionPropertyEditor is delegating to us. |
private void |
viewElement()
Called by actionPerformed() 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 |
Methods inherited from interface ARoad0.Gui1.AddRemoveBaseObjectListener |
---|
getSource |
Methods inherited from interface ARoad0.Gui1.NewBaseObjectListener |
---|
handleNewBaseObject |
Field Detail |
---|
javax.swing.DefaultListModel listModel_
protected boolean propertyIsArray_
protected java.lang.Class propertyTypeInGroup_
protected javax.swing.JScrollPane scrollPane_
protected java.lang.reflect.Method addMethod_
protected java.lang.reflect.Method removeMethod_
protected int maxSize_
public static final CollectionPropertyEditor EMPTY_INSTANCE
Constructor Detail |
---|
CollectionPropertyEditor()
Method Detail |
---|
public static CommonPropertyEditor valueOf(BaseObject _source, java.beans.PropertyDescriptor _propertyDescriptor) throws java.lang.NullPointerException, ProcessError
_source
- owning the property._propertyDescriptor
- is the descriptor of the property
java.lang.NullPointerException
- if _source or _displayName is null
ProcessError
- if BeanInfo and PropertyDecriptor calls failpublic java.lang.Object getValue()
getValue
in interface java.beans.PropertyEditor
getValue
in class SimplePropertyEditor
public java.lang.String getAsText()
getAsText
in interface java.beans.PropertyEditor
getAsText
in class SimplePropertyEditor
public void setAsText(java.lang.String _text) throws java.lang.IllegalArgumentException
setAsText
in interface java.beans.PropertyEditor
setAsText
in class SimplePropertyEditor
_text
- The string to be parsed.
java.lang.IllegalArgumentException
public void setValue(java.lang.Object _value)
setValue
in interface java.beans.PropertyEditor
setValue
in class SimplePropertyEditor
_value
- The java.util.Collection or Map to be edited.
This object is not modified by the PropertyEditor.public java.lang.String[] getTags()
getTags
in interface java.beans.PropertyEditor
getTags
in class SimplePropertyEditor
public java.awt.Component getCustomEditor()
getCustomEditor
in interface CommonPropertyEditor
getCustomEditor
in interface java.beans.PropertyEditor
getCustomEditor
in class SimplePropertyEditor
PropertyEditor.getCustomEditor()
public java.awt.Dimension getPreferedSizeForEditing()
getPreferedSizeForEditing
in interface CommonPropertyEditor
getPreferedSizeForEditing
in class SimplePropertyEditor
public void actionPerformed(java.awt.event.ActionEvent _evt)
actionPerformed
in interface java.awt.event.ActionListener
actionPerformed
in class SimplePropertyEditor
_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
propertyChange
in class SimplePropertyEditor
_evt
- with a new value which may be the new property value
(collection or array), and then the old value is not used, OR,
when the change is about only one element in the collection, map or the array,
it may be only ONE value to add or to remove in the collection or the array.public void addOneBaseObject(java.lang.Object[] _l_obj) throws ProcessError
addOneBaseObject
in interface AddRemoveBaseObjectListener
_l_obj
- is the BaseObject instance arguments to use
when the 'add' method is invoked
ProcessError
- if an InvocationTargetException is thrownpublic void removeOneBaseObject(java.lang.Object[] _l_obj) throws ProcessError
removeOneBaseObject
in interface AddRemoveBaseObjectListener
_l_obj
- is the BaseObject instance arguments to use
when the 'remove' method is invoked. May be null.
ProcessError
- if an InvocationTargetException is thrownpublic java.lang.String toString()
toString
in class SimplePropertyEditor
public void handleSelectionDialog(java.util.Map _validatedObjectsSetMap)
handleSelectionDialog
in interface SelectionDialogListener
handleSelectionDialog
in class SimplePropertyEditor
_validatedObjectsSetMap
- with one element, where
- the key is propertyTypeInGroup_,
- the value is a List of one selected object.
May be null or empty if the user cancels the operation.public void handleNewBaseObject(java.lang.Object _obj)
_obj
- is the BaseObject instance to add to this collectionpublic void finalizeForProcess()
finalizeForProcess
in interface CommonPropertyEditor
finalizeForProcess
in class SimplePropertyEditor
private boolean setValueControl(java.lang.Object _value)
_value
- is the parameter of the method setValue()
private void addElement()
Otherwise, the key 'choiceMethodForNew' is used to try to call a specific adding method from the BeanInfo class for the property, typically to create a Resource or an Eligible Party through the call of an gDMak.Action class.
If such a method does not exist, the key 'addMethod' is tested in the BeanInfo class for the property, to try to get the adding method.
If none of these tests gets any result, the BaseObject constructor is called.
In the two last cases (with an 'addMethod' or a constructor method), the BaseObjectHandler class is used to let the user enters the properties of the new BaseObject, and then to call the relevant method or contructor. Defined arguments may be set in the BeanInfo class for the property.
Stops all the actions on the beamer buttons until the ending of the method. No action and error message if there is no open ACS which manages AclEntries, for the creation of such an object.
Uses SimplePropertyEditor.getKnownValuesForNewElement() to get the defined arguments to use.
private void addOneStringOrNameElements()
private void addRestrictedStringElements(java.lang.String[] _l_ACSlimitedValues)
_l_ACSlimitedValues
- is the array of the allowed values. Never null.private void removeElements(java.lang.Object[] _l_objectsToRemove, java.lang.String _type)
1 - Uses the removing method if it exists. In this case, in the property descriptor, 'removeMethod' defines the removing method for the property. If 'removeMethod' is finalizeForUser() and _type is 'delete', it is used there to delete. Else, the removing method is a specific one which is returned by the property descriptor.
2 - otherwise, uses the writing method to update the collection with no direct use of finalizeForUser() on each element. Then, it is more general.
Caution: for Strings, the removing method cannot be used.
_l_objectsToRemove
- is the list of Strings or ImmutableNames
selected in the JList to be removed or deleted._type
- 'remove' for removing, or 'delete' for deletingvoid removeWithSpecificMethod(BaseObject _objectToRemove) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException
_objectToRemove
- is the object to remove which is associated to
a specific remove method. No operation if this object has not the right
property type.
thrown
- by Method.invoke(): ClassNotFoundException,
IllegalAccessException, InvocationTargetException, InstantiationException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
private void viewElement()
private javax.swing.JPanel getCollectionEditor()
private void initializeListModel()
private void handleSelectionUpdate(java.util.List _list)
_list
- contains the new selected objects
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |