1+ package org.epistatic.app5.controller
2+
3+ import javafx.collections.FXCollections
4+ import javafx.collections.ObservableList
5+ import javafx.fxml.FXML
6+ import javafx.scene.control.Button
7+ import javafx.scene.control.TableColumn
8+ import javafx.scene.control.TableView
9+ import javafx.scene.control.cell.PropertyValueFactory
10+ import javafx.stage.Stage
11+ import org.epistatic.app5.model.DateItem
12+ import java.time.OffsetDateTime
13+ import java.time.ZoneOffset
14+
15+ /* *
16+ * Licensed to the Apache Software Foundation (ASF) under one
17+ * or more contributor license agreements. See the NOTICE file
18+ * distributed with this work for additional information
19+ * regarding copyright ownership. The ASF licenses this file
20+ * to you under the Apache License, Version 2.0 (the
21+ * "License"); you may not use this file except in compliance
22+ * with the License. You may obtain a copy of the License at
23+ *
24+ * http://www.apache.org/licenses/LICENSE-2.0
25+ *
26+ * Unless required by applicable law or agreed to in writing,
27+ * software distributed under the License is distributed on an
28+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
29+ * KIND, either express or implied. See the License for the
30+ * specific language governing permissions and limitations
31+ * under the License.
32+ **/
33+
34+ /* *
35+ * Controller for app5/app5.fxml. Manages the main UI and all the other controllers
36+ */
37+ class ApplicationController {
38+
39+ @FXML lateinit var exitButton: Button
40+ @FXML lateinit var dateView: TableView <DateItem >
41+ @FXML lateinit var labelColumn: TableColumn <DateItem , String >
42+ @FXML lateinit var dateStringColumn: TableColumn <DateItem , String >
43+ @FXML lateinit var date2Column: TableColumn <DateItem , OffsetDateTime >
44+ @FXML lateinit var date3Column: TableColumn <DateItem , OffsetDateTime >
45+
46+ val model: ObservableList <DateItem > = FXCollections .observableArrayList<DateItem >()
47+
48+ @FXML
49+ fun initialize () {
50+ dateView.items = model
51+ labelColumn.cellValueFactory = PropertyValueFactory <DateItem , String >(" label" )
52+ dateStringColumn.cellValueFactory = PropertyValueFactory <DateItem , String >(" date1" )
53+ date2Column.cellValueFactory = PropertyValueFactory <DateItem , OffsetDateTime >(" date2" )
54+ date3Column.cellValueFactory = PropertyValueFactory <DateItem , OffsetDateTime >(" date3" )
55+
56+ addItems()
57+ }
58+
59+ @FXML
60+ fun closeApplication () {
61+ val stage = exitButton.scene.window as Stage
62+ stage.close()
63+ }
64+
65+ /* *
66+ * Add items to table
67+ */
68+ private fun addItems () {
69+ var item = DateItem (" Green Tree" , createDate(2018 , 2 , 3 ), createDate(2018 , 4 , 12 ), createDate(2018 , 8 , 21 ))
70+ model.add(item)
71+ item = DateItem (" Red Car" , createDate(2017 , 5 , 19 ), createDate(2017 , 3 , 15 ), createDate(2017 , 12 , 21 ))
72+ model.add(item)
73+ item = DateItem (" Blue Ship" , createDate(2016 , 12 , 19 ), createDate(2016 , 6 , 2 ), createDate(2017 , 7 , 28 ))
74+ model.add(item)
75+ item = DateItem (" Yellow Moon" , createDate(1990 , 4 , 4 ), createDate(1990 , 1 , 2 ), createDate(1990 , 3 , 11 ))
76+ model.add(item)
77+ }
78+
79+
80+ private fun createDate (year : Int , month : Int , day : Int ): OffsetDateTime {
81+ return OffsetDateTime .of(year, month, day, 14 , 30 , 0 , 0 , ZoneOffset .UTC )
82+ }
83+ }
0 commit comments