Issue #1196 Changes for AlarmAlertSaveLoadDlg.

Change-Id: I9baab44a7c5c97af86ea7446e265a873444fc47e

Former-commit-id: 34cd5b61cf [formerly fd248ac744] [formerly 407bd9f25e [formerly 80b29e5da16e908ed2855ee5c645b911e054e7f7]]
Former-commit-id: 407bd9f25e
Former-commit-id: cdd02b9000
This commit is contained in:
Roger Ferrel 2012-09-20 15:17:27 -05:00
parent 7b73a0f166
commit 79f1dff095
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.AlarmAlertLists;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
import com.raytheon.viz.ui.dialogs.ModeListener;
/**
@ -69,6 +70,7 @@ import com.raytheon.viz.ui.dialogs.ModeListener;
* ------------ ---------- ----------- --------------------------
* Sep 9, 2009 mnash Initial creation
* Oct 31,2011 8510 rferrel Cleaned up code made more robust
* Sep 20,2011 1196 rferrel Change dialogs so they do not block.
*
* </pre>
*
@ -178,8 +180,6 @@ public class AlarmAlertDlg extends CaveSWTDialog {
preOpened();
// shell.open();
opened();
}
@ -270,29 +270,14 @@ public class AlarmAlertDlg extends CaveSWTDialog {
// open dialog
AlarmAlertSaveLoadDlg dialog = new AlarmAlertSaveLoadDlg(shell,
SaveOrLoad.SAVE);
dialog.open();
String fname = dialog.getFileName();
fname = validateFileName(fname);
// AlarmAlertFunctions.validateName(fname);
dialog.setCloseCallback(new ICloseCallback() {
if (fname != null && !fname.isEmpty()) {
setShellText(fname);
setLastFile(fname);
// save alert products
LocalizationFile lFile = AlarmAlertFunctions.getFile(
AlarmAlertFunctions.initUserLocalization(), fname);
if (lFile != null) {
AlarmAlertFunctions.saveAlarms(
aapList.subList(siteAdminNumberAA - 1,
aapList.size()),
papList.subList(siteAdminNumberPA - 1,
papList.size()), lFile);
} else {
statusHandler.handle(Priority.SIGNIFICANT,
"Null localization file", new VizException(
"Null localization file"));
@Override
public void dialogClosed(Object returnValue) {
doSaveAs(returnValue.toString());
}
}
});
dialog.open();
}
});
@ -303,43 +288,72 @@ public class AlarmAlertDlg extends CaveSWTDialog {
// open dialog
AlarmAlertSaveLoadDlg dialog = new AlarmAlertSaveLoadDlg(shell,
SaveOrLoad.LOAD);
dialog.open();
// load file
String fname = dialog.getFileName();
fname = validateFileName(fname);
// AlarmAlertFunctions.validateName(fname);
if (fname != null && !fname.isEmpty()) {
dialog.setCloseCallback(new ICloseCallback() {
// load alert products
LocalizationFile lFile = AlarmAlertFunctions.getFile(
AlarmAlertFunctions.initUserLocalization(), fname);
if (lFile != null) {
File file = lFile.getFile();
setShellText(fname);
setLastFile(fname);
currentFile = file;
AAPACombined combined = null;
try {
combined = AlarmAlertFunctions.loadFile(file);
} catch (FileNotFoundException e) {
combined = AlarmAlertFunctions
.createDefaultAAPACombined();
}
if (combined != null) {
populateLists(combined.getAaList(),
combined.getPaList());
}
} else {
statusHandler.handle(Priority.SIGNIFICANT,
"Null localization file", new VizException(
"Null localization file"));
@Override
public void dialogClosed(Object returnValue) {
doLoad(returnValue.toString());
}
}
});
dialog.open();
}
});
}
private void doSaveAs(String fname) {
fname = validateFileName(fname);
// AlarmAlertFunctions.validateName(fname);
if (fname != null && !fname.isEmpty()) {
setShellText(fname);
setLastFile(fname);
// save alert products
LocalizationFile lFile = AlarmAlertFunctions.getFile(
AlarmAlertFunctions.initUserLocalization(), fname);
if (lFile != null) {
AlarmAlertFunctions.saveAlarms(
aapList.subList(siteAdminNumberAA - 1, aapList.size()),
papList.subList(siteAdminNumberPA - 1, papList.size()),
lFile);
} else {
statusHandler.handle(Priority.SIGNIFICANT,
"Null localization file", new VizException(
"Null localization file"));
}
}
}
private void doLoad(String fname) {
fname = validateFileName(fname);
// AlarmAlertFunctions.validateName(fname);
if (fname != null && !fname.isEmpty()) {
// load alert products
LocalizationFile lFile = AlarmAlertFunctions.getFile(
AlarmAlertFunctions.initUserLocalization(), fname);
if (lFile != null) {
File file = lFile.getFile();
setShellText(fname);
setLastFile(fname);
currentFile = file;
AAPACombined combined = null;
try {
combined = AlarmAlertFunctions.loadFile(file);
} catch (FileNotFoundException e) {
combined = AlarmAlertFunctions.createDefaultAAPACombined();
}
if (combined != null) {
populateLists(combined.getAaList(), combined.getPaList());
}
} else {
statusHandler.handle(Priority.SIGNIFICANT,
"Null localization file", new VizException(
"Null localization file"));
}
}
}
/**
* Create the buttons right below the menu
*/
@ -602,11 +616,11 @@ public class AlarmAlertDlg extends CaveSWTDialog {
lists.getFilteredProducts().clear();
lists.getFilteredProducts().addAll(aapList);
lists.getFilteredProducts().addAll(papList);
LocalizationFile lFile = AlarmAlertFunctions.getFile(
AlarmAlertFunctions.initUserLocalization(),
currentFile.getName());
AlarmAlertFunctions.saveAlarms(
aapList.subList(siteAdminNumberAA - 1, aapList.size()),
papList.subList(siteAdminNumberPA - 1, papList.size()), lFile);

View file

@ -58,6 +58,8 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* AWIPS2 DR Work
* 07/25/2012 953 jkorman Modified file "search" to return LocalizationFile
* 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>
*
@ -74,8 +76,6 @@ public class AlarmAlertSaveLoadDlg extends CaveSWTDialog {
private Composite shellComp;
private static AlarmAlertSaveLoadDlg saveLoadDlg = null;
private static String fileName = "";
private SaveOrLoad saveLoad;
@ -91,7 +91,7 @@ public class AlarmAlertSaveLoadDlg extends CaveSWTDialog {
*/
protected AlarmAlertSaveLoadDlg(Shell parentShell, SaveOrLoad saveLoad) {
super(parentShell, SWT.APPLICATION_MODAL | SWT.CLOSE | SWT.TITLE,
CAVE.PERSPECTIVE_INDEPENDENT);
CAVE.PERSPECTIVE_INDEPENDENT | CAVE.DO_NOT_BLOCK);
if (saveLoad == SaveOrLoad.SAVE) {
setText("Save Lists As...");
} else {
@ -148,7 +148,7 @@ public class AlarmAlertSaveLoadDlg extends CaveSWTDialog {
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
lists.setLayoutData(gd);
LocalizationContext lc = AlarmAlertFunctions.initUserLocalization();
// Get a list of localization files!
LocalizationFile[] fList = PathManagerFactory.getPathManager()
.listFiles(lc, "alarms", new String[] { "xml" }, false, true);
@ -191,7 +191,12 @@ public class AlarmAlertSaveLoadDlg extends CaveSWTDialog {
loadButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// Set the filename to be returned through getFileName()
fileName = lists.getSelection()[0];
if (lists.getSelectionCount() > 0) {
fileName = lists.getSelection()[0];
} else {
fileName = "";
}
setReturnValue(fileName);
shell.close();
}
});
@ -285,6 +290,7 @@ public class AlarmAlertSaveLoadDlg extends CaveSWTDialog {
public void widgetSelected(SelectionEvent event) {
// Set the filename to be returned through getFileName()
fileName = textBox.getText();
setReturnValue(fileName);
shell.close();
}
});
@ -311,12 +317,4 @@ public class AlarmAlertSaveLoadDlg extends CaveSWTDialog {
public String getFileName() {
return fileName;
}
/**
* @param args
*/
public static void main(String[] args) {
saveLoadDlg = new AlarmAlertSaveLoadDlg(new Shell(), SaveOrLoad.LOAD);
saveLoadDlg.open();
}
}