105 /***************************************************************************
106 * *
107 * Constructor *
108 * *
109 **************************************************************************/
110
111 /**
112 * Creates a new NestedTableColumnHeader instance to visually represent the given
113 * {@link TableColumnBase} instance.
114 *
115 * @param skin The skin used by the UI control.
116 * @param tc The table column to be visually represented by this instance.
117 */
118 public NestedTableColumnHeader(final TableViewSkinBase skin, final TableColumnBase tc) {
119 super(skin, tc);
120
121 getStyleClass().setAll("nested-column-header");
122 setFocusTraversable(false);
123
124 // init UI
125 label = new TableColumnHeader(skin, getTableColumn());
126 label.setTableHeaderRow(getTableHeaderRow());
127 label.setParentHeader(getParentHeader());
128 label.setNestedColumnHeader(this);
129
130 if (getTableColumn() != null) {
131 changeListenerHandler.registerChangeListener(getTableColumn().textProperty(), e ->
132 label.setVisible(getTableColumn().getText() != null && ! getTableColumn().getText().isEmpty()));
133 }
134
135 changeListenerHandler.registerChangeListener(TableSkinUtils.columnResizePolicyProperty(skin), e -> updateContent());
136 }
137
138
139
140 /***************************************************************************
141 * *
142 * Listeners *
143 * *
144 **************************************************************************/
145
339
340 return width;
341 }
342
343 /** {@inheritDoc} */
344 @Override protected double computePrefHeight(double width) {
345 checkState();
346
347 double height = 0.0F;
348
349 if (getColumnHeaders() != null) {
350 for (TableColumnHeader n : getColumnHeaders()) {
351 height = Math.max(height, n.prefHeight(-1));
352 }
353 }
354
355 return height + label.prefHeight(-1) + snappedTopInset() + snappedBottomInset();
356 }
357
358 /**
359 * Creates a new TableColumnHeader instance for the given TableColumnBase instance. By default this method should
360 * not be overridden, but in some circumstances it makes sense (e.g. testing, or when extreme customization is desired).
361 * If the given TableColumnBase instance has child columns, then it is suggested to return a
362 * {@link NestedTableColumnHeader} instance instead.
363 *
364 * @return A new TableColumnHeader instance.
365 */
366 protected TableColumnHeader createTableColumnHeader(TableColumnBase col) {
367 return col.getColumns().isEmpty() ?
368 new TableColumnHeader(getTableViewSkin(), col) :
369 new NestedTableColumnHeader(getTableViewSkin(), col);
370 }
371
372
373
374 /***************************************************************************
375 * *
376 * Private Implementation *
377 * *
378 **************************************************************************/
379
380 @Override void setTableHeaderRow(TableHeaderRow header) {
381 super.setTableHeaderRow(header);
382
383 label.setTableHeaderRow(header);
384
385 // tell all children columns what TableHeader they belong to
386 for (TableColumnHeader c : getColumnHeaders()) {
387 c.setTableHeaderRow(header);
|
105 /***************************************************************************
106 * *
107 * Constructor *
108 * *
109 **************************************************************************/
110
111 /**
112 * Creates a new NestedTableColumnHeader instance to visually represent the given
113 * {@link TableColumnBase} instance.
114 *
115 * @param skin The skin used by the UI control.
116 * @param tc The table column to be visually represented by this instance.
117 */
118 public NestedTableColumnHeader(final TableViewSkinBase skin, final TableColumnBase tc) {
119 super(skin, tc);
120
121 getStyleClass().setAll("nested-column-header");
122 setFocusTraversable(false);
123
124 // init UI
125 label = createTableColumnHeader(getTableColumn());
126 label.setTableHeaderRow(getTableHeaderRow());
127 label.setParentHeader(getParentHeader());
128 label.setNestedColumnHeader(this);
129
130 if (getTableColumn() != null) {
131 changeListenerHandler.registerChangeListener(getTableColumn().textProperty(), e ->
132 label.setVisible(getTableColumn().getText() != null && ! getTableColumn().getText().isEmpty()));
133 }
134
135 changeListenerHandler.registerChangeListener(TableSkinUtils.columnResizePolicyProperty(skin), e -> updateContent());
136 }
137
138
139
140 /***************************************************************************
141 * *
142 * Listeners *
143 * *
144 **************************************************************************/
145
339
340 return width;
341 }
342
343 /** {@inheritDoc} */
344 @Override protected double computePrefHeight(double width) {
345 checkState();
346
347 double height = 0.0F;
348
349 if (getColumnHeaders() != null) {
350 for (TableColumnHeader n : getColumnHeaders()) {
351 height = Math.max(height, n.prefHeight(-1));
352 }
353 }
354
355 return height + label.prefHeight(-1) + snappedTopInset() + snappedBottomInset();
356 }
357
358 /**
359 * Creates a new TableColumnHeader instance for the given TableColumnBase instance. The general pattern for
360 * implementing this method is as follows:
361 *
362 * <ul>
363 * <li>If the given TableColumnBase instance is null, has no child columns, or if the given TableColumnBase
364 * instance equals the TableColumnBase instance returned by calling {@link #getTableColumn()}, then it is
365 * suggested to return a {@link TableColumnHeader} instance comprised of the given column.</li>
366 * <li>Otherwise, we can presume that the given TableColumnBase instance has child columns, and in this case
367 * it is suggested to return a {@link NestedTableColumnHeader} instance instead.</li>
368 * </ul>
369 *
370 * <strong>Note: </strong>In most circumstances this method should not be overridden, but in some circumstances it
371 * makes sense (e.g. testing, or when extreme customization is desired).
372 *
373 * @return A new TableColumnHeader instance.
374 */
375 protected TableColumnHeader createTableColumnHeader(TableColumnBase col) {
376 return col == null || col.getColumns().isEmpty() || col == getTableColumn() ?
377 new TableColumnHeader(getTableViewSkin(), col) :
378 new NestedTableColumnHeader(getTableViewSkin(), col);
379 }
380
381
382
383 /***************************************************************************
384 * *
385 * Private Implementation *
386 * *
387 **************************************************************************/
388
389 @Override void setTableHeaderRow(TableHeaderRow header) {
390 super.setTableHeaderRow(header);
391
392 label.setTableHeaderRow(header);
393
394 // tell all children columns what TableHeader they belong to
395 for (TableColumnHeader c : getColumnHeaders()) {
396 c.setTableHeaderRow(header);
|