Skip to content

Commit 0057dde

Browse files
authored
Merge pull request #229 from Dokyeongyun/ft-220429-expandableAlertLogList
Ft 220429 expandable alert log list
2 parents caa5b55 + c179e86 commit 0057dde

File tree

4 files changed

+190
-15
lines changed

4 files changed

+190
-15
lines changed

src/main/java/root/javafx/CustomView/AlertLogMonitoringSummaryAP.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
import java.util.List;
77
import java.util.ResourceBundle;
88

9+
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
910
import javafx.beans.property.SimpleDoubleProperty;
1011
import javafx.beans.property.SimpleIntegerProperty;
1112
import javafx.collections.FXCollections;
1213
import javafx.fxml.FXML;
1314
import javafx.fxml.FXMLLoader;
1415
import javafx.fxml.Initializable;
1516
import javafx.scene.control.Label;
16-
import javafx.scene.control.ListView;
1717
import javafx.scene.control.TableColumn;
1818
import javafx.scene.control.TableView;
1919
import javafx.scene.layout.AnchorPane;
20+
import javafx.scene.layout.VBox;
21+
import javafx.scene.paint.Paint;
2022
import lombok.Data;
2123
import lombok.extern.slf4j.Slf4j;
2224
import root.core.domain.AlertLog;
@@ -26,6 +28,9 @@
2628
@Slf4j
2729
public class AlertLogMonitoringSummaryAP extends AnchorPane implements Initializable {
2830

31+
@FXML
32+
VBox wrapVBox;
33+
2934
@FXML
3035
Label alertLogFileLB;
3136

@@ -43,12 +48,11 @@ public class AlertLogMonitoringSummaryAP extends AnchorPane implements Initializ
4348

4449
@FXML
4550
private TableColumn<AlertLogSummary, Double> errorRateCL;
46-
47-
@FXML
48-
private ListView<Log> errorLogLV;
49-
51+
52+
private ExpandableListView<Log> errorLogLV;
53+
5054
private AlertLog alertLog;
51-
55+
5256
private List<Log> errorLogs = new ArrayList<>();
5357

5458
public AlertLogMonitoringSummaryAP(AlertLog alertLog) {
@@ -71,8 +75,21 @@ public void initialize(URL location, ResourceBundle resources) {
7175
errorCL.setCellValueFactory(cellData -> cellData.getValue().getErrorLogCount().asObject());
7276
errorRateCL.setCellValueFactory(cellData -> cellData.getValue().getErrorRate().asObject());
7377

74-
// Set cell factory of error log listview
75-
errorLogLV.setCellFactory(categoryList -> new AlertLogListViewCell());
78+
errorLogLV = new ExpandableListView<>(FontAwesomeIcon.CLOCK_ALT, Paint.valueOf("#183279"));
79+
80+
// Set content provider for expandable listview
81+
errorLogLV.setContentProvider(new ExpandableListView.ContentProvider<Log>() {
82+
@Override
83+
public String getTitleOf(final Log log) {
84+
return log.getLogTimeStamp() + "\t(Index: " + (log.getIndex() + 1) + ")";
85+
}
86+
87+
@Override
88+
public String getContentOf(final Log log) {
89+
return log.getFullLogString();
90+
}
91+
});
92+
wrapVBox.getChildren().add(errorLogLV);
7693

7794
render();
7895
}
@@ -83,7 +100,8 @@ private void render() {
83100

84101
// Set summary tableview value
85102
summaryTV.setItems(FXCollections.observableArrayList(List.of(getSummaryData())));
86-
103+
104+
// Set errorLog listview values
87105
errorLogLV.getItems().addAll(errorLogs);
88106
}
89107

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package root.javafx.CustomView;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
7+
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
8+
import javafx.collections.ObservableList;
9+
import javafx.event.EventHandler;
10+
import javafx.scene.control.ListCell;
11+
import javafx.scene.control.ListView;
12+
import javafx.scene.control.TitledPane;
13+
import javafx.scene.input.MouseEvent;
14+
import javafx.scene.layout.BorderPane;
15+
import javafx.scene.paint.Paint;
16+
import javafx.scene.text.Text;
17+
import javafx.util.Callback;
18+
19+
public class ExpandableListView<E> extends ListView<E> {
20+
21+
private ContentProvider<E> contentProvider = new ContentProvider<E>() {
22+
@Override
23+
public String getTitleOf(final E item) {
24+
return item.toString();
25+
}
26+
27+
@Override
28+
public String getContentOf(final E item) {
29+
return getTitleOf(item);
30+
}
31+
};
32+
33+
private final Set<E> expandedItems = new HashSet<E>();
34+
35+
public ExpandableListView(FontAwesomeIcon icon, Paint iconColor) {
36+
setSelectionModel(null);
37+
setCellFactory(new Callback<ListView<E>, ListCell<E>>() {
38+
@Override
39+
public ListCell<E> call(final ListView<E> param) {
40+
final TitledPane titledPane = new TitledPane();
41+
final Text contentArea = new Text();
42+
final FontAwesomeIconView iconView = new FontAwesomeIconView(icon);
43+
iconView.setFill(Paint.valueOf("#183279"));
44+
45+
titledPane.setAnimated(false);
46+
titledPane.setCollapsible(true);
47+
titledPane.setExpanded(false);
48+
titledPane.setGraphic(iconView);
49+
titledPane.setContent(contentArea);
50+
51+
final BorderPane contentAreaWrapper = new BorderPane();
52+
contentAreaWrapper.setLeft(contentArea);
53+
titledPane.setContent(contentAreaWrapper);
54+
55+
titledPane.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
56+
@SuppressWarnings("unchecked")
57+
@Override
58+
public void handle(final MouseEvent event) {
59+
final boolean expanded = titledPane.isExpanded();
60+
final E item = (E) titledPane.getUserData();
61+
if (item == null) {
62+
return;
63+
}
64+
if (expanded) {
65+
expandedItems.add(item);
66+
} else {
67+
expandedItems.remove(item);
68+
}
69+
}
70+
});
71+
72+
return new ListCell<E>() {
73+
@Override
74+
protected void updateItem(final E item, final boolean empty) {
75+
super.updateItem(item, empty);
76+
if (empty) {
77+
titledPane.setText("");
78+
contentArea.setText("");
79+
return;
80+
}
81+
final boolean expanded = isExpanded(item);
82+
titledPane.setUserData(item);
83+
titledPane.setExpanded(expanded);
84+
titledPane.setText(contentProvider.getTitleOf(item));
85+
contentArea.setText(contentProvider.getContentOf(item));
86+
setGraphic(titledPane);
87+
}
88+
};
89+
}
90+
});
91+
getStyleClass().addAll("expandable-listview", "gray-scrollbar");
92+
}
93+
94+
public void setContentProvider(final ContentProvider<E> contentProvider) {
95+
this.contentProvider = contentProvider;
96+
}
97+
98+
public void expand(E item) {
99+
expand(item, true);
100+
}
101+
102+
public void collapse(E item) {
103+
expand(item, false);
104+
}
105+
106+
private void expand(E item, boolean expand) {
107+
if (expand) {
108+
this.expandedItems.add(item);
109+
} else {
110+
this.expandedItems.remove(item);
111+
}
112+
113+
ObservableList<E> o = getItems();
114+
setItems(null);
115+
setItems(o);
116+
}
117+
118+
public boolean isExpanded(E item) {
119+
return this.expandedItems.contains(item);
120+
}
121+
122+
public static interface ContentProvider<E> {
123+
String getTitleOf(E item);
124+
125+
String getContentOf(E item);
126+
}
127+
128+
public static class Item {
129+
String title;
130+
String content;
131+
132+
public Item(String title, String content) {
133+
this.title = title;
134+
this.content = content;
135+
}
136+
137+
public String getTitle() {
138+
return title;
139+
}
140+
141+
public String getContent() {
142+
return content;
143+
}
144+
}
145+
}

