ARoad0.Gui1
Class StringMapPropertyEditor

java.lang.Object
  extended by ARoad0.Gui1.SimplePropertyEditor
      extended by ARoad0.Gui1.StringMapPropertyEditor
All Implemented Interfaces:
CommonPropertyEditor, NewBaseObjectListener, SelectionDialogListener, MVC_Controller, MVC_View, java.awt.event.ActionListener, java.beans.PropertyChangeListener, java.beans.PropertyEditor, java.util.EventListener, javax.swing.event.ListSelectionListener
Direct Known Subclasses:
BaseObjectMapPropertyEditor, StringTwoKeysMapPropertyEditor

public class StringMapPropertyEditor
extends SimplePropertyEditor
implements javax.swing.event.ListSelectionListener

This class is responsible for displaying, by the mean of panels, a property map of a gBase BaseObject, for which the type is a map where keys are Strings and the values are only String arrays.

The map updating is never done through a write method or a 'choiceMethodForNew' in the property descriptor, but only through 'add/remove' methods set in the property descriptor. On the other hand, 'choiceMethodForNew' is used in super.getRestrictedValues() to get the constrained keys, if any.

The keys updating may be forbidden or constrained, and if this updating is allowed, the deleting of a key is always through the call of the removing method with a null value for each key to delete. The maximal number of constrained keys is 84.

The values updating may be constrained by a specific method which declares the allowed values. A maximal value may be defined for the number of map keys, through the property 'MaxSize'. Through the property 'MaxValueSize', a maximal value may be defined for the number of values in the map. The default maximal size for the keys set is 50, and 100 for the values set.

The updating of the keys and the values handles all the exceptions in the same way, like the superclass. A message is displayed to the user from the exception, and the map is reset through the call to the current value. So, the called gBase class may set in the updating methods how the exception impacts the current value. This class complements CollectionPropertyEditor, which handles more complex types but manages maps only as collections of values.

StringTwoKeysMapPropertyEditor is a subclass for handling two-parts, structured keys. AssociationMapPropertyEditor is its subclass and it creates associations to use as scripts calling the constuctors and methods in any gBase class.

BaseObjectMapPropertyEditor is a subclass for BaseObjects or ImmutableNames in the values. RightMapPropertyEditor is a subclass for StringRights in the values.

The getCustomEditor() method is the main method. This class is specified by some BeanInfo classes in gBase, for instance in their property descriptors for ACSFactory.SpecializedTypesAndExplorerSet, ACSImpl.m_TypesAndGUIPolicy and M_ContainerPolicy. This class is called by Gui1.BeamerManager.addPropertyEditor().

The unique property type is String, both for the keys and the values, but some methods are more general and they are used by the subclasses. This class is a PropertyEditor that gets, and listens the property in the relevant gBase instance, and edits the keys and the values. 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 gBase objects when the program updates the property. So, the GUI always DISPLAYS THE RIGHT DATA which is in the base. 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.

As a PropertyEditor, it must be able to register PropertyChangeListeners but this is not a feature to use so far. It uses only registration on gBase BoundBeans, that handle PropertyChangeListeners. In the same way, does not use the ActionEvents handling - add/removeActionListener() - in the JComponent property. An instance is constructed through the factory method valueOf() which calls the super valueOf() method, and it is possible to get a reusable empty instance. java.beans.PropertyEditorManager is not used. setValue(), setAsText() and getAsText() are not operational.


Field Summary
protected  java.lang.reflect.Method addMethod_
          The add method if it exists, for the property.
protected  javax.swing.JComponent boundComponentTwo_
          The values list that displays a bound property.
protected  javax.swing.JScrollPane keyScrollPane_
          The scrollpane that displays the keys list.
protected  javax.swing.DefaultListModel keysModel_
          The ListModel of Strings, in the JList which displays the keys
protected  boolean keysUpdateInMap_
          True if the key list may be updated.
protected  java.lang.reflect.Method limitedValuesMethod_
          The limited values method if it exists, for the property.
protected  int maxKeySize_
          The maximal size which is allowed for the keys set.
protected  int maxValueSize_
          The maximal size which is allowed for the values set.
protected  java.lang.Class propertyTypeInGroup_
          When the property type is a map (Map there), propertyTypeInGroup_ is the type of the elements in the arrays which are the map values.
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  java.lang.Class selectedTypeInGroup_
          When the property type is a map (Map there), selectedTypeInGroup_ is the type of the elements to select in the explorer.
protected  javax.swing.JScrollPane valueScrollPane_
          The scrollpane that displays the values list.
protected  javax.swing.DefaultListModel valuesModel_
          The ListModel of Strings, in the JList which displays the values
 
Fields inherited from class ARoad0.Gui1.SimplePropertyEditor
boundComponent_, displayName_, EMPTY_INSTANCE, EMPTY_OBJECT, INITIAL_CAPACITY, isRestrictedArgument_, listeners_, propertyDescriptor_, propertyType_, readMethod_, source_, sourceBeanInfo_, writeMethod_
 
Fields inherited from interface ARoad0.Gui1.CommonPropertyEditor
BOOLEAN_FIELD_DIMENSION, BOOLEAN_NAME_DIMENSION, BUTTON_DIMENSION, BUTTON_DIMENSION_2, BUTTON_DIMENSION_3, COLOMN_DIMENSION, COMBOBOX_FIELD_DIMENSION, EMPTY_FIELD_DIMENSION, HEIGHT_DIMENSION, INT_EMPTY_FIELD_DIMENSION, INT_FIELD_DIMENSION, LIST_HEIGHT_DIMENSION, LIST_WIDTH_DIMENSION, MAP_NAME_WIDTH_DIMENSION, NAME_DIMENSION, NAME_MAP_DIMENSION, NAME_WIDTH_DIMENSION, NAME_WIDTH_DIMENSION_2, NO_BUTTON_FIELD_DIMENSION, NO_BUTTON_WIDTH_DIMENSION, ONE_BUTTON_FIELD_DIMENSION, THREE_BUTTONS_FIELD_DIMENSION, TWO_BUTTONS_FIELD_DIMENSION
 
Constructor Summary
StringMapPropertyEditor()
          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 buttons 'New' and 'Delete' for the map keys, and 'Select', 'Remove' for the map values, in the JPanel displayed by getCustomEditor().
protected  void addKeyElement()
          Called by actionPerformed() when the user clicks on the button 'New' to add a new key in the map.
protected  void addRestrictedValueElements(java.lang.String _key)
          Called when the user clicks on the button 'Select' or 'NewV' to add a new value in the map, among the constrained values given by the property limitedValuesMethod_.
protected  void addValueElements(java.lang.Object[] _l_values)
          Adds some values in the map, from an user click on 'Select', 'NewV' or 'Prev.'.
 void changeDimensions()
          Updates the dimensions of the key and value panels.
private  void deleteKeyElements(java.lang.Object[] _l_keysToRemove)
          Deletes some selected keys in the map, from an user click on 'Delete'.
 void finalizeForProcess()
          Finalizes 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.
 java.awt.Component getCustomEditor()
          Return a full custom Component that edits its property value, with the relevant buttons following the property descriptor.
protected  int getMaximumValuesListSize()
          Called by the setPanelDimension method for the subclasses.
 void propertyChange(java.beans.PropertyChangeEvent _evt)
          Manages the events fired by the BaseObject source_, if it is a bound property and when the property value changes.
protected  void removeValueElements(java.lang.Object[] _l_valuesToRemove, boolean _toConfirm)
          Remove some selected values in the map, from an user click on 'Remove'.
 void setAsText(java.lang.String _text)
          Sets the property value by parsing a given String.
protected  void setKeysModel()
          Called by getCustomEditor(), propertyChange(), and the subclasses, to set the keys list, without database update.
 void setPanelDimension(boolean _keyButtons, boolean _valueButtons)
          Sets the two panels for the keys and the values lists.
 void setValue(java.lang.Object _value)
          No use.
