Merge "Issue #1351. Changes for non-blocking FogMonThreshSetupDlg. Changes according to comments." into development

Former-commit-id: f58f5cc4ed [formerly bf83e5b5c6] [formerly 2c44afd3ab] [formerly f58f5cc4ed [formerly bf83e5b5c6] [formerly 2c44afd3ab] [formerly 37b91cccb0 [formerly 2c44afd3ab [formerly 4bab9df17245e28128644fcdbfb8bac6d4c6dc7e]]]]
Former-commit-id: 37b91cccb0
Former-commit-id: f6646b8740 [formerly b33bdc354e] [formerly bc9b5eb2d123fbb8428632e7961a9e398a1b7f54 [formerly 78af1aa566]]
Former-commit-id: f0f3069aed67ed2f874c44e4c62a9a5c868d66fb [formerly 9ee06391e8]
Former-commit-id: f17c2d0bc0
This commit is contained in:
Lee Venable 2012-12-07 12:52:44 -06:00 committed by Gerrit Code Review
commit fa3a0b96b4
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.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory; 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.filename.DefaultFilenameMgr;
import com.raytheon.uf.viz.monitor.fog.xml.FogMonitorAlgorithmXML; 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 { 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"; private final String defaultAlgFilename = "FogMonitorAlgThresh.xml";
/** Current Algorithm Threshold full file path **/
private String currFullPathAndFileName; private String currFullPathAndFileName;
/** Algorithm Threshold XML **/
private FogMonitorAlgorithmXML algXML; private FogMonitorAlgorithmXML algXML;
/** Default File Manager **/
private DefaultFilenameMgr defaultFileNameMgr; private DefaultFilenameMgr defaultFileNameMgr;
/**
* Gets instance of Fog Algorithm Threshold Manager.
*
* @return
*/
public static FogAlgorithmMgr getInstance() {
return classInstance;
}
/**
* Constructor
*/
private FogAlgorithmMgr() { private FogAlgorithmMgr() {
init(); init();
} }
public static FogAlgorithmMgr getInstance() { /**
if (classInstance == null) { * Fog Algorithm Threshold Manager initialization.
classInstance = new FogAlgorithmMgr(); */
}
return classInstance;
}
private void init() { private void init() {
defaultFileNameMgr = new DefaultFilenameMgr(getDefaultFileNamePath()); defaultFileNameMgr = new DefaultFilenameMgr(getDefaultFileNamePath());
defaultFileNameMgr.readXmlConfig(); defaultFileNameMgr.readXmlConfig();
readInDefaultXML(); readInDefaultXML();
} }
/**
* Reads default Threshold XML file.
*/
private void readInDefaultXML() { private void readInDefaultXML() {
if (defaultFileNameMgr.getDefaultThresholdFilename() != null if (defaultFileNameMgr.getDefaultThresholdFilename() != null
&& defaultFileNameMgr.getDefaultThresholdFilename().length() > 0) { && defaultFileNameMgr.getDefaultThresholdFilename().length() > 0) {
@ -80,28 +117,39 @@ public class FogAlgorithmMgr {
} }
} }
/**
* Gets path of current Algorithm Threshold file
*
* @return file path
*/
public String getAlgorithmThresholdPath() { public String getAlgorithmThresholdPath() {
String fs = String.valueOf(File.separatorChar); String fs = IPathManager.SEPARATOR;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("fog").append(fs); sb.append("fog").append(fs);
sb.append("algorithm").append(fs); sb.append("algorithm").append(fs);
return sb.toString(); return sb.toString();
} }
/**
* Gets path of default Algorithm Threshold file
*
* @return file path
*/
public String getDefaultFileNamePath() { public String getDefaultFileNamePath() {
String fs = String.valueOf(File.separatorChar); String fs = IPathManager.SEPARATOR;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("fog").append(fs); sb.append("fog").append(fs);
sb.append("threshold").append(fs); sb.append("threshold").append(fs);
sb.append("display").append(fs); sb.append("display").append(fs);
sb.append("defaultThresh").append(fs); sb.append("defaultThresh").append(fs);
return sb.toString(); return sb.toString();
} }
/**
* Sets default Algorithm Threshold file path.
*
* @param fileName
*/
public void setDefaultAlgorithmFileName(String fileName) { public void setDefaultAlgorithmFileName(String fileName) {
if (fileName == null) { if (fileName == null) {
defaultFileNameMgr.setDefaultThresholdFilename(""); defaultFileNameMgr.setDefaultThresholdFilename("");
@ -109,11 +157,9 @@ public class FogAlgorithmMgr {
+ defaultAlgFilename; + defaultAlgFilename;
return; return;
} }
if (fileName.endsWith(".xml") == false) { if (fileName.endsWith(".xml") == false) {
fileName.concat(".xml"); fileName.concat(".xml");
} }
if (fileName.compareTo(defaultAlgFilename) == 0) { if (fileName.compareTo(defaultAlgFilename) == 0) {
defaultFileNameMgr.setDefaultThresholdFilename(""); defaultFileNameMgr.setDefaultThresholdFilename("");
} else { } else {
@ -121,83 +167,102 @@ public class FogAlgorithmMgr {
} }
} }
/**
* Reads Algorithm Threshold XML.
*/
public void readAlgorithmXml() { public void readAlgorithmXml() {
try { try {
algXML = null; algXML = null;
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
File path = pm.getStaticFile(currFullPathAndFileName); File path = pm.getStaticFile(currFullPathAndFileName);
System.out.println("**** readAlgorithmXml() path = " + path);
algXML = JAXB.unmarshal(path, FogMonitorAlgorithmXML.class); algXML = JAXB.unmarshal(path, FogMonitorAlgorithmXML.class);
} catch (Exception e) { } 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) { public void saveAlgorithmXmlAs(String newFileName) {
if (newFileName.trim().compareTo(defaultAlgFilename) == 0) { if (newFileName.trim().compareTo(defaultAlgFilename) == 0) {
return; return;
} }
currFullPathAndFileName = getAlgorithmThresholdPath() + newFileName; currFullPathAndFileName = getAlgorithmThresholdPath() + newFileName;
saveAlgorithmXml(); saveAlgorithmXml();
} }
/**
* Menu option Save... Algorithm Threshold XML file.
*/
public void saveAlgorithmXml() { public void saveAlgorithmXml() {
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext context = pm.getContext( LocalizationContext context = pm.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.SITE); LocalizationType.CAVE_STATIC, LocalizationLevel.SITE);
LocalizationFile locFile = pm.getLocalizationFile(context, LocalizationFile locFile = pm.getLocalizationFile(context,
currFullPathAndFileName); currFullPathAndFileName);
if (locFile.getFile().getParentFile().exists() == false) { if (locFile.getFile().getParentFile().exists() == false) {
System.out.println("Creating new directory"); locFile.getFile().getParentFile().mkdirs();
if (locFile.getFile().getParentFile().mkdirs() == false) {
System.out.println("Could not create new directory...");
}
} }
try { try {
System.out.println("saveAlgorithmXml() -- "
+ locFile.getFile().getAbsolutePath());
JAXB.marshal(algXML, locFile.getFile()); JAXB.marshal(algXML, locFile.getFile());
locFile.save(); locFile.save();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); statusHandler.handle(Priority.ERROR, e.getMessage());
} }
} }
/**
* Menu option Delete... Algorithm Threshold XML file.
*/
public void deleteCurrentAlgorithmFile() { public void deleteCurrentAlgorithmFile() {
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext context = pm.getContext( LocalizationContext context = pm.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.SITE); LocalizationType.CAVE_STATIC, LocalizationLevel.SITE);
LocalizationFile locFile = pm.getLocalizationFile(context, LocalizationFile locFile = pm.getLocalizationFile(context,
currFullPathAndFileName); currFullPathAndFileName);
try { try {
if (locFile != null) { if (locFile != null) {
locFile.delete(); locFile.delete();
} }
} catch (Exception e) { } 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) { public void loadAlgorithmThreashold(String fileName) {
currFullPathAndFileName = getAlgorithmThresholdPath() + fileName; currFullPathAndFileName = getAlgorithmThresholdPath() + fileName;
readAlgorithmXml(); readAlgorithmXml();
} }
/**
* Menu option Load default... Algorithm Threshold XML file.
*/
public void loadDefaultAlgorithmData() { public void loadDefaultAlgorithmData() {
readInDefaultXML(); readInDefaultXML();
} }
/**
* Gets default Algorithm Threshold XML file name.
*
* @return defaultAlgFilename
*/
public String getDefaultAlgorithmFileName() { public String getDefaultAlgorithmFileName() {
return defaultAlgFilename; return defaultAlgFilename;
} }
/**
* Gets Algorithm Threshold XML.
*
* @return algXML
*/
public FogMonitorAlgorithmXML getAlgorithmXML() { public FogMonitorAlgorithmXML getAlgorithmXML() {
return algXML; return algXML;
} }

View file

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