77import java .util .Map ;
88import java .util .ResourceBundle ;
99
10+ import org .apache .commons .lang3 .StringUtils ;
11+
1012import com .jfoenix .controls .JFXComboBox ;
1113import com .jfoenix .controls .JFXListView ;
1214
15+ import javafx .application .Platform ;
1316import javafx .event .ActionEvent ;
17+ import javafx .event .Event ;
18+ import javafx .event .EventHandler ;
1419import javafx .fxml .FXML ;
1520import javafx .fxml .Initializable ;
1621import javafx .scene .control .Alert .AlertType ;
1722import javafx .scene .control .DatePicker ;
23+ import javafx .scene .control .TextField ;
24+ import javafx .scene .input .KeyCode ;
25+ import javafx .scene .input .KeyEvent ;
1826import javafx .scene .layout .AnchorPane ;
1927import javafx .scene .layout .StackPane ;
28+ import lombok .extern .slf4j .Slf4j ;
2029import root .common .server .implement .JschServer ;
2130import root .core .domain .AlertLog ;
2231import root .core .domain .JschConnectionInfo ;
3342import root .core .usecase .implement .ServerMonitoringUsecaseImpl ;
3443import root .javafx .CustomView .AlertLogListViewCell ;
3544import root .javafx .CustomView .AlertLogMonitoringSummaryAP ;
45+ import root .javafx .CustomView .NumberTextFormatter ;
3646import root .javafx .CustomView .dateCell .DisableAfterTodayDateCell ;
3747import root .utils .AlertUtils ;
3848
49+ @ Slf4j
3950public 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}
0 commit comments