package utask.ui.dialogs;

import com.google.common.eventbus.Subscribe;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDialog;
import com.jfoenix.controls.JFXDialog.DialogTransition;
import com.jfoenix.controls.JFXDialogLayout;

import javafx.event.ActionEvent;
import javafx.scene.layout.StackPane;
import utask.commons.core.EventsCenter;
import utask.staging.ui.events.KeyboardEscapeKeyPressedEvent;

public abstract class UTDialog {
    protected final JFXDialog dialog;
    protected final JFXDialogLayout contentLayout;
    private boolean isShowing = false;

    public UTDialog(StackPane parent) {
        dialog = new JFXDialog();
        contentLayout = new JFXDialogLayout();
        initialize(parent);
        initialize();
        EventsCenter.getInstance().registerHandler(this);
    }

    private void initialize(StackPane parent) {
        dialog.setDialogContainer(parent);
        dialog.setContent(contentLayout);
        dialog.setTransitionType(DialogTransition.CENTER);

        JFXButton closeButton = new JFXButton("CLOSE [ESC]");
        closeButton.setStyle("-fx-text-fill: -fx-utask-accentcolor");
        closeButton.setOnAction(this::onClose);

        contentLayout.setActions(closeButton);
    }

    protected abstract void initialize();

    protected void show() {
        isShowing = true;
        dialog.show();
    }

    private void onClose(ActionEvent event) {
        isShowing = false;
        dialog.close();
    }

    @Subscribe
    private void handleKeyboardEscapeKeyPressedEvent(KeyboardEscapeKeyPressedEvent event) {
        if (isShowing) {
            onClose(null);
        }
    }
}

@@ -20,16 +20,50 @@
 alogs;%0A%0A
+import java.util.logging.Logger;%0A%0A
 import c
@@ -99,16 +99,16 @@
 scribe;%0A
-
 import c
@@ -283,41 +283,8 @@
 t;%0A%0A
-import javafx.event.ActionEvent;%0A
 impo
@@ -357,16 +357,92 @@
 Center;%0A
+import utask.commons.core.LogsCenter;%0Aimport utask.staging.ui.UTMainWindow;%0A
 import u
@@ -531,31 +531,112 @@
 log %7B%0A    pr
-otec
+ivate static final Logger logger = LogsCenter.getLogger(UTMainWindow.class);%0A    priva
 te
-d
  final JFXDi
@@ -771,32 +771,90 @@
 kPane parent) %7B%0A
+        assert parent != null : %22Parent cannot be null%22;%0A%0A
         dialog =
@@ -1394,21 +1394,53 @@
 ion(
-this::onClose
+(event) -%3E %7B%0A            onClose();%0A        %7D
 );%0A%0A
@@ -1560,24 +1560,121 @@
 id show() %7B%0A
+        logger.fine(%22Showing dialog window for detailed view of alias, tag colors or message.%22);%0A
         isSh
@@ -1746,25 +1746,8 @@
 ose(
-ActionEvent event
 ) %7B%0A
@@ -1932,24 +1932,95 @@
 sShowing) %7B%0A
+            logger.info(LogsCenter.getEventHandlingLogMessage(event));%0A
             
@@ -2027,20 +2027,16 @@
 onClose(
-null
 );%0A     

add logging to dialogs