Saving contents of a view [message #459465] |
Tue, 09 August 2005 15:17 |
Eclipse User |
|
|
|
Originally posted by: kruttik.a.tcs.com
Hi,
i have created a small view in Eclipse 3.0
public class HelloWorldView extends ViewPart {
it has two Text controls and a push button.
Now i want to save the data typed in these text fields into a file on
click of the button.
I used the button.addSelectionListener() method which does capture the
button click but i do not know how to access the values of other fields in
the view.
I tried creating my own selection listener class
class OkSelectionListener extends SelectionAdapter{
and then passing the Scrolled form instance
OkSelectionListener(ScrolledForm f){
form=f;
}
and then accessed the controls using
Control[] c=form.getBody().getChildren();
but i am not able to get the text value
the second problem with this is that form values would not be captured on
click..
Please help!!
|
|
|
Re: Saving contents of a view [message #459466 is a reply to message #459465] |
Tue, 09 August 2005 15:56 |
Eclipse User |
|
|
|
Originally posted by: friederich.kupzog.de
Hi,
(without knowing how a ViewPart works in Eclipse) You have created the
Text controls somewhere. So you should have a reference to them. Then
just use myText.getText(). Or did I miss something?
Hope that helped,
Friederich
Kruttik Aggarwal wrote:
> Hi,
> i have created a small view in Eclipse 3.0
> public class HelloWorldView extends ViewPart {
>
>
> it has two Text controls and a push button.
> Now i want to save the data typed in these text fields into a file on
> click of the button.
> I used the button.addSelectionListener() method which does capture the
> button click but i do not know how to access the values of other fields
> in the view.
>
> I tried creating my own selection listener class
> class OkSelectionListener extends SelectionAdapter{
>
> and then passing the Scrolled form instance
> OkSelectionListener(ScrolledForm f){
> form=f;
> }
> and then accessed the controls using
> Control[] c=form.getBody().getChildren();
> but i am not able to get the text value
> the second problem with this is that form values would not be captured
> on click..
> Please help!!
>
>
--
Friederich Kupzog
Elektronik & Software
Neusser Str. 5-7
50670 Köln
Tel 0241 160696-1
Fax 0221 726670
www.kupzog.de/fkmk
|
|
|
Re: Saving contents of a view [message #459468 is a reply to message #459466] |
Tue, 09 August 2005 16:15 |
Eclipse User |
|
|
|
Originally posted by: kruttik.a.tcs.com
this is my code for the ViewPart
public class HelloWorldView extends ViewPart {
Label label;
FormToolkit toolkit;
ScrolledForm form;
public HelloWorldView() {
}
public void createPartControl(Composite parent) {
FormToolkit toolkit=new FormToolkit(parent.getDisplay());
form=toolkit.createScrolledForm(parent);
form.setText("Forms in eclipse");
GridLayout layout=new GridLayout(2,false);
form.getBody().setLayout(layout);
Hyperlink link=toolkit.createHyperlink(form.getBody(),"I want a
click", SWT.WRAP);
GridData gd=new GridData();
gd.horizontalSpan=2;
link.setLayoutData(gd);
link.addHyperlinkListener(new HyperlinkAdapter(){
public void linkActivated(HyperlinkEvent e){
System.out.println("HyperLink Was Activated");
}
});
Label label1=toolkit.createLabel(form.getBody(), "Input Feild1 :
");
Text text1=toolkit.createText(form.getBody(),"Default Text1");
text1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label label2=toolkit.createLabel(form.getBody(), "Input Feild2 :
");
Text text2=new Text(form.getBody(),SWT.RIGHT);
toolkit.adapt(text2,true,true);
text2.setText("475");
text2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
text2.setData(FormToolkit.KEY_DRAW_BORDER,FormToolkit.TREE_B ORDER);
Button button=toolkit.createButton(form.getBody(),"Ok
Button",SWT.PUSH);
/*******PROBLEM AREA****/
SelectionListener sl=(SelectionListener)new
OkSelectionListener(form);
button.addSelectionListener(sl);
gd=new GridData();
gd.horizontalSpan=2;
button.setLayoutData(gd);
toolkit.paintBordersFor(form.getBody());
}
public void setFocus() {
}
How do i access the form controls(text in text boxes) in the
OkSelectionListener??
|
|
|
Re: Saving contents of a view [message #459469 is a reply to message #459468] |
Tue, 09 August 2005 16:44 |
Eclipse User |
|
|
|
Originally posted by: friederich.kupzog.de
Hi Kruttik,
sorry, the problem is that I only know swt but not the eclipse
framework. I do not see your ok listener implementation. Here is how I
would do it:
final Text text1 = toolkit.createText(
form.getBody(),"Default Text1");
final Text text2 = new Text(parent, SWT.SOMESTYLE);
final Button but = toolkit.createButton(
form.getBody(),"Ok Button",SWT.PUSH);
but.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e)
{
System.out.println(text1.getText());
}
});
Note that the control variables are final so that you can access them
from within the listener.
Hope that helped,
Friederich
Kruttik Aggarwal wrote:
> this is my code for the ViewPart
> public class HelloWorldView extends ViewPart {
> Label label;
> FormToolkit toolkit;
> ScrolledForm form;
> public HelloWorldView() {
> }
> public void createPartControl(Composite parent) {
> FormToolkit toolkit=new FormToolkit(parent.getDisplay());
> form=toolkit.createScrolledForm(parent);
> form.setText("Forms in eclipse");
> GridLayout layout=new GridLayout(2,false);
> form.getBody().setLayout(layout);
> Hyperlink link=toolkit.createHyperlink(form.getBody(),"I want a
> click", SWT.WRAP);
> GridData gd=new GridData();
> gd.horizontalSpan=2;
> link.setLayoutData(gd);
> link.addHyperlinkListener(new HyperlinkAdapter(){
> public void linkActivated(HyperlinkEvent e){
> System.out.println("HyperLink Was Activated");
> }
> });
> Label label1=toolkit.createLabel(form.getBody(), "Input Feild1 : ");
> Text text1=toolkit.createText(form.getBody(),"Default Text1");
> text1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
> Label label2=toolkit.createLabel(form.getBody(), "Input
> Feild2 : ");
> Text text2=new Text(form.getBody(),SWT.RIGHT);
> toolkit.adapt(text2,true,true);
> text2.setText("475");
> text2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
> text2.setData(FormToolkit.KEY_DRAW_BORDER,FormToolkit.TREE_B ORDER);
> Button button=toolkit.createButton(form.getBody(),"Ok
> Button",SWT.PUSH);
> /*******PROBLEM AREA****/
> SelectionListener sl=(SelectionListener)new
> OkSelectionListener(form);
> button.addSelectionListener(sl);
> gd=new GridData();
> gd.horizontalSpan=2;
> button.setLayoutData(gd);
> toolkit.paintBordersFor(form.getBody());
> }
> public void setFocus() {
> }
>
> How do i access the form controls(text in text boxes) in the
> OkSelectionListener??
>
>
>
--
Friederich Kupzog
Elektronik & Software
Neusser Str. 5-7
50670 Köln
Tel 0241 160696-1
Fax 0221 726670
www.kupzog.de/fkmk
|
|
|
|
|
Re: Saving contents of a view [message #459477 is a reply to message #459465] |
Wed, 10 August 2005 05:24 |
|
Hello
Just for your information: According to the "Eclipse UI Guidelines"
"Modifications made in a view should be saved immediately" whereas
"Modifications made in an editor follow an open-save-close lifecycle".
URL: http://www.eclipse.org/articles/Article-UI-Guidelines/
Guidelines: 1.2, 1.3, 6.1, 6.2, 7.1, 7.2
Michael
Kruttik Aggarwal wrote:
> Hi,
> i have created a small view in Eclipse 3.0
> public class HelloWorldView extends ViewPart {
>
>
> it has two Text controls and a push button.
> Now i want to save the data typed in these text fields into a file on
> click of the button.
> I used the button.addSelectionListener() method which does capture the
> button click but i do not know how to access the values of other fields in
> the view.
>
> I tried creating my own selection listener class
> class OkSelectionListener extends SelectionAdapter{
>
> and then passing the Scrolled form instance
> OkSelectionListener(ScrolledForm f){
> form=f;
> }
> and then accessed the controls using
> Control[] c=form.getBody().getChildren();
> but i am not able to get the text value
> the second problem with this is that form values would not be captured on
> click..
> Please help!!
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03425 seconds