protected  void setValuesModel(java.lang.String _key)
          Sets the values list in the JList of Objects, without database update.
 java.lang.String toString()
          Get the values of variables for the instance.
 void valueChanged(javax.swing.event.ListSelectionEvent _e)
          When a key is selected by the user in the beamer, displays the right values list.
static CommonPropertyEditor valueOf(BaseObject _source, java.beans.PropertyDescriptor _propertyDescriptor)
          Factory method to use when a StringMapPropertyEditor is delegating to us.
protected  void viewElement()
          Called by a subclass actionPerformed() method, when the user clicks on the button 'See'.
 
Methods inherited from class ARoad0.Gui1.SimplePropertyEditor
addPropertyChangeListener, getButtonsDisplaying, getDisplayName, getJavaInitializationString, getKnownValuesForNewElement, getNameFromDetailledName, getPreferedSizeForEditing, getPropertyDescriptor, getPropertyType, getRestrictedValues, getSource, getTags, getValue, getWriteMethod, handleNewBaseObject, handleSelectionDialog, isPaintable, paintValue, removePropertyChangeListener, setListPanelDimension, setVerticalButtonsInEditor, supportsCustomEditor, viewOneElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

propertyTypeInGroup_

protected java.lang.Class propertyTypeInGroup_
When the property type is a map (Map there), propertyTypeInGroup_ is the type of the elements in the arrays which are the map values.


selectedTypeInGroup_

protected java.lang.Class selectedTypeInGroup_
When the property type is a map (Map there), selectedTypeInGroup_ is the type of the elements to select in the explorer. Generally speaking, it is propertyTypeInGroup_, except for BaseObjectPropertyEditor when a BaseObject is selected to put its name in an array map value. This property is then equal to ImmutableName.


keysModel_

protected javax.swing.DefaultListModel keysModel_
The ListModel of Strings, in the JList which displays the keys


valuesModel_

protected javax.swing.DefaultListModel valuesModel_
The ListModel of Strings, in the JList which displays the values


boundComponentTwo_

protected javax.swing.JComponent boundComponentTwo_
The values list that displays a bound property. Used as boundComponent_ which is the keys list.


keyScrollPane_

protected javax.swing.JScrollPane keyScrollPane_
The scrollpane that displays the keys list.


valueScrollPane_

protected javax.swing.JScrollPane valueScrollPane_
The scrollpane that displays the values list.


addMethod_

protected java.lang.reflect.Method addMethod_
The add method if it exists, for the property. If it is non null, the writeMethod in 'super' may be still non null.


removeMethod_

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.


limitedValuesMethod_

protected java.lang.reflect.Method limitedValuesMethod_
The limited values method if it exists, for the property.


keysUpdateInMap_

protected boolean keysUpdateInMap_
True if the key list may be updated. If it is false, and if there is some updating methods, only the value list in the map may be updated for any key.


maxKeySize_

protected int maxKeySize_
The maximal size which is allowed for the keys set.


maxValueSize_

protected int maxValueSize_
The maximal size which is allowed for the values set.

Constructor Detail

StringMapPropertyEditor

StringMapPropertyEditor()
Constructor FOR USE ONLY through the valueOf() method, EMPTY_INSTANCE and the subclasses.

Method Detail

valueOf

public static CommonPropertyEditor valueOf(BaseObject _source,
                                           java.beans.PropertyDescriptor _propertyDescriptor)
                                    throws java.lang.NullPointerException,
                                           ProcessError
Factory method to use when a StringMapPropertyEditor is delegating to us.

It constructs the adding and removing methods for the property, from the BeanInfo information. From the same information, it uses 'KeysUpdateInMap' to allow the updating of keys. It uses also 'limitedValuesMethod' to construct the limited-values method which defines the set of the allowed values in any map value. This is the equivalent for values, of the SimplePropertyEditor work to set the limited-keys method from the property descriptor, with 'choiceMethodForNew'. The property must be a map. These 2 'limit' methods are also used by the subclasses of this class.

Called by BeamerManager.addPropertyEditor(). Overrides the SimplePropertyEditor method and calls it.

