[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Hi all,
while looking through the code, I noticed, that the Preference Page is
managed using individual widgets.
Is there a reason for not using FieldEditors?
Regards
Martin
PS: I attached a patch, which introduces the use of FieldEditors for
some Preferences
### Eclipse Workspace Patch 1.0
#P org.eclipse.ve.java.core
Index: core/org/eclipse/ve/internal/java/vce/VCEPreferencePage.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.ve.java.core/core/org/eclipse/ve/internal/java/vce/VCEPreferencePage.java,v
retrieving revision 1.36
diff -u -r1.36 VCEPreferencePage.java
--- core/org/eclipse/ve/internal/java/vce/VCEPreferencePage.java 24 Oct 2005 18:58:19 -0000 1.36
+++ core/org/eclipse/ve/internal/java/vce/VCEPreferencePage.java 19 Sep 2008 18:47:59 -0000
@@ -22,7 +22,7 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.preference.*;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableLayout;
@@ -46,8 +46,6 @@
import org.eclipse.ve.internal.java.core.JavaVEPlugin;
import org.eclipse.ve.internal.java.vce.rules.*;
-import org.eclipse.ve.internal.propertysheet.PropertysheetMessages;
-
public class VCEPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
public static final String USER_ITEM = "USER_ITEM"; //$NON-NLS-1$
@@ -76,13 +74,10 @@
protected Button splitRadioButton;
protected Button notebookRadioButton;
- protected Button generateExpressionComment;
protected Table stylesTable;
protected StackLayout stylesContributorAreaLayout;
protected Composite styleContributorArea;
// protected Button requireIVJforComponents ;
- protected Button generateTryCatchBlock;
- protected Text sourceToVisual;
protected Group sourceSyncGrp;
protected Image fJavaBeansToSourceImage;
@@ -99,6 +94,7 @@
private TableItem currentLookAndFeelItem;
private String fStyleID = null;
+ private java.util.List<FieldEditor> fieldEditors = new ArrayList<FieldEditor>();
protected Label createLabel(Composite group, String aLabelString, Image aLabelImage) {
Label label = new Label(group, SWT.LEFT);
@@ -424,6 +420,14 @@
}
}
+
+ protected void addVCEFieldEditor(FieldEditor editor, Composite targetComponent, int width) {
+ editor.setPreferenceStore(VCEPreferences.getPlugin().getPreferenceStore());
+ editor.fillIntoGrid(targetComponent, width);
+ fieldEditors.add(editor);
+ editor.setPage(this);
+ }
+
protected void createCodeGenerationTab() {
codeGenTab = new TabItem(tabFolder, SWT.NONE);
@@ -435,26 +439,19 @@
Group codeGenGroup_Gen = createGroup(codeGenComposite, VCEMessages.PreferencePage_CodeGen_ParsingGeneration_Style_1, 1);
- generateExpressionComment = createCheckBox(codeGenGroup_Gen, VCEMessages.PreferencePage_NewExpressionCommentPrompt, 0);
- generateTryCatchBlock = createCheckBox(codeGenGroup_Gen, VCEMessages.PreferencePage_GenerateTryCatchBlock, 0);
+ addVCEFieldEditor(new BooleanFieldEditor(VCEPreferences.GENERATE_COMMENT, VCEMessages.PreferencePage_NewExpressionCommentPrompt, SWT.NONE, codeGenGroup_Gen), codeGenGroup_Gen, 1);
+ addVCEFieldEditor(new BooleanFieldEditor(VCEPreferences.GENERATE_TRY_CATCH_BLOCK, VCEMessages.PreferencePage_GenerateTryCatchBlock, SWT.NONE, codeGenGroup_Gen), codeGenGroup_Gen, 1);
- // Create a listener to see when the values in text boxes changes so we can trigger revalidation
- ModifyListener modifyListener = new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- // Validate that the value in the sourceToVisual is an integer between 1 and 9;
- validateFields();
- }
- };
-
- sourceSyncGrp = createGroup(codeGenComposite, VCEMessages.PreferencePage_CodeGen_Source_Synchronization_Delay, 6);
- // The group is 5 wide.
+
+ sourceSyncGrp = createGroup(codeGenComposite, VCEMessages.PreferencePage_CodeGen_Source_Synchronization_Delay, 3);
- // The JavaBeansToSource are 6 wide in the group
- createLabel(sourceSyncGrp, VCEMessages.PreferencePage_CodeGen_SourceToJavaBeans, null);
- sourceToVisual = createText(sourceSyncGrp, 11, 1); //$NON-NLS-1$
- sourceToVisual.addModifyListener(modifyListener);
- sourceToVisual.setTextLimit(9);
+ IntegerFieldEditor fieldEditor = new IntegerFieldEditor(VCEPreferences.SOURCE_SYNC_DELAY, VCEMessages.PreferencePage_CodeGen_SourceToJavaBeans, sourceSyncGrp, 9);
+ fieldEditor.setValidateStrategy(IntegerFieldEditor.VALIDATE_ON_KEY_STROKE);
+ fieldEditor.setValidRange(VCEPreferences.DEFAULT_SYNC_DELAY, Integer.MAX_VALUE);
+ fieldEditor.setErrorMessage(VCEMessages.PreferencePage_CodeGen_Error_DelayTimeMustBeInteger_ERROR_);
+ addVCEFieldEditor(fieldEditor, sourceSyncGrp, 2);
+
Label spacer = new Label(sourceSyncGrp, SWT.NONE);
spacer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
@@ -689,7 +686,7 @@
protected void initializeGUIControlsFromStore() {
getStore();
-
+
initializeBasicLookAndFeelItems(lookAndFeelTable);
// Get the current look and feel class name
String lookAndFeelClass = fStore.getString(VCEPreferences.SWING_LOOKANDFEEL);
@@ -746,52 +743,33 @@
// requireIVJforComponents.setSelection(fStore.getString(VCEPreferences.REQUIRE_IVJ_COMPONENTS).length()==0 ?
// false : fStore.getBoolean(VCEPreferences.REQUIRE_IVJ_COMPONENTS)) ;
- generateExpressionComment.setSelection(fStore.getBoolean(VCEPreferences.GENERATE_COMMENT));
- generateTryCatchBlock.setSelection(fStore.getBoolean(VCEPreferences.GENERATE_TRY_CATCH_BLOCK));
- sourceToVisual.setText(fStore.getString(VCEPreferences.SOURCE_SYNC_DELAY));
- calculateTotalSourceToVisualTime();
- }
- protected void validateFields() {
- // Validate that the sourceSyncDelayText is an integer greater than the default of 500ms
- boolean isValid = true;
- try {
- int val = Integer.parseInt(sourceToVisual.getText());
- if (val < VCEPreferences.DEFAULT_SYNC_DELAY) {
- isValid = false;
- setErrorMessage(VCEMessages.PreferencePage_CodeGen_Error_DelayTimeMinimum_ERROR_);
- setValid(false);
- }
- } catch (NumberFormatException ex) {
- isValid = false;
- setErrorMessage(VCEMessages.PreferencePage_CodeGen_Error_DelayTimeMustBeInteger_ERROR_);
- setValid(false);
- }
- // If we got no errors then clear the error message and refresh the total source to visual time
- if (isValid) {
- // The next step is to calculate the total time which is the delay time * the factor
- // it is possible that is an integer that is too large.
- boolean isValidTotalTime = calculateTotalSourceToVisualTime();
- if (isValidTotalTime) {
- setValid(true);
- setErrorMessage(null);
- } else {
- setValid(false);
- }
+ for (FieldEditor fieldEditor : fieldEditors ) {
+ fieldEditor.load();
+ }
+ checkFieldEditorsForErrors();
+
+ for (FieldEditor fieldEditor : fieldEditors) {
+ fieldEditor.load();
}
}
- protected boolean calculateTotalSourceToVisualTime() {
- try {
- int total = Integer.parseInt(sourceToVisual.getText());
- if(total<0 || total>Integer.MAX_VALUE){
- setErrorMessage(PropertysheetMessages.not_integer_WARN_);
+
+ protected boolean checkFieldEditorsForErrors() {
+ for (FieldEditor f : fieldEditors) {
+ if (!f.isValid()) {
+ setValid(false);
return false;
}
- return true;
- } catch (NumberFormatException exc) {
- // This should not occur because the number have already been validated
- return false;
}
+ setValid(true);
+ return true;
}
+
+ @Override
+ public void setErrorMessage(String newMessage) {
+ checkFieldEditorsForErrors();
+ super.setErrorMessage(newMessage);
+ }
+
public boolean performOk() {
// Save the Swing look and feel
@@ -843,13 +821,14 @@
fStore.setValue(VCEPreferences.OPEN_PROPERTIES_VIEW, openPropertiesViewIfRequired.getSelection());
fStore.setValue(VCEPreferences.OPEN_JAVABEANS_VIEW, openJavaBeansViewIfRequired.getSelection());
- fStore.setValue(VCEPreferences.GENERATE_COMMENT, generateExpressionComment.getSelection());
- fStore.setValue(VCEPreferences.GENERATE_TRY_CATCH_BLOCK, generateTryCatchBlock.getSelection());
- fStore.setValue(VCEPreferences.SOURCE_SYNC_DELAY, Integer.parseInt(sourceToVisual.getText()));
// fStore.setValue(VCEPreferences.REQUIRE_IVJ_COMPONENTS,requireIVJforComponents.getSelection()) ;
fStore.setValue(VCEPreferences.JVE_PATTERN_STYLE_ID, fStyleID);
+ for (FieldEditor fieldEditor : fieldEditors) {
+ fieldEditor.store();
+ }
+
ProxyPlugin.getPlugin().getPluginPreferences().setValue(ProxyPlugin.PREFERENCES_VM_NOVERIFY_KEY, noverifyCheckbox.getSelection());
ProxyPlugin.getPlugin().savePluginPreferences();
@@ -905,16 +884,17 @@
currentLookAndFeelItem.setChecked(true);
notebookRadioButton.setSelection(store.getDefaultBoolean(VCEPreferences.NOTEBOOK_PAGE));
- generateExpressionComment.setSelection(store.getDefaultBoolean(VCEPreferences.GENERATE_COMMENT));
- generateTryCatchBlock.setSelection(store.getDefaultBoolean(VCEPreferences.GENERATE_TRY_CATCH_BLOCK));
splitRadioButton.setSelection(!store.getDefaultBoolean(VCEPreferences.NOTEBOOK_PAGE));
- sourceToVisual.setText(Integer.toString(VCEPreferences.DEFAULT_SYNC_DELAY));
openPropertiesViewIfRequired.setSelection(true);
openJavaBeansViewIfRequired.setSelection(true);
// requireIVJforComponents.setSelection(false) ;
noverifyCheckbox.setSelection(ProxyPlugin.getPlugin().getPluginPreferences().getDefaultBoolean(ProxyPlugin.PREFERENCES_VM_NOVERIFY_KEY));
+
+ for (FieldEditor fieldEditor : fieldEditors) {
+ fieldEditor.loadDefault();
+ }
restoreDefaultStyle();
}