pausing a java program so user can complete input into SWT shell

G

gaff

Hi,

I am trying to open a SWT shell so a user can input data into the shell
that then gets used in the rest of the program.

The shell is being open from a running application so doesn't need a
Display, in fact the shell doesn't open at all with a Display. The
application is Eclipse GMF based, and the class must return a value at
the end. What I want to happen is the Shell to open, for the user to
enter some text and for this text to be used in the returning value.
BUT, the entire program just runs straight through, which means the
Shell does open but the program just keeps on running so an empty
String is used for calculating the return value without the user have
been given a chance to enter Text.

The application is GMF based the user completes some actions that calls
this which must return a value at the end:

public class ChangePropEditPolicy extends OpenEditPolicy{
private String inputtext; // text to be read in

@Override
protected Command getOpenCommand(Request request) {

Command ret = null; // value to be returned at the end

SOME GMF STUFF...

final Shell s = new Shell(SWT.CLOSE|SWT.RESIZE|SWT.APPLICATION_MODAL);
s.setSize(500, 600);
s.setMinimumSize(500, 600);

final Text t1 = new Text(s,SWT.BORDER);
t1.setBounds(10, 10, 100, 20);
Button b1 = new Button(s, SWT.PUSH);
b1.setBounds(10, 50, 40, 40);
b1.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
inputtext = t1.getText();
s.close();
}
});
s.open();


SOME MORE GMF STUFF THAT USES inputtext THAT THE USER INPUTS, BUT THE
PROGRAM JUST KEEPS RUNNING BEFORE THE USER CAN INPUT IT SO IS ALWAYS
EMPTY

return ret;
}}


I need a way of pausing the Shell maybe so nothing else happens until
it is closed OR pausing the program all together that is then over
ridden when the Shell closes OR any other suggestions on how I could
fix this, maybe putting the entire SWT part in some kind of while loop?

Thanks for your help.
 
A

Andrew Thompson

gaff wrote:
....
I am trying to open a SWT shell so a user can input data into the shell
that then gets used in the rest of the program.

Best source of advice on SWT is the SWT
forum, (linked from here)
<http://www.eclipse.org/swt/>

But, while I've never used SWT, a quick Google
suggests that an SWT Shell is roughly equivalent
to a Swing JFrame, except in that it supports
modality (on supported platforms), that suggest
that if you adjust the 'modal' parameters of the
Shell, it might block inpt until dismissed, having
the effect you want. Otherwise, you might
instead try an SWT Dialog.

HTH

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top