Parameters:
_source - owning the property.
_propertyDescriptor - is the descriptor of the property
Returns:
a StringMapPropertyEditor instance
Throws:
java.lang.NullPointerException - if _source or _displayName is null
ProcessError - if BeanInfo and PropertyDecriptor calls fail

setValue

public void setValue(java.lang.Object _value)
No use. Sets the map value.

Specified by:
setValue in interface java.beans.PropertyEditor
Overrides:
setValue in class SimplePropertyEditor
Parameters:
_value - The new target object to be edited. Note that this object is not modified by the PropertyEditor. May be null.

getAsText

public java.lang.String getAsText()
Gets the property value as a string suitable for presentation to a human to edit. Return null.

Specified by:
getAsText in interface java.beans.PropertyEditor
Overrides:
getAsText in class SimplePropertyEditor
Returns:
'null'

setAsText

public void setAsText(java.lang.String _text)
               throws java.lang.IllegalArgumentException
Sets the property value by parsing a given String. Raise java.lang.IllegalArgumentException, because this kind of property can't be expressed as text.

Specified by:
setAsText in interface java.beans.PropertyEditor
Overrides:
setAsText in class SimplePropertyEditor
Parameters:
_text - The string to be parsed.
Throws:
java.lang.IllegalArgumentException

getCustomEditor

public java.awt.Component getCustomEditor()
Return a full custom Component that edits its property value, with the relevant buttons following the property descriptor. Override the super method. Overridden in the RightMapPropertyEditor, but not in AssociationMapPropertyEditor and BaseObjectMapPropertyEditor. Called by BeamerManager.addPropertyEditor().

Specified by:
getCustomEditor in interface CommonPropertyEditor
Specified by:
getCustomEditor in interface java.beans.PropertyEditor
Overrides:
getCustomEditor in class SimplePropertyEditor
Returns:
a JPanel which contains one panel for the keys and their buttons, and one panel for the values and their buttons.
See Also:
PropertyEditor.getCustomEditor()

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent _evt)
Manages the events fired by the buttons 'New' and 'Delete' for the map keys, and 'Select', 'Remove' for the map values, in the JPanel displayed by getCustomEditor(). Overrides the super method. Overridden and called by the subclasses method.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Overrides:
actionPerformed in class SimplePropertyEditor
Parameters:
_evt - is the event fired by a button

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent _evt)
Manages the events fired by the BaseObject source_, if it is a bound property and when the property value changes. The main behavior is that the old and new property values in the argument are not ridden to update the values. This allow to process a PropertyChangeEvent that does not describe these values, but is fired by the gBase package when the relevant values are trully changed. The selected key is kept if possible. Manages the different pane dimensions which are required. Called by addRestrictedValueElements() when an exception is thrown by the method which gives the restricted values. Not overridden in the subclasses.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Overrides:
propertyChange in class SimplePropertyEditor
Parameters:
_evt - only source and property name in _evt are used in this method

changeDimensions

public void changeDimensions()
Updates the dimensions of the key and value panels. Called by propertyChange(). Overridden by the RightMapPropertyEditor subclass.


valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent _e)
When a key is selected by the user in the beamer, displays the right values list.

Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener
Parameters:
_e - from the key list

setPanelDimension

public void setPanelDimension(boolean _keyButtons,
                              boolean _valueButtons)
Sets the two panels for the keys and the values lists. Called by getCustomEditor(). Calls setListPanelDimension(). Overridden by AssociationMapPropertyEditor, but not by RightMapPropertyEditor.

Parameters:
_keyButtons - true if there is a vertical panel for key buttons.
_valueButtons - true if there is a vertical panel for value buttons.

toString

public java.lang.String toString()
Get the values of variables for the instance.

Overrides:
toString in class SimplePropertyEditor
Returns:
source, propertyName and listeners (if they have toString() methods).

finalizeForProcess

public void finalizeForProcess()
Finalizes the instance; the call is reserved to BeamerManager.

Specified by:
finalizeForProcess in interface CommonPropertyEditor
Overrides:
finalizeForProcess in class SimplePropertyEditor

