org.jdesktop.swingx.table
Class DatePickerCellEditor

java.lang.Object
  extended by javax.swing.AbstractCellEditor
      extended by org.jdesktop.swingx.table.DatePickerCellEditor
All Implemented Interfaces:
Serializable, CellEditor, TableCellEditor, TreeCellEditor

public class DatePickerCellEditor
extends AbstractCellEditor
implements TableCellEditor, TreeCellEditor

A CellEditor using a JXDatePicker as editor component.

NOTE: this class will be moved!

See Also:
Serialized Form

Field Summary
protected  int clickCountToStart
           
protected  DateFormat dateFormat
           
protected  JXDatePicker datePicker
           
protected  boolean ignoreAction
           
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
DatePickerCellEditor()
          Instantiates a editor with the default dateFormat.
DatePickerCellEditor(DateFormat dateFormat)
          Instantiates an editor with the given dateFormat.
 
Method Summary
protected  boolean commitChange()
          Commits any pending edits and returns a boolean indicating whether the commit was successful.
protected  ActionListener createPickerActionListener()
          Creates and returns the ActionListener for the Picker.
 Date getCellEditorValue()
          Returns the pickers date.
 int getClickCountToStart()
          Returns the number of clicks needed to start editing.
 DateFormat[] getFormats()
           
protected  ActionListener getPickerActionListener()
          Returns the ActionListener to add to the datePicker.
 Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
          Sets an initial value for the editor.
 Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
          Sets an initial value for the editor.
protected  Date getValueAsDate(Object value)
          Returns the given value as Date.
protected  void handleParseException(ParseException e)
           
 boolean isCellEditable(EventObject anEvent)
          Returns true.
protected  boolean isEmpty(Object value)
           
 void setClickCountToStart(int count)
          Specifies the number of clicks needed to start editing.
 void setFormats(DateFormat... formats)
           
 boolean stopCellEditing()
          Calls fireEditingStopped and returns true.
 
Methods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, cancelCellEditing, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, removeCellEditorListener, shouldSelectCell
 
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, cancelCellEditing, removeCellEditorListener, shouldSelectCell
 

Field Detail

datePicker

protected JXDatePicker datePicker

dateFormat

protected DateFormat dateFormat

clickCountToStart

protected int clickCountToStart

ignoreAction

protected boolean ignoreAction
Constructor Detail

DatePickerCellEditor

public DatePickerCellEditor()
Instantiates a editor with the default dateFormat. PENDING: always override default from DatePicker?


DatePickerCellEditor

public DatePickerCellEditor(DateFormat dateFormat)
Instantiates an editor with the given dateFormat. If null, the datePickers default is used.

Parameters:
dateFormat -
Method Detail

getCellEditorValue

public Date getCellEditorValue()
Returns the pickers date. Note: the date is only meaningful after a stopEditing and before the next call to getTableCellEditorComponent.

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

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)

stopCellEditing

public boolean stopCellEditing()
Calls fireEditingStopped and returns true.

Overridden to commit pending edits. If commit successful, returns super, else returns false.

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

setClickCountToStart

public void setClickCountToStart(int count)
Specifies the number of clicks needed to start editing.

Parameters:
count - an int specifying the number of clicks needed to start editing
See Also:
getClickCountToStart()

getClickCountToStart

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

Returns:
the number of clicks needed to start editing

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

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 is the cell is to be renderer 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

getValueAsDate

protected Date getValueAsDate(Object value)
Returns the given value as Date. PENDING: abstract into something pluggable (like StringValue in ComponentProvider?)

Parameters:
value - the value to map as Date
Returns:
the value as Date or null, if not successful.

handleParseException

protected void handleParseException(ParseException e)
Parameters:
e -

isEmpty

protected boolean isEmpty(Object value)

commitChange

protected boolean commitChange()
Commits any pending edits and returns a boolean indicating whether the commit was successful.

Returns:
true if the edit was valid, false otherwise.

getFormats

public DateFormat[] getFormats()
Returns:
the DatePicker's formats.
See Also:
JXDatePicker.getFormats().

setFormats

public void setFormats(DateFormat... formats)
Parameters:
formats - the formats to use in the datepicker.
See Also:
JXDatePicker.setFormats(DateFormat...)

getPickerActionListener

protected ActionListener getPickerActionListener()
Returns the ActionListener to add to the datePicker.

Returns:
the action listener to listen for datePicker's action events.

createPickerActionListener

protected ActionListener createPickerActionListener()
Creates and returns the ActionListener for the Picker.

Returns:
the ActionListener to listen for Picker's action events.