Skip to content

Commit 2c551c9

Browse files
DavidDamkeddamkeDeath111
authored
Enhancement/report has button to expand and close (#125)
* add expand/collapse button to Report * delete unnecessary comments and change Button text to be more useful * rework design Co-authored-by: ddamke <[email protected]> Co-authored-by: Nico <[email protected]>
1 parent 264191c commit 2c551c9

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

src/main/java/de/doubleslash/keeptime/view/ReportController.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public class ReportController {
9191
@FXML
9292
private Canvas colorTimeLineCanvas;
9393

94+
@FXML
95+
private Button expandCollapseButton;
96+
9497
private static final Logger LOG = LoggerFactory.getLogger(ReportController.class);
9598

9699
private final Model model;
@@ -105,6 +108,8 @@ public class ReportController {
105108

106109
private final TreeItem<TableRow> rootItem = new TreeItem<>();
107110

111+
private boolean expanded = true;
112+
108113
@Autowired
109114
public ReportController(final Model model, final Controller controller) {
110115
this.model = model;
@@ -117,8 +122,9 @@ private void initialize() {
117122
currentReportDate = LocalDate.now();
118123

119124
colorTimeLine = new ColorTimeLine(colorTimeLineCanvas);
120-
initTableView();
121125

126+
expandCollapseButton.setOnMouseClicked(event ->toggleCollapseExpandReport());
127+
initTableView();
122128
}
123129

124130
private void initTableView() {
@@ -207,6 +213,24 @@ protected void updateItem(TableRow workItem, boolean empty) {
207213
rootItem.setExpanded(true);
208214
}
209215

216+
private void toggleCollapseExpandReport(){
217+
218+
if(expanded){
219+
expandAll(false);
220+
expandCollapseButton.setText("Expand");
221+
222+
}else {
223+
expandAll(true);
224+
expandCollapseButton.setText("Collapse");
225+
}
226+
expanded = !expanded;
227+
}
228+
229+
private void expandAll(boolean expand){
230+
for (int i=0; i<rootItem.getChildren().size(); i++){
231+
rootItem.getChildren().get(i).setExpanded(expand);
232+
}
233+
}
210234
private void updateReport(final LocalDate dateToShow) {
211235
this.currentReportDate = dateToShow;
212236
rootItem.getChildren().clear();
@@ -260,7 +284,7 @@ private void updateReport(final LocalDate dateToShow) {
260284
projectRow.getChildren().add(workRow);
261285
}
262286

263-
projectRow.setExpanded(true);
287+
projectRow.setExpanded(expanded);
264288
rootItem.getChildren().add(projectRow);
265289

266290
}

src/main/resources/layouts/report.fxml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
<?import javafx.geometry.Insets?>
2020
<?import javafx.scene.canvas.Canvas?>
21+
<?import javafx.scene.control.Button?>
2122
<?import javafx.scene.control.Label?>
2223
<?import javafx.scene.control.TreeTableView?>
2324
<?import javafx.scene.layout.AnchorPane?>
@@ -26,13 +27,13 @@
2627
<?import javafx.scene.layout.VBox?>
2728
<?import javafx.scene.text.Font?>
2829

29-
<AnchorPane fx:id="reportRoot" focusTraversable="true" prefWidth="500.0" xmlns="http://javafx.com/javafx/8.0.202-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.doubleslash.keeptime.view.ReportController">
30+
<AnchorPane fx:id="reportRoot" focusTraversable="true" prefWidth="500.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.doubleslash.keeptime.view.ReportController">
3031
<children>
3132
<VBox>
3233
<children>
33-
<BorderPane fx:id="topBorderPane">
34+
<BorderPane fx:id="topBorderPane" prefWidth="480.0">
3435
<left>
35-
<VBox fillWidth="false" prefHeight="85.0" prefWidth="187.0" BorderPane.alignment="CENTER">
36+
<VBox fillWidth="false" prefHeight="185.0" prefWidth="213.0" BorderPane.alignment="CENTER">
3637
<children>
3738
<Label text="Report">
3839
<font>
@@ -83,12 +84,19 @@
8384
<VBox.margin>
8485
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
8586
</VBox.margin>
87+
<padding>
88+
<Insets bottom="10.0" />
89+
</padding>
8690
</BorderPane>
87-
<Canvas fx:id="colorTimeLineCanvas" height="5.0" width="480.0">
91+
<HBox prefHeight="26.0" prefWidth="210.0">
92+
<children>
93+
<Button fx:id="expandCollapseButton" mnemonicParsing="false" prefHeight="25.0" prefWidth="80.0" text="Collapse" />
94+
</children>
8895
<VBox.margin>
89-
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
96+
<Insets right="10.0" top="10.0" />
9097
</VBox.margin>
91-
</Canvas>
98+
</HBox>
99+
<Canvas fx:id="colorTimeLineCanvas" height="7.0" width="499.0" />
92100
<TreeTableView fx:id="workTableTreeView" prefHeight="300.0" prefWidth="500.0" showRoot="false" stylesheets="@../css/dialog.css" />
93101
</children>
94102
</VBox>

0 commit comments

Comments
 (0)