Skip to content

Commit d0b55f0

Browse files
authored
Merge pull request #230 from Dokyeongyun/ft-220430-alertLogNavigator
Ft 220430 alert log navigator
2 parents 0057dde + acb15d8 commit d0b55f0

File tree

2 files changed

+134
-5
lines changed

2 files changed

+134
-5
lines changed

src/main/java/root/javafx/Controller/AlertLogMonitoringMenuController.java

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@
77
import java.util.Map;
88
import java.util.ResourceBundle;
99

10+
import org.apache.commons.lang3.StringUtils;
11+
1012
import com.jfoenix.controls.JFXComboBox;
1113
import com.jfoenix.controls.JFXListView;
1214

15+
import javafx.application.Platform;
1316
import javafx.event.ActionEvent;
17+
import javafx.event.Event;
18+
import javafx.event.EventHandler;
1419
import javafx.fxml.FXML;
1520
import javafx.fxml.Initializable;
1621
import javafx.scene.control.Alert.AlertType;
1722
import javafx.scene.control.DatePicker;
23+
import javafx.scene.control.TextField;
24+
import javafx.scene.input.KeyCode;
25+
import javafx.scene.input.KeyEvent;
1826
import javafx.scene.layout.AnchorPane;
1927
import javafx.scene.layout.StackPane;
28+
import lombok.extern.slf4j.Slf4j;
2029
import root.common.server.implement.JschServer;
2130
import root.core.domain.AlertLog;
2231
import root.core.domain.JschConnectionInfo;
@@ -33,9 +42,11 @@
3342
import root.core.usecase.implement.ServerMonitoringUsecaseImpl;
3443
import root.javafx.CustomView.AlertLogListViewCell;
3544
import root.javafx.CustomView.AlertLogMonitoringSummaryAP;
45+
import root.javafx.CustomView.NumberTextFormatter;
3646
import root.javafx.CustomView.dateCell.DisableAfterTodayDateCell;
3747
import root.utils.AlertUtils;
3848

49+
@Slf4j
3950
public class AlertLogMonitoringMenuController implements Initializable {
4051

4152
/* Dependency Injection */
@@ -60,6 +71,12 @@ public class AlertLogMonitoringMenuController implements Initializable {
6071
@FXML
6172
StackPane alertLogSummarySP;
6273

74+
@FXML
75+
TextField navigatorTF;
76+
77+
@FXML
78+
TextField statusTF;
79+
6380
@FXML
6481
AnchorPane mainNodataAP;
6582

@@ -154,6 +171,18 @@ private void initAlertLogMonitoringElements() {
154171
// AlertLog ListView
155172
alertLogLV.setCellFactory(categoryList -> new AlertLogListViewCell());
156173

174+
// AlertLog Navigator
175+
navigatorTF.setTextFormatter(new NumberTextFormatter());
176+
navigatorTF.setOnKeyReleased(new EventHandler<KeyEvent>() {
177+
@Override
178+
public void handle(KeyEvent e) {
179+
if (e.getCode().equals(KeyCode.ENTER)) {
180+
focusAlertLog(e);
181+
e.consume();
182+
}
183+
}
184+
});
185+
157186
// Set view visible
158187
mainNodataAP.setVisible(true);
159188
alertLogLV.setVisible(false);
@@ -230,4 +259,101 @@ public void monitoringAlertLog(ActionEvent e) throws Exception {
230259
summaryNodataAP.setVisible(false);
231260
summaryNodataAP.toBack();
232261
}
262+
263+
public void prevAlertLog(ActionEvent e) {
264+
String input = navigatorTF.getText();
265+
if (!validateAlertLogNavigatorInput(input)) {
266+
return;
267+
}
268+
269+
int toIndex = Integer.parseInt(input) - 1;
270+
if (toIndex == 0) {
271+
updateStatusMessage("첫번째 Log입니다.");
272+
return;
273+
}
274+
275+
navigatorTF.setText(String.valueOf(toIndex));
276+
focusAlertLog(e);
277+
}
278+
279+
public void nextAlertLog(ActionEvent e) {
280+
String input = navigatorTF.getText();
281+
if (!validateAlertLogNavigatorInput(input)) {
282+
return;
283+
}
284+
285+
286+
int toIndex = Integer.parseInt(input) + 1;
287+
if (toIndex > alertLogLV.getItems().size()) {
288+
updateStatusMessage("마지막 Log입니다.");
289+
return;
290+
}
291+
292+
navigatorTF.setText(String.valueOf(toIndex));
293+
focusAlertLog(e);
294+
}
295+
296+
public void focusAlertLog(Event e) {
297+
String input = navigatorTF.getText();
298+
if (!validateAlertLogNavigatorInput(input)) {
299+
return;
300+
}
301+
302+
int toIndex = Integer.parseInt(input);
303+
alertLogLV.scrollTo(toIndex - 1);
304+
alertLogLV.getSelectionModel().select(toIndex - 1);
305+
updateStatusMessage(String.format("[%d]번째 Log로 이동합니다.", toIndex));
306+
}
307+
308+
private boolean validateAlertLogNavigatorInput(String input) {
309+
if (StringUtils.isEmpty(input)) {
310+
updateStatusMessage("조회를 원하는 Log index를 입력해주세요.");
311+
return false;
312+
}
313+
314+
int toIndex = 0;
315+
try {
316+
toIndex = Integer.parseInt(input);
317+
} catch (NumberFormatException ex) {
318+
updateStatusMessage("숫자만 입력하실 수 있습니다.");
319+
return false;
320+
}
321+
322+
int alertLogSize = alertLogLV.getItems().size();
323+
if (alertLogSize == 0) {
324+
updateStatusMessage("Alert Log 조회 후 이용해주세요.");
325+
return false;
326+
}
327+
328+
if (toIndex <= 0 || toIndex > alertLogSize) {
329+
updateStatusMessage(String.format("Log index를 올바르게 입력해주세요. (가능한 입력값 범위: 1 ~ %d)", alertLogSize));
330+
return false;
331+
}
332+
333+
return true;
334+
}
335+
336+
/**
337+
* Update message at bottom status TextField region
338+
*
339+
* @param message
340+
*/
341+
private void updateStatusMessage(String message) {
342+
Thread statusTextUpdateThread = new Thread(() -> {
343+
Platform.runLater(() -> {
344+
statusTF.setText(message);
345+
});
346+
347+
try {
348+
Thread.sleep(1000);
349+
} catch (InterruptedException e) {
350+
log.error(e.getMessage());
351+
}
352+
Platform.runLater(() -> {
353+
statusTF.setText("");
354+
});
355+
});
356+
statusTextUpdateThread.setDaemon(true);
357+
statusTextUpdateThread.start();
358+
}
233359
}

src/main/resources/fxml/AlertLogMonitoringMenu.fxml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@
239239
</Label>
240240
<HBox alignment="CENTER_LEFT" layoutY="39.20000076293945" style="-fx-border-color: #e1e1e1; -fx-border-width: 0.5px;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="42.0">
241241
<children>
242-
<JFXButton contentDisplay="GRAPHIC_ONLY">
242+
<JFXButton contentDisplay="GRAPHIC_ONLY" onAction="#prevAlertLog">
243243
<graphic>
244244
<FontAwesomeIconView fill="#3c4584" glyphName="ARROW_CIRCLE_LEFT" size="20" strokeMiterLimit="0.0" tabSize="0" />
245245
</graphic>
246246
<HBox.margin>
247247
<Insets left="10.0" />
248248
</HBox.margin>
249249
</JFXButton>
250-
<JFXButton contentDisplay="GRAPHIC_ONLY">
250+
<JFXButton contentDisplay="GRAPHIC_ONLY" onAction="#nextAlertLog">
251251
<graphic>
252252
<FontAwesomeIconView fill="#3c4584" glyphName="ARROW_CIRCLE_RIGHT" size="20" strokeMiterLimit="0.0" tabSize="0" />
253253
</graphic>
@@ -257,12 +257,12 @@
257257
<Insets left="10.0" right="8.0" />
258258
</HBox.margin>
259259
</Separator>
260-
<TextField maxHeight="25.0" maxWidth="100.0" minHeight="25.0" minWidth="100.0" prefHeight="25.0" prefWidth="100.0">
260+
<TextField fx:id="navigatorTF" maxHeight="25.0" maxWidth="100.0" minHeight="25.0" minWidth="100.0" prefHeight="25.0" prefWidth="100.0">
261261
<HBox.margin>
262262
<Insets left="10.0" />
263263
</HBox.margin>
264264
</TextField>
265-
<JFXButton alignment="CENTER" maxHeight="30.0" maxWidth="60.0" minHeight="25.0" minWidth="60.0" nodeOrientation="RIGHT_TO_LEFT" prefHeight="25.0" prefWidth="60.0" ripplerFill="#d4d4d4" style="-fx-background-color: #3c4584;" text="Go" textFill="WHITE" wrapText="true">
265+
<JFXButton alignment="CENTER" maxHeight="30.0" maxWidth="60.0" minHeight="25.0" minWidth="60.0" nodeOrientation="RIGHT_TO_LEFT" onAction="#focusAlertLog" prefHeight="25.0" prefWidth="60.0" ripplerFill="#d4d4d4" style="-fx-background-color: #3c4584;" text="Go" textFill="WHITE" wrapText="true">
266266
<graphic>
267267
<FontAwesomeIconView fill="WHITE" glyphName="LONG_ARROW_RIGHT" size="14" />
268268
</graphic>
@@ -301,7 +301,10 @@
301301
</AnchorPane>
302302
</center>
303303
<bottom>
304-
<AnchorPane maxHeight="30.0" minHeight="30.0" style="-fx-background-color: #f7f7f7; -fx-border-width: 0.2px; -fx-border-color: gray;" BorderPane.alignment="CENTER" />
304+
<AnchorPane maxHeight="30.0" minHeight="30.0" style="-fx-background-color: #f7f7f7; -fx-border-width: 0.2px; -fx-border-color: gray;" BorderPane.alignment="CENTER">
305+
<children>
306+
<TextField fx:id="statusTF" style="-fx-font-size: 10px;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
307+
</children></AnchorPane>
305308
</bottom>
306309
</BorderPane>
307310
</children>

0 commit comments

Comments
 (0)