org.tentackle.ui
Class FormComponentCellEditor

java.lang.Object
  extended by javax.swing.AbstractCellEditor
      extended by org.tentackle.ui.FormComponentCellEditor
All Implemented Interfaces:
Serializable, CellEditor, TableCellEditor, TreeCellEditor
Direct Known Subclasses:
FormFieldComponentCellEditor

public class FormComponentCellEditor
extends AbstractCellEditor
implements TableCellEditor, TreeCellEditor

Cell editor for FormComponents.
Provides cell editors for tables and trees.

Author:
harald
See Also:
Serialized Form

Field Summary
protected  int clickCountToStart
          number of clicks to start editing (default is 2)
protected  int column
          current column (table only)
protected  FormComponent editor
          the editor component
protected  boolean expanded
          true if cell is expanded (tree only)
protected  boolean leaf
          true if cell is a leaf node (tree only)
protected  int row
          current row (table and tree)
protected  boolean selected
          true if cell is selected (table only)
protected  FormTable table
          last table referenced
protected  FormTree tree
          last tree referenced
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
FormComponentCellEditor()
          Creates a cell-editor with a default editing component.
FormComponentCellEditor(FormComponent editorComponent)
          Creates a cell-editor from a FormComponent.
 
Method Summary
 void cancelCellEditing()
          Calls fireEditingCanceled.
 void clearInhibitCellTraversal()
          Clears inhibit if for some reason set erroneously
 void clearStartOver()
          clears the startOver flag
 Object getCellEditorValue()
          Gets the form value of the editor.
 int getClickCountToStart()
          Gets the number of clicks to start editing.
 FormComponent getEditorComponent()
          Gets the current editor component.
 FormTable getFormTable()
          Gets the table.
 FormComponent getTableCellEditorComponent(FormTable table, boolean selected, int row, int column)
          Returns the editor initialized for the table cell.
Does _not_ set the value.
 Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
          Sets an initial value for the editor.
 FormComponent getTreeCellEditorComponent(FormTree tree, boolean selected, boolean expanded, boolean leaf, int row)
          Returns the editor initialized for the tree cell.
Does _not_ set the value.
 Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
          Sets an initial value for the editor.
 void inhibitCellTraversal()
          Inhibits enter-key traversal once.
Useful if we should stay in selected field even after Enter-key has been pressed.
 boolean isAutoRowHeight()
          Returns whether auto row height is enabled.
 boolean isCellEditable(EventObject anEvent)
          Returns true.
 void prepare(FormTableEntry entry, int column)
          In some cases it is necessary to update celleditors before invocations of getTableCellEditorComponent(), especially if FormTableEntry.isCellEditorFixed()==true, which is the default.
protected  void prepareTableCellEditorComponent(FormTable table, boolean selected, int row, int column)
          Prepares the table cell editor.
protected  void prepareTreeCellEditorComponent(FormTree tree, boolean selected, boolean expanded, boolean leaf, int row)
          Prepares the tree cell editor.
 boolean requestFocusInWindow()
          Requests the focus of the editing component.
 void requestFocusLater()
          Requests the focus of the editing component as late as possible.
 void setAutoRowHeight(boolean autoRowHeight)
          Turns automatic adjustment of the row height on/off.
 void setClickCountToStart(int clicks)
          Sets the number of clicks to start editing.
 void setEditorComponent(FormComponent editor)
          Sets the editor Component.
 boolean shouldSelectCell(EventObject anEvent)
          Returns true.
 void startOver()
          Sets a flag that will inhibit stopCellEditing() once, i.e.
 boolean stopCellEditing()
          Calls fireEditingStopped and returns true.
 boolean wasEditingCanceled()
          Determines whether editing was stopped due to canceling.
 
Methods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, removeCellEditorListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.CellEditor
addCellEditorListener, removeCellEditorListener
 

Field Detail

table

protected FormTable table
last table referenced


tree

protected FormTree tree
last tree referenced


row

protected int row
current row (table and tree)


column

protected int column
current column (table only)


selected

protected boolean selected
true if cell is selected (table only)


expanded

protected boolean expanded
true if cell is expanded (tree only)


leaf

