Issue #1298 Convert UserEntryDialog to CaveSWTDialog but keep it a blocking dialog.

Change-Id: I5c2ae63c0461d5e3e96a050c0055a625b1271072

Former-commit-id: eadf4e9a28df6687a8e0bee6c6cef74356cd26d7
This commit is contained in:
Roger Ferrel 2012-11-13 15:46:05 -06:00
parent 7663818f6c
commit 590eca2cba
2 changed files with 27 additions and 43 deletions

View file

@ -65,6 +65,7 @@ import com.raytheon.viz.ui.widgets.ToggleSelectList;
* Mar 7, 2008 Eric Babin Initial Creation
* Oct 27, 2012 1287 rferrel Code cleanup for non-blocking dialog.
* Oct 25, 2012 1287 rferrel Code changes for non-blocking PublishDialog.
* Nov 13, 2012 1298 rferrel Code changes for non-blocking UserEntryDialog.
*
* </pre>
*
@ -318,16 +319,22 @@ public class ProductScriptsDialog extends CaveJFACEDialog {
String[] entry = cmd.substring(entryIdx + 1, endEntryIdx)
.split(":");
String configFile = entry[2];
// The dialog being opened is modal to the parent dialog.
// This will prevent the launching of another dialog until
// the modal dialog is closed.
// Keep this a blocking dialog so the loop will only display
// one dialog at a time.
UserEntryDialog entryDlg = new UserEntryDialog(
this.getShell(), entry[1] + " Entry", entry[1]
+ ":", entry[2]);
String returnMsg = entryDlg.open();
Object returnMsg = entryDlg.open();
if (returnMsg == null) {
// cancel pressed
run = false;
continue;
}
configFile = returnMsg;
configFile = returnMsg.toString();
cmd = cmd.substring(0, entryIdx) + configFile
+ cmd.substring(endEntryIdx + 1);

View file

@ -26,14 +26,14 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
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.Shell;
import org.eclipse.swt.widgets.Text;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
/**
* TODO Add Description
* Dialog to get user text.
*
* <pre>
*
@ -41,24 +41,14 @@ import org.eclipse.swt.widgets.Text;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 16, 2010 lvenable Initial creation
* Nov 14, 2012 1298 rferrel Convert to CaveSWTDialog for non-blocking.
*
* </pre>
*
* @author lvenable
* @version 1.0
*/
public class UserEntryDialog extends Dialog {
/**
* Dialog shell.
*/
private Shell shell;
/**
* The display control.
*/
private Display display;
private String dialogTitle;
public class UserEntryDialog extends CaveSWTDialog {
private String message;
@ -68,21 +58,18 @@ public class UserEntryDialog extends Dialog {
public UserEntryDialog(Shell parentShell, String title, String message,
String defaultText) {
super(parentShell, 0);
super(parentShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL, CAVE.NONE);
if (title != null) {
setText(title);
}
this.dialogTitle = title;
this.message = message;
this.inputText = defaultText;
}
public String open() {
Shell parent = getParent();
display = parent.getDisplay();
shell = new Shell(parent, SWT.DIALOG_TRIM);
if (dialogTitle != null) {
shell.setText(dialogTitle);
}
@Override
protected void initializeComponents(Shell shell) {
// Create the main layout for the shell.
GridLayout mainLayout = new GridLayout(1, false);
@ -90,17 +77,6 @@ public class UserEntryDialog extends Dialog {
// Initialize data and all of the controls and layouts
initializeComponents();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return inputText;
}
private void initializeComponents() {
@ -127,7 +103,7 @@ public class UserEntryDialog extends Dialog {
inputTF = new Text(controlComp, SWT.BORDER);
inputTF.setLayoutData(gd);
if (this.inputText != null) {
if (inputText != null) {
inputTF.setText(inputText);
}
}
@ -147,8 +123,9 @@ public class UserEntryDialog extends Dialog {
okBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
inputText = inputTF.getText().trim();
shell.dispose();
String inputText = inputTF.getText().trim();
setReturnValue(inputText);
close();
}
});
@ -160,8 +137,8 @@ public class UserEntryDialog extends Dialog {
cancelBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
inputText = null;
shell.dispose();
setReturnValue(null);
close();
}
});
}