My Modal Dialog (again) [message #109727] |
Mon, 17 October 2005 20:49 |
Vitor Tortorello Messages: 6 Registered: July 2009 |
Junior Member |
|
|
Hello,
The code listed below open a modal dialog
[like "Create my own dialog / Norbert Plöt / 16-09-2005 10:37"]
Please,
==> the way to FormMain gets the "text" and "text1" values, after
buttonOk click.
==> the way to gets in FormMain how button was clicked?
Thank you.
Vitor
---------------------------------
ps.
What I want:
a. FormMain open the modal dialog.
b. When modal dialog closes (by window close button, buttonOk or
buttonCancel, or ALT F4,...):
- FormMain gets data application needs (how button clicked, texts
values, etc.)
- FormMain disposes modal dialog
Something like (pseudo-code):
private void openMyDialog() {
String firstText = null;
String secondText = null;
FormDialog dlg = new FormDialog();
dlg.initialize(sShell);
try {
dlg.sShell.open();
// .....
if (buttonOk_Clicked) {
firstText = dlg.text.getText();
secondText = dlg.text1.getText();
}
finally {
dlg.dispose();
}
}
-----------------------------------
/***********
Main
***********/
package teste2;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
public class FormMain {
private Shell sShell = null; //
@jve:decl-index=0:visual-constraint="10,10"
private Button buttonOpenDialog = null;
/**
* @param args
*/
public static void main(String[] args) {
Display display = Display.getDefault();
FormMain thisClass = new FormMain();
thisClass.createSShell();
thisClass.sShell.open();
while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
/**
* This method initializes sShell
*/
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell - Main");
sShell.setSize(new org.eclipse.swt.graphics.Point(300,125));
buttonOpenDialog = new Button(sShell, SWT.NONE);
buttonOpenDialog.setBounds(new
org.eclipse.swt.graphics.Rectangle(46,31,200,39));
buttonOpenDialog.setText("Open dialog");
buttonOpenDialog.addSelectionListener(new
org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
openMyDialog();
}
});
}
private void openMyDialog() {
FormDialog dlg = new FormDialog();
dlg.initialize(sShell);
dlg.sShell.open();
// here <=================================
System.out.println("Text = " + dlg.text.getText());
System.out.println("Text1= " + dlg.text1.getText());
}
}
/***********
MyDialog
***********/
package teste2;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
public class FormDialog {
public Shell sShell = null; //
@jve:decl-index=0:visual-constraint="24,10"
public Text text = null;
public Text text1 = null;
private Button buttonOk = null;
private Button buttonCancel = null;
private Label label = null;
private Label label1 = null;
/**
* This method initializes sShell
*/
private void createSShell() {
// changed here
if (sShell == null)
sShell = new Shell();
sShell.setText("Shell- Dialog");
sShell.setSize(new Point(300, 200));
text = new Text(sShell, SWT.BORDER);
text.setBounds(new org.eclipse.swt.graphics.Rectangle(78,31,172,26));
text1 = new Text(sShell, SWT.BORDER);
text1.setBounds(new org.eclipse.swt.graphics.Rectangle(79,71,170,26));
buttonOk = new Button(sShell, SWT.NONE);
buttonOk.setBounds(new org.eclipse.swt.graphics.Rectangle(29,110,108,30));
buttonOk.setText("Ok");
buttonCancel = new Button(sShell, SWT.NONE);
buttonCancel.setBounds(new
org.eclipse.swt.graphics.Rectangle(159,109,103,30));
buttonCancel.setText("Cancel");
label = new Label(sShell, SWT.NONE);
label.setBounds(new org.eclipse.swt.graphics.Rectangle(28,31,39,18));
label.setText("Text:");
label1 = new Label(sShell, SWT.NONE);
label1.setBounds(new org.eclipse.swt.graphics.Rectangle(16,76,48,18));
label1.setText("Text1:");
}
// added this [ Main calls this sShell.open() ]
public void initialize(Shell parent) {
sShell = new Shell(parent, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
createSShell();
}
}
|
|
|
Re: My Modal Dialog (again) [message #109733 is a reply to message #109727] |
Mon, 17 October 2005 22:26 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Well you can't do that directly. The dialog is disposed after the open
returns. Because of that the text areas are disposed and you can't get
their values.
What you need to do is inside FormDialog you need to add an event
listener to text and text1. The listener would be a "modifyText" event.
Then in the code created by the VE under the modifyText method you would
need to get the text from the text field and save it in a variable in
FormDialog. Then you would need to create an accessor on FormDialog to
return the text. You can't walk into FormDialog from the outside to get
the text directly from the text widgets.
--
Thanks,
Rich Kulp
|
|
|
Re: My Modal Dialog (again) [message #611210 is a reply to message #109727] |
Mon, 17 October 2005 22:26 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Well you can't do that directly. The dialog is disposed after the open
returns. Because of that the text areas are disposed and you can't get
their values.
What you need to do is inside FormDialog you need to add an event
listener to text and text1. The listener would be a "modifyText" event.
Then in the code created by the VE under the modifyText method you would
need to get the text from the text field and save it in a variable in
FormDialog. Then you would need to create an accessor on FormDialog to
return the text. You can't walk into FormDialog from the outside to get
the text directly from the text widgets.
--
Thanks,
Rich Kulp
|
|
|
Powered by
FUDForum. Page generated in 0.02462 seconds