GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing wiki.eclipse.org — Nebula PreferenceWindow - Eclipsepedia
Jump to: navigation,
search
Nebula PreferenceWindowIntroductionA widget that displays a window to set up preferences. Why did I create this widget whereas the PreferenceDialog exists in JFace ? Well, first of all the look is different. Then I think that even if my widget is less flexible, it is easier to configure and covers 95% of all cases. Finally, I had a lot of fun creating this widget :) Contents
UsageMethodologyFill dataThe first thing to do is to fill a
final Map<String, Object> data = new HashMap<String, Object>();
data.put("text", "A string");
data.put("int", new Integer(42));
data.put("float", new Float(3.14));
data.put("url", "http://www.google.fr/");
data.put("password", "password");
data.put("directory", "");
data.put("file", "");
data.put("textarea", "long long\nlong long\nlong long\ntext...");
data.put("comboReadOnly", "Value 1");
data.put("combo", "Other Value");
Create the windowInstanciating the window is done with the static method final PreferenceWindow window = PreferenceWindow.create(shell, data); Add the tabsOnce the window is created, simply call the method final PWTab documentTab = window.addTab(new Image(Display.getCurrent(), PreferenceWindowSnippet.class.getClassLoader().getResourceAsStream("org/mihalis/opal/preferenceWindow/images/document.png]]")), "Document");
Fill your tab with widgetsOnce the tab is created, you can add widgets, row or group :
documentTab.add(new PWPasswordText("Password :", "password"));
documentTab.add(new PWDirectoryChooser("Directory :", "directory"));
documentTab.add(new PWFileChooser("File :", "file"));
documentTab.add(new PWTextarea("Textarea :", "textarea"));
will display 4 widgets one below the others. The documentTab.add(new PWLabel("Let's start with Text, Separator, Combo and button")).//
add(new PWStringText("String :", "text").setAlignment(GridData.FILL)).//
add(new PWIntegerText("Integer :", "int"));
terminalTab.add(new PWRow().//
add(new PWButton("First button", new SelectionAdapter() {
})).//
add(new PWButton("Second button", new SelectionAdapter() {
})).//
add(new PWButton("Third button", new SelectionAdapter() {
})));
final PWGroup group = new PWGroup(false);
group.add(new PWRow().add(new PWCheckbox("First choice", "cb4")).add(new PWCheckbox("Second choice", "cb5")));
group.add(new PWRow().add(new PWCheckbox("Third choice", "cb6")).add(new PWCheckbox("Fourth choice", "cb7")));
group.add(new PWRow().add(new PWCheckbox("Fifth choice", "cb8")).add(new PWCheckbox("Sixth choice", "cb9")));
group.add(new PWRow().add(new PWCheckbox("Seventh choice", "cb10")).add(new PWCheckbox("Eighth choice", "cb11")));
printerTab.add(group);
Open the window and retrieve dataOnce the window is built, simply use the method Available widgetsMost of the widget are binded to a key. The key correspond to a key in the map used to configure the PreferenceWindow. PWLabelAccepted data type : None Constructor : This widgdet is a label. The text can contains some pseudo-HTML tags for formatting :
PWSeparatorAccepted data type : 'None Constructors :
PWGroupAccepted data type : None Constructors :
PWStringTextAccepted data type : String Constructor : This widget is a text box. The user can type anything, there is no validation rule. PWIntegerTextAccepted data type : Integer Constructor : This widget is a text box. The user can type only integers. PWFloatTextAccepted data type : Float Constructor : This widget is a text box. The user can type only floats. PWURLTextAccepted data type : String Constructor : This widget is a text box. The user can type only URL. If a typed URL is not typed correctly, an error message is displayed. PWPasswordTextAccepted data type : String Constructor : This widget is a text box. The user can type passwords. PWTextareaAccepted data type : String Constructor : This widget is a text box for long texts (more than one line, for example a description). PWDirectoryChooserAccepted data type : String Constructor : This widget can be use to select a directory. Once the user clicks on the "Choose..." button, a pop-up directory selector is displayed. PWFileChooserAccepted data type : String Constructor : This widget can be use to select a file. Once the user clicks on the "Choose..." button, a pop-up file selector is displayed. PWFontChooserAccepted data type : FontData Constructor : This widget can be use to select a font. Once the user clicks on the "Choose..." button, a pop-up font selector is displayed. PWColorChooserAccepted data type : Color Constructor : This widget can be use to select a color. Once the user clicks on the button, a pop-up color selector is displayed. PWButtonAccepted data type : None Constructor : This widget is a button, not associated to a value. You must specify an instance of SelectionListener to execute the code when the button is pressed. PWSpinnerAccepted data type : Integer Constructor : This widget is a spinner. The value entered by the user should be between min and max. PWScaleAccepted data type : Integer Constructor : This widget is a slider. The value entered by the user should be between min and max. PWCheckboxAccepted data type : Boolean Constructor : This widget is a chekbox. PWComboAccepted data type : String if the combo box is editable, any object otherwise Constructors :
If the widget is not editable, you can initialize the combo with a list of objects. The value displayed in the combo box is the String representation of the Object ( PWRadioAccepted data type : Any object Constructor : This widget is a list of radio buttons : the user has to pick one value in a list. Otherwise, the user can choose one given value or type any value. The value displayed for each button is the String representation of the Object ( Additional methods for widgetsYou can set up some extra parameters for each widget with the following setters :
printerTab.add(new PWRow().//
add(new PWCheckbox("Automatically check for new versions", "cb12").setWidth(300)).//
add(new PWButton("Check for updates...", new SelectionAdapter() {
}). //
setWidth(250).setAlignment(GridData.END)));
Enable/disable a widget, a row or a groupYou can decide to enable or disable a widget regarding the value of another widget. Because a widget is binded to a property, you have to establish a link beetwen the key (that stores a value) and the widget. This link is done by an object called an Enabler. 3 enablers are provided by the library :
You can set an enabler to a widget, a row or a group. If a row has an enabler and a widget in this row has another enabler, the widget is enabled only if both conditions are true. Example : systemTab.add(new PWGroup("Open Mode").setEnabler(new EnabledIfTrue("show")).//
add(new PWRadio(null, "openMode", "Double click", "Single click")).//
add(new PWCheckbox("Select on hover", "selectonhover").setIndent(10).setWidth(200).setEnabler(new EnabledIfEquals("openMode", "Single click"))).//
add(new PWCheckbox("Open when using arrow keys", "openarrow").setIndent(10).setWidth(200).setEnabler(new EnabledIfEquals("openMode", "Single click"))));
By default, the preference window will show that : When the user clicks on the "Show information button", the group "Open mode" is activated : And when the users clicks on the radio button "Single Click", the 2 checkboxes are enabled : ExampleA snippet called PreferenceWindowSnippet is available in the plugin org.eclipse.nebula.widgets.opal.preferencewindow.snippets. This example is also available here : PreferenceWindowSnippet.java This page was last modified 07:20, 19 March 2020 by Eclipsepedia anonymous user Unnamed Poltroon. |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |