Issue #1196 Changes for AlarmAlertSaveLoadDlg.

Change-Id: I9baab44a7c5c97af86ea7446e265a873444fc47e

Former-commit-id: 80b29e5da16e908ed2855ee5c645b911e054e7f7
This commit is contained in:
Roger Ferrel 2012-09-20 15:17:27 -05:00
parent 4f0ab091a4
commit 407bd9f25e
2 changed files with 81 additions and 69 deletions

View file

@ -57,6 +57,7 @@ import com.raytheon.viz.texteditor.alarmalert.util.AAPACombined;
import com.raytheon.viz.texteditor.alarmalert.util.AlarmAlertFunctions; import com.raytheon.viz.texteditor.alarmalert.util.AlarmAlertFunctions;
import com.raytheon.viz.texteditor.alarmalert.util.AlarmAlertLists; import com.raytheon.viz.texteditor.alarmalert.util.AlarmAlertLists;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog; import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
import com.raytheon.viz.ui.dialogs.ModeListener; import com.raytheon.viz.ui.dialogs.ModeListener;
/** /**
@ -69,6 +70,7 @@ import com.raytheon.viz.ui.dialogs.ModeListener;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Sep 9, 2009 mnash Initial creation * Sep 9, 2009 mnash Initial creation
* Oct 31,2011 8510 rferrel Cleaned up code made more robust * Oct 31,2011 8510 rferrel Cleaned up code made more robust
* Sep 20,2011 1196 rferrel Change dialogs so they do not block.
* *
* </pre> * </pre>
* *
@ -178,8 +180,6 @@ public class AlarmAlertDlg extends CaveSWTDialog {
preOpened(); preOpened();
// shell.open();
opened(); opened();
} }
@ -270,8 +270,37 @@ public class AlarmAlertDlg extends CaveSWTDialog {
// open dialog // open dialog
AlarmAlertSaveLoadDlg dialog = new AlarmAlertSaveLoadDlg(shell, AlarmAlertSaveLoadDlg dialog = new AlarmAlertSaveLoadDlg(shell,
SaveOrLoad.SAVE); SaveOrLoad.SAVE);
dialog.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
doSaveAs(returnValue.toString());
}
});
dialog.open(); dialog.open();
String fname = dialog.getFileName(); }
});
MenuItem loadMenuItem = new MenuItem(fileMenu, SWT.NONE);
loadMenuItem.setText("Load...");
loadMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// open dialog
AlarmAlertSaveLoadDlg dialog = new AlarmAlertSaveLoadDlg(shell,
SaveOrLoad.LOAD);
dialog.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
doLoad(returnValue.toString());
}
});
dialog.open();
}
});
}
private void doSaveAs(String fname) {
fname = validateFileName(fname); fname = validateFileName(fname);
// AlarmAlertFunctions.validateName(fname); // AlarmAlertFunctions.validateName(fname);
@ -283,10 +312,9 @@ public class AlarmAlertDlg extends CaveSWTDialog {
AlarmAlertFunctions.initUserLocalization(), fname); AlarmAlertFunctions.initUserLocalization(), fname);
if (lFile != null) { if (lFile != null) {
AlarmAlertFunctions.saveAlarms( AlarmAlertFunctions.saveAlarms(
aapList.subList(siteAdminNumberAA - 1, aapList.subList(siteAdminNumberAA - 1, aapList.size()),
aapList.size()), papList.subList(siteAdminNumberPA - 1, papList.size()),
papList.subList(siteAdminNumberPA - 1, lFile);
papList.size()), lFile);
} else { } else {
statusHandler.handle(Priority.SIGNIFICANT, statusHandler.handle(Priority.SIGNIFICANT,
"Null localization file", new VizException( "Null localization file", new VizException(
@ -294,18 +322,8 @@ public class AlarmAlertDlg extends CaveSWTDialog {
} }
} }
} }
});
MenuItem loadMenuItem = new MenuItem(fileMenu, SWT.NONE); private void doLoad(String fname) {
loadMenuItem.setText("Load...");
loadMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// open dialog
AlarmAlertSaveLoadDlg dialog = new AlarmAlertSaveLoadDlg(shell,
SaveOrLoad.LOAD);
dialog.open();
// load file
String fname = dialog.getFileName();
fname = validateFileName(fname); fname = validateFileName(fname);
// AlarmAlertFunctions.validateName(fname); // AlarmAlertFunctions.validateName(fname);
if (fname != null && !fname.isEmpty()) { if (fname != null && !fname.isEmpty()) {
@ -323,12 +341,10 @@ public class AlarmAlertDlg extends CaveSWTDialog {
try { try {
combined = AlarmAlertFunctions.loadFile(file); combined = AlarmAlertFunctions.loadFile(file);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
combined = AlarmAlertFunctions combined = AlarmAlertFunctions.createDefaultAAPACombined();
.createDefaultAAPACombined();
} }
if (combined != null) { if (combined != null) {
populateLists(combined.getAaList(), populateLists(combined.getAaList(), combined.getPaList());
combined.getPaList());
} }
} else { } else {
statusHandler.handle(Priority.SIGNIFICANT, statusHandler.handle(Priority.SIGNIFICANT,
@ -337,8 +353,6 @@ public class AlarmAlertDlg extends CaveSWTDialog {
} }
} }
} }
});
}
/** /**
* Create the buttons right below the menu * Create the buttons right below the menu

View file

@ -58,6 +58,8 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* AWIPS2 DR Work * AWIPS2 DR Work
* 07/25/2012 953 jkorman Modified file "search" to return LocalizationFile * 07/25/2012 953 jkorman Modified file "search" to return LocalizationFile
* instead of File so references are deleted in all locations. * instead of File so references are deleted in all locations.
* 09/20/2012 1196 rferrel Setup fileName now in return value for
* use with close callback.
* *
* </pre> * </pre>
* *
@ -74,8 +76,6 @@ public class AlarmAlertSaveLoadDlg extends CaveSWTDialog {
private Composite shellComp; private Composite shellComp;
private static AlarmAlertSaveLoadDlg saveLoadDlg = null;
private static String fileName = ""; private static String fileName = "";
private SaveOrLoad saveLoad; private SaveOrLoad saveLoad;
@ -91,7 +91,7 @@ public class AlarmAlertSaveLoadDlg extends CaveSWTDialog {
*/ */
protected AlarmAlertSaveLoadDlg(Shell parentShell, SaveOrLoad saveLoad) { protected AlarmAlertSaveLoadDlg(Shell parentShell, SaveOrLoad saveLoad) {
super(parentShell, SWT.APPLICATION_MODAL | SWT.CLOSE | SWT.TITLE, super(parentShell, SWT.APPLICATION_MODAL | SWT.CLOSE | SWT.TITLE,
CAVE.PERSPECTIVE_INDEPENDENT); CAVE.PERSPECTIVE_INDEPENDENT | CAVE.DO_NOT_BLOCK);
if (saveLoad == SaveOrLoad.SAVE) { if (saveLoad == SaveOrLoad.SAVE) {
setText("Save Lists As..."); setText("Save Lists As...");
} else { } else {
@ -191,7 +191,12 @@ public class AlarmAlertSaveLoadDlg extends CaveSWTDialog {
loadButton.addSelectionListener(new SelectionAdapter() { loadButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
// Set the filename to be returned through getFileName() // Set the filename to be returned through getFileName()
if (lists.getSelectionCount() > 0) {
fileName = lists.getSelection()[0]; fileName = lists.getSelection()[0];
} else {
fileName = "";
}
setReturnValue(fileName);
shell.close(); shell.close();
} }
}); });
@ -285,6 +290,7 @@ public class AlarmAlertSaveLoadDlg extends CaveSWTDialog {
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
// Set the filename to be returned through getFileName() // Set the filename to be returned through getFileName()
fileName = textBox.getText(); fileName = textBox.getText();
setReturnValue(fileName);
shell.close(); shell.close();
} }
}); });
@ -311,12 +317,4 @@ public class AlarmAlertSaveLoadDlg extends CaveSWTDialog {
public String getFileName() { public String getFileName() {
return fileName; return fileName;
} }
/**
* @param args
*/
public static void main(String[] args) {
saveLoadDlg = new AlarmAlertSaveLoadDlg(new Shell(), SaveOrLoad.LOAD);
saveLoadDlg.open();
}
} }