ehsbe CommonsTM
Version 1.1.0rc3

com.ehsbe.commons.gui
Class EditorPanel<T>

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.ehsbe.commons.gui.JxTitledPanel
                      extended by com.ehsbe.commons.gui.EditorPanel<T>
Type Parameters:
T - the target, which the editor is able o handle
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public abstract class EditorPanel<T>
extends JxTitledPanel

A more or less sophisticated bean editor.

Version:
$Revision: 432 $
Author:
Jens Elkner
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  JPanel buttonPanel
          the panel, where control buttons are added
static String COMMIT_FAILED
          action command usually send on a failed commits of changes
static String COMMIT_PARTIAL_SUCCESS
          action command usually send if a commit was canceled
static String COMMIT_SUCCESS
          action command usually send on a successful commit of changes
protected  InitialContext ctx
          the context for the given target
static int HGAP
          default distance in pixels between a label and its input component
static int SEPGAP
          default additional distance in pixels to separate two lines of components
protected  T target
          the currently attached target
static int VGAP
          default distance in pixels between two lines of components
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
EditorPanel()
          Create a panel with a border layout.
EditorPanel(String title)
          Create a panel with a border layout.
 
Method Summary
 void addActionListener(ActionListener listener)
          Add the given listener to this component.
 void addButton(AbstractButton... button)
          Add the given button to the panels button area.
 void addDefaultButtons(ActionListener listener, String... cmds)
          Convinience method to lookup and add default actions and add an appropriate button to the button panel.
protected  boolean askForCommit()
          Show a GUI dialog, which ask the user, whether changed properties should be saved.
 void commit(boolean doCommit)
          Persist all changes to the target back to the datastore.
 void dispose()
          Release all allocated resources and close and dispose all evtl. fired dialogs, frames and threads.
protected  void fireActionPerformed(ActionEvent e)
          Fire the given event to all action listeners of this component.
protected  void fireActionPerformed(String commandName)
          Convinience method to fire an action event to all action listeners of this component.
 JPanel getButtonPanel()
          Get the panel used to layout dialog buttons.
abstract  String getRawName()
          Get the raw name of this panel.
 T getTarget()
          Get the currently set target
 boolean needCommit()
          Check, whether any changes have been made to the target and thus need to be commited back to the datastore.
 void removeActionListener(ActionListener listener)
          Remove the given listener from the internal listener list.
 void removeButton(AbstractButton button)
          Remove the given button from the button panel.
 void setButtonPanel(JPanel panel)
          Set the panel used to layout dialog buttons.
 void setTarget(T target, InitialContext ctx)
          Stores the target and context to be edit.
 
Methods inherited from class com.ehsbe.commons.gui.JxTitledPanel
getTitledBorder, setTitle, setTitledBorder
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

target

protected T target
the currently attached target


ctx

protected InitialContext ctx
the context for the given target


buttonPanel

protected JPanel buttonPanel
the panel, where control buttons are added


HGAP

public static final int HGAP
default distance in pixels between a label and its input component

See Also:
Constant Field Values

VGAP

public static final int VGAP
default distance in pixels between two lines of components

See Also:
Constant Field Values

SEPGAP

public static final int SEPGAP
default additional distance in pixels to separate two lines of components

See Also:
Constant Field Values

COMMIT_SUCCESS

public static final String COMMIT_SUCCESS
action command usually send on a successful commit of changes

See Also:
Constant Field Values

COMMIT_FAILED

public static final String COMMIT_FAILED
action command usually send on a failed commits of changes

See Also:
Constant Field Values

COMMIT_PARTIAL_SUCCESS

public static final String COMMIT_PARTIAL_SUCCESS
action command usually send if a commit was canceled

See Also:
Constant Field Values
Constructor Detail

EditorPanel

public EditorPanel()
Create a panel with a border layout.


EditorPanel

public EditorPanel(String title)
Create a panel with a border layout.

Parameters:
title - title to set
Method Detail

