Issue #1229 Refactored OpenSaveDlg to OpenDlg and made non-blocking.
Change-Id: I4641260558b289bf7b29462032015b38ff6219a3 Former-commit-id:45918c826f
[formerly82637bea2a
] [formerlyceabf8446e
[formerly 2131624d82de6ae90929be45b4a706080b889699]] Former-commit-id:ceabf8446e
Former-commit-id:72df39c19b
This commit is contained in:
parent
62b6f1cf38
commit
8b31eb04ab
2 changed files with 49 additions and 141 deletions
|
@ -32,8 +32,6 @@ import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
import org.eclipse.swt.widgets.Button;
|
import org.eclipse.swt.widgets.Button;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Dialog;
|
|
||||||
import org.eclipse.swt.widgets.Display;
|
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
import org.eclipse.swt.widgets.List;
|
import org.eclipse.swt.widgets.List;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
@ -42,6 +40,7 @@ import com.raytheon.uf.common.localization.LocalizationContext;
|
||||||
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.viz.ui.dialogs.CaveSWTDialog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class generates a list of localized files that can be opened in the
|
* This class generates a list of localized files that can be opened in the
|
||||||
|
@ -53,38 +52,15 @@ import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||||
*
|
*
|
||||||
* Date Ticket# Engineer Description
|
* Date Ticket# Engineer Description
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Initial creation.
|
||||||
|
* Oct 12, 2012 1229 rferrel Made subclass of CaveSWTDialog
|
||||||
|
* and non-blocking.
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
public class OpenSaveDlg extends Dialog {
|
public class OpenDlg extends CaveSWTDialog {
|
||||||
/**
|
|
||||||
* Dialog shell.
|
|
||||||
*/
|
|
||||||
private Shell shell;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The display control.
|
|
||||||
*/
|
|
||||||
private Display display;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to indicate if the dialog is being used for open or save as dialog.
|
|
||||||
* Only the OPEN is used.
|
|
||||||
*/
|
|
||||||
// TODO remove the SAVE_AS code that is not used change the constructor to
|
|
||||||
// not use.
|
|
||||||
@Deprecated
|
|
||||||
public static enum DialogType {
|
|
||||||
OPEN, SAVE_AS
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dialog type. This is always OPEN.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private DialogType dialogType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Font used to display file list.
|
* Font used to display file list.
|
||||||
|
@ -96,11 +72,6 @@ public class OpenSaveDlg extends Dialog {
|
||||||
*/
|
*/
|
||||||
private List cfgFileList;
|
private List cfgFileList;
|
||||||
|
|
||||||
/**
|
|
||||||
* The localize file selected by the user.
|
|
||||||
*/
|
|
||||||
private LocalizationFile selectedFile;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of localized files used to generate the file list.
|
* List of localized files used to generate the file list.
|
||||||
*/
|
*/
|
||||||
|
@ -118,24 +89,13 @@ public class OpenSaveDlg extends Dialog {
|
||||||
* shell
|
* shell
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public OpenSaveDlg(Shell parent, DialogType type) {
|
public OpenDlg(Shell parent) {
|
||||||
super(parent, 0);
|
super(parent, SWT.TITLE, CAVE.DO_NOT_BLOCK);
|
||||||
|
setText("Open Configuration File");
|
||||||
dialogType = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Display dialog and sets the selected file when user clicks on the Open
|
protected void initializeComponents(Shell shell) {
|
||||||
* button. Any other close leaves the the selected file null.
|
|
||||||
*
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public Object open() {
|
|
||||||
Shell parent = getParent();
|
|
||||||
display = parent.getDisplay();
|
|
||||||
shell = new Shell(parent, SWT.TITLE);
|
|
||||||
shell.setText("Open Configuration File");
|
|
||||||
|
|
||||||
// Create the main layout for the shell.
|
// Create the main layout for the shell.
|
||||||
GridLayout mainLayout = new GridLayout(1, false);
|
GridLayout mainLayout = new GridLayout(1, false);
|
||||||
mainLayout.marginHeight = 2;
|
mainLayout.marginHeight = 2;
|
||||||
|
@ -145,19 +105,13 @@ public class OpenSaveDlg extends Dialog {
|
||||||
|
|
||||||
// Initialize all of the controls and layouts
|
// Initialize all of the controls and layouts
|
||||||
initializeComponents();
|
initializeComponents();
|
||||||
|
}
|
||||||
|
|
||||||
shell.pack();
|
@Override
|
||||||
shell.open();
|
protected void disposed() {
|
||||||
|
if (controlFont != null) {
|
||||||
while (!shell.isDisposed()) {
|
controlFont.dispose();
|
||||||
if (!display.readAndDispatch()) {
|
|
||||||
display.sleep();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
controlFont.dispose();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -203,8 +157,6 @@ public class OpenSaveDlg extends Dialog {
|
||||||
* bottom of the dialog.
|
* bottom of the dialog.
|
||||||
*/
|
*/
|
||||||
private void createBottomButtons() {
|
private void createBottomButtons() {
|
||||||
// TODO Only the DialogType.OPEN is ever used. Code needs to be
|
|
||||||
// modified to no longer use DialogType.
|
|
||||||
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);
|
||||||
mainButtonComp.setLayout(new GridLayout(1, false));
|
mainButtonComp.setLayout(new GridLayout(1, false));
|
||||||
|
@ -215,33 +167,20 @@ public class OpenSaveDlg extends Dialog {
|
||||||
buttonComp.setLayout(new GridLayout(2, false));
|
buttonComp.setLayout(new GridLayout(2, false));
|
||||||
buttonComp.setLayoutData(gd);
|
buttonComp.setLayoutData(gd);
|
||||||
|
|
||||||
if (dialogType == DialogType.OPEN) {
|
gd = new GridData(100, SWT.DEFAULT);
|
||||||
gd = new GridData(100, SWT.DEFAULT);
|
Button openBtn = new Button(buttonComp, SWT.PUSH);
|
||||||
Button openBtn = new Button(buttonComp, SWT.PUSH);
|
openBtn.setText("Open");
|
||||||
openBtn.setText("Open");
|
openBtn.setLayoutData(gd);
|
||||||
openBtn.setLayoutData(gd);
|
openBtn.addSelectionListener(new SelectionAdapter() {
|
||||||
openBtn.addSelectionListener(new SelectionAdapter() {
|
@Override
|
||||||
@Override
|
public void widgetSelected(SelectionEvent event) {
|
||||||
public void widgetSelected(SelectionEvent event) {
|
int selectedIndex = cfgFileList.getSelectionIndex();
|
||||||
int selectedIndex = cfgFileList.getSelectionIndex();
|
String str = cfgFileList.getItem(selectedIndex);
|
||||||
String str = cfgFileList.getItem(selectedIndex);
|
LocalizationFile selectedFile = locFileMap.get(str);
|
||||||
selectedFile = locFileMap.get(str);
|
setReturnValue(selectedFile);
|
||||||
shell.dispose();
|
close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (dialogType == DialogType.SAVE_AS) {
|
|
||||||
gd = new GridData(100, SWT.DEFAULT);
|
|
||||||
Button saveBtn = new Button(buttonComp, SWT.PUSH);
|
|
||||||
saveBtn.setText("Save");
|
|
||||||
saveBtn.setLayoutData(gd);
|
|
||||||
saveBtn.addSelectionListener(new SelectionAdapter() {
|
|
||||||
@Override
|
|
||||||
public void widgetSelected(SelectionEvent event) {
|
|
||||||
selectedFile = null;
|
|
||||||
shell.dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
gd = new GridData(100, SWT.DEFAULT);
|
gd = new GridData(100, SWT.DEFAULT);
|
||||||
Button cancelBtn = new Button(buttonComp, SWT.PUSH);
|
Button cancelBtn = new Button(buttonComp, SWT.PUSH);
|
||||||
|
@ -300,14 +239,4 @@ public class OpenSaveDlg extends Dialog {
|
||||||
cfgFileList.setSelection(0);
|
cfgFileList.setSelection(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtain the localized file selected by the user or null if no file
|
|
||||||
* selected.
|
|
||||||
*
|
|
||||||
* @return lfile
|
|
||||||
*/
|
|
||||||
public LocalizationFile getSelectedFile() {
|
|
||||||
return selectedFile;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -60,8 +60,8 @@ 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.localization.exception.LocalizationOpFailedException;
|
import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException;
|
||||||
import com.raytheon.uf.viz.core.localization.LocalizationManager;
|
import com.raytheon.uf.viz.core.localization.LocalizationManager;
|
||||||
import com.raytheon.viz.avnconfig.OpenSaveDlg.DialogType;
|
|
||||||
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
|
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
|
||||||
|
import com.raytheon.viz.ui.dialogs.ICloseCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple text Editor dialog allowing the user to modify a localized file.
|
* A simple text Editor dialog allowing the user to modify a localized file.
|
||||||
|
@ -144,6 +144,8 @@ public class TextEditorSetupDlg extends CaveSWTDialog {
|
||||||
|
|
||||||
private FindReplaceDlg findDlg;
|
private FindReplaceDlg findDlg;
|
||||||
|
|
||||||
|
private OpenDlg openDlg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
@ -846,9 +848,23 @@ public class TextEditorSetupDlg extends CaveSWTDialog {
|
||||||
* Show the 'Open' file dialog.
|
* Show the 'Open' file dialog.
|
||||||
*/
|
*/
|
||||||
private void openFile() {
|
private void openFile() {
|
||||||
OpenSaveDlg dlg = new OpenSaveDlg(shell, DialogType.OPEN);
|
if (mustCreate(openDlg)) {
|
||||||
dlg.open();
|
openDlg = new OpenDlg(shell);
|
||||||
openFile(dlg.getSelectedFile());
|
openDlg.setCloseCallback(new ICloseCallback() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dialogClosed(Object returnValue) {
|
||||||
|
LocalizationFile selectedFile = null;
|
||||||
|
if (returnValue instanceof LocalizationFile) {
|
||||||
|
selectedFile = (LocalizationFile) returnValue;
|
||||||
|
}
|
||||||
|
openFile(selectedFile);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
openDlg.open();
|
||||||
|
} else {
|
||||||
|
openDlg.bringToTop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -887,41 +903,4 @@ public class TextEditorSetupDlg extends CaveSWTDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void openFile() {
|
|
||||||
// FileDialog dlg = new FileDialog(shell, SWT.OPEN);
|
|
||||||
// IPathManager pm = PathManagerFactory.getPathManager();
|
|
||||||
// String path = pm.getFile(
|
|
||||||
// pm.getContext(LocalizationType.CAVE_STATIC,
|
|
||||||
// LocalizationLevel.BASE), "aviation").getAbsolutePath();
|
|
||||||
// dlg.setFilterPath(path);
|
|
||||||
// String fn = dlg.open();
|
|
||||||
// StringBuilder contents = new StringBuilder();
|
|
||||||
//
|
|
||||||
// if (fn != null) {
|
|
||||||
// try {
|
|
||||||
// BufferedReader input = new BufferedReader(new FileReader(
|
|
||||||
// new File(fn)));
|
|
||||||
// String line = null;
|
|
||||||
//
|
|
||||||
// while ((line = input.readLine()) != null) {
|
|
||||||
// contents.append(line);
|
|
||||||
// contents.append(System.getProperty("line.separator"));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// editorStTxt.setText(contents.toString());
|
|
||||||
//
|
|
||||||
// input.close();
|
|
||||||
// msgStatusComp.setMessageText("File " + fn
|
|
||||||
// + " opened successfully.", new RGB(0, 255, 0));
|
|
||||||
// } catch (FileNotFoundException e) {
|
|
||||||
// msgStatusComp.setMessageText("File " + fn + " not found.",
|
|
||||||
// new RGB(255, 0, 0));
|
|
||||||
// } catch (IOException e) {
|
|
||||||
// msgStatusComp.setMessageText(
|
|
||||||
// "An error occured while opening file " + fn, new RGB(
|
|
||||||
// 255, 0, 0));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue