com.ccg.values
Class ValuesEditorBean

java.lang.Object
  extended by com.ccg.values.ValuesEditorAdapter
      extended by com.ccg.values.ValuesEditorBean
All Implemented Interfaces:
ValuesEditor, ValuesHolder

public class ValuesEditorBean
extends ValuesEditorAdapter

A 'generic' ValuesEditor implementation for bean style object.

The ValuesEditorBean provides a full working implementation of a ValuesEditor for ANY bean style. Currently, it provides editable fields for the following pairs of methods:

The following TYPES are supported:

You can control the appearance and behavior through a optional resource file (this is yet to be defined).

The following example defines a simple email bean (having name and email address properties), it also includes a main() method (and one supporting class) such that when you compile and run it, you will end up with a full graphical editor allowing you to add, delete, and modify a collection of objects stored on disk:


import com.ccg.values.*;

public class Email {

  //----------------------------------------------------------------
  // Construct a ValuesConfigBean with a default constructor so we can
  // make use of ValuesConfigModel.
  //----------------------------------------------------------------

  public static class ValuesConfigEmail extends ValuesConfigBean {
    public ValuesConfigEmail() { super(Email.class); }
  }

  public static void main(String[] args) {
                                // Create model for bean we want to edit
    ValuesConfigModel vcm = new ValuesConfigModel();
    vcm.setValuesConfigClass(ValuesConfigEmail.class);

                                // Construct a full editor (user will
                                // be able to add, delete, and change
                                // a collection of Email entries)
    ValuesConfigEditor vce = new ValuesConfigEditor();
    vce.setModel(vcm);
    vce.setEditor(new ValuesEditorBean(Email.class));
    vce.setButtons(ValuesConfigEditor.ALL_BUTTONS);
    vce.showDialog("Email List",true);
    System.exit(0);
  }

  public Email() { _Name=_Email="unknown"; }

  public String getName() { return _Name; }
  public void setName(String name) { if (name != null) _Name = name; }

  public String getEmail() { return _Email; }
  public void setEmail(String email) { if (email != null) _Email = email; }

  public String toString() { return _Name+" <"+_Email+'>'; }

  private String _Name;
  private String _Email;
}
 

It actually took less code to create a full GUI than the email example shown in the ValuesConfigBean class. When you compile and run the above, you should see a GUI editor similar to whats shown below:

ValuesEditorBean Example

This class provides a static main(java.lang.String[]) method which allows one to look at the editor created for any particular bean. It only shows the panel used to edit the contents of the bean for testing purposes (it doesn't providea a ValuesConfig implementation, and as such, you won't be to load/save/modify persistent instances of your bean class). However, this means you can try it out to see the default editor you would see for any bean style class. Try the following, and you should see an editor for many of the fields in a JButton object:

[pkb@salsa swing]$ java com.ccg.values.ValuesEditorBean javax.swing.JButton
[pkb@salsa swing]$ 
 

Since:
1.0
Version:
$Revision$
Author:
$Author$
See Also:
ValuesConfigBean

Field Summary
(package private)  Class _Class
           
(package private)  JComponent _Component
           
(package private)  JComponent[] _Fields
           
(package private)  Method[] _GetMethods
           
(package private)  Method[] _SetMethods
           
 
Fields inherited from interface com.ccg.values.ValuesHolder
HAS_FROM, HAS_TO, HAS_TO_FROM
 
Constructor Summary
ValuesEditorBean(Class c)
          Default constructor for the ValuesEditorBean class.
 
Method Summary
 Object createObjectInstance()
          Creates a new instance of a object (with default values set) which the editor is designed to work with.
 void fromObject(Object o)
          Transfer values from a object into this "value holder".
 JComponent getComponent()
          Get the Swing component which the user sees.
 Class getObjectClass()
          Get the Class which the "values holder" is designed to work with.
 void init(Lookup props)
          Set the properties to be used when constructing the visual component.
static void main(String[] args)
          Main entry point into the applications.
 void toObject(Object o)
          Transfer values from this "value holder" into a object.
 String toString()
          Get a simple string representation of the object.
 void validate()
          Verify that all of the user input fields are valid.
 
Methods inherited from class com.ccg.values.ValuesEditorAdapter
addChangeListener, checkArgument, fireChangeEvent, getCapabilities, getProxyChangeListener, getProxyDocumentListener, getProxyInputMethodListener, getProxyItemListener, getProxyListDataListener, getProxyTableModelListener, removeChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_Class

Class _Class

_Component

JComponent _Component

