TT 12 Preference Pages in Java

Encoder Data Matrix in Java TT 12 Preference Pages
TT 12 Preference Pages
Data Matrix Generation In Java
Using Barcode printer for Java Control to generate, create ECC200 image in Java applications.
erences If the data you wish to present is more structured and complex, then you may need to build your preference page without field editors, subclassing PreferencePage rather than FieldEditorPreferencePage If you need to interact with a field editor directly or create a new type of field editor, then here are some of the field editor methods you might need to know:
Drawing Bar Code In Java
Using Barcode generator for Java Control to generate, create bar code image in Java applications.
adjustForNumColumns(int)
Recognize Barcode In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
- Adjusts the horizontal span of this
Data Matrix 2d Barcode Encoder In C#
Using Barcode encoder for .NET Control to generate, create Data Matrix image in VS .NET applications.
field editor's basic controls
Paint Data Matrix In VS .NET
Using Barcode maker for ASP.NET Control to generate, create DataMatrix image in ASP.NET applications.
dispose()
Data Matrix Generation In .NET Framework
Using Barcode creation for VS .NET Control to generate, create Data Matrix image in Visual Studio .NET applications.
- Cleans up any native resources allocated by this
ECC200 Creator In Visual Basic .NET
Using Barcode creation for VS .NET Control to generate, create Data Matrix 2d barcode image in .NET applications.
editor
EAN128 Encoder In Java
Using Barcode encoder for Java Control to generate, create EAN 128 image in Java applications.
doFillIntoGrid(Composite, int)
Code 128B Maker In Java
Using Barcode drawer for Java Control to generate, create Code-128 image in Java applications.
- Creates the controls compris-
Generate EAN13 In Java
Using Barcode generator for Java Control to generate, create EAN-13 Supplement 5 image in Java applications.
ing this editor
Code 3 Of 9 Maker In Java
Using Barcode creator for Java Control to generate, create Code 39 Full ASCII image in Java applications.
doLoad()
Painting Barcode In Java
Using Barcode drawer for Java Control to generate, create barcode image in Java applications.
- Initialize the editor content with the current value
Monarch Drawer In Java
Using Barcode generation for Java Control to generate, create 2 of 7 Code image in Java applications.
from the preference store
Code 39 Extended Drawer In .NET Framework
Using Barcode encoder for ASP.NET Control to generate, create Code 39 Full ASCII image in ASP.NET applications.
doLoadDefault()
EAN / UCC - 13 Drawer In Visual Studio .NET
Using Barcode generation for Visual Studio .NET Control to generate, create EAN 128 image in Visual Studio .NET applications.
- Initialize the editor content with the default
Decode Code128 In .NET Framework
Using Barcode recognizer for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
value
Generate Bar Code In Visual Studio .NET
Using Barcode encoder for ASP.NET Control to generate, create barcode image in ASP.NET applications.
doStore()
Data Matrix 2d Barcode Generator In .NET Framework
Using Barcode printer for .NET framework Control to generate, create Data Matrix ECC200 image in Visual Studio .NET applications.
- Save the current editor value into the preference
Encoding Code 128A In Visual Studio .NET
Using Barcode generation for Visual Studio .NET Control to generate, create Code 128 Code Set C image in Visual Studio .NET applications.
store
Printing UCC-128 In .NET
Using Barcode generation for ASP.NET Control to generate, create UCC.EAN - 128 image in ASP.NET applications.
Preference page APIs
fireStateChanged(String, boolean, boolean)
- Informs this field
editor's listener, if it has one, about a change to a booleanvalued properties Does nothing if the old and new values are the same
fireValueChanged(String, Object, Object)
- Informs this field
editor's listener, if it has one, about a change to a property
getLabelControl()
- Returns the label that is part of this editor
or null if none
getLabelControl(Composite)
- Returns the label that is part of
this editor Creates the label if label text has been specified either in the constructor or the setLabelText( ) method
getLabelText()
- Returns the label text specified either in the
constructor or the setLabelText( ) method
getNumberOfControls()
- Returns the number of controls com-
prising this editor This value is passed to the doFillIntoGrid(Composite, int) method
TT 12 Preference Pages
getPreferenceName()
- Returns the name/key of the preference
displayed by this editor
getPreferenceStore()
- Returns the preference store containing
the preference being edited
isValid()
- Returns whether the editor's contents are valid
Subclasses should override this method along with the
presentsDefaultValue()
method
load()
- Loads the current value from the preference store into
the editor Subclasses should override the doLoad() method rather than this method
loadDefault()
- Loads the default value into the editor Sub-
classes should override the doLoadDefault() method rather than this method
presentsDefaultValue()
- Returns whether this editor is cur-
rently displaying the default value
refreshValidState()
- Determines if this editor's content is in a
valid state Subclasses should override this method to per-
Preference page APIs
form the validation and the isValid() method to return the state
setFocus()
- Sets focus to this editor Subclasses may override
to set focus to a particular control within the editor
setLabelText(String)
- Sets the text to appear in the label asso-
ciated with this editor
setPreferenceName(String)
- Sets the name of the preference
being displayed by this editor
setPreferenceStore(IPreferenceStore)
- Sets the preference
store in which this editor's value is saved
setPresentsDefaultValue(boolean)
- Sets whether or not this
editor is displaying the default value
setPropertyChangeListener(IPropertyChangeListener)
- Sets the
property change listener that should be notified via the
fireStateChanged( )
or fireValueChanged( ) methods when
the editor's content has changed
showErrorMessage(String)
- Convenience method for displaying
TT 12 Preference Pages
an error message at the top of the preference page
showMessage(String)
- Convenience method for displaying a
message at the top of the preference page
store()
- Saves the editor's current value into the preference
store Subclasses should override doStore() rather than this method
PreferencePage assumes that all of the preferences on the page
FieldEditorPreferencePage
are field editors and handles much of the work involved in loading, validating, and saving field editor content For more complex preference pages, you can use PreferencePage instead, which is the superclass of FieldEditorPreferencePage
The downside is that you must do more of the work yourself
createContents(Composite)
Create the controls for the prefer-
ence page
doGetPreferenceStore()
- Answer a page specific preference
Preference page APIs
store or null to use the container's preference store Subclasses may override as necessary
getPreferenceStore()
- Answers the preference store for this
preference page
isValid()
- Returns whether the contents of this preference
page is currently in a valid state
performDefaults()
- Load all fields with their default values
performOk()
- Save all field values in the preference store - Used to display an error message at
setErrorMessage(String)
the top of the preference page when a field's value is invalid
setMessage(String, int)
- Used to display a message at the top
of the preference page
setValid(boolean)
- Sets whether the contents of this prefer-
ence page is currently in a valid state
TT 12 Preference Pages
If you use PreferencePage, then you can still use the various types of field editors, but you must do more of the work yourself loading, validating, and saving values The extra work involves adding some method calls when the field editors are constructed, for example:
protected Control createContents(Composite parent) { editor = new BooleanFieldEditor( "boolean", "Boolean", parent); editorsetPreferencePage(this); editorsetPreferenceStore(getPreferenceStore()); editorload(); }
And when the user resets the values to their default:
protected void performDefaults() { editorloadDefault(); superperformDefaults(); }
And when the user decides to save the current preference value:
public boolean performOk() { editorstore(); return true; }
And to perform any additional validation other than that which is enforced by the field
Preference page APIs
Favorites preference page
For the Favorites view, we need one boolean preference for each column, indicating whether or not that column is to be visible in the Favorites view First we create an interface containing preference constants that can be shared by various classes in the Favorites product
public interface IFavoritesPreferences { public static final String FAVORITES_VIEW_NAME_COLUMN_VISIBLE_PREF = "favoritesviewnamecolumnvisible"; public static final String FAVORITES_VIEW_LOCATION_COLUMN_VISIBLE_PREF = "favoritesviewlocationcolumnvisible"; }
The FavoritesPreferencePage is then modified to display these two preferences using boolean preference field editors
public class FavoritesPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage, IFavoritesPreferences { private BooleanFieldEditor namePrefEditor; private BooleanFieldEditor locationPrefEditor; public FavoritesPreferencePage() { super(GRID); setPreferenceStore( FavoritesPlugingetDefault()getPreferenceStore()); setDescription("Favorites view column visibility:"); } public void init(IWorkbench workbench) {
TT 12 Preference Pages
} public void createFieldEditors() { namePrefEditor = new BooleanFieldEditor( FAVORITES_VIEW_NAME_COLUMN_VISIBLE_PREF, "Show name column", getFieldEditorParent()); addField(namePrefEditor); locationPrefEditor = new BooleanFieldEditor( FAVORITES_VIEW_LOCATION_COLUMN_VISIBLE_PREF, "Show location column", getFieldEditorParent()); addField(locationPrefEditor); } }
Now, when the Favorites preference page is displayed, it shows our two column visibility preferences (see Figure 12-5)
Preference page APIs
Figure 12-5 Favorites preference page with column visibility
Validation
Our preference page looks good (see Figure 12-5), but there are two problems First, the visibility for the name and location columns should default to true; that problem is addressed in Sections 1233 and 1234 Second, we want at least one column visible at all times Field editors enforce local validation of their own contents based upon the type of editor and the parameters specified during creation If we want validation between various editors, then we must enforce it ourselves in the preference page class by overriding the FieldEditorPreferencePage
checkState()
method
protected void checkState() { supercheckState(); if (!isValid()) return; if (!namePrefEditorgetBooleanValue() && !locationPrefEditorgetBooleanValue()) { setErrorMessage( "Must have at least one column visible"); setValid(false); } else { setErrorMessage(null); setValid(true); } }