getRawName

public abstract String getRawName()
Get the raw name of this panel.

The name is usually used to lookup the i18n name for this editor (e.g. which is displayed in a JTab) or might be carefully used for identifying the editor.

Returns:
the raw name of this panel

askForCommit

protected boolean askForCommit()
Show a GUI dialog, which ask the user, whether changed properties should be saved.

Usually invoked by setTarget(T, javax.naming.InitialContext) before a new target gets set, if needCommit() returns true.

Returns:
true if properties have been changed and should be commited back to the backing store.

setTarget

public void setTarget(T target,
                      InitialContext ctx)
Stores the target and context to be edit.

Does nothing, if the given target has a reference to the target currently set. Otherwise it uses the needCommit() method, to determine, whether field values have been changed and asks for commit, if changes were made. After that it stores the new target and context and returns the control to the calling instance.

Parameters:
target - an editable target. If null, this is an indication, that the controller perhaps want this instance inform to commit all changes, if required.
ctx - context to use, if the editor needs more information.
See Also:
askForCommit(), getTarget(), ctx

getTarget

public T getTarget()
Get the currently set target

Returns:
the current target, which might be null
See Also:
setTarget(T, javax.naming.InitialContext)

needCommit

public boolean needCommit()
Check, whether any changes have been made to the target and thus need to be commited back to the datastore.

This gives the controller the opportunity to instruct commits before it disposes this instance.

Returns:
true if the target has been changed.

commit

public void commit(boolean doCommit)
Persist all changes to the target back to the datastore.

Parameters:
doCommit - if false, the values should not be commited to the backing datastore and the GUI controls should be reset to their inital values, so that a subsequent request to needCommit() return false as long as no new changes have been made after the reset.

dispose

public void dispose()
Release all allocated resources and close and dispose all evtl. fired dialogs, frames and threads. After a controller has called this method, this instance does not needed to work correctly anymore.

Per default it sets the references to the currently set target and context to null.


addDefaultButtons

public void addDefaultButtons(ActionListener listener,
                              String... cmds)
Convinience method to lookup and add default actions and add an appropriate button to the button panel.

The locale of this panel is used for i18n.

Parameters:
listener - listener to add to created buttons. Ignored if null.
cmds - commands to lookup. Ignored if null.
See Also:
ActionFactory.getDefaultAction(java.util.Locale, java.lang.String), JButton.JButton(javax.swing.Action), addButton(AbstractButton[])

addButton

public void addButton(AbstractButton... button)
Add the given button to the panels button area.

Parameters:
button - button to add. Ignored if null.

removeButton

public void removeButton(AbstractButton button)
Remove the given button from the button panel.

Parameters:
button - button to remove. Ignored if null.

getButtonPanel

public JPanel getButtonPanel()
Get the panel used to layout dialog buttons.

Returns:
a button panel.

setButtonPanel

public void setButtonPanel(JPanel panel)
Set the panel used to layout dialog buttons.

Parameters:
panel - a button panel. ignored if null.

addActionListener

public void addActionListener(ActionListener listener)
Add the given listener to this component.

Parameters:
listener - listener to add.

removeActionListener

public void removeActionListener(ActionListener listener)
Remove the given listener from the internal listener list.

Parameters:
listener - listener to remove

fireActionPerformed

protected void fireActionPerformed(String commandName)
Convinience method to fire an action event to all action listeners of this component. The generated action event has this instance as its source, the id 0 and the given commandName set as its action command.

Parameters:
commandName - the name of the action command in the generated action event.

fireActionPerformed

protected void fireActionPerformed(ActionEvent e)
Fire the given event to all action listeners of this component.

Parameters:
e - event to fire.

ehsbe CommonsTM
Version 1.1.0rc3

Copyright ©2005-2009 EHSBE, Walther-Rathenau-Str. 58, 39104 Magdeburg, Sachsen-Anhalt, Germany. All Rights Reserved.