Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Nebula PropertyTable
Introduction
A widget that allow user to set up properties in a table or a tree table.
Contents
- 1 Introduction
- 2 Usage
- 3 Editors
- 3.1 PTStringEditor
- 3.2 PTIntegerEditor
- 3.3 PTFloatEditor
- 3.4 PTURLEditor
- 3.5 PTPasswordEditor
- 3.6 PTSpinnerEditor
- 3.7 PTFileEditor
- 3.8 PTDirectoryEditor
- 3.9 PTComboEditor
- 3.10 PTCheckboxEditor
- 3.11 PTColorEditor
- 3.12 PTFontEditor
- 3.13 PTDateEditor
- 3.14 PTDimensionEditor
- 3.15 PTRectangleEditor
- 3.16 PTInsetsEditor
- 4 Listeners
- 5 Update
- 6 Discard change
- 7 Example
Usage
The first thing to do is to instantiate the widget :
final PropertyTable table = new PropertyTable(tabFolder, SWT.NONE);
By default, the table shows items in categories, the "sort" and "show description" buttons are displayed, and the description panel is present.
You can customize your widget with the following methods :
final PropertyTable table = new PropertyTable(tabFolder, SWT.NONE); table.showButtons(); table.hideButtons(); table.viewAsCategories(); table.viewAsFlatList(); table.showDescription(); table.hideDescription();
Then you fill your table with PTProperty objects. These objects are composed of the following fields :
- String name: The name of the property
- String displayName: The label that is displayed in the PropertyTable
- String description: The description (if the description panel is shown). You can use the following HTML tags for the presentation : <b>, <i> and <u>.
- Object value: The value
- String category: The category
- boolean enabled: if true (default value), the property can be modified.
- PTEditor editor: An editor (optional, see below)
2 constructors are available :
public PTProperty(final String name, final String displayName, final String description); public PTProperty(final String name, final String displayName, final String description, final Object value):
You can group your properties in the same category. If you choose the view "as category", all properties will appear in a tree under the category. Because all setters return the PTProperty itself, you can chain multiple setters :
table.addProperty(new PTProperty("id", "Identifier", "Description for identifier", "My id")).setCategory("General"); table.addProperty(new PTProperty("text", "Description", "Description for the description field", "blahblah...")).setCategory("General"); table.addProperty(new PTProperty("url", "URL:", "This is a nice URL", "http://www.google.com").setCategory("General")).setEditor(new PTURLEditor()); table.addProperty(new PTProperty("password", "Password", "Enter your password and keep it secret...", "password")).setCategory("General").setEditor(new PTPasswordEditor());
Editors
If no editor is set, the PropertyTable will use by default the PTStringEditor.
PTStringEditor
Accepted data type : All
Constructor : public PTStringEditor()
This editor is used to modify any kind of property. It is represented by a Text widget.
PTIntegerEditor
Accepted data type : Integer
Constructor : public PTIntegerEditor()
This editor is used to modify an Integer. It is represented by a Text widget that accepts only integer values.
PTFloatEditor
Accepted data type : Float
Constructor : public PTFloatEditor()
This editor is used to modify a Float. It is represented by a Text widget that accepts only float values.
PTURLEditor
Accepted data type : String (URL)
Constructor : public PTURLEditor()
This editor is used to modify any kind of property. It is represented by a Text widget.
PTPasswordEditor
Accepted data type : All
Constructor : public PTPasswordEditor()
This editor is used to modify any kind of property. It is represented by a Text widget.
PTSpinnerEditor
Accepted data type : Integer
Constructor : public PTSpinnerEditor(int minimumValue, int maximumValue)
This editor is used to modify an Integer. It is represented by a Spinner widget.
PTFileEditor
Accepted data type : String
Constructor : public PTFileEditor()
This editor is used to modify any kind of property that correspond to a file path. It is represented by a text with 2 buttons. The "X" button erases the value of the property (set it to null). The "..." button opens a new window that allow the user to pick a file.
PTDirectoryEditor
Accepted data type : String
Constructor : public PTDirectoryEditor()
This editor is used to modify any kind of property that correspond to a directory path. It is represented by a text with 2 buttons. The "X" button erases the value of the property (set it to null). The "..." button opens a new window that allow the user to pick a directory.
PTComboEditor
Accepted data type : All
Constructors :
public PTComboEditor(final boolean readOnly, final Object... data) public PTComboEditor(final Object... data)
This editor is used to modify any kind of property. It is represented by a Combo widget. The PropertyTable uses the toString() method of the object to display value, so you can use a Java Bean.
PTCheckboxEditor
Accepted data type : Boolean
Constructor : public PTCheckboxEditor()
This editor is used to modify a boolean property. It is represented by a Checkbox widget.
PTColorEditor
Accepted data type : org.eclipse.swt.graphics.Color
Constructor : public PTColorEditor()
This editor is used to modify A Color. It is represented by a text with 2 buttons. The "X" button erases the value of the property (set it to null). The "..." button opens a new window that allow the user to pick a color.
PTFontEditor
Accepted data type : org.eclipse.swt.graphics.FontData
Constructor : public PTFontEditor()
This editor is used to modify a Font. It is represented by a text with 2 buttons. The "X" button erases the value of the property (set it to null). The "..." button opens a new window that allow the user to pick a Font.
PTDateEditor
Accepted data type : java.util.date
Constructor : public PTDateEditor()
This editor is used to modify a date (no time). It is represented by a DateTime widget.
PTDimensionEditor
Accepted data type : 'java.awt.Dimension'
Constructor : public PTDimensionEditor()
This editor is used to modify a Dimension. It is represented by a text with 2 buttons. The "X" button erases the value of the property (set it to null). The "..." button opens a new window that allow the user to enter the width and the height of a dimension.
PTRectangleEditor
Accepted data type : org.eclipse.swt.graphics.Rectangle
Constructor : public PTRectangleEditor()
This editor is used to modify a Dimension. It is represented by a text with 2 buttons. The "X" button erases the value of the property (set it to null). The "..." button opens a new window that allow the user to enter the x coordinate, the y coordinate, the width and the height of a rectangle.
PTInsetsEditor
Accepted data type : java.awt.Insets
Constructor : public PTInsetsEditor()
This editor is used to modify a Insets object. It is represented by a text with 2 buttons. The "X" button erases the value of the property (set it to null). The "..." button opens a new window that allow the user to enter the top, the left, the bottom and the right part of an insets.
Listeners
You can add a PTPropertyChangeListener that is called when the value of the property has changed. The method is called addChangeListener()
.
When a change is detected, you can access the PTProperty underlying object. One can change the font, the background color or the foreground color of the "display name".
Example:
final Font font = SWTGraphicUtil.buildFontFrom(table, SWT.BOLD, 10); table.addListener(SWT.Dispose, e -> { SWTGraphicUtil.safeDispose(font); }); table.addChangeListener(property -> { System.out.println("Change for " + property.getDisplayName() + ": new value is " + property.getValue()); property.changeFont(font); property.changeForegroundColor(table.getDisplay().getSystemColor(SWT.COLOR_WHITE)); property.changeBackgroundColor(table.getDisplay().getSystemColor(SWT.COLOR_RED)); });
Update
If you wish to update the values, just call the methods setProperties()
or refresh
.
Discard change
You can discard changes by calling the method discardChanges()
: the values will be set to the original values.
Example
3 snippets called PropertyTableSnippet, PropertyTableSnippetRefresh and PropertyTableSnippetChangeListener are available in the plugin org.eclipse.nebula.widgets.opal.propertytable.snippets.
The examples are available here: