Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jdesktop.swingx.treetable
Class TreeTableCellEditor

    java.lang.Object
      javax.swing.AbstractCellEditor
          javax.swing.DefaultCellEditor
              org.jdesktop.swingx.treetable.TreeTableCellEditor

All Implemented Interfaces:
  java.io.Serializable, javax.swing.CellEditor, javax.swing.table.TableCellEditor, javax.swing.tree.TreeCellEditor

    public class TreeTableCellEditor

extends javax.swing.DefaultCellEditor

An editor that can be used to edit the tree column. This extends DefaultCellEditor and uses a JTextField (actually, TreeTableTextField) to perform the actual editing.

To support editing of the tree column we can not make the tree editable. The reason this doesn't work is that you can not use the same component for editing and rendering. The table may have the need to paint cells, while a cell is being edited. If the same component were used for the rendering and editing the component would be moved around, and the contents would change. When editing, this is undesirable, the contents of the text field must stay the same, including the caret blinking, and selections persisting. For this reason the editing is done via a TableCellEditor.

Another interesting thing to be aware of is how tree positions its render and editor. The render/editor is responsible for drawing the icon indicating the type of node (leaf, branch...). The tree is responsible for drawing any other indicators, perhaps an additional +/- sign, or lines connecting the various nodes. So, the renderer is positioned based on depth. On the other hand, table always makes its editor fill the contents of the cell. To get the allusion that the table cell editor is part of the tree, we don't want the table cell editor to fill the cell bounds. We want it to be placed in the same manner as tree places it editor, and have table message the tree to paint any decorations the tree wants. Then, we would only have to worry about the editing part. The approach taken here is to determine where tree would place the editor, and to override the `reshape` method in the JTextField component to nudge the textfield to the location tree would place it. Since JXTreeTable will paint the tree behind the editor everything should just work. So, that is what we are doing here. Determining of the icon position will only work if the TreeCellRenderer is an instance of DefaultTreeCellRenderer. If you need custom TreeCellRenderers, that don't descend from DefaultTreeCellRenderer, and you want to support editing in JXTreeTable, you will have to do something similar.

Author:
  Scott Violet, Ramesh Gupta
See Also:
  Serialized Form

Nested Class Summary

Nested classes/interfaces inherited from class javax.swing.DefaultCellEditor
`javax.swing.DefaultCellEditor.EditorDelegate`

Field Summary

Fields inherited from class javax.swing.DefaultCellEditor
`clickCountToStart, delegate, editorComponent`

Fields inherited from class javax.swing.AbstractCellEditor
`changeEvent, listenerList`

Constructor Summary
`TreeTableCellEditor(javax.swing.JTree tree)`

Method Summary
`java.awt.Component` | `getTableCellEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int column)` Overriden to determine an offset that tree would place the editor at.
`protected void` | `initEditorOffset(javax.swing.JTable table, int row, int column, boolean isSelected)`
`boolean` | `isCellEditable(java.util.EventObject e)` This is overriden to forward the event to the tree.

Methods inherited from class javax.swing.DefaultCellEditor
`cancelCellEditing, getCellEditorValue, getClickCountToStart, getComponent, getTreeCellEditorComponent, setClickCountToStart, shouldSelectCell, stopCellEditing`

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`

Constructor Detail

### TreeTableCellEditor

    public TreeTableCellEditor(javax.swing.JTree tree)

Method Detail

### getTableCellEditorComponent

    public java.awt.Component getTableCellEditorComponent(javax.swing.JTable table,
                                                          java.lang.Object value,
                                                          boolean isSelected,
                                                          int row,
                                                          int column)

  Overriden to determine an offset that tree would place the editor at. The offset is determined from the `getRowBounds` JTree method, and additionaly from the icon DefaultTreeCellRenderer will use.

  The offset is then set on the TreeTableTextField component created in the constructor, and returned.

  Specified by:
    `getTableCellEditorComponent` in interface `javax.swing.table.TableCellEditor`
  Overrides:
    `getTableCellEditorComponent` in class `javax.swing.DefaultCellEditor`

### initEditorOffset

    protected void initEditorOffset(javax.swing.JTable table,
                                    int row,
                                    int column,
                                    boolean isSelected)

  Parameters:
    `row` -
    `isSelected` -

### isCellEditable

    public boolean isCellEditable(java.util.EventObject e)

  This is overriden to forward the event to the tree. This will return true if the click count >= clickCountToStart, or the event is null.

  Specified by:
    `isCellEditable` in interface `javax.swing.CellEditor`
  Overrides:
    `isCellEditable` in class `javax.swing.DefaultCellEditor`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2010. All Rights Reserved.