-
Notifications
You must be signed in to change notification settings - Fork 68
/
TableView.scala
445 lines (387 loc) · 17.3 KB
/
TableView.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/*
* Copyright (c) 2011-2015, ScalaFX Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ScalaFX Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE SCALAFX PROJECT OR ITS CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package scalafx.scene.control
import javafx.scene.{control => jfxsc}
import javafx.{collections => jfxc, event => jfxe, scene => jfxs, util => jfxu}
import scala.language.implicitConversions
import scalafx.Includes._
import scalafx.beans.property.{BooleanProperty, DoubleProperty, ObjectProperty, ReadOnlyObjectProperty}
import scalafx.collections.ObservableBuffer
import scalafx.delegate.SFXDelegate
import scalafx.delegate.SFXDelegate.delegateOrNull
import scalafx.scene.Node
/**
* $OBJCOMPSTA$TV$OBJCOMPEND
*
* @define OBJCOMPSTA Object companion for [[scalafx.scene.control
* @define OBJCOMPEND ]].
* @define JFX JavaFX
* @define SFX ScalaFX
* @define WRAPSTA Wraps a $JFX [[http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/
* @define WRAPEND ]].
* @define CONSSTA Creates a new $SFX
* @define CONSEND from its $JFX counterpart.
* @define CONSPARAM to be wrapped.
* @define TV TableView
* @define RF ResizeFeatures
* @define TVSM TableViewSelectionModel
* @define TVFM TableViewFocusModel
*/
object TableView {
/**
* Converts a ScalaFX $TV instance to its $JFX counterpart.
*
* @param tv ScalaFX $TV
* @return $JFX $TV
*/
implicit def sfxTableView2jfx[S](tv: TableView[S]): jfxsc.TableView[S] = delegateOrNull(tv)
/**
* Very simple resize policy that just resizes the specified column by the provided delta and
* shifts all other columns (to the right of the given column) further to the right (when the delta is positive)
* or to the left (when the delta is negative).
*
* It delegates to JavaFX
* [[https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableView.html#UNCONSTRAINED_RESIZE_POLICY UNCONSTRAINED_RESIZE_POLICY]]
*/
val UnconstrainedResizePolicy = jfxsc.TableView.UNCONSTRAINED_RESIZE_POLICY
/**
* Simple policy that ensures the width of all visible leaf columns in this table sum up to equal
* the width of the table itself.
* When the user resizes a column width with this policy, the table automatically adjusts the width of the right
* hand side columns. When the user increases a column width, the table decreases the width of the rightmost column
* until it reaches its minimum width.
* Then it decreases the width of the second rightmost column until it reaches minimum width and so on.
* When all right hand side columns reach minimum size, the user cannot increase the size of resized column any more.
*
* It delegates to JavaFX [[https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableView.html#CONSTRAINED_RESIZE_POLICY CONSTRAINED_RESIZE_POLICY]]
*/
val ConstrainedResizePolicy = jfxsc.TableView.CONSTRAINED_RESIZE_POLICY
/**
* $OBJCOMPSTA$TV.$RF$OBJCOMPEND
*/
object ResizeFeatures {
/**
* Converts a ScalaFX ResizeFeatures instance to its JavaFX counterpart.
*
* @param rf ScalaFX ResizeFeatures
* @return JavaFX ResizeFeatures
*/
implicit def sfxResizeFeatures2jfx[S](rf: ResizeFeatures[S]): jfxsc.TableView.ResizeFeatures[S] = delegateOrNull(rf)
}
/**
* $WRAPSTA$TV.$RF.html $RF$WRAPEND
*
* @constructor $CONSSTA $RF $CONSEND
* @param delegate $JFX $RF $CONSPARAM
*/
class ResizeFeatures[S](override val delegate: jfxsc.TableView.ResizeFeatures[S])
extends ResizeFeaturesBase[S](delegate)
with SFXDelegate[jfxsc.TableView.ResizeFeatures[S]] {
/**
* Creates an instance of this class, with the provided TableView, TableColumn and delta
* values being set and stored in this immutable instance.
*
* @param table The TableView upon which the resize operation is occurring.
* @param column The column upon which the resize is occurring, or `null` if this
* `ResizeFeatures` instance is being created as a result of a TableView resize operation.
* @param delta The amount of horizontal space added or removed in the resize operation.
*/
def this(table: TableView[S], column: TableColumn[S, _], delta: Double) =
this(new jfxsc.TableView.ResizeFeatures(table, column, delta))
/**
* Returns the column upon which the resize is occurring, or `null` if this
* `ResizeFeatures` instance was created as a result of a TableView resize operation.
*/
def table: TableView[S] = delegate.getTable
}
/**
* $OBJCOMPSTA$TV.$TVSM$OBJCOMPEND
*/
object TableViewSelectionModel {
/**
* Converts a ScalaFX TableViewSelectionModel instance to its JavaFX counterpart.
*
* @param tvsm ScalaFX TableViewSelectionModel
* @return JavaFX TableViewSelectionModel
*/
implicit def sfxTableViewSelectionModel2jfx[S](tvsm: TableViewSelectionModel[S]): jfxsc.TableView.TableViewSelectionModel[S] =
delegateOrNull(tvsm)
}
/**
* $WRAPSTA$TV.$TVSM.html $TVSM$WRAPEND
*
* @constructor $CONSSTA $TVSM $CONSEND
* @param delegate $JFX $TVSM $CONSPARAM
*/
abstract class TableViewSelectionModel[S](override val delegate: jfxsc.TableView.TableViewSelectionModel[S])
extends TableSelectionModel[S](delegate)
with SFXDelegate[jfxsc.TableView.TableViewSelectionModel[S]] {
/**
* Clears all selection, and then selects the cell at the given row/column intersection.
*/
def clearAndSelect(row: Int, column: TableColumn[S, _]) {
delegate.clearAndSelect(row, delegateOrNull(column))
}
/**
* Removes selection from the specified row/column position (in view indexes).
*/
def clearSelection(row: Int, column: TableColumn[S, _]) {
delegate.clearSelection(row, delegateOrNull(column))
}
def focusedIndex: Int = delegate.getFocusedIndex
/**
* A read-only ObservableList representing the currently selected cells in this TableView.
*/
def selectedCells: ObservableBuffer[TablePosition[_, _]] =
ObservableBuffer(delegate.getSelectedCells.map(jtp => new TablePosition(jtp)))
/**
* Returns the TableView instance that this selection model is installed in.
*/
def tableView: TableView[S] = delegate.getTableView
/**
* Selects the cell at the given row/column intersection.
*/
def select(row: Int, column: TableColumn[S, _]) {
delegate.select(row, delegateOrNull(column))
}
/**
* Selects the cell at the given row/column intersection.
*/
def isSelected(row: Int, column: TableColumn[S, _]): Boolean =
delegate.isSelected(row, delegateOrNull(column))
}
/**
* $OBJCOMPSTA$TV.$TVFM$OBJCOMPEND
*/
object TableViewFocusModel {
/**
* Converts a ScalaFX TableViewFocusModel instance to its JavaFX counterpart.
*
* @param tvfm ScalaFX TableViewFocusModel
* @return JavaFX TableViewFocusModel
*/
implicit def sfxTableViewFocusModel2jfx[S](tvfm: TableViewFocusModel[S]): jfxsc.TableView.TableViewFocusModel[S] =
delegateOrNull(tvfm)
}
/**
* $WRAPSTA$TV.$TVFM.html $TVFM$WRAPEND
*
* @constructor $CONSSTA $TVFM $CONSEND
* @param delegate $JFX $TVFM $CONSPARAM
*/
class TableViewFocusModel[S](override val delegate: jfxsc.TableView.TableViewFocusModel[S])
extends TableFocusModel[S, jfxsc.TableColumn[S, _]](delegate)
with SFXDelegate[jfxsc.TableView.TableViewFocusModel[S]] {
/**
* Creates a default TableViewFocusModel instance that will be used to manage focus of the provided TableView
* control.
*
* @param tableView The tableView upon which this focus model operates.
*/
def this(tableView: TableView[S]) = this(new jfxsc.TableView.TableViewFocusModel(tableView))
/**
* The position of the current item in the TableView which has the focus.
*/
def focusedCell: ReadOnlyObjectProperty[jfxsc.TablePosition[_, _]] = delegate.focusedCellProperty
/**
* Causes the item at the given index to receive the focus.
*
* @param index The row index of the item to give focus to.
* @param column The column of the item to give focus to. Can be `null`.
*/
def focus(index: Int, column: TableColumn[S, _]) {
delegate.focus(index, delegateOrNull(column))
}
/**
* Convenience method for setting focus on a particular row or cell using a
* [[scalafx.scene.control.TablePosition]].
*
* @param pos The table position where focus should be set.
*/
def focus(pos: TablePosition[_, _]) {
delegate.focus(pos.delegate)
}
}
}
/**
* Wraps JavaFX [[http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableView.html TableView]].
*
* @constructor Creates a new ScalaFX TableView Wrapping a JavaFX TableView.
* @param delegate JavaFX TableView to be wrapped. Its default value is a new JavaFX TableView.
* @tparam S The type of the objects contained within the TableView items list.
*/
class TableView[S](override val delegate: jfxsc.TableView[S] = new jfxsc.TableView[S])
extends Control(delegate)
with SFXDelegate[jfxsc.TableView[S]] {
/**
* Creates a TableView with the content provided in the items ObservableBuffer.
*
* @param items The items to insert into the TableView, and the list to watch for changes
* (to automatically show in the TableView).
*/
def this(items: ObservableBuffer[S]) = this(new jfxsc.TableView(items))
/**
* The TableColumns that are part of this TableView.
*/
def columns: ObservableBuffer[jfxsc.TableColumn[S, _]] = delegate.getColumns
/**
* This is the function called when the user completes a column-resize operation.
*
* There are predefined resize policies defined by
* [[scalafx.scene.control.TableView#ConstrainedResizePolicy UnconstrainedResizePolicy]] and
* [[scalafx.scene.control.TableView#UnconstrainedResizePolicy UnconstrainedResizePolicy]].
*
* Example use:
* {{{
* tableView.columnResizePolicy = TableView.UnconstrainedResizePolicy
* }}}
*/
def columnResizePolicy: ObjectProperty[TableView.ResizeFeatures[S] => Boolean] =
ObjectProperty((features: TableView.ResizeFeatures[S]) => delegate.columnResizePolicyProperty.value.call(features))
def columnResizePolicy_=(p: TableView.ResizeFeatures[_] => Boolean) {
delegate.columnResizePolicyProperty().setValue(new jfxu.Callback[jfxsc.TableView.ResizeFeatures[_], java.lang.Boolean] {
def call(v: jfxsc.TableView.ResizeFeatures[_]): java.lang.Boolean = {
p(v)
}
})
}
def columnResizePolicy_=(p: jfxu.Callback[jfxsc.TableView.ResizeFeatures[_], java.lang.Boolean]) {
delegate.columnResizePolicyProperty().setValue(p)
}
/** The comparator property is a read-only property that is representative of the current state of the `sort order` list. */
def comparator: ReadOnlyObjectProperty[java.util.Comparator[S]] = delegate.comparatorProperty
/**
* Specifies whether this TableView is editable - only if the TableView, the TableColumn (if applicable) and the
* TableCells within it are both editable will a TableCell be able to go into their editing state.
*/
def editable: BooleanProperty = delegate.editableProperty
def editable_=(v: Boolean) {
editable() = v
}
/**
* Represents the current cell being edited, or null if there is no cell being edited.
*/
def editingCell: ReadOnlyObjectProperty[jfxsc.TablePosition[S, _]] = delegate.editingCellProperty
/** Specifies whether this control has cells that are a fixed height (of the specified value). */
def fixedCellSize: DoubleProperty = delegate.fixedCellSizeProperty
def fixedCellSize_=(v: Double) {
fixedCellSize() = v
}
/**
* Represents the currently-installed TableView.TableViewFocusModel for this TableView.
*/
def focusModel: ObjectProperty[jfxsc.TableView.TableViewFocusModel[S]] = delegate.focusModelProperty
def focusModel_=(v: TableView.TableViewFocusModel[S]) {
focusModel() = v
}
/**
* The underlying data model for the TableView.
*/
def items = delegate.itemsProperty
def items_=(v: ObservableBuffer[S]) {
items() = v
}
/**
* This Node is shown to the user when the table has no content to show.
*/
def placeholder: ObjectProperty[jfxs.Node] = delegate.placeholderProperty
def placeholder_=(v: Node) {
placeholder() = v
}
/**
* A function which produces a TableRow.
*/
def rowFactory: ObjectProperty[TableView[S] => TableRow[S]] =
ObjectProperty((view: TableView[S]) => delegate.rowFactoryProperty.value.call(view))
def rowFactory_=(factory: TableView[S] => TableRow[S]) {
delegate.rowFactoryProperty.setValue(new jfxu.Callback[jfxsc.TableView[S], jfxsc.TableRow[S]] {
def call(v: jfxsc.TableView[S]): jfxsc.TableRow[S] = {
factory(v)
}
})
}
/**
* The SelectionModel provides the API through which it is possible to select single or multiple items within a
* TableView, as well as inspect which items have been selected by the user.
*/
def selectionModel: ObjectProperty[jfxsc.TableView.TableViewSelectionModel[S]] = delegate.selectionModelProperty
def selectionModel_=(v: TableView.TableViewSelectionModel[S]) {
selectionModel() = v
}
/**
* The sortOrder list defines the order in which `TableColumn` instances are sorted.
*/
def sortOrder: ObservableBuffer[jfxsc.TableColumn[S, _]] = delegate.getSortOrder
/**
* This controls whether a menu button is available when the user clicks in a designated space within the TableView,
* within which is a radio menu item for each TableColumn in this table.
*/
def tableMenuButtonVisible: BooleanProperty = delegate.tableMenuButtonVisibleProperty
def tableMenuButtonVisible_=(v: Boolean) {
tableMenuButtonVisible() = v
}
/**
* Causes the cell at the given row/column view indexes to switch into its editing state, if it is not already in
* it, and assuming that the TableView and column are also editable.
*/
def edit(row: Int, column: TableColumn[S, _]) {
delegate.edit(row, delegateOrNull(column))
}
/**
* Applies the currently installed resize policy against the given column, resizing it based on the delta value
* provided.
*/
def resizeColumn(column: TableColumn[S, _], delta: Double) = delegate.resizeColumn(column.delegate, delta)
/**
* Called when there's a request to scroll an index into view using `scrollTo(int)` or `scrollTo(Object)`
*/
def onScrollTo: ObjectProperty[jfxe.EventHandler[jfxsc.ScrollToEvent[Integer]]] = delegate.onScrollToProperty
def onScrollTo_=(v: jfxe.EventHandler[jfxsc.ScrollToEvent[Integer]]) {
ObjectProperty.fillProperty[jfxe.EventHandler[jfxsc.ScrollToEvent[Integer]]](onScrollTo, v)
}
/**
* Called when there's a request to scroll a column into view using `scrollToColumn(TableColumn)` or `scrollToColumnIndex(int)`.
*/
def onScrollToColumn: ObjectProperty[jfxe.EventHandler[jfxsc.ScrollToEvent[jfxsc.TableColumn[S, _]]]] = delegate.onScrollToColumnProperty
def onScrollToColumn_=(v: jfxe.EventHandler[jfxsc.ScrollToEvent[jfxsc.TableColumn[S, _]]]) {
ObjectProperty.fillProperty[jfxe.EventHandler[jfxsc.ScrollToEvent[jfxsc.TableColumn[S, _]]]](onScrollToColumn, v)
}
/** Called when there's a request to sort the control. */
def onSort: ObjectProperty[jfxe.EventHandler[jfxsc.SortEvent[jfxsc.TableView[S]]]] = delegate.onSortProperty
def onSort_=(v: jfxe.EventHandler[jfxsc.SortEvent[jfxsc.TableView[S]]]) {
ObjectProperty.fillProperty[jfxe.EventHandler[jfxsc.SortEvent[jfxsc.TableView[S]]]](onSort, v)
}
/** Scrolls the TableView so that the given object is visible within the viewport. */
def scrollToColumn(column: TableColumn[S, _]) {
delegate.scrollToColumn(column.delegate)
}
/** The sort policy specifies how sorting in this TableView should be performed. */
def sortPolicy: ObjectProperty[jfxu.Callback[jfxsc.TableView[S], java.lang.Boolean]] = delegate.sortPolicyProperty
def sortPolicy_=(v: jfxu.Callback[jfxsc.TableView[S], java.lang.Boolean]) {
ObjectProperty.fillProperty[jfxu.Callback[jfxsc.TableView[S], java.lang.Boolean]](sortPolicy, v)
}
}