On the swt,jface of RCP development

Source: Internet
Author: User
Tags gettext
on the swt,jface of RCP developmentSwt
What is SWT?
SWT full name is Standard Widget Toolkit is an open source GUI programming framework, each of US Java developers, Learning Java development will be exposed to the AWT and swing two graphics libraries, and awt,swing two graphics libraries, SWT's advantage is embodied in the low-level call local graphics library, greatly improve the running speed (loss of a certain cross-platform). An important point of SWT is that a control does not exist alone, but is present in the parent control. This way the child controls must be disposed when the parent control is disposed. The constructors for each SWT control are based on a parent container.
Table table = new Table (PARENT,SWT. multi| Swt. H_scroll);
Since there is SWT, why there is jface birth. Of course, in order to not be able to stop the view layer, control layer, data layer isolation, the MVC is encapsulated. For example, the data source is model.
Tableviewer.setinput (OBJS);

How data is organized (Controller)

Tableviewer.setcontentprovider (New Arraycontentprovider)

How data is displayed (Viewer)

Tableviewer.setlabelprovider (..);

Table display data depends on the index, JFace encapsulates a lot of methods, you just pass some objects can play into the data filtering, sorting, organizing and other functions.

Here is a demo of a concrete table and Tableviewer:
Relies on 5 packages:

Import java.util.List;
Import Org.eclipse.jface.viewers.ArrayContentProvider;
Import Org.eclipse.jface.viewers.ColumnLabelProvider;
Import Org.eclipse.jface.viewers.TableViewer;
Import Org.eclipse.jface.viewers.TableViewerColumn;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.layout.GridData;
Import Org.eclipse.swt.layout.GridLayout;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Shell;
Import org.eclipse.swt.widgets.Table;
Import Org.eclipse.swt.widgets.TableColumn;

Import Org.eclipse.swt.widgets.TableItem;

Import com.google.common.collect.Lists;
    class people {String name;
    String age;

    int index;
        Public people (int index, string name, String age) {this.name = name;
        This.age = age;
    This.index = index;
    Public String GetName () {return name;
    Public String Getage () {return age;
    public int GetIndex () {return index; } public class Demo {public statIC void Main (string[] args) {Display display = Display.getdefault ();
        Shell shell = new shell (display);
        Shell.setmaximized (TRUE);
        Shell.setlayout (New GridLayout (2, false)); Table table = new Table (Shell, SWT. MULTI | Swt. full_selection | Swt.
        Table.settooltiptext ("SWT table demo"); Table.setlayoutdata (SWT, New Griddata. FILL, SWT.
        FILL, False, true);
        Table.setheadervisible (TRUE);
        Table.setlinesvisible (TRUE);
        Createcolumlabel (table);
        List<people> Objs = Createdata (); for (int row = 0; row < objs.size (); row++) {Tableitem item = new Tableitem (table, SWT.
            FILL); Depends on the specific parameter for (int col = 0; col < Table.getcolumncount (); col++) {if (Objs.get (row)!= Nu LL) {switch (col) {case 0:item.settext (col, Objs.get (ro
                    W). GetIndex () + "");    Break
                        Case 1:item.settext (col, Objs.get (Row). GetName ());
                    Case 2:item.settext (col, Objs.get (Row). Getage ());
        }}} table.pack (); Tableviewer tableviewer = new Tableviewer (Shell, SWT. CHECK | Swt.
        Createcolumlabel (Tableviewer);
        Tableviewer.setcontentprovider (New Arraycontentprovider ());
        Tableviewer.setinput (OBJS);

        Shell.open ();
            while (!shell.isdisposed ()) {if (!display.readanddispatch ()) {continue;
            }} private static void Createcolumlabel (table table) {for (int i = 0; i < 3; i++) { TableColumn TC = new TableColumn (table, SWT.
            Tc.setresizable (FALSE);
        Tc.setwidth (250); }} private static List<People> Createdata () {list<people> peoples = lists.newarraylist ();
        Peoples.add (New people (1, "Li Hua", "20"));
        Peoples.add (New People (2, "Wang Qiang", "30"));
        Peoples.add (New People (3, "Zhang Wei", "40"));
    return peoples; private static void Createcolumlabel (Tableviewer tableviewer) {tableviewercolumn viewerColum1 = new Tablev Iewercolumn (Tableviewer, SWT.
        NONE); Viewercolum1.setlabelprovider (New Columnlabelprovider () {@Override public String getText (Object E Lement) {if (element instanceof people) {return People.class.cast (Element). GetIndex (
                ) + "";
            return Super.gettext (Element);
        }); Tableviewercolumn viewerColum2 = new Tableviewercolumn (Tableviewer, SWT.
    Viewercolum2.setlabelprovider (New Columnlabelprovider () {@Override        Public String GetText (Object Element) {if (element instanceof people) {retur
                n People.class.cast (Element). GetName ();
            return Super.gettext (Element);
        }); Tableviewercolumn viewerColum3 = new Tableviewercolumn (Tableviewer, SWT.
        NONE); Viewercolum3.setlabelprovider (New Columnlabelprovider () {@Override public String getText (Object E 
                Lement) {if (element instanceof people) {return People.class.cast (Element). Getage ();
            return Super.gettext (Element);
        TableColumn TableColumn = Viewercolum1.getcolumn ();
        Tablecolumn.setresizable (FALSE);
        Tablecolumn.setwidth (250);
        TableColumn = Viewercolum2.getcolumn ();
        Tablecolumn.setresizable (FALSE);
        Tablecolumn.setwidth (250); TableColumn = Viewercolum3.getcoLumn ();
        Tablecolumn.setresizable (FALSE);

    Tablecolumn.setwidth (250);


The first RCP is written here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.