A "Rich" Alternative for System i GUI Development
RCP DtaQ Demo's "preferences" are hard-coded into Me.java. Remember that class from 101? The stuff which varies for each System i -- where the system name or IP address and data queue paths were defined? It would be nice if the user could change that instead of having the programmer modify and compile Me.java. A preference page would look like this:

Lets do it.
The PDE Preference Page extension point wizard
Eclipse PDE provides a wizard to get you stared with preference pages. The PreferencePage template creates a preference page with sample preferences for
- directory
- boolean preference
- choice preference (from a list)
- string preference
The RCP DtaQ preferences will be added to the wizard so as not to break the code. After the new preferences are added go back and remove the samples.
Open PDE, go to the extensions tab and click Add button. At the extension point filter
start to type "org.eclipse.ui.preferencesPage" until you see this extensoin point in the list. Highlight it and choose the template for a sample preference page, and click Next.

Change Page Class Name from "SamplePreferencePage" to "PreferencePage"
Change Page Name from "Sample Preferences" to "RCP DtaQ Demo Preferences"
Press Finish button.
A new package will be added. In my case the package is "info.billblalock.eclispercp.dataqdemo2.preferences". The package contains three source files.
- PreferenceConstants.java
- PreferenceInitialized.java
- PreferencePage.java
PreferenceConstants.java class
This class creates a set of constants which will be used to access the preferences which are stored and edited. Make five copies of
public static final String P_STRING = "stringPreference";
and modify them for these preference constants:
public static final String P_SYSTEM = "systemPreference";
public static final String P_USER_ID = "userIdPreference";
public static final String P_MDLI_DTAQ = "mdliDtaqPreference";
public static final String P_MDLO_DTAQ = "mdloDtaqPreference";
public static final String P_DTAQ_KEY = "dtaqKeyPreference";
You will recognized them from ME.java
PreferenceInitializer.java class
The preferences, once they are set, are restored each time RCP DtaQ Demo starts. This provides the initial values the first time the application is run, before the preferences are initially set by the user. Remember each time you clean the workspace you are starting the application for the first time.
If you put real values in this class, as was done in Me.java, then you don't have to set them before testing. The package is set to run in your test environment out of the box. That sort of defeats the purpose of a preference page, but it is convenient for testing.
If you don't put real values in this class, use either empty string, or dummy values, then the preference page will have a real use. During testing this will be a pain because the developer will have to reset the preferences set each time the workspace is cleared.
I'll use a combination of these two choices, real paths to the IFS for the data queue (more work to key) and dummy values for the system and user. The data queue key will be initialized
by the string to initially use the IP address.
Makes five copies of
store.setDefault(PreferenceConstants.P_STRING,
"Default value");
and change them to
store.setDefault(PreferenceConstants.P_SYSTEM,
"SYSTEM_I");
store.setDefault(PreferenceConstants.P_USER_ID,
"A_USER_ID");
store.setDefault(PreferenceConstants.P_MDLI_DTAQ,
"/QSYS.LIB/BBLALOCKD.LIB/MDLI.DTAQ");
store.setDefault(PreferenceConstants.P_MDLO_DTAQ,
"/QSYS.LIB/BBLALOCKD.LIB/MDLO.DTAQ");
store.setDefault(PreferenceConstants.P_DTAQ_KEY,
"*IP");
Notice how the constants of PreferenceConstants match the ones just added? The value in quotes is the value from your Me.java class. This gives RCP DtaQ Demo starting values for these preferences which the user can later modify.
PreferenceInitializer.java class
Add these calls to StringFieldEditor at the end of createFieldEditors() method. Make five copies of
addField(
new StringFieldEditor(PreferenceConstants.P_STRING,
"A &text preference:", getFieldEditorParent()));
and change them to
addField( new StringFieldEditor(PreferenceConstants.P_SYSTEM,
"System i domain or &IP:", getFieldEditorParent()));
addField( new StringFieldEditor(PreferenceConstants.P_USER_ID,
"System i default user id:", getFieldEditorParent()));
addField( new StringFieldEditor(PreferenceConstants.P_MDLI_DTAQ,
"IFS path to demo model input &data queue:", getFieldEditorParent()));
addField( new StringFieldEditor(PreferenceConstants.P_MDLO_DTAQ,
"IFS path to demo model output data &queue:", getFieldEditorParent()));
The data queue key field editor is a little more complicated, it needs a tool tip to help explain its function. To add the tool tip we have to get to the underlying Text widget. We also
want to make sure it is six characters or less. Instead of using the convenience method to build the StringFieldEditor for the data queue key we will do it ourselves. Use this code:
StringFieldEditor dtaqKeyEditor =
new StringFieldEditor(PreferenceConstants.P_DTAQ_KEY,
"*IP or constant value for data queue key:", getFieldEditorParent());
Text dtaqKeyText = dtaqKeyEditor.getTextControl(this.getFieldEditorParent());
dtaqKeyText.setToolTipText(
"*IP will dynamially build data queue key from IP address, " +
"anything else will be a constant static value for the data queue key.");
dtaqKeyText.setTextLimit(6);
addField(dtaqKeyEditor);
Finally, in the constructor change the description from "A demonstration of a preference page implementation" to something like "System i connection and data queue preference page".
Add "Preferences" action to File Menu
The About and Logon Dialog actions have been added to the File menu already. This is very similar to the About action.
Define the preference action:
private IWorkbenchAction preferenceAction;
Instantiate and then register the preference action in mackActions() method:
preferenceAction = ActionFactory.PREFERENCES.create(window);
register(preferenceAction);
Add it to the File menu, probably before the Exit action:
fileMenu.add(preferenceAction);
Try it now!
Cancel the log on dialog when the application starts. File > Preferences will give you this:

