Class SpreadsheetCellEditor

java.lang.Object
org.controlsfx.control.spreadsheet.SpreadsheetCellEditor
Direct Known Subclasses:
SpreadsheetCellEditor.DateEditor, SpreadsheetCellEditor.DoubleEditor, SpreadsheetCellEditor.IntegerEditor, SpreadsheetCellEditor.ListEditor, SpreadsheetCellEditor.ObjectEditor, SpreadsheetCellEditor.StringEditor, SpreadsheetCellEditor.TextAreaEditor

public abstract class SpreadsheetCellEditor extends Object
SpreadsheetCellEditor are used by SpreadsheetCellType and SpreadsheetCell in order to control how each value will be entered.

General behavior:

Editors will be displayed if the user double-click in an editable cell ( see SpreadsheetCell.setEditable(boolean) ).
If the user does anything outside the editor, the editor will be forced to try to commit the edition and close itself. If the value is not valid, the editor will cancel the value and close itself. The editor is just here to allow communication between the user and the SpreadsheetView. It will just be given a value, and it will just give back another one after. The policy regarding validation of a given value is defined in SpreadsheetCellType.match(Object). If the value doesn't meet the requirements when saving the cell, nothing happens and the editor keeps editing.
You can abandon a current modification by pressing "esc" key.
You can specify a maximum height to your spreadsheetCellEditor with getMaxHeight(). This can be used in order to control the display of your editor. If they should grow or not in a big cell. (for example a SpreadsheetCellEditor.TextAreaEditor want to grow with the cell in order to take full space for display.

Specific behavior:

This class offers some static classes in order to create a SpreadsheetCellEditor. Here are their properties:

Creating your editor:

You can of course create your own SpreadsheetCellEditor for displaying other controls.
You just have to override the four abstract methods. Remember that you will never call those methods directly. They will be called by the SpreadsheetView when needed.
  • startEdit(Object): You will configure your control with the given value which is SpreadsheetCell.getItem() converted to an object. You do not instantiate your control here, you do it in the constructor.
  • getEditor(): You will return which control you're using (for display).
  • getControlValue(): You will return the value inside your editor in order to submit it for validation.
  • end(): When editing is finished, you can properly close your own control.

Keep in mind that you will interact only with endEdit(boolean) where a true value means you want to commit, and a false means you want to cancel. The SpreadsheetView will handle all the rest for you and call your methods at the right moment.

Use case :

Use case of SpreadsheetCellEditor

Visual:

String
Screenshot of SpreadsheetCellEditor.StringEditor
List
Screenshot of SpreadsheetCellEditor.ListEditor
Double
Screenshot of SpreadsheetCellEditor.DoubleEditor
Date
Screenshot of SpreadsheetCellEditor.DateEditor
See Also:
  • Constructor Details

    • SpreadsheetCellEditor

      public SpreadsheetCellEditor(SpreadsheetView view)
      Construct the SpreadsheetCellEditor.
      Parameters:
      view -
  • Method Details

    • endEdit

      public final void endEdit(boolean b)
      Whenever you want to stop the edition, you call that method.
      True means you're trying to commit the value, then SpreadsheetCellType.convertValue(Object) will be called in order to verify that the value is correct.
      False means you're trying to cancel the value and it will be follow by end().
      See SpreadsheetCellEditor description
      Parameters:
      b - true means commit, false means cancel
    • startEdit

      public void startEdit(Object item)
      This method will be called when edition start.
      You will then do all the configuration of your editor.
      Parameters:
      item -
    • startEdit

      public abstract void startEdit(Object item, String format, Object... options)
      Does the same as startEdit(java.lang.Object) but you have also the SpreadsheetCell.getFormat() sent. This is useful when editing Date for example, when you want to display it with the cell format. Also options given by a Spreadsheetcell with SpreadsheetCell.getOptionsForEditor() are given.
      Parameters:
      item -
      format -
      options -
    • getEditor

      public abstract javafx.scene.control.Control getEditor()
      Return the control used for controlling the input. This is called at the beginning in order to display your control in the cell.
      Returns:
      the control used.
    • getControlValue

      public abstract String getControlValue()
      Return the value within your editor as a string. This will be used by the SpreadsheetCellType.convertValue(Object) in order to compute whether the value is valid regarding the SpreadsheetCellType policy.
      Returns:
      the value within your editor as a string.
    • end

      public abstract void end()
      This method will be called at the end of edition.
      You will be offered the possibility to do the configuration post editing.
    • getMaxHeight

      public double getMaxHeight()
      Return the maximum height of the editor.
      Returns:
      50 by default.