A simple Question about JFace action

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

A simple Question about JFace action

Postby kabbesy » Thu Jun 23, 2005 10:53 pm

This question maybe quite simple ,but I'm really a new man to SWT&Jface.

I am a beginner to swt&Jface by some tutorial ebooks.
what i have read about the Jface action is all coded like :

Code: Select all
import org.eclipse.jface.action.*;
import org.eclipse.jface.window.*;

public class ExitAction extends Action
{
  ApplicationWindow window;

  public ExitAction(ApplicationWindow w)
  {
    window = w;
    setText("E&xit");
  }

  public void run()
  {
    window.close();
  }
}




but all the actions which are generated by Designer seems like:
Code: Select all
    private Action exit;
    private void createActions() {
        exit = new Action("&Exit") {
            public void run() {
                System.exit(1);
            }
        };
    }


Though it is a very simple and convenience way to control the action itself . But ,how can make the ACTION control/access other widget component in such a createAction method ? Example, I want to change one Label's text on the shell before the System.exit ??
To declare another reference of the class itself ? And access it's component in a SWT way ?

PS:My english is so poor that I even can not describe my simple question in such a correct sentence.

thanks a lot [/code]
kabbesy
 
Posts: 1
Joined: Thu Jun 23, 2005 10:23 pm

Re: A simple Question about JFace action

Postby Eric Clayberg » Sun Jun 26, 2005 3:37 pm

kabbesy wrote:all the actions which are generated by Designer seems like

Note that you can use Designer to create new actions or you can select existing Action classes.

kabbesy wrote:Though it is a very simple and convenience way to control the action itself . But ,how can make the ACTION control/access other widget component in such a createAction method ? Example, I want to change one Label's text on the shell before the System.exit ?

Why not just make the label widget a field and reference it directly or through an accessor?
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Make it a field

Postby Slot Head » Sun Jul 10, 2005 7:11 pm

There's a rally cool way to make the widget into a field.

Right click on the variable name of it in the code,
select Refactor,
find it in the context menu-- I think it's ctrl+shft+F
Slot Head
 
Posts: 36
Joined: Sun Jul 10, 2005 9:50 am

Re: Make it a field

Postby Eric Clayberg » Sun Jul 10, 2005 7:40 pm

Slot Head wrote:There's a rally cool way to make the widget into a field. Right click on the variable name of it in the code,
select Refactor, find it in the context menu-- I think it's ctrl+shft+F

An even faster way to do this from Designer's design view is to click on the Convert local to field button Image.

If you want to convert multiple widgets into fields all at once, you can also use Designer's new (in v4.1.0) multi widget Rename or convert dialog:

Image . Image
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest