From 624ae21f3792ae7e4d3d6655e6c0e70c585ccca8 Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Tue, 23 Oct 2012 12:40:48 -0500 Subject: [PATCH] Issue #1287 Changes for non-blocking FormatterLauncherDialog and code cleanup. Change-Id: If2fbef2f2a128ff151525eed4feaf4273fa99855 Former-commit-id: d0a88b88a3102d4e40b3d18d5a5f67cc9fb69eac [formerly 257bdcaa9141567d93e9c316368c490b7f9c9251] [formerly 656f582e224a27ad539891fffaf037727528f519] [formerly 525a5bb8d1b101e7f394f0e342d1415358fd5ceb [formerly 656f582e224a27ad539891fffaf037727528f519 [formerly 936092efc2f69ab3e2060334fddd630100da4157]]] Former-commit-id: 525a5bb8d1b101e7f394f0e342d1415358fd5ceb Former-commit-id: c93f8795e80bbe1ad3e4947807e86c58c7778004 [formerly cc5ef23f23c2a8db3502165da8fc5d001464427a] Former-commit-id: d82d50faf161373fa74d6c8f113c96472f6d06a0 --- .../gfe/actions/FormatterlauncherAction.java | 32 ++-- .../gfe/dialogs/FormatterLauncherDialog.java | 181 +++++++----------- .../perspective/GFEPerspectiveManager.java | 12 +- 3 files changed, 91 insertions(+), 134 deletions(-) diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/actions/FormatterlauncherAction.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/actions/FormatterlauncherAction.java index a75169c76e..ef0a34ad85 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/actions/FormatterlauncherAction.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/actions/FormatterlauncherAction.java @@ -35,6 +35,7 @@ import com.raytheon.viz.gfe.dialogs.FormatterLauncherDialog; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Apr 11, 2008 Eric Babin Initial Creation + * Oct 23, 2012 1287 rferrel Changes for non-blocking FormatterLauncherDialog. * * * @@ -56,28 +57,31 @@ public class FormatterlauncherAction extends AbstractHandler { @Override public Object execute(ExecutionEvent arg0) throws ExecutionException { - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() - .getShell(); - - if (dialog == null) { + if (dialog == null || dialog.getShell() == null || dialog.isDisposed()) { + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getShell(); dialog = new FormatterLauncherDialog(shell); - dialog.setBlockOnOpen(true); - dialog.open(); - dialog.dispose(); - dialog = null; - } else if (dialog.getShell() == null) { + dialog.setBlockOnOpen(false); dialog.open(); } else { - dialog.getShell().setVisible(true); - dialog.getShell().setActive(); + dialog.bringToTop(); if (dialog.buttonBar != null) { dialog.buttonBar.moveAbove(null); } } return null; } - - public static FormatterLauncherDialog getFormatterLauncher() { - return dialog; + + public static void closeFormatters() { + if (dialog != null && dialog.getShell() != null && !dialog.isDisposed()) { + dialog.closeFormatters(); + } + } + + public static void closeDialog() { + if (dialog != null && dialog.getShell() != null && !dialog.isDisposed()) { + dialog.closeDialog(); + } + dialog = null; } } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/FormatterLauncherDialog.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/FormatterLauncherDialog.java index 9f123d61a4..c9f0f3f5ff 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/FormatterLauncherDialog.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/dialogs/FormatterLauncherDialog.java @@ -89,6 +89,7 @@ import com.raytheon.viz.ui.dialogs.CaveJFACEDialog; * Sep 16, 2010 6831 ryu Show same product for different areas on a sub-menu * Nov 22, 2011 8781 mli remove Processor menu * Jul 26, 2012 15165 ryu Set default db source when formatter has no db defined. + * Oct 23, 2012 1287 rferrel Changes for non-blocking dialogs and code clean up. * * * @@ -98,27 +99,22 @@ import com.raytheon.viz.ui.dialogs.CaveJFACEDialog; public class FormatterLauncherDialog extends CaveJFACEDialog implements IProductTab { - private static final transient IUFStatusHandler statusHandler = UFStatus + private final transient IUFStatusHandler statusHandler = UFStatus .getHandler(FormatterLauncherDialog.class); - private static final String BASELINE = "Baseline"; + private final String BASELINE = "Baseline"; - private static final String CIVIL_EMERGENCY = "CivilEmergency"; + private final String CIVIL_EMERGENCY = "CivilEmergency"; - private static final String HAZARD = "Hazard"; + private final String HAZARD = "Hazard"; - private static final String BASELINE_HAZARD = BASELINE + HAZARD; + private final String BASELINE_HAZARD = BASELINE + HAZARD; - private static final String REGION = "Region"; + private final String REGION = "Region"; - private static final String OTHERS = ""; + private final String OTHERS = ""; - private static final String PRODUCT_EDITOR = "Product Editor"; - - /** - * Return object when the shell is disposed. - */ - private Boolean returnObj = null; + private final String PRODUCT_EDITOR = "Product Editor"; /** * Tab folder containing the product tabs. @@ -207,6 +203,8 @@ public class FormatterLauncherDialog extends CaveJFACEDialog implements private String selectedDataSource = null; + private boolean doClose = false; + /** * Constructor. * @@ -273,7 +271,6 @@ public class FormatterLauncherDialog extends CaveJFACEDialog implements createProductsMenu(menuBar); createDataSourceMenu(menuBar); -// createProcessorMenu(menuBar); createIssuedByMenu(menuBar); createHelpMenu(menuBar); @@ -380,67 +377,12 @@ public class FormatterLauncherDialog extends CaveJFACEDialog implements public void widgetSelected(SelectionEvent event) { } }); - // - // // Set selected data source to official database name - // try { - // ServerResponse> sr = DataManager - // .getCurrentInstance().getClient().getOfficialDBName(); - // selectedDataSource = sr.getPayload().get(0).toString(); - // } catch (GFEServerException e) { - // UFStatus.handle(Priority.PROBLEM, Activator.PLUGIN_ID, - // StatusConstants.CATEGORY_GFE, - // StatusConstants.SUBCATEGORY_TEXTFORMATTER, - // "Unable to determine official db", e); - // } } else { selectedDataSource = DataManager.getCurrentInstance() .getParmManager().getMutableDatabase().toString(); } } - /** - * Create the Processor menu. - * - * @param menuBar - * Menu bar. - */ - /* - private void createProcessorMenu(Menu menuBar) { - // ------------------------------------- - // Create the Processor menu - // ------------------------------------- - MenuItem processorMenuItem = new MenuItem(menuBar, SWT.CASCADE); - processorMenuItem.setText("&Processor"); - - // Create the Processor menu item with a Products "dropdown" menu - Menu processorMenu = new Menu(menuBar); - processorMenuItem.setMenu(processorMenu); - - // ------------------------------------------------------ - // Create all the items in the Processor dropdown menu - // ------------------------------------------------------ - - // Server menu item - MenuItem serverMI = new MenuItem(processorMenu, SWT.RADIO); - serverMI.setText("Server"); - serverMI.setSelection(true); - serverMI.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent event) { - } - }); - - // Local menu item - MenuItem localMI = new MenuItem(processorMenu, SWT.RADIO); - localMI.setText("Local"); - localMI.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent event) { - } - }); - } - */ - /** * Create the Issued By menu. * @@ -932,9 +874,13 @@ public class FormatterLauncherDialog extends CaveJFACEDialog implements return null; } - public void createHideButton() { + /** + * Have the Hide button act like an OK button so it will call the close + * method when selected. + */ + private void createHideButton() { Composite bar = (Composite) super.createButtonBar(top); - createButton(bar, IDialogConstants.CLIENT_ID, "Hide", false); + createButton(bar, IDialogConstants.OK_ID, "Hide", false); } /** @@ -976,31 +922,34 @@ public class FormatterLauncherDialog extends CaveJFACEDialog implements } private void showViewMessagesDialog() { - viewMessageDialog = new ViewMessagesDialog(getParentShell()); - - viewMessageDialog.open(); + if (viewMessageDialog == null || viewMessageDialog.getShell() == null + || viewMessageDialog.isDisposed()) { + viewMessageDialog = new ViewMessagesDialog(getParentShell()); + viewMessageDialog.setBlockOnOpen(false); + viewMessageDialog.open(); + } else { + viewMessageDialog.setMessageItems(); + viewMessageDialog.bringToTop(); + } } - public void dispose() { + private void dispose() { textProductMgr.dispose(); } - class ViewMessagesDialog extends org.eclipse.swt.widgets.Dialog { + class ViewMessagesDialog extends CaveJFACEDialog { private List messageList; - private Shell shell; - - private Display display; - public ViewMessagesDialog(Shell parentShell) { super(parentShell); + setShellStyle(SWT.DIALOG_TRIM); + } - display = getParent().getDisplay(); - shell = new Shell(getParent(), SWT.DIALOG_TRIM); - + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); shell.setText("View Messages"); - // Create the main layout for the shell. GridLayout mainLayout = new GridLayout(1, false); mainLayout.marginHeight = 2; @@ -1016,31 +965,15 @@ public class FormatterLauncherDialog extends CaveJFACEDialog implements gd.heightHint = 320; gd.widthHint = 475; messageList.setLayoutData(gd); - + setMessageItems(); } - public void setMessageItems(String[] messageItems) { - messageList.removeAll(); - messageList.setItems(messageItems); - - } - - public Object open() { + public void setMessageItems() { String[] messages = new String[statusMessages.size()]; statusMessages.toArray(messages); + messageList.removeAll(); messageList.setItems(messages); - - shell.pack(); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - - return returnObj; } } @@ -1093,18 +1026,42 @@ public class FormatterLauncherDialog extends CaveJFACEDialog implements return source; } - @Override - public boolean close() { - // make clicking the x in the upper right corner just hide the dialog - // instead of closing it - getShell().setVisible(false); - return false; + /** + * Perform a real close of the dialog instead of just hiding it. + * + * @return + */ + public boolean closeDialog() { + doClose = true; + return close(); } + /** + * This hides the fromat launcher dialog and any dialogs it creates. + */ + public void hideDialog() { + if (viewMessageDialog != null) { + viewMessageDialog.hide(); + } + hide(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.Dialog#close() + */ @Override - protected void finalize() throws Throwable { - dispose(); - super.finalize(); + public boolean close() { + if (doClose) { + dispose(); + return super.close(); + } + + // make clicking the x in the upper right corner just hide the dialog + // instead of closing it + hideDialog(); + return false; } public void closeFormatters() { diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/perspective/GFEPerspectiveManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/perspective/GFEPerspectiveManager.java index 0537c4b3d8..712f93f141 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/perspective/GFEPerspectiveManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/perspective/GFEPerspectiveManager.java @@ -48,8 +48,8 @@ import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.IDisplayPaneContainer; import com.raytheon.uf.viz.core.IExtent; import com.raytheon.uf.viz.core.PixelExtent; -import com.raytheon.uf.viz.core.drawables.IRenderableDisplay; import com.raytheon.uf.viz.core.RGBColors; +import com.raytheon.uf.viz.core.drawables.IRenderableDisplay; import com.raytheon.uf.viz.core.drawables.ResourcePair; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.map.IMapDescriptor; @@ -88,6 +88,7 @@ import com.raytheon.viz.ui.perspectives.VizPerspectiveListener; * Apr 27, 2010 mschenke refactor for common perspective switching * Jul 7, 2011 #9897 ryu close formatters on perspective close/reset * Aug 20,2012 #1077 randerso Added support for bgColor setting + * Oct 23, 2012 #1287 rferrel Changes for non-blocking FormattrLauncherDialog. * * * @author randerso @@ -247,9 +248,7 @@ public class GFEPerspectiveManager extends AbstractCAVEPerspectiveManager { SmartToolJob.shutdown(); } }).start(); - if (FormatterlauncherAction.getFormatterLauncher() != null) { - FormatterlauncherAction.getFormatterLauncher().closeFormatters(); - } + FormatterlauncherAction.closeDialog(); } @Override @@ -258,10 +257,7 @@ public class GFEPerspectiveManager extends AbstractCAVEPerspectiveManager { if (IWorkbenchPage.CHANGE_RESET.equals(VizPerspectiveListener .getInstance().getPerspectiveChangeId( GFEPerspective.ID_PERSPECTIVE))) { - if (FormatterlauncherAction.getFormatterLauncher() != null) { - FormatterlauncherAction.getFormatterLauncher() - .closeFormatters(); - } + FormatterlauncherAction.closeFormatters(); } }