protected boolean leaf
true if cell is a leaf node (tree only)


editor

protected FormComponent editor
the editor component


clickCountToStart

protected int clickCountToStart
number of clicks to start editing (default is 2)

Constructor Detail

FormComponentCellEditor

public FormComponentCellEditor(FormComponent editorComponent)
Creates a cell-editor from a FormComponent.

Parameters:
editorComponent - the editor form component

FormComponentCellEditor

public FormComponentCellEditor()
Creates a cell-editor with a default editing component.

See Also:
StringFormField
Method Detail

setEditorComponent

public void setEditorComponent(FormComponent editor)
Sets the editor Component.

Parameters:
editor - the editor component

getEditorComponent

public FormComponent getEditorComponent()
Gets the current editor component.

Returns:
the editor component

setAutoRowHeight

public void setAutoRowHeight(boolean autoRowHeight)
Turns automatic adjustment of the row height on/off.

Parameters:
autoRowHeight - true to enable automatic row height, false if fixed

isAutoRowHeight

public boolean isAutoRowHeight()
Returns whether auto row height is enabled.

Returns:
true if automatic row height is active

startOver

public void startOver()
Sets a flag that will inhibit stopCellEditing() once, i.e. force the editing mode staying in the current field. Useful after error-messages. The flag will always be cleared during the next stopCellEditing().


clearStartOver

public void clearStartOver()
clears the startOver flag


inhibitCellTraversal

public void inhibitCellTraversal()
Inhibits enter-key traversal once.
Useful if we should stay in selected field even after Enter-key has been pressed. For ex. to disable wrapping to the next line if we are at end of line.


clearInhibitCellTraversal

public void clearInhibitCellTraversal()
Clears inhibit if for some reason set erroneously


wasEditingCanceled

public boolean wasEditingCanceled()
Determines whether editing was stopped due to canceling.

Returns:
true if editing was cancelled

requestFocusInWindow

public boolean requestFocusInWindow()
Requests the focus of the editing component.

Returns:
true if request will succeed, false if failed

requestFocusLater

public void requestFocusLater()
Requests the focus of the editing component as late as possible.


setClickCountToStart

public void setClickCountToStart(int clicks)
Sets the number of clicks to start editing. Default ist 2. (even for CheckBoxes!)

Parameters:
clicks - the number of clicks to start editing

getClickCountToStart

public int getClickCountToStart()
Gets the number of clicks to start editing.

Returns:
the number of clicks to start editing

getFormTable

public FormTable getFormTable()
Gets the table.

Returns:
the form table

isCellEditable

public boolean isCellEditable(EventObject anEvent)
Description copied from class: javax.swing.AbstractCellEditor
Returns true.

Specified by:
isCellEditable in interface CellEditor
Overrides:
isCellEditable in class AbstractCellEditor
Parameters:
anEvent - an event object
Returns:
true
See Also:
CellEditor.shouldSelectCell(java.util.EventObject)

shouldSelectCell

public boolean shouldSelectCell(EventObject anEvent)
Description copied from class: javax.swing.AbstractCellEditor
Returns true.

Specified by:
shouldSelectCell in interface CellEditor
Overrides:
shouldSelectCell in class AbstractCellEditor
Parameters:
anEvent - an event object
Returns:
true
See Also:
CellEditor.isCellEditable(java.util.EventObject)

stopCellEditing

public boolean stopCellEditing()
Description copied from class: javax.swing.AbstractCellEditor
Calls fireEditingStopped and returns true.

Specified by:
stopCellEditing in interface CellEditor
Overrides:
stopCellEditing in class AbstractCellEditor
Returns:
true

cancelCellEditing

public void cancelCellEditing()
Description copied from class: javax.swing.AbstractCellEditor
Calls fireEditingCanceled.

Specified by:
cancelCellEditing in interface CellEditor
Overrides:
cancelCellEditing in class AbstractCellEditor

prepare

public void prepare(FormTableEntry entry,
                    int column)
In some cases it is necessary to update celleditors before invocations of getTableCellEditorComponent(), especially if FormTableEntry.isCellEditorFixed()==true, which is the default.

