SWTworkbench.com SWT, The Standard Widget Toolkit A simple, productive path to effective cross-platform interfaces
Dec 20, 2015
SWTworkbench.com
SWT, The Standard Widget Toolkit
A simple, productive path to effective cross-platform interfaces
SWTworkbench.com
Objectives
● Cut through the hype and explain what SWT really is
● Describe SWT's advantages and disadvantages
● Explain SWT's technical relationship to Swing
● Provide a taste of coding with SWT● List where to find additional SWT resources
SWTworkbench.com
Assumptions
● You feel comfortable with Java● You have prior experience programming
using Swing, Visual Basic, Delphi, C++ Builder, or a similar visual programming environment
SWTworkbench.com
What is SWT?
● Strict technical● Common usage
SWTworkbench.com
What is SWT?
● Technical description– org.eclipse.swt.*– A portable toolkit providing access to the native
platform's graphical resources
SWTworkbench.com
What is SWT?
● Implementation strategy– A thin layer of Java objects over the native
operating system's “objects”– Minimum abstraction required to be portable
SWTworkbench.com
What is SWT?
● Common Usage:– The GUI toolkit used to create:
● Eclipse plug-ins● Standalone applications based on Eclipse technology● New SWT controls
– This definition includes Eclipse technologies in addition to SWT
SWTworkbench.com
What is SWT (common usage)?
● Related technologies– JFace – Swing-like MVC layer built on top of
SWT plus other helpful user interface classes
SWTworkbench.com
What is SWT (common usage)?
● Related technologies– Java2d – An object-based drawing toolkit built on
top of SWT– GEF – A toolkit built on top of Java2d for
creating GUI builders, HTML editors, UML diagrammers, object-based drawing editors, etc.
SWTworkbench.com
What is SWT (common usage)?
● Related technologies– Sweet – A component layer on top of SWT
similar to Active-X or VCL for the Win32 API● JavaBeans for SWT● http://sweet-swt.sourceforge.net
SWTworkbench.com
What is SWT (common usage)?
● Related technologies– All of the Eclipse framework, when used as an
application framework for custom applications and not as an IDE
SWTworkbench.com
SWT Advantages
● Native Look & Feel – almost for free● Lightweight and simple● “Familiarly” Fast● Open source
SWTworkbench.com
SWT Advantages – Win2k
Used by permission from: http://gallery.livemedia.com.au/
SWTworkbench.com
SWT Advantages – Win2k
SWTworkbench.com
SWT Advantages – WinXP + theme
Used by permission from: http://gallery.livemedia.com.au/
SWTworkbench.com
SWT Advantages – GTK + theme
Used by permission from: http://gallery.livemedia.com.au/
SWTworkbench.com
SWT Advantages – GTK + theme
Used by permission from: http://gallery.livemedia.com.au/
SWTworkbench.com
SWT Advantages – GTK + theme
Used by permission from: http://gallery.livemedia.com.au/
SWTworkbench.com
SWT Advantages – MacOS X
Used by permission from: http://gallery.livemedia.com.au/
SWTworkbench.com
SWT Disadvantages
● Lightweight● Immature compared to Swing● A few fewer platforms supported
SWTworkbench.com
How does SWT relate to Swing?
● Swing's main strengths– Consistent look & feel across all platforms;
attractive themes are available.– Sun-supported
– (What else would you add?)
SWTworkbench.com
How does SWT relate to Swing?
● SWT's main strengths– Native look and feel, because it is native.– Open source support
SWTworkbench.com
How does SWT relate to Swing?
● Swing's main strengths– Consistent look & feel across all platforms;
attractive themes are available.– Sun-supported.
● SWT's main strengths– Native look and feel, because it is native.– Open source support.
These are complementary, not competitive strengths
SWTworkbench.com
Why SWT?
● Web Services shift the emphasis on the client away from the web browser, back toward traditional GUI applications
● SWT strengthens Java's position in this market
● SWT provides features that compliment, rather than replace, Swing
SWTworkbench.com
A Taste of SWT
● Hello, SWTpublic class HelloSWT {
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch())
display.sleep(); } display.dispose();
}}
SWTworkbench.com
A Taste of SWT
● Hello, SWT
SWTworkbench.com
A Taste of SWT
● A simple SWT controlpublic class HelloSWTControl extends Canvas implements PaintListener { public HelloSWTControl(Composite parent, int style) { super(parent, style); addPaintListener(this); }
public void paintControl(PaintEvent e) { e.gc.drawText("Hello, world", 5, 5); }}
SWTworkbench.com
A Taste of SWT
● A closer look at the constructorpublic class HelloSWTControl extends Canvas implements PaintListener { public HelloSWTControl(Composite parent, int style) { super(parent, style); addPaintListener(this); }
public void paintControl(PaintEvent e) { e.gc.drawText("Hello, world", 5, 5); }}
SWTworkbench.com
A Taste of SWT
● SWT constructors have 2 arguments:– The parent control
● SWT controls are added to their parents during construction, not by using an add( ) method
– Style bits● Some things you're used to seeing as properties of an
object show up as style bits on the constructor● This is the way the underlying O/S toolkits actually
work– (SWT just wraps the underlying O/S's objects)
SWTworkbench.com
A Taste of SWT
● Displaying the SWT controlpublic class HelloSWT {
public static void main(String[] args) { Display display = new Display();
Shell shell = new Shell(display); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch())
display.sleep(); } display.dispose();
}}
SWTworkbench.com
A Taste of SWT
● Displaying the SWT controlpublic class HelloSWT {
public static void main(String[] args) { Display display = new Display();
Shell shell = new Shell(display); shell.setLayout(new FillLayout()); new HelloSWTControl(shell, SWT.NULL); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch())
display.sleep(); } display.dispose();
}}
SWTworkbench.com
A Taste of SWT
● Displaying the SWT control
SWTworkbench.com
A Taste of SWT
● Managing graphical resources: a more complex example
SWTworkbench.com
A Taste of SWT
● Managing graphical resourcespublic class Blotter extends Canvas implements PaintListener { public Blotter(Composite parent, int style) { super(parent, style); addPaintListener(this); }
public void paintControl(PaintEvent e) { // Put our drawing code here }}
SWTworkbench.com
A Taste of SWT
● Managing graphical resourcespublic Blotter(Composite parent, int style) { super(parent, style); addPaintListener(this);}
SWTworkbench.com
A Taste of SWT
● Managing graphical resourcespublic Blotter(Composite parent, int style) { super(parent, style); addPaintListener(this);
// Set a default background color display = Display.getCurrent();
Color background = display.getSystemColor( SWT.COLOR_DARK_GREEN);
setBackground(background);}
private Display display;
SWTworkbench.com
A Taste of SWT
● Managing graphical resourcespublic class Blotter extends Canvas implements PaintListener { public Blotter(Composite parent, int style) { super(parent, style); addPaintListener(this); }
public void paintControl(PaintEvent e) { // Put our drawing code here }}
SWTworkbench.com
A Taste of SWT
● Managing graphical resourcespublic void paintControl(PaintEvent e) { // Put our drawing code here}
SWTworkbench.com
A Taste of SWT
● Managing graphical resourcespublic void paintControl(PaintEvent e) { GC gc = e.gc; Color black = display.getSystemColor(SWT.COLOR_BLACK); Color gray = display.getSystemColor(SWT.COLOR_GRAY);
Rectangle bounds = this.getBounds();
gc.setForeground(black); gc.drawLine(0, 0, 0, bounds.height); gc.setForeground(gray); gc.drawLine(1, 0, 1, bounds.height); // ...and so on...}
SWTworkbench.com
A Taste of SWT
● Managing graphical resources– This is all there is to creating this control!– Conclusion:
● If you don't construct a graphical resource, you do not have to dispose it
● You can get away with this an amazing amount of the time
SWTworkbench.com
What is JFace?
● A bunch of convenience classes for building SWT applications
– ApplicationWindow– Dialog– Wizard
● A framework for displaying and editing Java business model objects using SWT
– TableViewer– TreeViewer
SWTworkbench.com
What is JFace?
● A bunch of convenience classes for building SWT applications
– ApplicationWindow– Dialog– Wizard
● A framework for displaying and editing Java business model objects using SWT
– TableViewer– TreeViewer
SWTworkbench.com
A Taste of SWT + JFace
● Hello, JFacepublic class HelloJFace extends ApplicationWindow { public HelloJFace(Shell parentShell) { super(parentShell); setBlockOnOpen(true); }
public static void main(String[] args) { (new HelloJFace(null)).open(); }}
SWTworkbench.com
A Taste of SWT + JFace
● Hello, JFace
SWTworkbench.com
A Taste of SWT + JFace
● Ways to add features to your JFace application:
– Add code to constructor– Override protected methods– Add new methods or classes
SWTworkbench.com
A Taste of SWT + JFace
● Add menu bar, tool bar, status linepublic class HelloJFace extends ApplicationWindow { public HelloJFace(Shell parentShell) { super(parentShell); setBlockOnOpen(true); }
public static void main(String[] args) { (new HelloJFace(null)).open(); }}
SWTworkbench.com
A Taste of SWT + JFace
● Add menu bar, tool bar, status linepublic class HelloJFace extends ApplicationWindow { public HelloJFace(Shell parentShell) { super(parentShell); setBlockOnOpen(true);
addMenuBar(); addToolBar(SWT.FLAT); addStatusLine(); }
public static void main(String[] args) { (new HelloJFace(null)).open(); }}
SWTworkbench.com
A Taste of SWT + JFace
● Add application title and iconprotected void configureShell(Shell shell) { super.configureShell(shell);
shell.setText("Hello, JFace");
shell.setImage( ImageDescriptor.createFromFile( HelloJFace.class, "icons/app.png").createImage());}
SWTworkbench.com
A Taste of SWT + JFace
● Add menu to menu barprotected MenuManager createMenuManager() { MenuManager menuManager = new MenuManager(); menuManager.add(createFileMenu()); return menuManager;}private MenuManager createFileMenu() { MenuManager menu = new MenuManager("&File"); menu.add(new Action() { public String getText() { return "E&xit"; } public void run() { getShell().close(); } }); return menu;}
SWTworkbench.com
A Taste of SWT + JFace
● Add button to tool barprotected ToolBarManager createToolBarManager( int style) { ToolBarManager toolBar = new ToolBarManager(style);
toolBar.add(new NewAction()); return toolBar;}
SWTworkbench.com
A Taste of SWT + JFace
● Add private class NewAction for buttonprivate class NewAction extends Action { public String getText() { return "New"; } public String getToolTipText() { return "New"; } public ImageDescriptor getImageDescriptor() { ImageDescriptor imageDesc = ImageDescriptor.createFromFile( HelloJFace.class, "icons/new.png"); return imageDesc; } public ImageDescriptor getHoverImageDescriptor() { ImageDescriptor imageDesc = ImageDescriptor.createFromFile( HelloJFace.class, "icons/new-h.png"); return imageDesc; } public void run() { // add action code here }}
SWTworkbench.com
A Taste of SWT + JFace
● Add a blotter to the client areaprotected Control createContents(Composite parent) { Composite contents = new Blotter(parent, SWT.NULL);
return contents;}
SWTworkbench.com
A Taste of SWT + JFace
● Here's how it looks now...
SWTworkbench.com
A Taste of JFace Viewers
● Suppose we really want to build a “To-do” list...
SWTworkbench.com
What is JFace?
● A bunch of convenience classes for building SWT applications
– ApplicationWindow– Dialog– Wizard
● A framework for displaying and editing Java business model objects using SWT
– TableViewer– TreeViewer
SWTworkbench.com
A Taste of JFace Viewers
● Steps to add to-do list editor to application– Create TodoList “model” objects– Add TableViewer object to layout– Initialize TableViewer– Set TodoList object as the TableViewer's input– Write (or reuse existing classes) to specify the
following TableViewer event handler objects● ContentProvider, LabelProvider● CellEditor, CellModifier● RowSorter
SWTworkbench.com
A Taste of JFace Viewers
● JFace TableViewer usage
TableViewerTodoList
TreeMap
Todo
“input”
SWTworkbench.com
A Taste of JFace Viewers
● JFace TableViewer usage
TableViewerTodoList
TreeMap
Todo
“input”
ContentProvider
LabelProvider
RowSorter
CellEditor
CellModifier
SWTworkbench.com
● Steps to add to-do list editor to application– Create TodoList “model” objects– Add TableViewer object to layout– Initialize TableViewer– Set TodoList object as the TableViewer's input– Write (or reuse existing classes) to specify the
following TableViewer event handler objects● ContentProvider, LabelProvider● CellEditor, CellModifier● RowSorter
A Taste of JFace Viewers
SWTworkbench.com
A Taste of JFace Viewers
● Create TodoList “model” objectpublic class TodoList implements Serializable {
// The Model's entry-point is here... public static TodoList theList = null;
public TodoList() { theList = this; }
// <continued/>...
SWTworkbench.com
A Taste of JFace Viewers
● Create TodoList “model” object (continued) public Object[] toArray() { Object[] results = new Object[todoList.size()]; int i = 0; Iterator iter = todoList.keySet().iterator(); while (iter.hasNext()) { results[i] = todoList.get(iter.next()); ++i; } return results; }
}
SWTworkbench.com
A Taste of JFace Viewers
● Steps to add to-do list editor to application– Create TodoList “model” object– Add TableViewer object to layout– Initialize TableViewer– Set TodoList object as the TableViewer's input– Write (or reuse existing classes) to specify the
following TableViewer event handler objects● ContentProvider, LabelProvider● CellEditor, CellModifier● RowSorter
SWTworkbench.com
A Taste of JFace Viewers
● Add TableViewer object to layoutprotected Control createContents(Composite parent) { Composite contents = new Blotter(parent, SWT.NULL);
return contents;}
SWTworkbench.com
A Taste of JFace Viewers
● Add TableViewer object to layoutprotected Control createContents(Composite parent) { Composite contents = new Blotter(parent, SWT.NULL); GridLayout layout = new GridLayout(1, false); layout.marginHeight = 20; layout.marginWidth = 20; contents.setLayout(layout);
table = new TableViewer(contents, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); table.setLayoutData( new GridData(GridData.FILL_BOTH)); return contents;}
SWTworkbench.com
A Taste of JFace Viewers
● Steps to add to-do list editor to application– Create TodoList “model” object– Add TableViewer object to layout– Initialize TableViewer– Set TodoList object as the TableViewer's input– Write (or reuse existing classes) to specify the
following TableViewer event handler objects● ContentProvider, LabelProvider● CellEditor, CellModifier● RowSorter
SWTworkbench.com
A Taste of JFace Viewers
● Initialize TableViewer...protected Control createContents(Composite parent) { Composite contents = new Blotter(parent, SWT.NULL); GridLayout layout = new GridLayout(1, false); layout.marginHeight = 20; layout.marginWidth = 20; contents.setLayout(layout);
table = new TableViewer(contents, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); table.setLayoutData( new GridData(GridData.FILL_BOTH)); return contents;}
SWTworkbench.com
A Taste of JFace Viewers
● Initialize TableViewer...protected Control createContents(Composite parent) { Composite contents = new Blotter(parent, SWT.NULL); GridLayout layout = new GridLayout(1, false); layout.marginHeight = 20; layout.marginWidth = 20; contents.setLayout(layout);
table = new TableViewer(contents, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); table.setLayoutData( new GridData(GridData.FILL_BOTH)); initTable(); return contents;}
SWTworkbench.com
A Taste of JFace Viewers
● Initialize TableViewer... private void initTable() { addColumns(); addProvidersAndEditors(); }
private static final String[] colNames = { "Done", "Priority", "Description" }; private static final int[] colWeight = { 5, 5, 90 };
private static final int COL_DONE = 0; private static final int COL_PRIORITY = 1; private static final int COL_DESC = 2;
SWTworkbench.com
A Taste of JFace Viewers
● JFace TableViewer usage
TableViewerTodoList
TreeMap
Todo
“input”
ContentProvider
LabelProvider
RowSorter
CellEditor
CellModifier
SWTworkbench.com
A Taste of JFace Viewers
● Implement addProvidersAndEditors()private void addProvidersAndEditors() { table.setContentProvider( new ContentProvider()); table.setLabelProvider(new LabelProvider());
CellEditor[] editors = { new CheckboxCellEditor(table.getTable()), new TextCellEditor(table.getTable()), new TextCellEditor(table.getTable())}; table.setCellEditors(editors);
table.setCellModifier(new CellModifier()); table.setSorter(new RowSorter());
table.setColumnProperties(colNames);}
SWTworkbench.com
A Taste of JFace Viewers
● Steps to add to-do list editor to application– Create TodoList “model” object– Add TableViewer object to layout– Initialize TableViewer– Set TodoList object as the TableViewer's input– Write (or reuse existing classes) to specify the
following TableViewer event handler objects● ContentProvider, LabelProvider● CellEditor, CellModifier● RowSorter
SWTworkbench.com
A Taste of JFace Viewers
● Set TodoList as the TableViewer's input private void initTable() { addColumns(); addProvidersAndEditors(); }
private static final String[] colNames = { "Done", "Priority", "Description" }; private static final int[] colWeight = { 5, 5, 90 };
private static final int COL_DONE = 0; private static final int COL_PRIORITY = 1; private static final int COL_DESC = 2;
SWTworkbench.com
A Taste of JFace Viewers
● Set TodoList as the TableViewer's input private void initTable() { addColumns(); addProvidersAndEditors(); table.setInput(TodoList.theList); }
private static final String[] colNames = { "Done", "Priority", "Description" }; private static final int[] colWeight = { 5, 5, 90 };
private static final int COL_DONE = 0; private static final int COL_PRIORITY = 1; private static final int COL_DESC = 2;
SWTworkbench.com
A Taste of JFace Viewers
● Steps to add to-do list editor to application– Create TodoList “model” object– Add TableViewer object to layout– Initialize TableViewer– Set TodoList object as the TableViewer's input– Write (or reuse existing classes) to specify the
following TableViewer event handler objects● ContentProvider, LabelProvider● CellEditor, CellModifier● RowSorter
SWTworkbench.com
A Taste of JFace Viewers
● Implement addProvidersAndEditors()private void addProvidersAndEditors() { table.setContentProvider( new ContentProvider()); table.setLabelProvider(new LabelProvider());
CellEditor[] editors = { new CheckboxCellEditor(table.getTable()), new TextCellEditor(table.getTable()), new TextCellEditor(table.getTable())}; table.setCellEditors(editors);
table.setCellModifier(new CellModifier()); table.setSorter(new RowSorter());
table.setColumnProperties(colNames);}
SWTworkbench.com
A Taste of JFace Viewers
● JFace TableViewer usage
TableViewerTodoList
TreeMap
Todo
“input”
ContentProvider
LabelProvider
RowSorter
CellEditor
CellModifier
SWTworkbench.com
A Taste of JFace Viewers
● A closer look at JFace “event handler objects”
Event Handler When TriggeredContentProvider On setInput(), refresh(), update()LabelProvider A cell needs redrawingCellEditor Edit cell valueCellModifier Fetch editable value / store valueRowSorter On table redraw
SWTworkbench.com
A Taste of JFace Viewers
● A closer look at JFace “event handler objects”
Event Handler When TriggeredContentProvider On setInput(), refresh(), update()LabelProvider A cell needs redrawingCellEditor Edit cell valueCellModifier Fetch editable value / store valueRowSorter On table redraw
SWTworkbench.com
A Taste of JFace Viewers
● Implementing ContentProviderprivate class ContentProvider implements IStructuredContentProvider { public Object[] getElements( Object inputElement) { return ((TodoList)inputElement).toArray(); }
public void dispose() {} public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}}
SWTworkbench.com
A Taste of JFace Viewers
● JFace TableViewer usage
TableViewerTodoList
TreeMap
Todo
“input”
ContentProvider
LabelProvider
RowSorter
CellEditor
CellModifier
SWTworkbench.com
A Taste of JFace Viewers
● A closer look at JFace “event handler objects”
Event Handler When TriggeredContentProvider On setInput(), refresh(), update()LabelProvider A cell needs redrawingCellEditor Edit cell valueCellModifier Fetch editable value / store valueRowSorter On table redraw
SWTworkbench.com
A Taste of JFace Viewers
● Implementing LabelProviderprivate class LabelProvider implements ITableLabelProvider {
private Image done; private Image notdone; public LabelProvider() { done = ImageDescriptor.createFromFile( TodoListWindow.class, "icons/task-done.png").createImage(); notdone = ImageDescriptor.createFromFile( TodoListWindow.class, "icons/task-open.png").createImage(); }
// <continued/>...
SWTworkbench.com
A Taste of JFace Viewers
● Implementing LabelProvider public Image getColumnImage(Object element, int columnIndex) { if (columnIndex == COL_DONE) { Todo todo = (Todo) element; if (todo.isDone()) { return done; } else { return notdone; } } return null; }
// <continued/>...
SWTworkbench.com
A Taste of JFace Viewers
● Implementing LabelProvider public String getColumnText(Object element, int columnIndex) {
Todo todo = (Todo) element; switch (columnIndex) { case COL_PRIORITY: return Integer.toString( todo.getPriority());
case COL_DESC: return todo.getDesc(); default: return ""; } } // <continued/>...
SWTworkbench.com
A Taste of JFace Viewers
● Implementing LabelProvider public boolean isLabelProperty( Object element, String property) { return true; }
public void dispose() { done.dispose(); notdone.dispose(); }
public void addListener( ILabelProviderListener listener) {}
public void removeListener( ILabelProviderListener listener) {}}
SWTworkbench.com
A Taste of JFace Viewers
● A closer look at JFace “event handler objects”
Event Handler When TriggeredContentProvider On setInput(), refresh(), update()LabelProvider A cell needs redrawingCellEditor Edit cell valueCellModifier Fetch editable value / store valueRowSorter On table redraw
SWTworkbench.com
A Taste of JFace Viewers
● JFace TableViewer usage
TableViewerTodoList
TreeMap
Todo
“input”
ContentProvider
LabelProvider
RowSorter
CellEditor
CellModifier
SWTworkbench.com
A Taste of JFace Viewers
● JFace TableViewer usage
TableViewerTodoList
TreeMap
Todo
“input”
ContentProvider
LabelProvider
RowSorter
CellEditor
CellModifier
The visible editor
SWTworkbench.com
A Taste of JFace Viewers
● JFace TableViewer usage
TableViewerTodoList
TreeMap
Todo
“input”
ContentProvider
LabelProvider
RowSorter
CellEditor
CellModifier
Translates betweenvisible editor's
data type and themodel's storage
data type
SWTworkbench.com
A Taste of JFace Viewers
● Implementing CellModifierprivate class CellModifier implements ICellModifier {
public boolean canModify(Object element, String property) { return true; }
// <continued/>...
SWTworkbench.com
A Taste of JFace Viewers
● Implementing CellModifierpublic Object getValue(Object element, String property) { Todo todo = (Todo) element; if (property.equals(colNames[COL_DONE])) { return new Boolean(todo.isDone()); } else if (property.equals(colNames[COL_PRIORITY])) { return Integer.toString(todo.getPriority()); } else if (property.equals(colNames[COL_DESC])) { return todo.getDesc(); } return null;}// <continued/>...
SWTworkbench.com
A Taste of JFace Viewers
● Implementing CellModifier public void modify(Object element, String property, Object value) { Item item = (Item) element; Todo todo = (Todo) item.getData();
if (property.equals(colNames[COL_DONE])) { boolean val = ((Boolean)value).booleanValue(); todo.setDone(val); } else if (property.equals(colNames[COL_PRIORITY])) { // ...handle the other columns similarly } table.refresh(); }}
SWTworkbench.com
A Taste of JFace Viewers
● A closer look at JFace “event handler objects”
Event Handler When TriggeredContentProvider On setInput(), refresh(), update()LabelProvider A cell needs redrawingCellEditor Edit cell valueCellModifier Fetch editable value / store valueRowSorter On table redraw
SWTworkbench.com
A Taste of JFace Viewers
● Implementing RowSorterprivate class RowSorter extends ViewerSorter {
public int compare(Viewer viewer, Object element1, Object element2) {
Todo t1 = (Todo) element1; Todo t2 = (Todo) element2;
return t1.getPriority() - t2.getPriority(); }}
SWTworkbench.com
A Taste of JFace Viewers
● A closer look at JFace “event handler objects”
Event Handler When RequiredContentProvider AlwaysLabelProvider AlwaysCellEditor If grid is not read-onlyCellModifier If grid is not read-onlyRowSorter If grid is sorted
SWTworkbench.com
A Taste of JFace Viewers
● So here's what we just built...
SWTworkbench.com
SWT GUI Builders
● Shortens the learning curve by handling layout tasks for you
● Easier to quickly prototype an interface● Several commercial SWT GUI builders are
under development
SWTworkbench.com
SWT GUI Builders (under development)
● V4All– Ramen Assisi
● Scott Stanchfield's unnamed GUI builder● SWTworkbench
– Advanced Systems Concepts
SWTworkbench.com
Summary
● SWT provides a fast, native user interface for rich client Java applications.
● SWT has taken two meanings depending on if a formal or informal context is being used:
– Formal: SWT = Java-wrapped O/S widgets.– Informal: SWT+JFace all the way up to the entire
Eclipse application framework.● SWT and Swing have complementary (not
competitive) strengths and weaknesses.
SWTworkbench.com
Source Code Availability
● Complete source code is available at– http://www.swtworkbench.com/wsee_2003.zip
SWTworkbench.com
SWT, the Standard Widget Toolkit
Any questions?
SWTworkbench.com
SWT Development Resources
● SWT Home Page– http://dev.eclipse.org/viewcvs/index.cgi/
%7Echeckout%7E/platform-swt-home/main.html● SWT articles at Eclipse.org
– http://www.eclipse.org/articles/index.html● SWT/JFace page on the Eclipse Wiki
– http://eclipsewiki.swiki.net/2● See especially the “Hello, world” examples provided
here.
SWTworkbench.com
SWT Development Resources (cont.)
● SWT Development Resources / Examples– http://dev.eclipse.org/viewcvs/index.cgi/
%7Echeckout%7E/platform-swt-home/dev.html● Especially note the code snippets starting about
halfway down the page.
● SWT FAQ– http://dev.eclipse.org/viewcvs/index.cgi/
%7Echeckout%7E/platform-swt-home/faq.html
SWTworkbench.com
SWT GUI Builder Resources
● GUI builder page on the Eclipse Wiki– http://eclipsewiki.swiki.net/145
● Sweet Project Home Page– http://sweet-swt.sourceforge.net
● Sweet is an open source, cross-vendor effort to provide SWT metadata to all SWT GUI builders. Basically, it's BeanInfo for SWT.
SWTworkbench.com
Relevant Eclipse Resources
● Eclipse.org newsgroups, archives, IRC– http://www.eclipse.org/newsgroups/index.html– http://www.eclipse.org/search/search.cgi– irc://irc.freenode.net/#eclipse
● Eclipse Wiki– http://eclipsewiki.swiki.net/1
● Eclipse plug-in registry– http://eclipse-plugins.2y.net/
SWTworkbench.com
SWTworkbench.com
SWTworkbench.com