1919import org .zkoss .zk .ui .event .Events ;
2020import org .zkoss .zul .*;
2121import tools .dynamia .commons .ClassMessages ;
22+ import tools .dynamia .commons .DateTimeUtils ;
2223import tools .dynamia .commons .Messages ;
24+ import tools .dynamia .commons .logger .LoggingService ;
2325import tools .dynamia .integration .ProgressEvent ;
2426import tools .dynamia .integration .ProgressMonitor ;
2527import tools .dynamia .ui .MessageType ;
2628import tools .dynamia .ui .UIMessages ;
2729import tools .dynamia .zk .util .LongOperation ;
2830import tools .dynamia .zk .util .ZKUtil ;
2931
32+ import java .util .Date ;
33+
3034public class LongOperationMonitorWindow extends Window {
3135
3236 private static final long serialVersionUID = 1L ;
@@ -40,6 +44,8 @@ public class LongOperationMonitorWindow extends Window {
4044 private Label messageLabel ;
4145
4246 private String messageTemplate = messages .get ("DefaultProgressMessage" );
47+ private Listbox logListbox ;
48+ private boolean showLog ;
4349
4450 public LongOperationMonitorWindow (LongOperation longOperation , ProgressMonitor monitor ) {
4551 this .longOperation = longOperation ;
@@ -56,6 +62,7 @@ public static LongOperationMonitorWindow show(String title,
5662 win .setTitle (title );
5763 win .setPosition ("center" );
5864 win .doModal ();
65+ longOperation .onException (e -> win .detach ());
5966 return win ;
6067 }
6168
@@ -104,6 +111,10 @@ private void updateProgress(ProgressEvent evt) {
104111 progress .setValue (evt .getPercent ());
105112 progress .setTooltiptext (evt .getPercent () + "%" );
106113 messageLabel .setValue (evt .getMessage ());
114+ if (isShowLog ()) {
115+ var item = logListbox .appendItem (DateTimeUtils .formatTime (new Date ()) + " - " + evt .getMessage (), "" );
116+ logListbox .scrollToIndex (item .getIndex ());
117+ }
107118
108119 String title = Messages .format (messageTemplate ,
109120 evt .getCurrent (), evt .getMax (), evt .getPercent ());
@@ -127,6 +138,11 @@ private void initUI() {
127138 layout .setHflex ("1" );
128139 layout .setParent (this );
129140
141+ logListbox = new Listbox ();
142+ logListbox .setVisible (false );
143+ logListbox .setHeight ("150px" );
144+ logListbox .setParent (layout );
145+
130146 progress = new Progressmeter ();
131147 progress .setHflex ("2" );
132148 progress .setValue (0 );
@@ -137,6 +153,43 @@ private void initUI() {
137153 messageLabel = new Label ();
138154 messageLabel .setParent (msg );
139155 msg .setParent (layout );
156+
157+ Hlayout hlayout = new Hlayout ();
158+ hlayout .setHflex ("1" );
159+ hlayout .setParent (layout );
160+ hlayout .setVisible (false );
161+
162+ Label confirmStopLabel = new Label (messages .get ("ConfirmStopProcess" ));
163+ confirmStopLabel .setStyle ("font-weight:bold" );
164+ confirmStopLabel .setParent (hlayout );
165+
166+ Button yesBtn = new Button (messages .get ("yes" ));
167+ yesBtn .setZclass ("btn btn-success btn-sm" );
168+ yesBtn .setParent (hlayout );
169+ yesBtn .addEventListener (Events .ON_CLICK , evt -> stop ());
170+
171+ Button noBtn = new Button (messages .get ("no" ));
172+ noBtn .setZclass ("btn btn-danger btn-sm" );
173+ noBtn .setParent (hlayout );
174+ noBtn .addEventListener (Events .ON_CLICK , evt -> hlayout .setVisible (false ));
175+
176+ addEventListener (Events .ON_CLOSE , evt -> {
177+ evt .stopPropagation ();
178+ hlayout .setVisible (true );
179+ });
180+
181+ }
182+
183+ protected void stop () {
184+ try {
185+ longOperation .onFinish (null );
186+ monitor .stop ();
187+ } catch (Exception e ) {
188+ LoggingService .get (LongOperationMonitorWindow .class ).error ("Error stopping long operation" , e );
189+ } finally {
190+ finish ();
191+ }
192+
140193 }
141194
142195 @ Override
@@ -147,4 +200,13 @@ public void setTitle(String title) {
147200 public void setMessageTemplate (String messageTemplate ) {
148201 this .messageTemplate = messageTemplate ;
149202 }
203+
204+ public boolean isShowLog () {
205+ return showLog ;
206+ }
207+
208+ public void setShowLog (boolean showLog ) {
209+ this .showLog = showLog ;
210+ logListbox .setVisible (showLog );
211+ }
150212}
0 commit comments