You see the original sample preferences are still there. They were left so as not to break the code as we developed, as a model and so you could see what preference pages have to offer.
Try this test to prove the preferences are saved.
1. Change the sample text preference to something you'll remember.
2. Press OK
3. End RCP DtaQ Demo
4. Restart RCP DtaQ Demo, make sure the work space is not cleared or reinitialized.
5. Cancel the logon dialog and open the preference page.
The sample text preference will be the value which you set it. The wizard and Eclipse automatically stored the preference when you changed it and pressed okay. The startup process automatically restored the preferences.
Now go back and remove the samples provided by the Preference Page Template. Work backward
- PreferencePage.java
- PreferenceInitialize.java
- PreferenceConstancts.java
Replace references to Me.java with the preference store
The preference page is now in RCP DtaQ Demo but it isn't being used. To fix that the references to Me.java which need to be changed are all in ListenForModelOutput.java class.
This is the reference to the default System i and user profile:
// ld.setSystem( Me.getSYSTEM(), false );
ld.setSystem( Activator.getDefault().getPreferenceStore().
getString(PreferenceConstants.P_SYSTEM), false );
// ld.setUserId( Me.getUSER(), false );
ld.setUserId( Activator.getDefault().getPreferenceStore().
getString(PreferenceConstants.P_USER_ID), false );
This is the reference to the IFS data queue path and data queue key string.
// mdloDq = new ModelOutputDataQueue(as400, Me.getMDLO_DTAQ(),
// IpDtaQKey.getDqKey() );
// get the data queue key from the preference store. If the value is *IP
// the use IpDtaQKey class to create one from the IP address, otherwise use the
// value in the preference.
String dqKey = Activator.getDefault().getPreferenceStore().
getString(PreferenceConstants.P_DTAQ_KEY);
if( dqKey.equals("*IP") )
dqKey = IpDtaQKey.getDqKey();
mdloDq = new ModelOutputDataQueue(as400,
Activator.getDefault().getPreferenceStore().
getString(PreferenceConstants.P_MDLO_DTAQ), dqKey );
This change allows the user to either let the system generate a key based on the IP address
or specify a key which will be used every time.
The constructor of the View class shows the key when the program starts. That code needs to get the data queue
key from the preference store and resolve it as necessary. Make this change:
// tableArray.add("The key generated for this client is: " +
// IpDtaQKey.getDqKey());
String dqKey = Activator.getDefault().getPreferenceStore().
getString(PreferenceConstants.P_DTAQ_KEY);
if( dqKey.equals("*IP") )
dqKey = IpDtaQKey.getDqKey() + " (based on IP address)";
tableArray.add("The key generated for this client is: " +
dqKey);
That is four of the five values in the preference page. The IFS path to the model input
data queue will be used later.
RCP DtaQ Demo now has a preference page
The complete source is in the CVS under info.billblalock.eclipsercp.dtaqdemo2.
Posted by Bill Blalock at June 10, 2007 8:30 PM

| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
We welcome your comments and opinions and encourage lively debate on the issues. However, Penton Media reserves the right to delete or move any content that it may determine, in its sole discretion, violates or may violate its Terms of Use or is otherwise unacceptable. For more information, see Penton Media's Terms of Use.