From b2f5691167d020724ba3fbafbbe8d0d89dab4b61 Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Mon, 30 Jan 2012 16:21:02 -0600 Subject: [PATCH] Issue #27 Changes for alertviz exit Former-commit-id: e4718d87aafbfabc185f3d391fe9373e5abc5250 [formerly fbc018e6786730b7b597fbe5a179dc6880186b99] Former-commit-id: b2254f8df4116d9429ebc47301836dec32cdbd0b --- .../ui/dialogs/AlertVisualization.java | 26 ++++++++---- .../product/alertviz/AlertVizApplication.java | 13 ++++-- .../META-INF/MANIFEST.MF | 5 ++- .../alertviz/ThinAlertVizComponent.java | 40 ++++++++++++++++++- 4 files changed, 71 insertions(+), 13 deletions(-) diff --git a/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/AlertVisualization.java b/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/AlertVisualization.java index beedd52a21..453e8d4e6f 100644 --- a/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/AlertVisualization.java +++ b/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/AlertVisualization.java @@ -21,6 +21,7 @@ package com.raytheon.uf.viz.alertviz.ui.dialogs; import java.io.File; import java.io.FileNotFoundException; +import org.eclipse.equinox.app.IApplication; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MenuDetectEvent; @@ -90,6 +91,7 @@ import com.raytheon.uf.viz.core.VizApp; * changed. * 03 May 2011 9101 cjeanbap Pass a clone object into AlertVizPython class. * 31 May 2011 8058 cjeanbap Kill sound based on TextMsgBox id. + * 17 Jan 2012 27 rferrel Refactored to allow override of createTrayMenuItems * * * @author lvenable @@ -102,7 +104,7 @@ public class AlertVisualization implements ITimerAction, IAudioAction, /** * Dialog shell. */ - private Shell shell; + protected Shell shell; /** * The display control. @@ -132,7 +134,7 @@ public class AlertVisualization implements ITimerAction, IAudioAction, /** * A pop-up menu for the tray item. */ - private Menu trayItemMenu; + protected Menu trayItemMenu; /** * Show alert visualization menu item. @@ -212,13 +214,15 @@ public class AlertVisualization implements ITimerAction, IAudioAction, /** * Is this running as a standalone application */ - private final boolean runningStandalone; + protected final boolean runningStandalone; private Rectangle prevLocation = null; private ConfigContext configContext; private Configuration prevConfigFile; + + private Integer exitStatus = IApplication.EXIT_OK; /** * Constructor. @@ -381,7 +385,7 @@ public class AlertVisualization implements ITimerAction, IAudioAction, /** * Create the tray menu items. */ - private void createTrayMenuItems() { + protected void createTrayMenuItems() { showAlertDialogMI = new MenuItem(trayItemMenu, SWT.CHECK); showAlertDialogMI.setText("Show Alert Dialog"); @@ -810,6 +814,10 @@ public class AlertVisualization implements ITimerAction, IAudioAction, } } + public Integer getExitStatus() { + return exitStatus; + } + /** * This is the button click event for the alertPopupDialog. This function is * called when "Hide Dialog" is clicked. @@ -825,9 +833,13 @@ public class AlertVisualization implements ITimerAction, IAudioAction, @Override public void restart() { if (runningStandalone) { - // exit with an error code. alertViz.sh will then - // restart AlertViz - System.exit(1); + // Must use EXIT_RELAUNCH. EXIT_RESTART causes the + // executable to do a restart without returning to + // the shell/bat script. This fails. Any other value + // such as Integer(1) the executable attempts to bring + // up an error screen before exiting with the error code. + exitStatus = IApplication.EXIT_RELAUNCH; + display.dispose(); } } diff --git a/cave/com.raytheon.uf.viz.product.alertviz/src/com/raytheon/uf/viz/product/alertviz/AlertVizApplication.java b/cave/com.raytheon.uf.viz.product.alertviz/src/com/raytheon/uf/viz/product/alertviz/AlertVizApplication.java index ac955f1f9f..d4bb663924 100644 --- a/cave/com.raytheon.uf.viz.product.alertviz/src/com/raytheon/uf/viz/product/alertviz/AlertVizApplication.java +++ b/cave/com.raytheon.uf.viz.product.alertviz/src/com/raytheon/uf/viz/product/alertviz/AlertVizApplication.java @@ -54,6 +54,7 @@ import com.raytheon.uf.viz.core.localization.LocalizationManager; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Sep 29, 2008 #1433 chammack Initial creation + * Jan 12, 2012 #27 rferrel Added createAlertVisualization * * * @author chammack @@ -126,7 +127,7 @@ public class AlertVizApplication implements IStandaloneComponent { } // Job is not running on port, launch UI. - AlertVisualization av = new AlertVisualization(true, display); + AlertVisualization av = createAlertVisualization(true, display); Throwable t = null; try { while (!display.isDisposed()) { @@ -152,13 +153,17 @@ public class AlertVizApplication implements IStandaloneComponent { display.dispose(); if (t != null) { // Killed because of error, set exit status to non zero value - System.exit(1); + return IApplication.EXIT_RELAUNCH; } } - return IApplication.EXIT_OK; + return av.getExitStatus(); + } + + protected AlertVisualization createAlertVisualization( + boolean runningStandalone, final Display display) { + return new AlertVisualization(runningStandalone, display); } - protected void initializeObservers() { CAVELocalizationNotificationObserver.register(); } diff --git a/cave/com.raytheon.uf.viz.thinclient.alertviz/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.thinclient.alertviz/META-INF/MANIFEST.MF index 4a9ee8ac57..1545367269 100644 --- a/cave/com.raytheon.uf.viz.thinclient.alertviz/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.thinclient.alertviz/META-INF/MANIFEST.MF @@ -10,6 +10,9 @@ Require-Bundle: com.raytheon.uf.viz.core, org.eclipse.core.runtime;bundle-version="3.6.0", org.eclipse.ui;bundle-version="3.6.1", com.raytheon.uf.viz.thinclient;bundle-version="1.0.0", - com.raytheon.uf.viz.product.alertviz;bundle-version="1.12.1174" + com.raytheon.uf.viz.product.alertviz;bundle-version="1.12.1174", + com.raytheon.uf.viz.alertviz.ui;bundle-version="1.12.1174", + com.raytheon.uf.viz.alertviz;bundle-version="1.12.1174", + com.raytheon.uf.common.message;bundle-version="1.12.1174" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy diff --git a/cave/com.raytheon.uf.viz.thinclient.alertviz/src/com/raytheon/uf/viz/thinclient/alertviz/ThinAlertVizComponent.java b/cave/com.raytheon.uf.viz.thinclient.alertviz/src/com/raytheon/uf/viz/thinclient/alertviz/ThinAlertVizComponent.java index f85e9f9b48..4f9ea86fc8 100644 --- a/cave/com.raytheon.uf.viz.thinclient.alertviz/src/com/raytheon/uf/viz/thinclient/alertviz/ThinAlertVizComponent.java +++ b/cave/com.raytheon.uf.viz.thinclient.alertviz/src/com/raytheon/uf/viz/thinclient/alertviz/ThinAlertVizComponent.java @@ -19,7 +19,16 @@ **/ package com.raytheon.uf.viz.thinclient.alertviz; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.MessageBox; + +import com.raytheon.uf.viz.alertviz.ui.dialogs.AlertVisualization; import com.raytheon.uf.viz.product.alertviz.AlertVizApplication; +import com.raytheon.uf.viz.thinclient.Activator; import com.raytheon.uf.viz.thinclient.IThinClientComponent; import com.raytheon.uf.viz.thinclient.StatsJob; import com.raytheon.uf.viz.thinclient.ThinClientNotificationManagerJob; @@ -37,6 +46,7 @@ import com.raytheon.uf.viz.thinclient.localization.ThinClientLocalizationInitial * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Nov 29, 2011 mschenke Initial creation + * Jan 12, 2012 27 rferrel Added exit option * * * @@ -53,7 +63,8 @@ public class ThinAlertVizComponent extends AlertVizApplication implements @Override public Object startComponent(String componentName) throws Exception { - // Start network statistics + Activator.getDefault().setComponent(this); + // Start network statistics statsJob = new StatsJob(); statsJob.schedule(); return super.startComponent(componentName); @@ -82,4 +93,31 @@ public class ThinAlertVizComponent extends AlertVizApplication implements ThinClientNotificationManagerJob.getInstance(); } + protected AlertVisualization createAlertVisualization( + boolean runningStandalone, final Display display) { + return new AlertVisualization(runningStandalone, display) { + + @Override + protected void createTrayMenuItems() { + super.createTrayMenuItems(); + if (!runningStandalone) { + new MenuItem(trayItemMenu, SWT.SEPARATOR); + } + MenuItem exitMI = new MenuItem(trayItemMenu, SWT.NONE); + exitMI.setText("Exit..."); + exitMI.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION + | SWT.YES | SWT.NO); + mb.setText("Confirm Exit"); + mb.setMessage("Any unsaved changes will be lost.\n Are you sure you want to exit?"); + if (mb.open() == SWT.YES) { + display.dispose(); + } + } + }); + } + }; + } }