Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Saving contents of a view
Saving contents of a view [message #459465] Tue, 09 August 2005 15:17 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #459470 is a reply to message #459468] Tue, 09 August 2005 16:45 Go to previous messageGo to next message
Neil Bartlett is currently offline Neil BartlettFriend
Messages: 93
Registered: July 2009
Member
Unless I've misunderstood your question, the answer is rather obvious:

text1.getText();
text2.getText();
Re: Saving contents of a view [message #459471 is a reply to message #459470] Tue, 09 August 2005 17:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Neil Bartlett" <neil@integility.com> wrote in message
news:1f8f263f5357b89ea228097fda7c2a3b$1@www.eclipse.org...
> Unless I've misunderstood your question, the answer is rather obvious:
>
> text1.getText();
> text2.getText();
>
lol.
---
Sunil
Re: Saving contents of a view [message #459477 is a reply to message #459465] Wed, 10 August 2005 05:24 Go to previous message
Michael Pellaton is currently offline Michael PellatonFriend
Messages: 289
Registered: July 2009
Senior Member
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!!
>
>
Previous Topic:Why is there not SWT.CAP_* in my eclipse3.1?
Next Topic:Get the location of a tray item
Goto Forum:
  


Current Time: Thu Apr 25 08:14:17 GMT 2024

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

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

Back to the top