Skip to content

Misc JFaceSnippets

Simeon Andreev edited this page Feb 23, 2023 · 1 revision

JFace-Snippets are small and easy understandable programming examples of how to use the JFace API. To browse the examples, navigate to the examples GIT repository.

  • Copy Paste The header section of each snippet is a link to the plain source. You can copy the source and paste it directly on the source folder or package in an eclipse project. The package and the class will be created automatically. * Click here for a visual explanation.

TOC

Dialogs

Demonstrates usage of Icons in Buttons of Dialogs

Image:Snippet012DialogWithImageButtons.png

Drop these icons also in the same package

Image:filesave.png Image:cancel.png

The JFace ColorSelector widget is a convenient composition of button and color selector dialog. The button displays a swatch of the selected color.

Snippet082ColorSelectDialog.gif

Notification

Demonstrates usage of the non-blocking notification API

Snippet081_Shell1.gif

Layout

Demonstrates usage of the GridLayoutFactory to enhance readability

Image:Snippet013_Shell1.png Image:Snippet013_Shell2.png Image:Snippet013_Shell3.png

Demonstrates (dynamic)layout support for TableColumns available as of JFace 3.3

Image:Snippet016.png

Demonstrates (dynamic)layout support for TreeColumns available as of JFace 3.3

Image:Snippet027.png

Viewers

Demonstrates a simply TableViewer with one column. It holds all important classes used for all Table-like JFace-Viewers (LabelProvider,IStructuredContentProvider)

Image:Snippet1.png

Demonstrates a simply TreeViewer with one column. It describes all important classes used for all Tree-like JFace-Viewers (LabelProvider,ITreeContentProvider)

Image:Snippet2.png

Demonstrates tables with more than one column and the usage of ITableLabelProvider

Image:Snippet003.png

Demonstrates how the selection can be hidden when the user clicks in a table-row/column which doesn't hold any information. The standard behavior of SWT-Table is to leave the selection on the last column. This snippet removes the selection if the user clicks in an area not selectable

Image:Snippet004.png

Demonstrates how to create a different context menu depending on which item in the tree is currently selected this can also be used with a table of course

Image:Snippet005.png

Demonstrates first use case for the OwnerDraw-Support added to JFace in 3.3 (available at SWT-Level since 3.2). This example uses the Viewers API in this special case the OwnerDrawLabelProvider to make items with more than one line of text.

Image:Snippet006.png

Demonstrates how you can use inline editing in tables with multiple columns that require to use SWT.FULL_SELECTION but hiding the selection from the user.

Image:Snippet007.png

Demonstrates how you can scroll a TableViewer to the specific model element using TableViewer#reveal(Object)

Image:Snippet008.png

Demonstrates minimal example when trying to add inline editing to tables to get familiar with the various classes needed (3.2 API)

Image:Snippet009.png

Demonstrates usage of the OwnerDraw-Support feature provided by JFace in 3.3(available in SWT since 3.2). This example uses the Viewers API in this special case the OwnerDrawLabelProvider.

Image:Snippet010.png

Demonstrates usage of custom tooltip support in 3.3 used to provide a tooltip for each cell in TableViewer

Image:Snippet011.png

Demonstrates usage of none mandatory LabelProviders in TableViewers to set colors and fonts with 3.2-API

file:jfacesnippet013.png

Demonstrates usage of none mandatory LabelProviders in TreeViewers to set colors and font with 3.2-API

Image:Snippet014TreeViewerNoMandatoryLabelProvider.png

Demonstrates usage of custom tooltip support used to provide a tooltip for each cell in a TreeViewer

Image:Snippet015CustomTooltipsForTree.png

Demonstrates hiding and showing columns (animated)

Image:Snippet017TableViewerHideShowColumns.png

Demonstrates adding/removing of columns in conjunction with the inline editing with JFace-API

Image:Snippet019TableViewerAddRemoveColumnsWithEditing.png

Demonstrates the base classes of 3.3 API

Image:Snippet024TableViewerExploreNewAPI.png

Demonstrates how one can use the 3.3 API to add tab-editing support to your viewer

Image:Snippet025TabEditing.png

Press Tab to jump from cell to cell

Demonstrates all fancy things one can do with the 3.3 API (Tab-Editing, Keyboard-Navigation from Cell to Cell, Editor-Activation with the Keyboard)

Image:Snippet026TreeViewerTabEditing.gif

Demonstrates usage of the ComboBoxCellEditor in JFace-Viewers

Image:Snippet027ComboBoxCellEditors.png

Demonstrates usage of JFace-Viewers in "virtual" mode with an ordinary content provider (often the bottleneck is not the model but the UI). Using these Virtual viewers in conjunction with an ordinary content provider has the advantage that Sorting and Filtering are supported in 3.3.

Demonstrates usage of JFace-Viewer virtual mode with a lazy content provider

Demonstrates creation of tooltips for cells for pre 3.3 users

Image:Snippet031TableViewerCustomTooltipsMultiSelection.png

Demonstrates different CellEditor-Types in one COLUMN of JFace-Viewers

Image:Snippet034CellEditorPerRow.png

Demonstrates keyboard navigation in TableViewers using a TableCursor showing the flexibility of the cell navigation support

You also need these classes:

Image:Snippet035TableCursorCellHighlighter.png

Demonstrates keyboard navigation by highlighting the currently selected cell with a focus border showing once more the flexibility of the cell navigation support

You also need:

Image:Snippet036FocusBorderCellHighlighter.png