src/main/resources/css/javaFx.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,18 @@
279279
-fx-pref-height: 0;
280280
-fx-max-height: 0;
281281
}
282+
283+
/* Expandable listview */
284+
.expandable-listview .list-cell {
285+
-fx-padding: 0;
286+
-fx-background-color: white;
287+
}
288+
289+
.expandable-listview .titled-pane:focused {
290+
-fx-text-fill: black;
291+
}
292+
293+
.expandable-listview .titled-pane > .title {
294+
-fx-background-color: -fx-box-border, -fx-inner-border, white;
295+
-fx-padding: 7 5 7 5;
296+
}

src/main/resources/fxml/AlertLogMonitoringSummary.fxml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<?import com.jfoenix.controls.JFXListView?>
43
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
54
<?import java.lang.String?>
65
<?import javafx.geometry.Insets?>
@@ -14,7 +13,7 @@
1413

1514
<fx:root styleClass="basic-font" stylesheets="@../css/javaFx.css" type="AnchorPane" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
1615
<children>
17-
<VBox layoutX="10.0" layoutY="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
16+
<VBox fx:id="wrapVBox" layoutX="10.0" layoutY="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
1817
<children>
1918
<HBox alignment="CENTER_LEFT">
2019
<children>
@@ -61,12 +60,10 @@
6160
<graphic>
6261
<FontAwesomeIconView glyphName="ASTERISK" size="8" />
6362
</graphic>
64-
</Label>
65-
<JFXListView fx:id="errorLogLV" styleClass="gray-scrollbar">
6663
<VBox.margin>
67-
<Insets top="5.0" />
64+
<Insets bottom="5.0" />
6865
</VBox.margin>
69-
</JFXListView>
66+
</Label>
7067
</children>
7168
</VBox>
7269
</children>

0 commit comments

Comments
 (0)