Issue #1353 Changes for non-blocking FFTIControlDlg.

Change-Id: Idf182e728a60d55aeb671201396c97beb3752bb3

Former-commit-id: 343c2c25dd [formerly d509833714] [formerly b81d12f775] [formerly 171dd5c3bf [formerly b81d12f775 [formerly 8bf40b32fc3d9e0fa11133d8fb7ac94e6dcf4c05]]]
Former-commit-id: 171dd5c3bf
Former-commit-id: 8658544258904029f7bf236ea6d3f1c93481904d [formerly 2f3b693576]
Former-commit-id: 778100f3d6
This commit is contained in:
Roger Ferrel 2012-12-05 15:24:01 -06:00
parent 58d8c919ae
commit 6d48ea303b
2 changed files with 142 additions and 100 deletions

View file

@ -20,20 +20,19 @@
package com.raytheon.uf.viz.monitor.ffmp.ffti; package com.raytheon.uf.viz.monitor.ffmp.ffti;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; 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.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; 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.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; 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.Label;
import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell; 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;
import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.localization.LocalizationManager; import com.raytheon.uf.viz.core.localization.LocalizationManager;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
public class FFTIControlDlg extends Dialog { /**
/** * Flash Flood Threat Indicator display dialog.
* Dialog shell. *
*/ * <pre>
private Shell shell; *
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Initial creation
* Dec 5, 2012 1353 rferrel Convert to CaveSWTDialog and made non-blocking.
*
* </pre>
*
* @author rferrel
* @version 1.0
*/
public class FFTIControlDlg extends CaveSWTDialog {
/** /**
* The display control. * THe CWAs monitor selection buttons.
*/ */
private Display display; private Map<String, Button> cwa_list;
private Hashtable<String, Button> cwa_list;
/**
* Adds setting tab items to the FFTI tab folder.
*/
private Button addSettingBtn; private Button addSettingBtn;
/**
* Remove setting tab items from the FFTI tab folder.
*/
private Button removeSettingBtn; private Button removeSettingBtn;
/**
* The FFTI tab folder.
*/
private TabFolder fftiTabFolder; 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" }; "Setting 3", "Setting 4", "Setting 5" };
private static final transient IUFStatusHandler statusHandler = UFStatus private final IUFStatusHandler statusHandler = UFStatus
.getHandler(FFTIControlDlg.class); .getHandler(FFTIControlDlg.class);
private boolean disposed = false; /**
* Constructor to set up non-blocking dialog.
*
* @param parent
*/
public FFTIControlDlg(Shell 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(); * (non-Javadoc)
display = parent.getDisplay(); *
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE); * @see
shell.setText("Flash Flood Threat Indicator (FFTI) Control"); * 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. // Create the main layout for the shell.
GridLayout mainLayout = new GridLayout(1, false); GridLayout mainLayout = new GridLayout(1, false);
@ -95,19 +126,11 @@ public class FFTIControlDlg extends Dialog {
// Initialize all of the controls and layouts // Initialize all of the controls and layouts
initializeComponents(); initializeComponents();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return null;
} }
/**
* Set up dialog components.
*/
private void initializeComponents() { private void initializeComponents() {
try { try {
createCwaControls(); createCwaControls();
@ -124,18 +147,14 @@ public class FFTIControlDlg extends Dialog {
updateTabSettings(); updateTabSettings();
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent event) {
disposed = true;
}
});
} catch (Exception e) { } catch (Exception e) {
statusHandler.handle(Priority.ERROR, "FFTI Can not load...", e); statusHandler.handle(Priority.ERROR, "FFTI Can not load...", e);
e.printStackTrace();
} }
} }
/**
* Set up selection buttons for the CWAs monitors.
*/
private void createCwaControls() { private void createCwaControls() {
GridLayout gl = new GridLayout(10, false); GridLayout gl = new GridLayout(10, false);
Composite cwaComp = new Composite(shell, SWT.NONE); Composite cwaComp = new Composite(shell, SWT.NONE);
@ -143,11 +162,11 @@ public class FFTIControlDlg extends Dialog {
Label cwaLbl = new Label(cwaComp, SWT.NONE); Label cwaLbl = new Label(cwaComp, SWT.NONE);
cwaLbl.setText("CWAs Monitored: "); cwaLbl.setText("CWAs Monitored: ");
cwa_list = new Hashtable<String, Button>(); cwa_list = new HashMap<String, Button>();
String siteName = LocalizationManager.getInstance().getCurrentSite() String siteName = LocalizationManager.getInstance().getCurrentSite()
.toUpperCase(); .toUpperCase();
// load a runner by finding the primey domain // load a runner by finding the primary domain
FFMPRunConfigurationManager frcm = FFMPRunConfigurationManager FFMPRunConfigurationManager frcm = FFMPRunConfigurationManager
.getInstance(); .getInstance();
FFMPRunXML runner = frcm.getRunner(siteName); 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() { private void createTabFolderControls() {
Composite tabControlComp = new Composite(shell, SWT.NONE); Composite tabControlComp = new Composite(shell, SWT.NONE);
tabControlComp.setLayout(new GridLayout(2, false)); tabControlComp.setLayout(new GridLayout(2, false));
@ -210,6 +232,9 @@ public class FFTIControlDlg extends Dialog {
}); });
} }
/**
* Layout the FFTI tab folder.
*/
private void createSettingTabFolder() { private void createSettingTabFolder() {
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
fftiTabFolder = new TabFolder(shell, SWT.NONE); fftiTabFolder = new TabFolder(shell, SWT.NONE);
@ -218,11 +243,14 @@ public class FFTIControlDlg extends Dialog {
fftiTabFolder.addSelectionListener(new SelectionAdapter() { fftiTabFolder.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
tabSelectedAction(); updateTabSettings();
} }
}); });
} }
/**
* The bottom save and close buttons.
*/
private void createBottomButtons() { private void createBottomButtons() {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
Composite buttonComp = new Composite(shell, SWT.NONE); Composite buttonComp = new Composite(shell, SWT.NONE);
@ -251,19 +279,18 @@ public class FFTIControlDlg extends Dialog {
closeBtn.addSelectionListener(new SelectionAdapter() { closeBtn.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
disposed = true; close();
shell.dispose();
} }
}); });
} }
/** /**
* get the duplicated settings * Get the duplicated settings.
* *
* @return duplicate list * @return duplicate list
*/ */
private HashSet<Integer> getDuplicates() { private Set<Integer> getDuplicates() {
HashSet<Integer> duplicateLst = new HashSet<Integer>(); Set<Integer> duplicateLst = new HashSet<Integer>();
for (int i = 0; i < fftiTabFolder.getItemCount(); i++) { for (int i = 0; i < fftiTabFolder.getItemCount(); i++) {
SettingComp thisItem = (SettingComp) fftiTabFolder.getItem(i) SettingComp thisItem = (SettingComp) fftiTabFolder.getItem(i)
.getControl(); .getControl();
@ -279,11 +306,19 @@ public class FFTIControlDlg extends Dialog {
&& (thisItem.getQpeDurHr() == nextItem.getQpeDurHr()) && (thisItem.getQpeDurHr() == nextItem.getQpeDurHr())
&& (thisItem.getGuidDurHr() == nextItem.getGuidDurHr()) && (thisItem.getGuidDurHr() == nextItem.getGuidDurHr())
&& (thisItem.getQpfDurHr() == nextItem.getQpfDurHr()) && (thisItem.getQpfDurHr() == nextItem.getQpfDurHr())
&& (thisItem.getTotalDurHr() == nextItem.getTotalDurHr()) && (thisItem.getTotalDurHr() == nextItem
&& (thisItem.getQpeSrc().length > 0 && nextItem.getQpeSrc().length > 0 && thisItem.getQpeSrc()[0].equals(nextItem.getQpeSrc()[0])) .getTotalDurHr())
&& (thisItem.getQpfSrc().length > 0 && nextItem.getQpfSrc().length > 0 && thisItem.getQpfSrc()[0].equals(nextItem.getQpfSrc()[0])) && (thisItem.getQpeSrc().length > 0
&& (thisItem.getGuidSrc().length > 0 && nextItem.getGuidSrc().length > 0 && thisItem.getGuidSrc()[0].equals(nextItem.getGuidSrc()[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(i + 1);
duplicateLst.add(j + 1); duplicateLst.add(j + 1);
} }
@ -293,25 +328,23 @@ public class FFTIControlDlg extends Dialog {
return duplicateLst; return duplicateLst;
} }
/**
* Save the current settings to the FFTIDataManger.
*/
protected void saveAllSettings() { protected void saveAllSettings() {
// Find duplicates // Find duplicates
HashSet<Integer> duplicates = getDuplicates(); Set<Integer> duplicates = getDuplicates();
if (duplicates.size() > 0) { if (duplicates.size() > 0) {
String setsStr = ""; StringBuilder message = new StringBuilder("Sets ");
int i = 0; String separator = "";
for (Integer setIndex : duplicates) { for (int setIndex : duplicates) {
setsStr += setIndex; message.append(separator).append(setIndex);
if (i != duplicates.size()-1) { separator = "/";
setsStr = setsStr + "/";
}
i++;
} }
message.append(" are duplicated!\nModify the configuration before saving.");
MessageBox messageBox = new MessageBox(shell, SWT.OK); MessageBox messageBox = new MessageBox(shell, SWT.OK);
messageBox.setText("Warning: Duplicate Setting(s)!"); messageBox.setText("Warning: Duplicate Setting(s)!");
messageBox messageBox.setMessage(message.toString());
.setMessage("Sets "
+ setsStr
+ " are duplicated!\nModify the configuration before saving.");
messageBox.open(); messageBox.open();
return; return;
} }
@ -322,13 +355,13 @@ public class FFTIControlDlg extends Dialog {
fdm.clear(); fdm.clear();
// get the selected CWA list // get the selected CWA list
ArrayList<String> selectedCwas = getCWASelectionIDs(); List<String> selectedCwas = getCWASelectionIDs();
fdm.setCwaList(selectedCwas); fdm.setCwaList((ArrayList<String>) selectedCwas);
// get attribute, and sources for each tab // get attribute, and sources for each tab
TabItem[] tabItemArray = fftiTabFolder.getItems(); TabItem[] tabItemArray = fftiTabFolder.getItems();
ArrayList<FFTISettingXML> settings = new ArrayList<FFTISettingXML>(); List<FFTISettingXML> settings = new ArrayList<FFTISettingXML>();
for (TabItem ti : tabItemArray) { for (TabItem ti : tabItemArray) {
SettingComp sc = (SettingComp) ti.getControl(); SettingComp sc = (SettingComp) ti.getControl();
@ -365,10 +398,13 @@ public class FFTIControlDlg extends Dialog {
settings.add(aSetting); settings.add(aSetting);
} }
fdm.setSettings(settings); fdm.setSettings((ArrayList<FFTISettingXML>) settings);
fdm.saveConfigXml(); fdm.saveConfigXml();
} }
/**
* Add a new setting tab in the FFTI tab folder.
*/
private void createSettingTabs() { private void createSettingTabs() {
FFTIDataManager fftiDataMgr = FFTIDataManager.getInstance(); 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) { private void addSeparator(Composite parentComp) {
GridLayout gl = (GridLayout) parentComp.getLayout(); GridLayout gl = (GridLayout) parentComp.getLayout();
@ -397,6 +438,9 @@ public class FFTIControlDlg extends Dialog {
sepLbl.setLayoutData(gd); sepLbl.setLayoutData(gd);
} }
/**
* Add a new settings tab.
*/
private void addSettingTab() { private void addSettingTab() {
// Add tab // Add tab
TabItem settingTab = new TabItem(fftiTabFolder, SWT.NONE); TabItem settingTab = new TabItem(fftiTabFolder, SWT.NONE);
@ -409,11 +453,10 @@ public class FFTIControlDlg extends Dialog {
removeSettingBtn.setEnabled(true); removeSettingBtn.setEnabled(true);
} }
/**
* Dispose of the control in the selected tab and then dispose of the tab.
*/
private void removeSettingTab() { private void removeSettingTab() {
/*
* Dispose of the control in the selected tab and then dispose of the
* tab.
*/
int selectedTab = fftiTabFolder.getSelectionIndex(); int selectedTab = fftiTabFolder.getSelectionIndex();
fftiTabFolder.getItem(selectedTab).getControl().dispose(); fftiTabFolder.getItem(selectedTab).getControl().dispose();
fftiTabFolder.getItem(selectedTab).dispose(); fftiTabFolder.getItem(selectedTab).dispose();
@ -425,10 +468,9 @@ public class FFTIControlDlg extends Dialog {
removeSettingBtn.setEnabled(false); removeSettingBtn.setEnabled(false);
} }
private void tabSelectedAction() { /**
updateTabSettings(); * Update the enable status of tab control buttons.
} */
private void updateTabSettings() { private void updateTabSettings() {
if (fftiTabFolder.getItemCount() > 1) { if (fftiTabFolder.getItemCount() > 1) {
if (fftiTabFolder.getSelectionIndex() == 0) { 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() { private void renameTabs() {
TabItem[] tabItemArray = fftiTabFolder.getItems(); 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 * Get CWA names whose buttons are selected.
* state. *
* @return cwaIds
*/ */
public ArrayList<String> getCWASelectionIDs() { public List<String> getCWASelectionIDs() {
ArrayList<String> cwaIds = new ArrayList<String>(); List<String> cwaIds = new ArrayList<String>();
for (Object id : cwa_list.keySet().toArray()) { for (Object id : cwa_list.keySet().toArray()) {
Button cwa_bt = cwa_list.get(id); Button cwa_bt = cwa_list.get(id);
if (cwa_bt.getSelection()) { if (cwa_bt.getSelection()) {
cwaIds.add((String) id); cwaIds.add(id.toString());
} }
} }
return cwaIds; return cwaIds;
} }
/**
* @return the disposed
*/
public boolean isDisposed() {
return disposed;
}
} }

View file

@ -22,6 +22,7 @@ package com.raytheon.uf.viz.monitor.ffmp.ui.actions;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
@ -37,6 +38,7 @@ import com.raytheon.uf.viz.monitor.ffmp.ffti.FFTIControlDlg;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 1/27/10 4265 dhladky Initial Creation. * 1/27/10 4265 dhladky Initial Creation.
* 12/05/2012 1353 rferrel Changes for non-blocking FFTIControlDlg.
* *
* </pre> * </pre>
* *
@ -49,18 +51,19 @@ public class FFTIAction extends AbstractHandler {
@Override @Override
public Object execute(ExecutionEvent arg0) throws ExecutionException { public Object execute(ExecutionEvent arg0) throws ExecutionException {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell(); .getShell();
shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
System.out.println("Activating/Action the FFTI dialogs..."); // 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
if ((fftiControlDlg == null) || fftiControlDlg.isDisposed()) { // changes.
if (fftiControlDlg == null || fftiControlDlg.getShell() == null
|| fftiControlDlg.isDisposed()) {
fftiControlDlg = new FFTIControlDlg(shell); fftiControlDlg = new FFTIControlDlg(shell);
fftiControlDlg.open();
fftiControlDlg = null;
} }
fftiControlDlg.open();
shell.setCursor(null);
return null; return null;
} }
} }