Merge "Issue #1298 Changes for non-blocking WeatherElementGroupDialog. Changes from reviewer comments." into development
Former-commit-id: 3106b10a003ca5985e29c69ee0f02185c88edc12
This commit is contained in:
commit
7634ea221b
2 changed files with 110 additions and 68 deletions
|
@ -54,6 +54,7 @@ import com.raytheon.viz.core.mode.CAVEMode;
|
|||
import com.raytheon.viz.gfe.core.DataManager;
|
||||
import com.raytheon.viz.gfe.core.parm.Parm;
|
||||
import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
|
||||
import com.raytheon.viz.ui.dialogs.ICloseCallback;
|
||||
import com.raytheon.viz.ui.widgets.ToggleSelectList;
|
||||
|
||||
/**
|
||||
|
@ -73,6 +74,7 @@ import com.raytheon.viz.ui.widgets.ToggleSelectList;
|
|||
* database list from ParmManager
|
||||
* not EDEX.
|
||||
* 10/30/2012 1298 rferrel Code clean up non-blocking dialog.
|
||||
* Changes for non-blocking WeatherElementGroupDialog.
|
||||
* </pre>
|
||||
*
|
||||
* @author ebabin
|
||||
|
@ -198,15 +200,33 @@ public class WeatherElementBrowserDialog extends CaveJFACEDialog {
|
|||
/**
|
||||
* Show the save weather element dialog.
|
||||
*/
|
||||
private void showSaveWeatherElementGroup(Menu loadWeatherElementGroupMenu) {
|
||||
|
||||
WeatherElementGroupDialog dialog = new WeatherElementGroupDialog(
|
||||
private void showSaveWeatherElementGroup(
|
||||
final Menu loadWeatherElementGroupMenu) {
|
||||
// The dialog being opened is modal to the parent dialog. This will
|
||||
// prevent the launching of another dialog until the modal dialog is
|
||||
// closed.
|
||||
final WeatherElementGroupDialog dialog = new WeatherElementGroupDialog(
|
||||
getShell(), dataManager, true);
|
||||
dialog.setBlockOnOpen(true);
|
||||
dialog.setBlockOnOpen(false);
|
||||
dialog.setCloseCallback(new ICloseCallback() {
|
||||
|
||||
dialog.open();
|
||||
if (dialog.getReturnCode() == Window.OK) {
|
||||
@Override
|
||||
public void dialogClosed(Object returnValue) {
|
||||
if (returnValue instanceof Integer) {
|
||||
int returnCode = (Integer) returnValue;
|
||||
if (returnCode == Window.OK) {
|
||||
String groupName = dialog.getSelectedItem();
|
||||
doSaveWeatherElementGroup(loadWeatherElementGroupMenu,
|
||||
groupName);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
private void doSaveWeatherElementGroup(Menu loadWeatherElementGroupMenu,
|
||||
String groupName) {
|
||||
if (groupName != null) {
|
||||
ParmID[] selectedParmIds = getSelectedParmIDS();
|
||||
if ((selectedParmIds != null) && (selectedParmIds.length > 0)) {
|
||||
|
@ -215,8 +235,7 @@ public class WeatherElementBrowserDialog extends CaveJFACEDialog {
|
|||
dataManager.getWEGroupManager().save(groupName,
|
||||
selectedParmIds, availIds);
|
||||
boolean alreadyListed = false;
|
||||
for (MenuItem item : loadWeatherElementGroupMenu
|
||||
.getItems()) {
|
||||
for (MenuItem item : loadWeatherElementGroupMenu.getItems()) {
|
||||
if (item.getText().equals(groupName)) {
|
||||
alreadyListed = true;
|
||||
}
|
||||
|
@ -228,28 +247,41 @@ public class WeatherElementBrowserDialog extends CaveJFACEDialog {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show delete weather element dialog.
|
||||
*/
|
||||
private void showDeleteWeatherElementGroup(Menu loadWeatherElementGroupMenu) {
|
||||
private void showDeleteWeatherElementGroup(
|
||||
final Menu loadWeatherElementGroupMenu) {
|
||||
// The dialog being opened is modal to the parent dialog. This will
|
||||
// prevent the launching of another dialog until the modal dialog is
|
||||
// closed.
|
||||
final WeatherElementGroupDialog dialog = new WeatherElementGroupDialog(
|
||||
getShell(), this.dataManager, false);
|
||||
dialog.setBlockOnOpen(true);
|
||||
dialog.open();
|
||||
if ((dialog.getReturnCode() == Window.OK)
|
||||
&& (dialog.getSelectedItem() != null)) {
|
||||
dialog.setBlockOnOpen(false);
|
||||
dialog.setCloseCallback(new ICloseCallback() {
|
||||
|
||||
@Override
|
||||
public void dialogClosed(Object returnValue) {
|
||||
if (returnValue instanceof Integer) {
|
||||
int returnCode = (Integer) returnValue;
|
||||
if (returnCode == Window.OK
|
||||
&& dialog.getSelectedItem() != null) {
|
||||
String groupName = dialog.getSelectedItem();
|
||||
// we may have just overridden a site or base level group, need to
|
||||
// verify menu item can be deleted
|
||||
// we may have just overridden a site or base level
|
||||
// group, need to verify menu item can be deleted
|
||||
if (dataManager.getWEGroupManager().remove(groupName)
|
||||
&& !dataManager.getWEGroupManager().getInventory()
|
||||
.contains(groupName)) {
|
||||
removeWEGroup(loadWeatherElementGroupMenu, groupName);
|
||||
&& !dataManager.getWEGroupManager()
|
||||
.getInventory().contains(groupName)) {
|
||||
removeWEGroup(loadWeatherElementGroupMenu,
|
||||
groupName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the menus for the dialog.
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package com.raytheon.viz.gfe.dialogs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.swt.SWT;
|
||||
|
@ -29,8 +30,10 @@ import org.eclipse.swt.events.SelectionAdapter;
|
|||
import org.eclipse.swt.events.SelectionEvent;
|
||||
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.Control;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.List;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
@ -53,6 +56,7 @@ import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* 02/22/2008 Eric Babin Initial Creation
|
||||
* 04/17/2009 #2282 rjpeter Added confirmation message on delete.
|
||||
* 11/14/2012 #1298 rferrel Changes for non-blocking dialog.
|
||||
* </pre>
|
||||
*
|
||||
* @author ebabin
|
||||
|
@ -60,7 +64,7 @@ import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
|
|||
*/
|
||||
|
||||
public class WeatherElementGroupDialog extends CaveJFACEDialog {
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
private final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(WeatherElementGroupDialog.class);
|
||||
|
||||
private Composite top;
|
||||
|
@ -75,6 +79,8 @@ public class WeatherElementGroupDialog extends CaveJFACEDialog {
|
|||
|
||||
private Text groupField;
|
||||
|
||||
private Button okButton;
|
||||
|
||||
private String selectedItem;
|
||||
|
||||
private DataManager dataManager;
|
||||
|
@ -84,9 +90,11 @@ public class WeatherElementGroupDialog extends CaveJFACEDialog {
|
|||
public WeatherElementGroupDialog(Shell parent, DataManager dataManager,
|
||||
boolean saveType) {
|
||||
super(parent);
|
||||
setShellStyle(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
|
||||
this.dataManager = dataManager;
|
||||
this.wegManager = this.dataManager.getWEGroupManager();
|
||||
this.saveType = saveType;
|
||||
this.selectedItem = "";
|
||||
|
||||
this.names = new ArrayList<String>();
|
||||
this.protectedNames = new ArrayList<String>();
|
||||
|
@ -119,6 +127,12 @@ public class WeatherElementGroupDialog extends CaveJFACEDialog {
|
|||
|
||||
private void initializeComponents() {
|
||||
|
||||
if (names.size() == 0 && !saveType) {
|
||||
Label label = new Label(top, SWT.CENTER);
|
||||
label.setText("No groups available for deletion.");
|
||||
return;
|
||||
}
|
||||
|
||||
GridData data = new GridData(GridData.FILL_BOTH);
|
||||
|
||||
groupList = new List(top, SWT.BORDER | SWT.SINGLE);
|
||||
|
@ -135,16 +149,21 @@ public class WeatherElementGroupDialog extends CaveJFACEDialog {
|
|||
}
|
||||
}
|
||||
});
|
||||
groupList.setItems(names.toArray(new String[names.size()]));
|
||||
|
||||
String[] items = names.toArray(new String[names.size()]);
|
||||
Arrays.sort(items);
|
||||
groupList.setItems(items);
|
||||
groupList.setSelection(0);
|
||||
groupList.deselectAll();
|
||||
groupList.setLayoutData(data);
|
||||
groupField = new Text(top, SWT.BORDER);
|
||||
data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
groupField.setLayoutData(data);
|
||||
groupField.setEnabled(saveType);
|
||||
groupField.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent arg0) {
|
||||
selectedItem = groupField.getText();
|
||||
selectedItem = groupField.getText().trim();
|
||||
okButton.setEnabled(selectedItem.length() > 0);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -177,7 +196,8 @@ public class WeatherElementGroupDialog extends CaveJFACEDialog {
|
|||
} else {
|
||||
label = "Delete";
|
||||
}
|
||||
createButton(parent, IDialogConstants.OK_ID, label, true);
|
||||
okButton = createButton(parent, IDialogConstants.OK_ID, label, true);
|
||||
okButton.setEnabled(false);
|
||||
createButton(parent, IDialogConstants.CANCEL_ID,
|
||||
IDialogConstants.CANCEL_LABEL, false);
|
||||
}
|
||||
|
@ -193,39 +213,29 @@ public class WeatherElementGroupDialog extends CaveJFACEDialog {
|
|||
@Override
|
||||
protected void okPressed() {
|
||||
boolean ok = true;
|
||||
|
||||
if (!saveType) {
|
||||
String groupName = getSelectedItem();
|
||||
|
||||
if (!FileUtil.isValidFilename(groupName)) {
|
||||
MessageBox mb = new MessageBox(super.getShell(), SWT.ICON_ERROR
|
||||
| SWT.OK);
|
||||
mb.setText("Invalid Group Name");
|
||||
mb.setMessage("Group name may only contain the following characters: "
|
||||
+ FileUtil.VALID_FILENAME_CHARS);
|
||||
mb.open();
|
||||
ok = false;
|
||||
} else if (!protectedNames.contains(groupName)
|
||||
&& names.contains(groupName)) {
|
||||
MessageBox mb = new MessageBox(super.getShell(),
|
||||
SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
|
||||
} else if (protectedNames.contains(groupName)) {
|
||||
statusHandler.handle(Priority.SIGNIFICANT, "Weather Element Group "
|
||||
+ getSelectedItem() + " is protected or an invalid name.");
|
||||
ok = false;
|
||||
} else if (!saveType) {
|
||||
MessageBox mb = new MessageBox(super.getShell(), SWT.ICON_QUESTION
|
||||
| SWT.OK | SWT.CANCEL);
|
||||
mb.setText("Item Delete");
|
||||
mb.setMessage(getSelectedItem() + " will be Deleted.");
|
||||
|
||||
if (mb.open() == SWT.CANCEL) {
|
||||
ok = false;
|
||||
}
|
||||
} else {
|
||||
statusHandler.handle(Priority.SIGNIFICANT,
|
||||
"Weather Element Group " + groupName
|
||||
+ " is protected or an invalid name.");
|
||||
ok = false;
|
||||
}
|
||||
} else {
|
||||
if (protectedNames.contains(getSelectedItem())) {
|
||||
statusHandler.handle(Priority.SIGNIFICANT,
|
||||
"Weather Element Group " + getSelectedItem()
|
||||
+ " is protected or an invalid name.");
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
|
|
Loading…
Add table
Reference in a new issue