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);
Jface
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.
CHECK);
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 ());
Break
Case 2:item.settext (col, Objs.get (Row). Getage ());
}}} table.pack (); Tableviewer tableviewer = new Tableviewer (Shell, SWT. CHECK | Swt.
Full_selection);
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.
CENTER);
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.
NONE);
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.