From f92986658064718bc73960274937892d39b603bc Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Wed, 5 Dec 2012 15:24:01 -0600 Subject: [PATCH] Issue #1353 Changes for non-blocking FFTIControlDlg. Change-Id: Idf182e728a60d55aeb671201396c97beb3752bb3 Former-commit-id: 343c2c25dd25712d98d23d73308bbb83d57c361a [formerly d5098337147114e51b526c212b4a2473d3e6d5eb] [formerly b81d12f775f7601aea367267e490a4c9fd3f9bd9] [formerly 343c2c25dd25712d98d23d73308bbb83d57c361a [formerly d5098337147114e51b526c212b4a2473d3e6d5eb] [formerly b81d12f775f7601aea367267e490a4c9fd3f9bd9] [formerly 171dd5c3bfb9e3ff0133dee521442ddc9dc6c0f1 [formerly b81d12f775f7601aea367267e490a4c9fd3f9bd9 [formerly 8bf40b32fc3d9e0fa11133d8fb7ac94e6dcf4c05]]]] Former-commit-id: 171dd5c3bfb9e3ff0133dee521442ddc9dc6c0f1 Former-commit-id: 6d48ea303b509c676ec7171518fe0e75256da14c [formerly 778100f3d6a3a5c379dcae1a16da70a7603c83cf] [formerly 8658544258904029f7bf236ea6d3f1c93481904d [formerly 2f3b6935763ceaeed57e1d01b5d3ef5c8dddf0ee]] Former-commit-id: b1e3e6c68a6392af3436ed15b6f0adde84a61aa6 [formerly 48943302fedad06b621cd294e1f73b74b760d925] Former-commit-id: 8afb72099b07783775a184e053a97b0c9ea4a5eb --- .../viz/monitor/ffmp/ffti/FFTIControlDlg.java | 225 ++++++++++-------- .../monitor/ffmp/ui/actions/FFTIAction.java | 17 +- 2 files changed, 142 insertions(+), 100 deletions(-) diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ffti/FFTIControlDlg.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ffti/FFTIControlDlg.java index 9ee15a3950..9fb38f3934 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ffti/FFTIControlDlg.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ffti/FFTIControlDlg.java @@ -20,20 +20,19 @@ package com.raytheon.uf.viz.monitor.ffmp.ffti; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; -import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.ShellAdapter; -import org.eclipse.swt.events.ShellEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Dialog; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; @@ -49,43 +48,75 @@ import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.localization.LocalizationManager; +import com.raytheon.viz.ui.dialogs.CaveSWTDialog; -public class FFTIControlDlg extends Dialog { - /** - * Dialog shell. - */ - private Shell shell; +/** + * Flash Flood Threat Indicator display dialog. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ *                                     Initial creation
+ * Dec 5, 2012  1353      rferrel      Convert to CaveSWTDialog and made non-blocking.
+ * 
+ * 
+ * + * @author rferrel + * @version 1.0 + */ +public class FFTIControlDlg extends CaveSWTDialog { /** - * The display control. + * THe CWAs monitor selection buttons. */ - private Display display; - - private Hashtable cwa_list; + private Map cwa_list; + /** + * Adds setting tab items to the FFTI tab folder. + */ private Button addSettingBtn; + /** + * Remove setting tab items from the FFTI tab folder. + */ private Button removeSettingBtn; + /** + * The FFTI tab folder. + */ private TabFolder fftiTabFolder; - private String[] tabTitles = new String[] { "Setting 1", "Setting 2", + /** + * Setting tab item names. + */ + private final String[] tabTitles = new String[] { "Setting 1", "Setting 2", "Setting 3", "Setting 4", "Setting 5" }; - private static final transient IUFStatusHandler statusHandler = UFStatus + private final IUFStatusHandler statusHandler = UFStatus .getHandler(FFTIControlDlg.class); - private boolean disposed = false; - + /** + * Constructor to set up non-blocking dialog. + * + * @param parent + */ public FFTIControlDlg(Shell parent) { - super(parent, 0); + super(parent, SWT.DIALOG_TRIM | SWT.RESIZE, CAVE.DO_NOT_BLOCK); + setText("Flash Flood Threat Indicator (FFTI) Control"); } - public Object open() { - Shell parent = getParent(); - display = parent.getDisplay(); - shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE); - shell.setText("Flash Flood Threat Indicator (FFTI) Control"); + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#initializeComponents(org + * .eclipse.swt.widgets.Shell) + */ + @Override + protected void initializeComponents(Shell shell) { // Create the main layout for the shell. GridLayout mainLayout = new GridLayout(1, false); @@ -95,19 +126,11 @@ public class FFTIControlDlg extends Dialog { // Initialize all of the controls and layouts initializeComponents(); - - shell.pack(); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - - return null; } + /** + * Set up dialog components. + */ private void initializeComponents() { try { createCwaControls(); @@ -124,18 +147,14 @@ public class FFTIControlDlg extends Dialog { updateTabSettings(); - shell.addShellListener(new ShellAdapter() { - @Override - public void shellClosed(ShellEvent event) { - disposed = true; - } - }); } catch (Exception e) { statusHandler.handle(Priority.ERROR, "FFTI Can not load...", e); - e.printStackTrace(); } } + /** + * Set up selection buttons for the CWAs monitors. + */ private void createCwaControls() { GridLayout gl = new GridLayout(10, false); Composite cwaComp = new Composite(shell, SWT.NONE); @@ -143,11 +162,11 @@ public class FFTIControlDlg extends Dialog { Label cwaLbl = new Label(cwaComp, SWT.NONE); cwaLbl.setText("CWAs Monitored: "); - cwa_list = new Hashtable(); + cwa_list = new HashMap(); String siteName = LocalizationManager.getInstance().getCurrentSite() .toUpperCase(); - // load a runner by finding the primey domain + // load a runner by finding the primary domain FFMPRunConfigurationManager frcm = FFMPRunConfigurationManager .getInstance(); FFMPRunXML runner = frcm.getRunner(siteName); @@ -181,6 +200,9 @@ public class FFTIControlDlg extends Dialog { } } + /** + * Buttons to add remove tab items from the FFTI tab. + */ private void createTabFolderControls() { Composite tabControlComp = new Composite(shell, SWT.NONE); tabControlComp.setLayout(new GridLayout(2, false)); @@ -210,6 +232,9 @@ public class FFTIControlDlg extends Dialog { }); } + /** + * Layout the FFTI tab folder. + */ private void createSettingTabFolder() { GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); fftiTabFolder = new TabFolder(shell, SWT.NONE); @@ -218,11 +243,14 @@ public class FFTIControlDlg extends Dialog { fftiTabFolder.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - tabSelectedAction(); + updateTabSettings(); } }); } + /** + * The bottom save and close buttons. + */ private void createBottomButtons() { GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); Composite buttonComp = new Composite(shell, SWT.NONE); @@ -251,19 +279,18 @@ public class FFTIControlDlg extends Dialog { closeBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - disposed = true; - shell.dispose(); + close(); } }); } /** - * get the duplicated settings + * Get the duplicated settings. * * @return duplicate list */ - private HashSet getDuplicates() { - HashSet duplicateLst = new HashSet(); + private Set getDuplicates() { + Set duplicateLst = new HashSet(); for (int i = 0; i < fftiTabFolder.getItemCount(); i++) { SettingComp thisItem = (SettingComp) fftiTabFolder.getItem(i) .getControl(); @@ -279,11 +306,19 @@ public class FFTIControlDlg extends Dialog { && (thisItem.getQpeDurHr() == nextItem.getQpeDurHr()) && (thisItem.getGuidDurHr() == nextItem.getGuidDurHr()) && (thisItem.getQpfDurHr() == nextItem.getQpfDurHr()) - && (thisItem.getTotalDurHr() == nextItem.getTotalDurHr()) - && (thisItem.getQpeSrc().length > 0 && nextItem.getQpeSrc().length > 0 && thisItem.getQpeSrc()[0].equals(nextItem.getQpeSrc()[0])) - && (thisItem.getQpfSrc().length > 0 && nextItem.getQpfSrc().length > 0 && thisItem.getQpfSrc()[0].equals(nextItem.getQpfSrc()[0])) - && (thisItem.getGuidSrc().length > 0 && nextItem.getGuidSrc().length > 0 && thisItem.getGuidSrc()[0].equals(nextItem.getGuidSrc()[0]))) { - + && (thisItem.getTotalDurHr() == nextItem + .getTotalDurHr()) + && (thisItem.getQpeSrc().length > 0 + && nextItem.getQpeSrc().length > 0 && thisItem + .getQpeSrc()[0].equals(nextItem.getQpeSrc()[0])) + && (thisItem.getQpfSrc().length > 0 + && nextItem.getQpfSrc().length > 0 && thisItem + .getQpfSrc()[0].equals(nextItem.getQpfSrc()[0])) + && (thisItem.getGuidSrc().length > 0 + && nextItem.getGuidSrc().length > 0 && thisItem + .getGuidSrc()[0] + .equals(nextItem.getGuidSrc()[0]))) { + duplicateLst.add(i + 1); duplicateLst.add(j + 1); } @@ -293,25 +328,23 @@ public class FFTIControlDlg extends Dialog { return duplicateLst; } + /** + * Save the current settings to the FFTIDataManger. + */ protected void saveAllSettings() { // Find duplicates - HashSet duplicates = getDuplicates(); + Set duplicates = getDuplicates(); if (duplicates.size() > 0) { - String setsStr = ""; - int i = 0; - for (Integer setIndex : duplicates) { - setsStr += setIndex; - if (i != duplicates.size()-1) { - setsStr = setsStr + "/"; - } - i++; + StringBuilder message = new StringBuilder("Sets "); + String separator = ""; + for (int setIndex : duplicates) { + message.append(separator).append(setIndex); + separator = "/"; } + message.append(" are duplicated!\nModify the configuration before saving."); MessageBox messageBox = new MessageBox(shell, SWT.OK); messageBox.setText("Warning: Duplicate Setting(s)!"); - messageBox - .setMessage("Sets " - + setsStr - + " are duplicated!\nModify the configuration before saving."); + messageBox.setMessage(message.toString()); messageBox.open(); return; } @@ -322,13 +355,13 @@ public class FFTIControlDlg extends Dialog { fdm.clear(); // get the selected CWA list - ArrayList selectedCwas = getCWASelectionIDs(); + List selectedCwas = getCWASelectionIDs(); - fdm.setCwaList(selectedCwas); + fdm.setCwaList((ArrayList) selectedCwas); // get attribute, and sources for each tab TabItem[] tabItemArray = fftiTabFolder.getItems(); - ArrayList settings = new ArrayList(); + List settings = new ArrayList(); for (TabItem ti : tabItemArray) { SettingComp sc = (SettingComp) ti.getControl(); @@ -365,10 +398,13 @@ public class FFTIControlDlg extends Dialog { settings.add(aSetting); } - fdm.setSettings(settings); + fdm.setSettings((ArrayList) settings); fdm.saveConfigXml(); } + /** + * Add a new setting tab in the FFTI tab folder. + */ private void createSettingTabs() { FFTIDataManager fftiDataMgr = FFTIDataManager.getInstance(); @@ -388,6 +424,11 @@ public class FFTIControlDlg extends Dialog { } } + /** + * Place horizontal separator in the component. + * + * @param parentComp + */ private void addSeparator(Composite parentComp) { GridLayout gl = (GridLayout) parentComp.getLayout(); @@ -397,6 +438,9 @@ public class FFTIControlDlg extends Dialog { sepLbl.setLayoutData(gd); } + /** + * Add a new settings tab. + */ private void addSettingTab() { // Add tab TabItem settingTab = new TabItem(fftiTabFolder, SWT.NONE); @@ -409,11 +453,10 @@ public class FFTIControlDlg extends Dialog { removeSettingBtn.setEnabled(true); } + /** + * Dispose of the control in the selected tab and then dispose of the tab. + */ private void removeSettingTab() { - /* - * Dispose of the control in the selected tab and then dispose of the - * tab. - */ int selectedTab = fftiTabFolder.getSelectionIndex(); fftiTabFolder.getItem(selectedTab).getControl().dispose(); fftiTabFolder.getItem(selectedTab).dispose(); @@ -425,10 +468,9 @@ public class FFTIControlDlg extends Dialog { removeSettingBtn.setEnabled(false); } - private void tabSelectedAction() { - updateTabSettings(); - } - + /** + * Update the enable status of tab control buttons. + */ private void updateTabSettings() { if (fftiTabFolder.getItemCount() > 1) { if (fftiTabFolder.getSelectionIndex() == 0) { @@ -447,6 +489,9 @@ public class FFTIControlDlg extends Dialog { } } + /** + * Adjust the names of the FFTI tab folder items. + */ private void renameTabs() { TabItem[] tabItemArray = fftiTabFolder.getItems(); @@ -455,26 +500,20 @@ public class FFTIControlDlg extends Dialog { } } - /* - * getCWASelection() return a listed names of CWA button that is on checking - * state. + /** + * Get CWA names whose buttons are selected. + * + * @return cwaIds */ - public ArrayList getCWASelectionIDs() { - ArrayList cwaIds = new ArrayList(); + public List getCWASelectionIDs() { + List cwaIds = new ArrayList(); for (Object id : cwa_list.keySet().toArray()) { Button cwa_bt = cwa_list.get(id); if (cwa_bt.getSelection()) { - cwaIds.add((String) id); + cwaIds.add(id.toString()); } } return cwaIds; } - - /** - * @return the disposed - */ - public boolean isDisposed() { - return disposed; - } } diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/actions/FFTIAction.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/actions/FFTIAction.java index e07ac7f9e2..54beb20c51 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/actions/FFTIAction.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/actions/FFTIAction.java @@ -22,6 +22,7 @@ package com.raytheon.uf.viz.monitor.ffmp.ui.actions; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; @@ -37,6 +38,7 @@ import com.raytheon.uf.viz.monitor.ffmp.ffti.FFTIControlDlg; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 1/27/10 4265 dhladky Initial Creation. + * 12/05/2012 1353 rferrel Changes for non-blocking FFTIControlDlg. * * * @@ -49,18 +51,19 @@ public class FFTIAction extends AbstractHandler { @Override public Object execute(ExecutionEvent arg0) throws ExecutionException { - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getShell(); + shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT)); - System.out.println("Activating/Action the FFTI dialogs..."); - - if ((fftiControlDlg == null) || fftiControlDlg.isDisposed()) { + // Must create new dialog when old is closed instead of just opening the + // old dialog again. This will restore the dialog to the last saved + // changes. + if (fftiControlDlg == null || fftiControlDlg.getShell() == null + || fftiControlDlg.isDisposed()) { fftiControlDlg = new FFTIControlDlg(shell); - fftiControlDlg.open(); - fftiControlDlg = null; } + fftiControlDlg.open(); + shell.setCursor(null); return null; } - }