Issue #1351. Changes for non-blocking FogMonThreshSetupDlg. Changes according to comments.

Change-Id: I605f6819def85f197e37e13803627baec67e6786

Former-commit-id: a284f0f50f [formerly a284f0f50f [formerly 64fffb1598b943dc9890d2b9ee04a690c006bfe7]]
Former-commit-id: b650fa6675
Former-commit-id: 1c16ed59c1
This commit is contained in:
Slav Korolev 2012-12-06 15:04:40 -05:00
parent d455c023a6
commit 61d69bbccf
4 changed files with 497 additions and 322 deletions

View file

@ -29,39 +29,76 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory;
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.monitor.filename.DefaultFilenameMgr;
import com.raytheon.uf.viz.monitor.fog.xml.FogMonitorAlgorithmXML;
/**
* Fog Algorithm Threshold Manager
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 3, 2012 1351 skorolev Cleaned code
*
* </pre>
*
* @author
* @version 1.0
*/
public class FogAlgorithmMgr {
private static FogAlgorithmMgr classInstance;
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(FogAlgorithmMgr.class);
/** Fog Algorithm Threshold Manager instance **/
private final static FogAlgorithmMgr classInstance = new FogAlgorithmMgr();
/** Default Algorithm Threshold file name **/
private final String defaultAlgFilename = "FogMonitorAlgThresh.xml";
/** Current Algorithm Threshold full file path **/
private String currFullPathAndFileName;
/** Algorithm Threshold XML **/
private FogMonitorAlgorithmXML algXML;
/** Default File Manager **/
private DefaultFilenameMgr defaultFileNameMgr;
/**
* Gets instance of Fog Algorithm Threshold Manager.
*
* @return
*/
public static FogAlgorithmMgr getInstance() {
return classInstance;
}
/**
* Constructor
*/
private FogAlgorithmMgr() {
init();
}
public static FogAlgorithmMgr getInstance() {
if (classInstance == null) {
classInstance = new FogAlgorithmMgr();
}
return classInstance;
}
/**
* Fog Algorithm Threshold Manager initialization.
*/
private void init() {
defaultFileNameMgr = new DefaultFilenameMgr(getDefaultFileNamePath());
defaultFileNameMgr.readXmlConfig();
readInDefaultXML();
}
/**
* Reads default Threshold XML file.
*/
private void readInDefaultXML() {
if (defaultFileNameMgr.getDefaultThresholdFilename() != null
&& defaultFileNameMgr.getDefaultThresholdFilename().length() > 0) {
@ -80,28 +117,39 @@ public class FogAlgorithmMgr {
}
}
/**
* Gets path of current Algorithm Threshold file
*
* @return file path
*/
public String getAlgorithmThresholdPath() {
String fs = String.valueOf(File.separatorChar);
String fs = IPathManager.SEPARATOR;
StringBuilder sb = new StringBuilder();
sb.append("fog").append(fs);
sb.append("algorithm").append(fs);
return sb.toString();
}
/**
* Gets path of default Algorithm Threshold file
*
* @return file path
*/
public String getDefaultFileNamePath() {
String fs = String.valueOf(File.separatorChar);
String fs = IPathManager.SEPARATOR;
StringBuilder sb = new StringBuilder();
sb.append("fog").append(fs);
sb.append("threshold").append(fs);
sb.append("display").append(fs);
sb.append("defaultThresh").append(fs);
return sb.toString();
}
/**
* Sets default Algorithm Threshold file path.
*
* @param fileName
*/
public void setDefaultAlgorithmFileName(String fileName) {
if (fileName == null) {
defaultFileNameMgr.setDefaultThresholdFilename("");
@ -109,11 +157,9 @@ public class FogAlgorithmMgr {
+ defaultAlgFilename;
return;
}
if (fileName.endsWith(".xml") == false) {
fileName.concat(".xml");
}
if (fileName.compareTo(defaultAlgFilename) == 0) {
defaultFileNameMgr.setDefaultThresholdFilename("");
} else {
@ -121,83 +167,102 @@ public class FogAlgorithmMgr {
}
}
/**
* Reads Algorithm Threshold XML.
*/
public void readAlgorithmXml() {
try {
algXML = null;
IPathManager pm = PathManagerFactory.getPathManager();
File path = pm.getStaticFile(currFullPathAndFileName);
System.out.println("**** readAlgorithmXml() path = " + path);
algXML = JAXB.unmarshal(path, FogMonitorAlgorithmXML.class);
} catch (Exception e) {
e.printStackTrace();
statusHandler.handle(Priority.ERROR, e.getMessage());
}
}
/**
* Menu option Save as... Algorithm Threshold XML file.
*
* @param newFileName
*/
public void saveAlgorithmXmlAs(String newFileName) {
if (newFileName.trim().compareTo(defaultAlgFilename) == 0) {
return;
}
currFullPathAndFileName = getAlgorithmThresholdPath() + newFileName;
saveAlgorithmXml();
}
/**
* Menu option Save... Algorithm Threshold XML file.
*/
public void saveAlgorithmXml() {
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext context = pm.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.SITE);
LocalizationFile locFile = pm.getLocalizationFile(context,
currFullPathAndFileName);
if (locFile.getFile().getParentFile().exists() == false) {
System.out.println("Creating new directory");
if (locFile.getFile().getParentFile().mkdirs() == false) {
System.out.println("Could not create new directory...");
}
locFile.getFile().getParentFile().mkdirs();
}
try {
System.out.println("saveAlgorithmXml() -- "
+ locFile.getFile().getAbsolutePath());
JAXB.marshal(algXML, locFile.getFile());
locFile.save();
} catch (Exception e) {
e.printStackTrace();
statusHandler.handle(Priority.ERROR, e.getMessage());
}
}
/**
* Menu option Delete... Algorithm Threshold XML file.
*/
public void deleteCurrentAlgorithmFile() {
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext context = pm.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.SITE);
LocalizationFile locFile = pm.getLocalizationFile(context,
currFullPathAndFileName);
try {
if (locFile != null) {
locFile.delete();
}
} catch (Exception e) {
e.printStackTrace();
statusHandler.handle(Priority.ERROR, e.getMessage());
}
}
/**
* Menu option Load... Algorithm Threshold XML file.
*
* @param fileName
*/
public void loadAlgorithmThreashold(String fileName) {
currFullPathAndFileName = getAlgorithmThresholdPath() + fileName;
readAlgorithmXml();
}
/**
* Menu option Load default... Algorithm Threshold XML file.
*/
public void loadDefaultAlgorithmData() {
readInDefaultXML();
}
/**
* Gets default Algorithm Threshold XML file name.
*
* @return defaultAlgFilename
*/
public String getDefaultAlgorithmFileName() {
return defaultAlgFilename;
}
/**
* Gets Algorithm Threshold XML.
*
* @return algXML
*/
public FogMonitorAlgorithmXML getAlgorithmXML() {
return algXML;
}

View file

@ -28,7 +28,7 @@ import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.viz.monitor.fog.ui.dialogs.FogMonThreshSetupDlg;
/**
* The Fog Monitor Action
* The Fog Algorithm Configuration Action.
*
* <pre>
*
@ -36,6 +36,7 @@ import com.raytheon.uf.viz.monitor.fog.ui.dialogs.FogMonThreshSetupDlg;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 19 2009 3963 dhladky Initial creation.
* Nov 29 2012 1351 skorolev Changes for non-blocking dialog.
*
* </pre>
*
@ -43,23 +44,17 @@ import com.raytheon.uf.viz.monitor.fog.ui.dialogs.FogMonThreshSetupDlg;
* @version 1.0
*/
public class FogAlgoConfigAction extends AbstractHandler
{
private FogMonThreshSetupDlg fogThreshSetup;
public class FogAlgoConfigAction extends AbstractHandler {
private FogMonThreshSetupDlg fogAlgoSetupDlg;
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
if (fogThreshSetup == null)
{
fogThreshSetup = new FogMonThreshSetupDlg(shell);
fogThreshSetup.open();
fogThreshSetup = null;
if (fogAlgoSetupDlg == null) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
fogAlgoSetupDlg = new FogMonThreshSetupDlg(shell);
}
fogAlgoSetupDlg.open();
return null;
}
}

View file

@ -38,49 +38,87 @@ import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
/**
* File Load/Save/Delete/Select Dialogs.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 5, 2012 #1351 skorolev Cleaned code
*
* </pre>
*
* @author
* @version 1.0
*/
public class LoadSaveDeleteSelectDlg extends CaveSWTDialog {
/** **/
public static enum DialogType {
OPEN, SAVE_AS, DELETE, SELECT_DEFAULT
};
/** Dialog Type **/
private DialogType dialogType;
/** Font **/
private Font controlFont;
/** Configuration File List **/
private List cfgFileList;
/** Selected File **/
private LocalizationFile selectedFile;
/** Localization Files **/
private LocalizationFile[] locFiles;
/** Localization Files Map **/
private TreeMap<String, LocalizationFile> locFileMap;
/** New file name **/
private Text newFileNameTF;
/** Action Button **/
private Button actionBtn;
/** File path **/
private String fileNamePath;
/** Excluded Name For Saving **/
private String excludedNameForSaving = "";
/**
* Constructor
*
* @param parent
* @param type
* Dialog type
* @param fileNamePath
* @param excludedNameForSaving
*/
public LoadSaveDeleteSelectDlg(Shell parent, DialogType type,
String fileNamePath, String excludedNameForSaving) {
super(parent, SWT.TITLE);
// TODO add Cave.DO_NOT_BLOCK once all dialogs using this class have
// been converted to use close call.
if (type == DialogType.OPEN) {
setText("Load");
} else if (type == DialogType.SAVE_AS) {
setText("Save");
} else if (type == DialogType.SELECT_DEFAULT) {
setText("Select Default");
} else if (type == DialogType.DELETE) {
setText("Delete");
}
dialogType = type;
this.fileNamePath = fileNamePath;
if (excludedNameForSaving != null) {
@ -88,6 +126,11 @@ public class LoadSaveDeleteSelectDlg extends CaveSWTDialog {
}
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#constructShellLayout()
*/
@Override
protected Layout constructShellLayout() {
// Create the main layout for the shell.
@ -98,34 +141,44 @@ public class LoadSaveDeleteSelectDlg extends CaveSWTDialog {
return mainLayout;
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#disposed()
*/
@Override
protected void disposed() {
controlFont.dispose();
setReturnValue(selectedFile);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#initializeComponents(org
* .eclipse.swt.widgets.Shell)
*/
@Override
protected void initializeComponents(Shell shell) {
locFileMap = new TreeMap<String, LocalizationFile>();
controlFont = new Font(shell.getDisplay(), "Monospace", 10, SWT.NORMAL);
createListControl();
// Create the buttons at the bottom of the display.
createBottomButtons();
getAvailableConfigFiles();
}
/**
* Creates List Control.
*/
private void createListControl() {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
Composite controlComp = new Composite(shell, SWT.NONE);
controlComp.setLayout(new GridLayout(1, false));
controlComp.setLayoutData(gd);
Label listLbl = new Label(controlComp, SWT.NONE);
listLbl.setText("Available Files:");
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 400;
gd.heightHint = 400;
@ -146,24 +199,23 @@ public class LoadSaveDeleteSelectDlg extends CaveSWTDialog {
}
}
});
if (dialogType == DialogType.SAVE_AS) {
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gd.horizontalSpan = ((GridLayout) controlComp.getLayout()).numColumns;
Label sepLbl = new Label(controlComp, SWT.SEPARATOR
| SWT.HORIZONTAL);
sepLbl.setLayoutData(gd);
Label newFileLbl = new Label(controlComp, SWT.NONE);
newFileLbl.setText("Enter file name:");
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
newFileNameTF = new Text(controlComp, SWT.BORDER);
newFileNameTF.setLayoutData(gd);
}
}
/**
* Creates Bottom Buttons.
*/
private void createBottomButtons() {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
Composite mainButtonComp = new Composite(shell, SWT.NONE);
@ -224,10 +276,12 @@ public class LoadSaveDeleteSelectDlg extends CaveSWTDialog {
});
}
/**
* Opens Delete confirmation message.
*/
private void openDeleteSelectAction() {
int selectedIndex = cfgFileList.getSelectionIndex();
String str = cfgFileList.getItem(selectedIndex);
if (dialogType == DialogType.DELETE) {
MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES
| SWT.NO);
@ -235,32 +289,35 @@ public class LoadSaveDeleteSelectDlg extends CaveSWTDialog {
mb.setMessage("You are about to delete the file:\n\n" + str
+ "\n\nDo you wish to continue?");
int result = mb.open();
if (result == SWT.NO) {
return;
}
}
selectedFile = locFileMap.get(str);
shell.dispose();
}
/**
* Save action.
*/
private void saveAction() {
String fileName = newFileNameTF.getText();
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext context = pm.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
String newFileName = fileNamePath + fileName;
selectedFile = pm.getLocalizationFile(context, newFileName);
shell.dispose();
}
/**
* Validates File Name.
*
* @return True/False
*/
private boolean validateFileName() {
StringBuffer strBuf = new StringBuffer(newFileNameTF.getText().trim());
newFileNameTF.setText(strBuf.toString());
if (strBuf.length() == 0) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setText("Warning");
@ -268,17 +325,14 @@ public class LoadSaveDeleteSelectDlg extends CaveSWTDialog {
mb.open();
return false;
}
if (strBuf.toString().matches("[A-Za-z0-9._-]+") == false) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setText("Warning");
mb
.setMessage("File name contains invalid charaters. The file name can only\n"
+ "contain A-Z, a-z, 0-9, or periods, underscores, or dashes.");
mb.setMessage("File name contains invalid charaters. The file name can only\n"
+ "contain A-Z, a-z, 0-9, or periods, underscores, or dashes.");
mb.open();
return false;
}
if (strBuf.toString().compareTo(excludedNameForSaving) == 0) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setText("Warning");
@ -287,20 +341,16 @@ public class LoadSaveDeleteSelectDlg extends CaveSWTDialog {
mb.open();
return false;
}
String[] listItems = cfgFileList.getItems();
for (String listItem : listItems) {
int idx = listItem.lastIndexOf("/");
String fn = listItem.substring(idx + 1);
if (fn.compareTo(strBuf.toString()) == 0) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.YES
| SWT.NO);
mb.setText("Warning");
mb
.setMessage("File name already exists. Do you wish to overwrite\n"
+ "the existing file?.");
mb.setMessage("File name already exists. Do you wish to overwrite\n"
+ "the existing file?.");
int result = mb.open();
if (result == SWT.NO) {
@ -308,24 +358,23 @@ public class LoadSaveDeleteSelectDlg extends CaveSWTDialog {
}
}
}
if (strBuf.toString().endsWith(".xml") == false) {
strBuf.append(".xml");
newFileNameTF.setText(strBuf.toString().trim());
}
return true;
}
/**
* Gets Available Configuration Files.
*/
private void getAvailableConfigFiles() {
String[] extensions = new String[] { ".xml" };
locFiles = PathManagerFactory.getPathManager().listStaticFiles(
fileNamePath, extensions, false, true);
if (locFiles == null) {
return;
}
for (int i = 0; i < locFiles.length; i++) {
/*
* Add the available files to the list as long as the file name does
@ -342,15 +391,12 @@ public class LoadSaveDeleteSelectDlg extends CaveSWTDialog {
locFileMap.put(locFiles[i].getFile().getName(), locFiles[i]);
}
}
for (String str : locFileMap.keySet()) {
cfgFileList.add(str);
}
if (cfgFileList.getSelectionCount() > 0) {
cfgFileList.setSelection(0);
}
if (cfgFileList.getItemCount() == 0) {
if (dialogType == DialogType.DELETE
|| dialogType == DialogType.SELECT_DEFAULT) {
@ -359,6 +405,11 @@ public class LoadSaveDeleteSelectDlg extends CaveSWTDialog {
}
}
/**
* Gets Selected File
*
* @return selectedFile
*/
public LocalizationFile getSelectedFile() {
return selectedFile;
}