setKeysModel

protected void setKeysModel()
Called by getCustomEditor(), propertyChange(), and the subclasses, to set the keys list, without database update. Controls the size. Caution: unregister this instance as ListSelectionListener of boundComponent_ before the call of this method, if it is outside getCustomEditor().


setValuesModel

protected void setValuesModel(java.lang.String _key)
Sets the values list in the JList of Objects, without database update. Controls the maximal size. Sets the scroll bar to right if it is not an AssociationMapPropertyEditor instance, for which the scroll bar is set to left. Called by getCustomEditor(), propertyChange(), valueChanged() and the subclasses.

Parameters:
_key - is a map key for the property. Clears the values if it is not a current key or if _key is null.

removeValueElements

protected void removeValueElements(java.lang.Object[] _l_valuesToRemove,
                                   boolean _toConfirm)
Remove some selected values in the map, from an user click on 'Remove'. Called by actionPerformed() and the same methods in the subclasses. Uses the 'remove' method to update the values for the current selected key.

Parameters:
_l_valuesToRemove - String or StringRight values to remove for the current selected key. Never null.
_toConfirm - true if the user has to confirm the removing

getMaximumValuesListSize

protected int getMaximumValuesListSize()
Called by the setPanelDimension method for the subclasses.

Returns:
the maximum size of the values list among the current keys

addKeyElement

protected void addKeyElement()
Called by actionPerformed() when the user clicks on the button 'New' to add a new key in the map. Noop if keysUpdateInMap_ is false. The key may be restricted or not, and to get it, it calls getRestrictedValues(). The maximal number of restricted keys is 111, since it is possible to display up to 4 lists of 28 items. There is a null argument if the source is not an ACSObject. The ACS of the source is used only if the source is an ACSObject, not for an ACSFActoryImpl for instance. Overridden in RightMapPropertyEditor and StringTwoKeysMapPropertyEditor, but not in BaseObjectMapPropertyEditor.


viewElement

protected void viewElement()
Called by a subclass actionPerformed() method, when the user clicks on the button 'See'. This is for the subclasses which handle BaseObjects and ImmutableNames as elementary items in the map values. This method selects a BaseObject in the explorer, and then it is displayed in the beamer. Copy of the same method in CollectionPropertyEditor. Call super.viewOneElement(). Called by RightMapPropertyEditor and BaseObjectPropertyEditor.


addValueElements

protected void addValueElements(java.lang.Object[] _l_values)
Adds some values in the map, from an user click on 'Select', 'NewV' or 'Prev.'. Controls the resulting array size and the current selection of a key. Called directly only by the subclasses BaseObjectMapPropertyEditor and RightMapPropertyEditor. Uses the 'add' method to update the values for the current selected key, and propertyTypeInGroup_ to define the correct type to handle. Called by addRestrictedValueElements() and BaseObjectMapPropertyEditor.actionPerformed().

Parameters:
_l_values - to add for the current selected key. Never null.

deleteKeyElements

private void deleteKeyElements(java.lang.Object[] _l_keysToRemove)
Deletes some selected keys in the map, from an user click on 'Delete'. Calls the removing method with a null value for each key to delete. Called by actionPerformed(), which is called by the subclasses. Noop if keysUpdateInMap_ is false.

Parameters:
_l_keysToRemove - map keys to remove with their associated values.

addRestrictedValueElements

protected void addRestrictedValueElements(java.lang.String _key)
Called when the user clicks on the button 'Select' or 'NewV' to add a new value in the map, among the constrained values given by the property limitedValuesMethod_. The type of the values is given by the BeanInfo. The values are get from the method sets by the property editor key 'limitedValuesMethod'. The values are limited to 66. There is no control of order in the selected values, until the call to the source from which an error message may be returned and displayed to the user. Called by actionPerformed() in this class, and in StringTwoKeysMapPropertyEditor, BaseObjectMapPropertyEditor. Overridden by AssociationMapPropertyEditor. Calls addValueElements().

Parameters:
_key - current selected key