Top Description Inners Fields Constructors Methods
org.controlsfx.control.spreadsheet

public abstract Class SpreadsheetCellType<T>

extends Object
Class Inheritance
Known Direct Subclasses
org.controlsfx.control.spreadsheet.SpreadsheetCellType.ObjectType, org.controlsfx.control.spreadsheet.SpreadsheetCellType.StringType, org.controlsfx.control.spreadsheet.SpreadsheetCellType.DoubleType, org.controlsfx.control.spreadsheet.SpreadsheetCellType.IntegerType, org.controlsfx.control.spreadsheet.SpreadsheetCellType.ListType, org.controlsfx.control.spreadsheet.SpreadsheetCellType.DateType
Imports
java.text.DecimalFormat, java.time.LocalDate, java.time.format.DateTimeFormatter, java.util.Collections, .List, javafx.util.StringConverter, javafx.util.converter.DefaultStringConverter, .DoubleStringConverter, .IntegerStringConverter

When instantiating a SpreadsheetCell, its SpreadsheetCellType will specify which values the cell can accept as user input, and which SpreadsheetCellEditor it will use to receive user input.
Different static methods are provided in order to give you access to basic types, and to create SpreadsheetCell easily:

Value verification

You can specify two levels of verification in your types.

Converter

You will have to specify a converter for your type. It will handle all the conversion between your real value type (Double, Integer, LocalDate etc) and its string representation for the cell.
You can either use a pre-built StringConverter or our StringConverterWithFormat. This one just add one method ( StringConverterWithFormat#toStringFormat(Object, String) which will convert your value with a String format (found in SpreadsheetCell#getFormat()).

Example

You can create several types which are using the same editor. Suppose you want to handle Double values. You will implement the createEditor(SpreadsheetView) method and use the SpreadsheetCellEditor.DoubleEditor.
Then for each type you will provide your own policy in match(Object) and in isError(Object), which most of the time will use your converter.
Here is an example of how to create a StringConverterWithFormat :

StringConverterWithFormat specialConverter = new StringConverterWithFormat<Double>(new DoubleStringConverter()) {
           @Override
            public String toString(Double item) {
                 //We just redirect to the other method.
                return toStringFormat(item, "");
            }

            @Override
            public String toStringFormat(Double item, String format) {
                if (item == null || Double.isNaN(item)) {
                    return missingLabel; // For example return something else that an empty cell.
                } else{
                    if (!("").equals(format) && !Double.isNaN(item)) {
                    //We format here the value
                        return new DecimalFormat(format).format(item);
                    } else {
                    //We call the DoubleStringConverter that we gave in argument
                        return myConverter.toString(item);
                    }
                }
            }

           @Override
            public Double fromString(String str) {
                if (str == null || str.isEmpty()) {
                    return Double.NaN;
                } else {
                    try {
                        //Just returning the value
                        Double myDouble = Double.parseDouble(str);
                        return myDouble;

                    } catch (NumberFormatException e) {
                        return myConverter.fromString(str);
                    }
                }
            }
        }

And then suppose you only want to accept double values between 0 and 100, and that a value superior to 10 is abnormal.
@Override
public boolean isError(Object value) {
    if (value instanceof Double) {
        if ((Double) value > 0 && (Double) value < 10) {
            return false;
        }
        return true;
    }
    return true;
}

@Override
public boolean match(Object value) {
    if (value instanceof Double) {
        return true;
    } else {
        try {
            Double convertedValue = converter.fromString(value == null ? null : value.toString());
            if (convertedValue >= 0 && convertedValue <= 100)
                return true;
            else
                return false;
        } catch (Exception e) {
            return false;
        }
    }
}
See Also
SpreadsheetView, SpreadsheetCellEditor, SpreadsheetCell

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
public static class
public static class
public static class
public static class

Field Summary

Modifier and TypeField and Description
protected StringConverter<T>
converter

An instance of converter from string to cell type.

public static final SpreadsheetCellType.DateType
DATE

The SpreadsheetCell LocalDate type instance.

public static final SpreadsheetCellType.DoubleType
DOUBLE

The SpreadsheetCell Double type instance.

public static final SpreadsheetCellType.IntegerType
INTEGER

The SpreadsheetCell Integer type instance.

public static final SpreadsheetCellType<Object>
OBJECT

The SpreadsheetCell Object type instance.

public static final SpreadsheetCellType.StringType
STRING

The SpreadsheetCell String type instance.

Constructor Summary

AccessConstructor and Description
public
SpreadsheetCellType()

Default constructor.

public
SpreadsheetCellType(StringConverter<T>
The converter to use
converter
)

Constructor with the StringConverter directly provided.

Method Summary

Modifier and TypeMethod and Description
public boolean
acceptDrop()

Returns: true if this SpreadsheetCellType accepts Objects to be dropped on the SpreadsheetCell.

public abstract T

Returns:

null if not valid or the correct value otherwise.
convertValue
(Object value)

This method will be called when a commit is happening.

public abstract SpreadsheetCellEditor

Returns:

the editor instance
createEditor
(SpreadsheetView
the spreadsheet that will own this editor
view
)

Creates an editor for this type of cells.

public boolean

Returns:

true if the value is an error.
isError
(Object value)

Returns true if the value is an error regarding the specification of its type.

public static final SpreadsheetCellType.ListType

Returns:

the instance
LIST
(final List<String>
the list items
items
)

Creates a ListType.

public boolean

Returns:

true if it matches.
match
(Object
the value to test
value
)

Verify that the upcoming value can be set to the current cell.

public abstract boolean

Returns:

true if it matches.
match
(Object
the value to test
value
,
Object... options)

Verify that the upcoming value can be set to the current cell.This is the first level of verification to prevent affecting a text to a double or a double to a date.

public String

Returns:

a string representation of the given item.
toString
(T object, String format)

Return a string representation of the given item for the SpreadsheetView to display using the inner SpreadsheetCellType#converter and the specified format.

public abstract String

Returns:

a string representation of the given item.
toString
(T object)

Return a string representation of the given item for the SpreadsheetView to display using the inner SpreadsheetCellType#converter.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait