Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Cannot get the updated content of Text.getText() value
Cannot get the updated content of Text.getText() value [message #525002] Mon, 05 April 2010 09:16 Go to next message
czetsuya is currently offline czetsuyaFriend
Messages: 9
Registered: March 2010
Location: Philippines
Junior Member
Hi,

I have 3 classes, controller (wizarddialog), wizard and composite

In the composite class I have defined a Text control, I added this composite in the wizard. And I want to get the Text's value in the wizard dialog. Unfortunately, I'm always getting the default value I assigned to textbox.

It's like:
Composite.add(textbox)
Wizard.add(Composite)
WizardDialog.get(Wizard).get(Composite).get(Text).getText

//Controller
@Override
	protected void nextPressed() {
		String currentPageTitle = getCurrentPage().getName();
		boolean isContinueNextPage = true;
		
		if(currentPageTitle.equals("page_1")) {
			DatabaseSelectPage currentWizardPage = (DatabaseSelectPage)getCurrentPage();
						
			//always returns the default value - xxxxx; even though I've already changed it
                        System.out.println(currentWizardPage.getContainerPart().getLocalConnectionString().toString());
			String err = "";
						
			if(err == "") {
				System.out.println("here");
			} else { //invalid connection string
				System.out.println("there");
				isContinueNextPage = false;
				currentWizardPage.setErrorMessage(err);
			}
		}
	
		if(isContinueNextPage) {
			super.nextPressed();
		}
	}

//wizardpage
public class DatabaseSelectPage extends WizardPage {
	public DatabaseSelect container;

	public DatabaseSelectPage() {
		super("page_1"); //$NON-NLS-1$		
	}

	@Override
	public void createControl(Composite parent) {
		container = new DatabaseSelect(this, parent, SWT.NONE);
		
		setControl(container);
		setPageComplete(false);
	}

	public DatabaseSelect getContainerPart() {
		return container;
	}
}

//composite
public class DatabaseSelect extends Composite {
	public Text textLocalOdbc;
	private Text textUsername;
	private Text textPassword;
	private WizardPage wpage;

	public DatabaseSelect(WizardPage wpage, Composite parent, int style) {
		super(parent, style);
		this.wpage = wpage;
		this.setLayout(new FormLayout());
		
		Group grpLocalOdbc = new Group(this, SWT.NONE);
		grpLocalOdbc.setText(Messages.DatabaseSelect_0);
		
		FormData formData = new FormData();
		formData.top = new FormAttachment(0, 10);
		formData.left = new FormAttachment(0, 10);
		formData.right = new FormAttachment(50, -5);
		formData.bottom = new FormAttachment(100, -10);
		grpLocalOdbc.setLayoutData(formData);
		
		GridLayout gridLayout = new GridLayout(2, false);
		gridLayout.marginHeight = 10;
		grpLocalOdbc.setLayout(gridLayout);
		
		Label lblOdbcString = new Label(grpLocalOdbc, SWT.NONE);
		lblOdbcString.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblOdbcString.setText(Messages.DatabaseSelect_1);
		
		textLocalOdbc = new Text(grpLocalOdbc, SWT.BORDER);
		textLocalOdbc.setText("xxxxx"); //default value here: xxxxx
		textLocalOdbc.setToolTipText(Messages.DatabaseSelect_2);
		textLocalOdbc.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));		
		
		handleEvents();
	}
	
	private void handleEvents() {
		textLocalOdbc.addKeyListener(new KeyAdapter() { //$NON-NLS-1$
			@Override
                        //in this part the code can detect that the value of textLocalOdbc is updating
			public void keyReleased(KeyEvent e) {
				if(	!getLocalConnectionString().getDns().isEmpty() && 
					!getCentralConnectionString().getDns().isEmpty()) {
					wpage.setPageComplete(true);
				} else {
					wpage.setPageComplete(false);
				}
			}
		});
		
		textCentralOdbc.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
				if(	!getLocalConnectionString().getDns().isEmpty() &&
					!getCentralConnectionString().getDns().isEmpty()) {
					wpage.setPageComplete(true);
				} else {
					wpage.setPageComplete(false);
				}
			}
		});
	}
	
	public ConnectionString getLocalConnectionString() {
		System.out.println("apple: " + textLocalOdbc.getText());
		ConnectionString cs = new ConnectionString();
		cs.setDns(textLocalOdbc.getText().trim());
		cs.setUsername(textUsername.getText().trim());
		cs.setPassword(textPassword.getText().trim());
		return cs;
	}
}




Thanks,
czetsuya


[Updated on: Mon, 05 April 2010 09:33]

Report message to a moderator

Re: Cannot get the updated content of Text.getText() value [message #525334 is a reply to message #525002] Tue, 06 April 2010 09:18 Go to previous message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 05.04.2010 11:16, czetsuya wrote:
> I have 3 classes, controller (wizarddialog), wizard and composite
>
> In the composite class I have defined a Text control, I added this
> composite in the wizard. And I want to get the Text's value in the
> wizard dialog. Unfortunately, I'm always getting the default value I
> assigned to textbox.
>
> It's like:
>
> Composite.add(textbox)
> Wizard.add(Composite)
> WizardDialog.get(Wizard).get(Composite).get(Text).getText

We need some code to see what's got wrong here. I suggest to prepare
a snippet like program like those seen in

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/wizard/Snippet047WizardWithLongRunningOperation.java?view= markup

but please remove all the stuff which is not required to reproduce
the problem.

As a general advice, I recommend to use data binding to get the values
form your input widgets, see e.g.

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.e xamples.databinding/src/org/eclipse/jface/examples/databindi ng/snippets/Snippet014WizardDialog.java?view=markup

for an example.

HTH & Greetings from Bremen,

Daniel Krügler
Previous Topic:Cut/Copy/Paste
Next Topic:How to do Session handling in RCP
Goto Forum:
  


Current Time: Wed Sep 25 15:24:14 GMT 2024

Powered by FUDForum. Page generated in 0.02764 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top