How to get value from RCP forms [message #992504] |
Fri, 21 December 2012 20:23 |
davy hu Messages: 2 Registered: December 2012 |
Junior Member |
|
|
I created a form by using the forms API:
My question is how can write the code to get the values of "first name" and "last name" when "submit" button is clicked. Theanks.
here is my code in View.java
public class View extends ViewPart {
public static final String ID = "com.test.forms.view";
private TableViewer viewer;
public void createPartControl(Composite parent) {
FormToolkit toolkit = new FormToolkit(parent.getDisplay());
Composite client = toolkit.createComposite(parent, SWT.WRAP);
Table t = toolkit.createTable(client, SWT.NULL);
viewer = new TableViewer(t);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setInput(getViewSite());
Form form = toolkit.createForm(parent);
Composite composite = form.getBody();
composite.setLayout (new GridLayout(2, true));
Label lblFirstName = toolkit.createLabel(composite, "First Name");
Label lblLastName = toolkit.createLabel(composite, "Last Name");
Text txtFirstName = toolkit.createText(composite, "");
Text txtLastName = toolkit.createText(composite, "");
Button b = toolkit.createButton(composite, "Submit", SWT.PUSH);
}
public void setFocus() {
viewer.getControl().setFocus();
}
}
|
|
|
Re: How to get value from RCP forms [message #994443 is a reply to message #992504] |
Thu, 27 December 2012 10:30 |
|
Hello davy,
you just have to add an selection listener to the button in order to get to know when the button is clicked.
And then use the txtFirstName.getText() and txtLastName.getText() methods to get the values.
By the way the FormToolkit also does only create SWT widgets internally.
Best regards,
Simon
|
|
|
|
Powered by
FUDForum. Page generated in 0.03469 seconds