FormTable will invoke prepare() *before* getTableCellEditorComponent() for every FormComponentCellEditor. The default implementation does nothing. Usually, the method will be overridden in a FormTableEntry like this:

   public TableCellEditor getCellEditor(int col) {
     return new MySpecialAppDbObjectCellEditor() {
       public void prepare(FormTableEntry entry, int column) {
         setContextDb(contextDb);
       }
     }
   }
 

Parameters:
entry - is the FormTableEntry the editor will edit some data of
column - is the column index (table-column)

getCellEditorValue

public Object getCellEditorValue()
Gets the form value of the editor.

Specified by:
getCellEditorValue in interface CellEditor
Returns:
the value contained in the editor

getTableCellEditorComponent

public FormComponent getTableCellEditorComponent(FormTable table,
                                                 boolean selected,
                                                 int row,
                                                 int column)
Returns the editor initialized for the table cell.
Does _not_ set the value. Useful for editors that can't use setFormValue())

Parameters:
table - the formtable
selected - true if cell is selected
row - the table row
column - the table column
Returns:
the editor component

getTableCellEditorComponent

public Component getTableCellEditorComponent(JTable table,
                                             Object value,
                                             boolean isSelected,
                                             int row,
                                             int column)
Description copied from interface: javax.swing.table.TableCellEditor
Sets an initial value for the editor. This will cause the editor to stopEditing and lose any partially edited value if the editor is editing when this method is called.

Returns the component that should be added to the client's Component hierarchy. Once installed in the client's hierarchy this component will then be able to draw and receive user input.

Specified by:
getTableCellEditorComponent in interface TableCellEditor
Parameters:
table - the JTable that is asking the editor to edit; can be null
value - the value of the cell to be edited; it is up to the specific editor to interpret and draw the value. For example, if value is the string "true", it could be rendered as a string or it could be rendered as a check box that is checked. null is a valid value
isSelected - true if the cell is to be rendered with highlighting
row - the row of the cell being edited
column - the column of the cell being edited
Returns:
the component for editing
Throws:
ClassCastException - if table is not a FormTable

getTreeCellEditorComponent

public FormComponent getTreeCellEditorComponent(FormTree tree,
                                                boolean selected,
                                                boolean expanded,
                                                boolean leaf,
                                                int row)
Returns the editor initialized for the tree cell.
Does _not_ set the value. Useful for editors that can't use setFormValue())

Parameters:
tree - the formtree
selected - true if cell is selected
expanded - if tree node is expanded
leaf - is node is a leaf node
row - the row index of the node being edited
Returns:
the editor component

getTreeCellEditorComponent

public Component getTreeCellEditorComponent(JTree tree,
                                            Object value,
                                            boolean isSelected,
                                            boolean expanded,
                                            boolean leaf,
                                            int row)
Description copied from interface: javax.swing.tree.TreeCellEditor
Sets an initial value for the editor. This will cause the editor to stopEditing and lose any partially edited value if the editor is editing when this method is called.

Returns the component that should be added to the client's Component hierarchy. Once installed in the client's hierarchy this component will then be able to draw and receive user input.

Specified by:
getTreeCellEditorComponent in interface TreeCellEditor
Parameters:
tree - the JTree that is asking the editor to edit; this parameter can be null
value - the value of the cell to be edited
isSelected - true if the cell is to be rendered with selection highlighting
expanded - true if the node is expanded
leaf - true if the node is a leaf node
row - the row index of the node being edited
Returns:
the component for editing
Throws:
ClassCastException - if tree is not a FormTree

prepareTableCellEditorComponent

protected void prepareTableCellEditorComponent(FormTable table,
                                               boolean selected,
                                               int row,
                                               int column)
Prepares the table cell editor.

Parameters:
table - the table
selected - true if cell is selected
row - the table row
column - the table column

prepareTreeCellEditorComponent

protected void prepareTreeCellEditorComponent(FormTree tree,
                                              boolean selected,
                                              boolean expanded,
                                              boolean leaf,
                                              int row)
Prepares the tree cell editor.

Parameters:
tree - the tree
selected - true if cell is selected
expanded - if tree node is expanded
leaf - is node is a leaf node
row - the row index of the node being edited


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de