Demonstrates customizability of the 3.3 JFace-Support for cell tooltips using the Browser-Widget and presenting HTML

Image:Snippet037FancyCustomTooltips.png

Demonstrates a very simple usage of ListViewer

Image:Snippet039ListViewer.png

Demonstrates sorting (ascending/descending) in TableViewers by clicking the column header.

Image:Snippet040TableViewerSorting.png

Demonstrates how to achieve alternating row-colors with TableViewer. It can also be used in conjunction with virtual-bits to even work with big tables (e.g. 100,000 rows in this example). In addition, this snippet provided a button that will demonstrate the usage of viewer filters.

Image:Snippet041TableViewerAlternatingColors.jpg

Demonstrates the JFace 3.3 keyboard editing support for Trees without columns. Tabbing from editor to editor is supported since 3.4. In addition, this snippet provided a button that shows how to enter in edit mode programmatically.

Image:Snippet043TreeViewerKeyboardEditing.png

Demonstrates the JFace 3.3 keyboard editing support for Tables without columns. Tabbing from editor to editor is supported since 3.4.

You also need:

Demonstrates how a TableViewer with a sorter can be filled from a NON-UI thread

Image:Snippet045TableViewerFillFromBackgroundThread.gif

Demonstrates how to update a viewer from a long-running task (which is executed in a thread) and calls back to the UI-Thread using "asyncExec".

Image:Snippet046UpdateViewerFromBackgroundThread.gif

Demonstrates the usage of ILazyContentProvider in conjunction with a Virtual-TreeViewer. The snippet shows how using a lazy tree can minimize the memory footprint and maximize the speed when viewing large models.

Image:Snippet047VirtualLazyTreeViewer.png

Demonstrates how to overcome a limitation when it comes to key-navigation and CheckBoxEditors in 3.3.1.

This is a workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=198502

Image:Snippet048TreeViewerTabWithCheckboxFor3_3.png

Demonstrates a LabelProvider-Type which uses StyleRanges. This Snippet requires SWT/JFace 3.4.

Image:Snippet049StyledCellLabelProvider.gif

Demonstrates how you can add styled text by wrapping an existing label provider. This Snippet requires SWT/JFace 3.4.

Image:Snippet050DelegatingStyledCellLabelProvider.jpg

Demonstrate how to center an image and create graphics in a cell using a technique called "owner draw".

Image:Snippet051TableCenteredImage.png

Demonstrate how to start cell-editors on double click.

Image:Snippet052DoubleClickCellEditor.png

Demonstrate how to start up a cell editor with a context menu and not with mouse clicking on the cell.

Image:Snippet053StartEditorWithContextMenu.png

Demonstrate hiding and showing columns and starting a cell editor programmatically.

Image:Snippet055HideShowColumn.png

Demonstrate a custom cell-editor which uses a real Checkbox-Button

You also need these classes:

Image:Snippet056BooleanCellEditor.png

Example of showing how easy cell-navigation with hidden cells is. Use the cursor keys to navigate between cells. Then use the context menu to hide a column.

Image:Snippet057TableViewerSkipHiddenCells.png

Shows how to automatically reveal cells when navigating. Run the snippet and then edit the first cell by double-clicking. Pressing the tab key will advance to the next cell in edit mode and reveal the cell if it is not in the viewport.

Image:Snippet058CellNavigationIn34.gif

Show how to use content-proposal inside a CellEditor

Image:Snippet060TextCellEditorWithContentProposal.png

Full-featured native-looking viewer with checkboxes in an arbitrary column

You also need these classes:

Image:Snippet061FakedNativeCellEditor.png

Demonstrates usage of TextAndDialogCellEditor. The email column uses the TextAndDialogCellEditor; othe columns use ordinary TextCellEditor.

You also need these classes:

Image:Snippet062TextAndDialogCellEditor.png

Show how to use ComboViewer and set an initial selection

Image:Snippet063ComboViewer.png

A TreeViewer with observable collections as input, to demonstrate, how elements are replaced, especially what happens to selected items on replacement

Image:Snippet064TreeViewerReplacingElements.png

A TreeViewer with observable collections as input, to demonstrate, how elements are replaced, especially what happens to selected items on replacement

Image:Snippet065TableViewerReplacingElements.png

A TableViewer that shows how to add a status icon to a Label with IStyledLabelProvider and DecorationOverlayIcon

Image:Snippet066TableViewerWithLabelDecorator.png

Window

Demonstrates usage of JFace 3.3 to show really cool ToolTips for your controls

For full fun you also need:

Image:Snippet020CustomizedControlTooltips.png

Demonstrates creation of ToolTips for Tables without using the JFace-Viewers API but only JFace-Tooltips

Image:Snippet031TableStaticTooltip.png

Wizard

Demonstrates how to work with JFace-Wizards and fill a TableViewer from a Background-Thread without blocking the UI showing a progress bar in the meanwhile

Image:Snippet047.gif

Demonstrates a wizard with internal progress.

Image:Snippet071WizardWithProgressAndCancel.gif

https://raw.githubusercontent.com/eclipse-platform/eclipse.platform.ui/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/FocusBorderCellHighlighter.java Demonstrates a wizard with internal progress using SubMonitor and subtasks.

Image:Snippet072WizardWithProgressSubtasksAndCancel.png

Demonstrates a wizard that enables access to the calling shell...

Image:Snippet074ModelesWizard.gif

Category:Snippets Category:RCP Category:Platform_UI

Clone this wiki locally