65
66 /**
67 * Table-like controls (such as {@link TableView} and {@link TreeTableView}) are
68 * made up of zero or more instances of a concrete TableColumnBase subclass
69 * ({@link TableColumn} and {@link TreeTableColumn}, respectively). Each
70 * table column in a table is responsible for displaying (and editing) the contents
71 * of that column. As well as being responsible for displaying and editing data
72 * for a single column, a table column also contains the necessary properties to:
73 * <ul>
74 * <li>Be resized (using {@link #minWidthProperty() minWidth}/{@link #prefWidthProperty() prefWidth}/{@link #maxWidthProperty() maxWidth}
75 * and {@link #widthProperty() width} properties)
76 * <li>Have its {@link #visibleProperty() visibility} toggled
77 * <li>Display {@link #textProperty() header text}
78 * <li>Display any {@link #getColumns() nested columns} it may contain
79 * <li>Have a {@link #contextMenuProperty() context menu} when the user
80 * right-clicks the column header area
81 * <li>Have the contents of the table be sorted (using
82 * {@link #comparatorProperty() comparator}, {@link #sortable sortable} and
83 * sortType).
84 * </ul>
85 * </p>
86 *
87 * When instantiating a concrete subclass of TableColumnBase, perhaps the two
88 * most important properties to set are the column {@link #textProperty() text}
89 * (what to show in the column header area), and the column
90 * {@code cell value factory} (which is used to populate individual cells in the
91 * column). Refer to the class documentation for {@link TableColumn} and
92 * {@link TreeTableColumn} for more information.
93 *
94 * @param <S> The type of the UI control (e.g. the type of the 'row').
95 * @param <T> The type of the content in all cells in this table column.
96 * @see TableColumn
97 * @see TreeTableColumn
98 * @see TablePositionBase
99 * @since JavaFX 8.0
100 */
101 @IDProperty("id")
102 public abstract class TableColumnBase<S,T> implements EventTarget, Styleable {
103 static {
104 TableColumnBaseHelper.setTableColumnBaseAccessor(
105 new TableColumnBaseHelper.TableColumnBaseAccessor() {
388 * providing a default sort node.
389 *
390 * <p>The sort node is commonly seen represented as a triangle that rotates
391 * on screen to indicate whether the table column is part of the sort order,
392 * and if so, whether the sort is ascending or descending, and what position in
393 * the sort order it is in.
394 */
395 private ObjectProperty<Node> sortNode = new SimpleObjectProperty<Node>(this, "sortNode");
396 public final void setSortNode(Node value) { sortNodeProperty().set(value); }
397 public final Node getSortNode() { return sortNode.get(); }
398 public final ObjectProperty<Node> sortNodeProperty() { return sortNode; }
399
400
401 // --- Width
402 /**
403 * The width of this column. Modifying this will result in the column width
404 * adjusting visually. It is recommended to not bind this property to an
405 * external property, as that will result in the column width not being
406 * adjustable by the user through dragging the left and right borders of
407 * column headers.
408 */
409 public final ReadOnlyDoubleProperty widthProperty() { return width.getReadOnlyProperty(); }
410 public final double getWidth() { return width.get(); }
411 void setWidth(double value) { width.set(value); }
412 private ReadOnlyDoubleWrapper width = new ReadOnlyDoubleWrapper(this, "width", DEFAULT_WIDTH);
413
414
415 // --- Minimum Width
416 /**
417 * The minimum width the table column is permitted to be resized to.
418 */
419 private DoubleProperty minWidth;
420 public final void setMinWidth(double value) { minWidthProperty().set(value); }
421 public final double getMinWidth() { return minWidth == null ? DEFAULT_MIN_WIDTH : minWidth.get(); }
422 public final DoubleProperty minWidthProperty() {
423 if (minWidth == null) {
424 minWidth = new SimpleDoubleProperty(this, "minWidth", DEFAULT_MIN_WIDTH) {
425 @Override protected void invalidated() {
426 if (getMinWidth() < 0) {
427 setMinWidth(0.0F);
428 }
429
430 doSetWidth(getWidth());
431 }
432 };
433 }
434 return minWidth;
435 }
436
437
438 // --- Preferred Width
439 /**
440 * The preferred width of the TableColumn.
441 */
442 public final DoubleProperty prefWidthProperty() { return prefWidth; }
443 public final void setPrefWidth(double value) { prefWidthProperty().set(value); }
444 public final double getPrefWidth() { return prefWidth.get(); }
445 private final DoubleProperty prefWidth = new SimpleDoubleProperty(this, "prefWidth", DEFAULT_WIDTH) {
446 @Override protected void invalidated() {
447 doSetWidth(getPrefWidth());
448 }
449 };
450
451
452 // --- Maximum Width
453 // The table does not resize properly if this is set to Number.MAX_VALUE,
454 // so I've arbitrarily chosen a better, smaller number.
455 /**
456 * The maximum width the table column is permitted to be resized to.
457 */
458 public final DoubleProperty maxWidthProperty() { return maxWidth; }
459 public final void setMaxWidth(double value) { maxWidthProperty().set(value); }
460 public final double getMaxWidth() { return maxWidth.get(); }
461 private DoubleProperty maxWidth = new SimpleDoubleProperty(this, "maxWidth", DEFAULT_MAX_WIDTH) {
462 @Override protected void invalidated() {
463 doSetWidth(getWidth());
464 }
465 };
466
467
468 // --- Resizable
469 /**
470 * Used to indicate whether the width of this column can change. It is up
471 * to the resizing policy to enforce this however.
472 */
473 private BooleanProperty resizable;
474 public final BooleanProperty resizableProperty() {
475 if (resizable == null) {
476 resizable = new SimpleBooleanProperty(this, "resizable", true);
718 * {@link TreeTableColumn.CellDataFeatures TreeTableColumn} for more
719 * information).
720 *
721 * @param item The item (of type S) for which an ObservableValue<T> is
722 * sought.
723 * @return An ObservableValue<T> for this specific table column.
724 */
725 public abstract ObservableValue<T> getCellObservableValue(S item);
726
727 /** {@inheritDoc} */
728 @Override public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail) {
729 return tail.prepend(eventHandlerManager);
730 }
731
732 /**
733 * Registers an event handler to this table column. The TableColumnBase class allows
734 * registration of listeners which will be notified when editing occurs.
735 * Note however that TableColumnBase is <b>not</b> a Node, and therefore no visual
736 * events will be fired on it.
737 *
738 * @param eventType the type of the events to receive by the handler
739 * @param eventHandler the handler to register
740 * @throws NullPointerException if the event type or handler is null
741 */
742 public <E extends Event> void addEventHandler(EventType<E> eventType, EventHandler<E> eventHandler) {
743 eventHandlerManager.addEventHandler(eventType, eventHandler);
744 }
745
746 /**
747 * Unregisters a previously registered event handler from this table column. One
748 * handler might have been registered for different event types, so the
749 * caller needs to specify the particular event type from which to
750 * unregister the handler.
751 *
752 * @param eventType the event type from which to unregister
753 * @param eventHandler the handler to unregister
754 * @throws NullPointerException if the event type or handler is null
755 */
756 public <E extends Event> void removeEventHandler(EventType<E> eventType, EventHandler<E> eventHandler) {
757 eventHandlerManager.removeEventHandler(eventType, eventHandler);
758 }
759
760
761
762 /***************************************************************************
763 * *
764 * Private Implementation *
765 * *
766 **************************************************************************/
767
768 void doSetWidth(double width) {
769 setWidth(Utils.boundedSize(width, getMinWidth(), getMaxWidth()));
770 }
771
|
65
66 /**
67 * Table-like controls (such as {@link TableView} and {@link TreeTableView}) are
68 * made up of zero or more instances of a concrete TableColumnBase subclass
69 * ({@link TableColumn} and {@link TreeTableColumn}, respectively). Each
70 * table column in a table is responsible for displaying (and editing) the contents
71 * of that column. As well as being responsible for displaying and editing data
72 * for a single column, a table column also contains the necessary properties to:
73 * <ul>
74 * <li>Be resized (using {@link #minWidthProperty() minWidth}/{@link #prefWidthProperty() prefWidth}/{@link #maxWidthProperty() maxWidth}
75 * and {@link #widthProperty() width} properties)
76 * <li>Have its {@link #visibleProperty() visibility} toggled
77 * <li>Display {@link #textProperty() header text}
78 * <li>Display any {@link #getColumns() nested columns} it may contain
79 * <li>Have a {@link #contextMenuProperty() context menu} when the user
80 * right-clicks the column header area
81 * <li>Have the contents of the table be sorted (using
82 * {@link #comparatorProperty() comparator}, {@link #sortable sortable} and
83 * sortType).
84 * </ul>
85 *
86 * When instantiating a concrete subclass of TableColumnBase, perhaps the two
87 * most important properties to set are the column {@link #textProperty() text}
88 * (what to show in the column header area), and the column
89 * {@code cell value factory} (which is used to populate individual cells in the
90 * column). Refer to the class documentation for {@link TableColumn} and
91 * {@link TreeTableColumn} for more information.
92 *
93 * @param <S> The type of the UI control (e.g. the type of the 'row').
94 * @param <T> The type of the content in all cells in this table column.
95 * @see TableColumn
96 * @see TreeTableColumn
97 * @see TablePositionBase
98 * @since JavaFX 8.0
99 */
100 @IDProperty("id")
101 public abstract class TableColumnBase<S,T> implements EventTarget, Styleable {
102 static {
103 TableColumnBaseHelper.setTableColumnBaseAccessor(
104 new TableColumnBaseHelper.TableColumnBaseAccessor() {
387 * providing a default sort node.
388 *
389 * <p>The sort node is commonly seen represented as a triangle that rotates
390 * on screen to indicate whether the table column is part of the sort order,
391 * and if so, whether the sort is ascending or descending, and what position in
392 * the sort order it is in.
393 */
394 private ObjectProperty<Node> sortNode = new SimpleObjectProperty<Node>(this, "sortNode");
395 public final void setSortNode(Node value) { sortNodeProperty().set(value); }
396 public final Node getSortNode() { return sortNode.get(); }
397 public final ObjectProperty<Node> sortNodeProperty() { return sortNode; }
398
399
400 // --- Width
401 /**
402 * The width of this column. Modifying this will result in the column width
403 * adjusting visually. It is recommended to not bind this property to an
404 * external property, as that will result in the column width not being
405 * adjustable by the user through dragging the left and right borders of
406 * column headers.
407 * @return the width property
408 */
409 public final ReadOnlyDoubleProperty widthProperty() { return width.getReadOnlyProperty(); }
410 public final double getWidth() { return width.get(); }
411 void setWidth(double value) { width.set(value); }
412 private ReadOnlyDoubleWrapper width = new ReadOnlyDoubleWrapper(this, "width", DEFAULT_WIDTH);
413
414
415 // --- Minimum Width
416 /**
417 * The minimum width the table column is permitted to be resized to.
418 */
419 private DoubleProperty minWidth;
420 public final void setMinWidth(double value) { minWidthProperty().set(value); }
421 public final double getMinWidth() { return minWidth == null ? DEFAULT_MIN_WIDTH : minWidth.get(); }
422 public final DoubleProperty minWidthProperty() {
423 if (minWidth == null) {
424 minWidth = new SimpleDoubleProperty(this, "minWidth", DEFAULT_MIN_WIDTH) {
425 @Override protected void invalidated() {
426 if (getMinWidth() < 0) {
427 setMinWidth(0.0F);
428 }
429
430 doSetWidth(getWidth());
431 }
432 };
433 }
434 return minWidth;
435 }
436
437
438 // --- Preferred Width
439 /**
440 * The preferred width of the TableColumn.
441 * @return preferred width property
442 */
443 public final DoubleProperty prefWidthProperty() { return prefWidth; }
444 public final void setPrefWidth(double value) { prefWidthProperty().set(value); }
445 public final double getPrefWidth() { return prefWidth.get(); }
446 private final DoubleProperty prefWidth = new SimpleDoubleProperty(this, "prefWidth", DEFAULT_WIDTH) {
447 @Override protected void invalidated() {
448 doSetWidth(getPrefWidth());
449 }
450 };
451
452
453 // --- Maximum Width
454 // The table does not resize properly if this is set to Number.MAX_VALUE,
455 // so I've arbitrarily chosen a better, smaller number.
456 /**
457 * The maximum width the table column is permitted to be resized to.
458 * @return maximum width property
459 */
460 public final DoubleProperty maxWidthProperty() { return maxWidth; }
461 public final void setMaxWidth(double value) { maxWidthProperty().set(value); }
462 public final double getMaxWidth() { return maxWidth.get(); }
463 private DoubleProperty maxWidth = new SimpleDoubleProperty(this, "maxWidth", DEFAULT_MAX_WIDTH) {
464 @Override protected void invalidated() {
465 doSetWidth(getWidth());
466 }
467 };
468
469
470 // --- Resizable
471 /**
472 * Used to indicate whether the width of this column can change. It is up
473 * to the resizing policy to enforce this however.
474 */
475 private BooleanProperty resizable;
476 public final BooleanProperty resizableProperty() {
477 if (resizable == null) {
478 resizable = new SimpleBooleanProperty(this, "resizable", true);
720 * {@link TreeTableColumn.CellDataFeatures TreeTableColumn} for more
721 * information).
722 *
723 * @param item The item (of type S) for which an ObservableValue<T> is
724 * sought.
725 * @return An ObservableValue<T> for this specific table column.
726 */
727 public abstract ObservableValue<T> getCellObservableValue(S item);
728
729 /** {@inheritDoc} */
730 @Override public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail) {
731 return tail.prepend(eventHandlerManager);
732 }
733
734 /**
735 * Registers an event handler to this table column. The TableColumnBase class allows
736 * registration of listeners which will be notified when editing occurs.
737 * Note however that TableColumnBase is <b>not</b> a Node, and therefore no visual
738 * events will be fired on it.
739 *
740 * @param <E> The type of event
741 * @param eventType the type of the events to receive by the handler
742 * @param eventHandler the handler to register
743 * @throws NullPointerException if the event type or handler is null
744 */
745 public <E extends Event> void addEventHandler(EventType<E> eventType, EventHandler<E> eventHandler) {
746 eventHandlerManager.addEventHandler(eventType, eventHandler);
747 }
748
749 /**
750 * Unregisters a previously registered event handler from this table column. One
751 * handler might have been registered for different event types, so the
752 * caller needs to specify the particular event type from which to
753 * unregister the handler.
754 *
755 * @param <E> The type of event
756 * @param eventType the event type from which to unregister
757 * @param eventHandler the handler to unregister
758 * @throws NullPointerException if the event type or handler is null
759 */
760 public <E extends Event> void removeEventHandler(EventType<E> eventType, EventHandler<E> eventHandler) {
761 eventHandlerManager.removeEventHandler(eventType, eventHandler);
762 }
763
764
765
766 /***************************************************************************
767 * *
768 * Private Implementation *
769 * *
770 **************************************************************************/
771
772 void doSetWidth(double width) {
773 setWidth(Utils.boundedSize(width, getMinWidth(), getMaxWidth()));
774 }
775
|