com.ccg.values
Class ValuesConfigEditor

java.lang.Object
  extended by com.ccg.values.ValuesConfigEditor

public class ValuesConfigEditor
extends Object

Complete configuration/value editor for a ValuesEditor and ValuesConfig implementation.

This class builds a working "configuration editor" for use with a ValuesConfig and its corresponding ValuesEditor implemenation. It provides an alternative to the ValuesFactoryTree. It allows the user to do the following:

As the applications developer, you make use of this class in the following manner:

The following shows how simple this can be:

 import com.ccg.values.*;
 
 class Example {
        public static void foo(ValuesConfig vc, ValuesEditor ve) {
                ValuesConfigModel vcm = new ValuesConfigModel();
                vcm.setValuesConfigClass(vc.getClass());
 
                ValuesConfigEditor vce = new ValuesConfigEditor();
                vce.setModel(vcm);
                vce.setEditor(ve);
                vce.setButtons(ValuesConfigEditor.ALL_BUTTONS);
                vce.showDialog("Edit Config", true);
        }
 }
 

In addition, you can use this class as a test bed for any ValuesConfig/ValuesEditor implementation. For example, lets assume that you created a com.glatmos.ld.QueryDA class and then created a associated com.glatmos.ld.swing.QueryDAConfig (ValuesConfig implementation) and com.glatmos.ld.swing.QueryDAEditor (ValuesEditor implementation). You could use the following command line to verify that your config/editor implementations behaved properly:

  java com.ccg.values.ValuesConfigEditor \
    com.glatmos.ld.swing.QueryDAConfig \
    com.glatmos.ld.swing.QueryDAEditor
 

Since:
1.0
Version:
$Revision: 1.5 $
Author:
$Author: pkb $
See Also:
ValuesFactoryTree

Nested Class Summary
(package private)  class ValuesConfigEditor.Listener
           
 
Field Summary
static int ALL_BUTTONS
          Bit flag indicating that ALL buttons should be made available.
static int APPLY_BUTTON
          Bit flag indicating that a "Apply" button should be made available.
static String APPLY_NAME
          The constant name associated with the Apply button.
static int CANCEL_BUTTON
          Bit flag indicating that a "Cancel" button should be made available.
static String CANCEL_NAME
          The constant name associated with the Cancel button.
static int DELETE_BUTTON
          Bit flag indicating that a "Delete" button should be made available.
static String DELETE_NAME
          The constant name associated with the Delete button.
static int NEW_BUTTON
          Bit flag indicating that a "New" button should be made available.
static String NEW_NAME
          The constant name associated with the New button.
static int OK_BUTTON
          Bit flag indicating that a "OK" button should be made available.
static String OK_NAME
          The constant name associated with the Ok button.
static int REVERT_BUTTON
          Bit flag indicating that a "Revert" button should be made available.
static String REVERT_NAME
          The constant name associated with the Revert button.
 
Constructor Summary
ValuesConfigEditor()
           
 
Method Summary
 void addActionListener(ActionListener al)
          Allows one to monitor when buttons are pressed.
 int getButtons()
          Get the buttons (if any) that will be/have been created for the component.
 JComponent getComponent()
          Get the Swing component which the user interacts with to edit or view the configuration.
 ValuesEditor getEditor()
          Get the ValuesEditor which the user uses to adjust the values for a particular configuration.
 ValuesConfigModel getModel()
          Get the ValuesConfigModel used to select config choices from.
 Object getObject()
          Get the object which the config and edit implementations work with.
static void main(String[] args)
          Main entry point into the application.
 void removeActionListener(ActionListener al)
           
 void selectAndLoad(Object cfgname)
          Specify the configuration you want loaded, selected and ready to edit.
 void setButtons(int val)
          Set the buttons (if any) to be created for the component.
 void setEditor(ValuesEditor val)
          Set the ValuesEditor which the user uses to adjust the values for a particular configuration.
 void setModel(ValuesConfigModel val)
          Set the ValuesConfigModel used to select config choices from.
 void setObject(Object val)
          Set the object which the config and edit implementations work with.
 int showDialog(String title, boolean modal)
          Show a dialog box which allows the user to interract.
(package private)  void updateButtons()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL_BUTTONS

public static final int ALL_BUTTONS
Bit flag indicating that ALL buttons should be made available.

This constant can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get ALL of the available buttons (and their associated behaviors) added. This constant is the bitwise OR of: OK_BUTTON, CANCEL_BUTTON, APPLY_BUTTON, REVERT_BUTTON, DELETE_BUTTON, and NEW_BUTTON.

Since:
1.0
See Also:
setButtons(int), Constant Field Values

OK_BUTTON

public static final int OK_BUTTON
Bit flag indicating that a "OK" button should be made available.

This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "Ok" button on the panel - the actual label may be different, but the component name will ALWAYS be "ok" (incase you trap the action handler).

Since:
1.0
See Also:
setButtons(int), Constant Field Values

OK_NAME

public static final String OK_NAME
The constant name associated with the Ok button.

If you indicated that you wanted the Ok button available in your component (had the OK_BUTTON bit flag set in a call to #setButtons setButtons). You can use this constant name in your registered {@link ActionListener ActionListener} to tell when the user presses the Ok button. Here is a code fragment of how you might use this in your action listener:


 
  public void actionPerformed(ActionEvent ae) {
    Component c = (Component) ae.getSource();
    if (c.getName().equals(ValuesConfigEditor.OK_NAME)) {
      System.err.println("You pressed Ok");
    } else if (...
 

Since:
1.0
See Also:
setButtons(int), Constant Field Values

CANCEL_BUTTON

public static final int CANCEL_BUTTON
Bit flag indicating that a "Cancel" button should be made available.

This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "Cancel" button on the panel - the actual label may be different, but the component name will ALWAYS be "cancel" (incase you trap the action handler).

Since:
1.0
See Also:
setButtons(int), Constant Field Values

CANCEL_NAME

public static final String CANCEL_NAME
The constant name associated with the Cancel button.

If you indicated that you wanted the Cancel button available in your component (had the CANCEL_BUTTON bit flag set in a call to #setButtons setButtons). You can use this constant name in your registered {@link ActionListener ActionListener} to tell when the user presses the Cancel button. Here is a code fragment of how you might use this in your action listener:


 
  public void actionPerformed(ActionEvent ae) {
    Component c = (Component) ae.getSource();
    if (c.getName().equals(ValuesConfigEditor.CANCEL_NAME)) {
      System.err.println("You pressed Cancel");
    } else if (...
 

Since:
1.0
See Also:
setButtons(int), Constant Field Values

APPLY_BUTTON

public static final int APPLY_BUTTON
Bit flag indicating that a "Apply" button should be made available.

This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "Apply" button on the panel - the actual label may be different, but the component name will ALWAYS be "apply" (incase you trap the action handler).

Since:
1.0
See Also:
setButtons(int), Constant Field Values

APPLY_NAME

public static final String APPLY_NAME
The constant name associated with the Apply button.

If you indicated that you wanted the Apply button available in your component (had the APPLY_BUTTON bit flag set in a call to #setButtons setButtons). You can use this constant name in your registered {@link ActionListener ActionListener} to tell when the user presses the Apply button. Here is a code fragment of how you might use this in your action listener:


 
  public void actionPerformed(ActionEvent ae) {
    Component c = (Component) ae.getSource();
    if (c.getName().equals(ValuesConfigEditor.APPLY_NAME)) {
      System.err.println("You pressed Apply");
    } else if (...
 

Since:
1.0
See Also:
setButtons(int), Constant Field Values

REVERT_BUTTON

public static final int REVERT_BUTTON
Bit flag indicating that a "Revert" button should be made available.

This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "Revert" button on the panel - the actual label may be different, but the component name will ALWAYS be "revert" (incase you trap the action handler).

Since:
1.0
See Also:
setButtons(int), Constant Field Values

REVERT_NAME

public static final String REVERT_NAME
The constant name associated with the Revert button.

If you indicated that you wanted the Revert button available in your component (had the REVERT_BUTTON bit flag set in a call to #setButtons setButtons). You can use this constant name in your registered {@link ActionListener ActionListener} to tell when the user presses the Revert button. Here is a code fragment of how you might use this in your action listener:


 
  public void actionPerformed(ActionEvent ae) {
    Component c = (Component) ae.getSource();
    if (c.getName().equals(ValuesConfigEditor.REVERT_NAME)) {
      System.err.println("You pressed Revert");
    } else if (...
 

Since:
1.0
See Also:
setButtons(int), Constant Field Values

NEW_BUTTON

public static final int NEW_BUTTON
Bit flag indicating that a "New" button should be made available.

This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "New" button on the panel - the actual label may be different, but the component name will ALWAYS be "new" (incase you trap the action handler).

Since:
1.0
See Also:
setButtons(int), Constant Field Values

NEW_NAME

public static final String NEW_NAME
The constant name associated with the New button.

If you indicated that you wanted the New button available in your component (had the NEW_BUTTON bit flag set in a call to #setButtons setButtons). You can use this constant name in your registered {@link ActionListener ActionListener} to tell when the user presses the New button. Here is a code fragment of how you might use this in your action listener:


 
  public void actionPerformed(ActionEvent ae) {
    Component c = (Component) ae.getSource();
    if (c.getName().equals(ValuesConfigEditor.NEW_NAME)) {
      System.err.println("You pressed New");
    } else if (...
 

Since:
1.0
See Also:
setButtons(int), Constant Field Values

DELETE_BUTTON

public static final int DELETE_BUTTON
Bit flag indicating that a "Delete" button should be made available.

This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "Delete" button on the panel - the actual label may be different, but the component name will ALWAYS be "delete" (incase you trap the action handler).

Since:
1.0
See Also:
setButtons(int), Constant Field Values

DELETE_NAME

public static final String DELETE_NAME
The constant name associated with the Delete button.

If you indicated that you wanted the Delete button available in your component (had the DELETE_BUTTON bit flag set in a call to #setButtons setButtons). You can use this constant name in your registered {@link ActionListener ActionListener} to tell when the user presses the Delete button. Here is a code fragment of how you might use this in your action listener:


 
  public void actionPerformed(ActionEvent ae) {
    Component c = (Component) ae.getSource();
    if (c.getName().equals(ValuesConfigEditor.DELETE_NAME)) {
      System.err.println("You pressed Delete");
    } else if (...
 

Since:
1.0
See Also:
setButtons(int), Constant Field Values
Constructor Detail

ValuesConfigEditor

public ValuesConfigEditor()
Method Detail

setEditor

public void setEditor(ValuesEditor val)
Set the ValuesEditor which the user uses to adjust the values for a particular configuration.

Parameters:
val - New ValuesEditor value to assign - must not be null and can only be set one time.
See Also:
getEditor()

getEditor

public ValuesEditor getEditor()
Get the ValuesEditor which the user uses to adjust the values for a particular configuration.

Returns:
Current ValuesEditor value assigned.
See Also:
setEditor(com.ccg.values.ValuesEditor)

setModel

public void setModel(ValuesConfigModel val)
Set the ValuesConfigModel used to select config choices from.

NOTE: You can only set this once - you'll trigger a IllegalStateException if you try to set this twice.

Parameters:
val - ValuesConfigModel to associate with editor (must not be null).
See Also:
getModel()

getModel

public ValuesConfigModel getModel()
Get the ValuesConfigModel used to select config choices from.

Returns:
Current ValuesConfigModel value assigned.
See Also:
setModel(com.ccg.values.ValuesConfigModel)

setObject

public void setObject(Object val)
Set the object which the config and edit implementations work with.

Parameters:
val - New Object value to assign - you can pass null to force the next invocation of getObject to try and load a fresh copy.
See Also:
getObject()

selectAndLoad

public void selectAndLoad(Object cfgname)
                   throws ConfigException,
                          IOException
Specify the configuration you want loaded, selected and ready to edit.

This method can be used once the model AND editor have been set (the component need not be realized yet - though it doesn't hurt if it is). When you invoke this method, the following occurs:

Parameters:
cfgname - Name of configuration to load.
Throws:
ConfigException - If there was a problem with the configuration.
IOException - If there was an underlying I/O problem trying to load the configuration.
Since:
1.0

getObject

public Object getObject()
Get the object which the config and edit implementations work with.

Returns:
Current Object which is used for loading/editing (never returns null).
Throws:
IllegalStateException - If we needed to construct a new instance and the associated ValuesEditor was not yet set or not acceptable.
See Also:
setObject(java.lang.Object)

getComponent

public JComponent getComponent()
Get the Swing component which the user interacts with to edit or view the configuration.

This method retrieves the Swing component the user interacts with to edit/view the configuration(s). Before invoking this method, one should set the properties for the editor (or be faced with a IllegalStateException). At a minimum, you MUST set the config model and the editor. Most likely, you will also want to set what buttons should be included (as none are include by default).

This method returns the same value on subsequent calls.

This method is typically only used if you need to build up a custom component. Most developers will find that using the showDialog method is a simpler mechanism and will meet most needs.

Returns:
The config editor for the user to interact with - never returns null.
Throws:
IllegalStateException - If the object hasn't been properly initialized.
Since:
1.0
See Also:
showDialog(java.lang.String, boolean)

setButtons

public void setButtons(int val)
Set the buttons (if any) to be created for the component.

Note: it is illegal to attempt to change this if the component has already been realized via getComponent or the installation of action listeneners.

Parameters:
val - New int value to assign (set of bit flag constants).
See Also:
getButtons(), ALL_BUTTONS

getButtons

public int getButtons()
Get the buttons (if any) that will be/have been created for the component.

Returns:
Bit flags indicating what buttons were added.
See Also:
setButtons(int)

addActionListener

public void addActionListener(ActionListener al)
Allows one to monitor when buttons are pressed.

You can install any action listener here for the purpose of detecting when the user presses one of the standard buttons.

Parameters:
al - ActionListener to be installed - must not be null.
Since:
1.0

removeActionListener

public void removeActionListener(ActionListener al)

showDialog

public int showDialog(String title,
                      boolean modal)
Show a dialog box which allows the user to interract.

This method retrieves the GUI component and places it into a dialog box and then shows the dialog box to the user (allowing the user to edit the values contained).

This is probably the simplest means to make use of this class as it only involves initializing the object and then invoking this method. Refer to the getComponent documentation for what values MUST be set prior to using this method.

Parameters:
title - Title for dialog box - must not be null.
modal - true if you want a modal dialog, false if non-blocking (affects value of return code).
Returns:
0 if non-modal. CANCEL_BUTTON if user closed dialog without "ok" or "apply", OK_BUTTON if user closed dialog with "ok" button, APPLY_BUTTON if user applied changes and then closed window with "cancel" method.
Since:
1.0

main

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

Parameters:
args - Array of command line arguments.

updateButtons

void updateButtons()


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