Skip to content

Commit 8aa9ea2

Browse files
committed
Move and focus alert log cell using AlertLog Navigator
1 parent 444ce1f commit 8aa9ea2

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@
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;
1417
import javafx.fxml.FXML;
1518
import javafx.fxml.Initializable;
1619
import javafx.scene.control.Alert.AlertType;
1720
import javafx.scene.control.DatePicker;
21+
import javafx.scene.control.TextField;
1822
import javafx.scene.layout.AnchorPane;
1923
import javafx.scene.layout.StackPane;
24+
import lombok.extern.slf4j.Slf4j;
2025
import root.common.server.implement.JschServer;
2126
import root.core.domain.AlertLog;
2227
import root.core.domain.JschConnectionInfo;
@@ -33,9 +38,11 @@
3338
import root.core.usecase.implement.ServerMonitoringUsecaseImpl;
3439
import root.javafx.CustomView.AlertLogListViewCell;
3540
import root.javafx.CustomView.AlertLogMonitoringSummaryAP;
41+
import root.javafx.CustomView.NumberTextFormatter;
3642
import root.javafx.CustomView.dateCell.DisableAfterTodayDateCell;
3743
import root.utils.AlertUtils;
3844

45+
@Slf4j
3946
public class AlertLogMonitoringMenuController implements Initializable {
4047

4148
/* Dependency Injection */
@@ -60,6 +67,12 @@ public class AlertLogMonitoringMenuController implements Initializable {
6067
@FXML
6168
StackPane alertLogSummarySP;
6269

70+
@FXML
71+
TextField navigatorTF;
72+
73+
@FXML
74+
TextField statusTF;
75+
6376
@FXML
6477
AnchorPane mainNodataAP;
6578

@@ -154,6 +167,9 @@ private void initAlertLogMonitoringElements() {
154167
// AlertLog ListView
155168
alertLogLV.setCellFactory(categoryList -> new AlertLogListViewCell());
156169

170+
// AlertLog Navigator
171+
navigatorTF.setTextFormatter(new NumberTextFormatter());
172+
157173
// Set view visible
158174
mainNodataAP.setVisible(true);
159175
alertLogLV.setVisible(false);
@@ -230,4 +246,68 @@ public void monitoringAlertLog(ActionEvent e) throws Exception {
230246
summaryNodataAP.setVisible(false);
231247
summaryNodataAP.toBack();
232248
}
249+
250+
public void focusAlertLog(ActionEvent e) {
251+
String input = navigatorTF.getText();
252+
if (!validateAlertLogNavigatorInput(input)) {
253+
return;
254+
}
255+
256+
int toIndex = Integer.parseInt(input);
257+
alertLogLV.scrollTo(toIndex - 1);
258+
alertLogLV.getSelectionModel().select(toIndex - 1);
259+
updateStatusMessage(String.format("[%d]번째 Log로 이동합니다.", toIndex));
260+
}
261+
262+
private boolean validateAlertLogNavigatorInput(String input) {
263+
if (StringUtils.isEmpty(input)) {
264+
updateStatusMessage("조회를 원하는 Log index를 입력해주세요.");
265+
return false;
266+
}
267+
268+
int toIndex = 0;
269+
try {
270+
toIndex = Integer.parseInt(input);
271+
} catch (NumberFormatException ex) {
272+
updateStatusMessage("숫자만 입력하실 수 있습니다.");
273+
return false;
274+
}
275+
276+
int alertLogSize = alertLogLV.getItems().size();
277+
if (alertLogSize == 0) {
278+
updateStatusMessage("Alert Log 조회 후 이용해주세요.");
279+
return false;
280+
}
281+
282+
if (toIndex <= 0 || toIndex > alertLogSize) {
283+
updateStatusMessage(String.format("Log index를 올바르게 입력해주세요. (가능한 입력값 범위: 1 ~ %d)", alertLogSize));
284+
return false;
285+
}
286+
287+
return true;
288+
}
289+
290+
/**
291+
* Update message at bottom status TextField region
292+
*
293+
* @param message
294+
*/
295+
private void updateStatusMessage(String message) {
296+
Thread statusTextUpdateThread = new Thread(() -> {
297+
Platform.runLater(() -> {
298+
statusTF.setText(message);
299+
});
300+
301+
try {
302+
Thread.sleep(1000);
303+
} catch (InterruptedException e) {
304+
log.error(e.getMessage());
305+
}
306+
Platform.runLater(() -> {
307+
statusTF.setText("");
308+
});
309+
});
310+
statusTextUpdateThread.setDaemon(true);
311+
statusTextUpdateThread.start();
312+
}
233313
}

src/main/resources/fxml/AlertLogMonitoringMenu.fxml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)