_SetMethods

Method[] _SetMethods

_GetMethods

Method[] _GetMethods

_Fields

JComponent[] _Fields
Constructor Detail

ValuesEditorBean

public ValuesEditorBean(Class c)
Default constructor for the ValuesEditorBean class.

Parameters:
c - Class which the editor should be used on - must not be null, and must have a public default constructor.
Since:
1.0
Method Detail

main

public static void main(String[] args)
Main entry point into the applications.

This method was stubbed in by default. You will want to either delete it entirely, or modify it to do something more useful.

Parameters:
args - Array of command line arguments.
Since:
1.0

toString

public String toString()
Get a simple string representation of the object.

Overrides:
toString in class Object
Returns:
Simple string representation of the object.
Since:
1.0

getObjectClass

public Class getObjectClass()
Get the Class which the "values holder" is designed to work with.

This method returns the Class which the "values holder" is designed to work with. All objects which are passed to the toObject or fromObject methods MUST be instances of this class.

Returns:
The class this "values holder" is designed to work with - never returns null.
Since:
1.0

toObject

public void toObject(Object o)
              throws IllegalStateException,
                     IllegalArgumentException,
                     UnsupportedOperationException,
                     NullPointerException
Transfer values from this "value holder" into a object.

This method transfers all of the values held into the object passed. It transfers ALL values if successful. It transfers ZERO values if a exception is thrown.

Throws:
NullPointerException - If you pass null.
IllegalArgumentException - If the object passed is not the proper type.
IllegalStateException - If the "values holder" isn't in the proper state to do the transfer.
UnsupportedOperationException - If the "value holder" doesn't implement the setting of values in the associated objects.
Since:
1.0
See Also:
fromObject(java.lang.Object)

fromObject

public void fromObject(Object o)
                throws IllegalStateException,
                       IllegalArgumentException,
                       UnsupportedOperationException,
                       NullPointerException
Transfer values from a object into this "value holder".

This method transfers all of the values of interest from the object passed into this "value holder". It transfers ALL values if successful. It transfers ZERO values if a exception is thrown.

Throws:
NullPointerException - If you pass null.
IllegalArgumentException - If the object passed is not the proper type.
IllegalStateException - If the object isn't in the proper state to do the transfer into this "values holder".
UnsupportedOperationException - If the "value holder" doesn't implement the getting of values from associated objects.
Since:
1.0
See Also:
toObject(java.lang.Object)

validate

public void validate()
              throws IllegalStateException
Verify that all of the user input fields are valid.

After allowing the user to modify the fields, it is often desirable to "validate" what the user has entered. This method checks the data entered by the user. If any of the user information looks bad, it throws an IllegalStateException.

Throws:
IllegalStateException - If any of the user input fields have invalid values contained which the user needs to fix prior to a commit.
Since:
1.0
See Also:
ValuesHolder.toObject(java.lang.Object)

getComponent

public JComponent getComponent()
                        throws IllegalStateException
Get the Swing component which the user sees.

All classes which implement this interface need to be able to create a GUI editor.

The first invocation triggers the "creation" of the component.

Multiple invocations will return a reference to the same component as returned by the first invocation.

Returns:
A graphical editor for the object - never returns null.
Throws:
IllegalStateException - If the object was not properly initialized.
Since:
1.0

createObjectInstance

public Object createObjectInstance()
Creates a new instance of a object (with default values set) which the editor is designed to work with.

This is method should ALWAYS be implemented when possible and is a requirement for the ValuesEditor implementation to be used in "factories".

Specified by:
createObjectInstance in interface ValuesEditor
Overrides:
createObjectInstance in class ValuesEditorAdapter
Returns:
Newly allocated and initialized object (should be suitable for either the fromObject or toObject implementation. Never returns null.
Since:
1.0

init

public void init(Lookup props)
Set the properties to be used when constructing the visual component.

Implementations may optionally implement this method (it doesn't need to do anything). It allows one to pass a set of properties which the implementation may optionally use when constructing its visual component.

The properties recognized (if any) are implementation dependent. Typically these properties include custom labels, tooltips, format rules, etc.

If this method is invoked (it is not required), it must be invoked prior to the invocation of the getComponent method (otherwise it would be too late now wouldn't it).

Specified by:
init in interface ValuesEditor
Overrides:
init in class ValuesEditorAdapter
Parameters:
props - Set of properties (implementation dependent) to initialize object with (must not be null).
Since:
1.0


Copyright 1998-1998-2006 null. All Rights Reserved.