Convert MobotOpenUrlPreferences and BulkEditorPreferencePage to
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 28 Oct 2015 07:42:16 +0000 (08:42 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 28 Oct 2015 14:27:28 +0000 (15:27 +0100)
FieldEditorPreferencePage (#5336, #5338)

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/preference/BulkEditorMarkerPreferencePage.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/MobotOpenUrlPreferences.java

index 2830dd8..b183539 100644 (file)
 
 package eu.etaxonomy.taxeditor.bulkeditor.preference;
 
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
 
 import eu.etaxonomy.cdm.model.common.MarkerType;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.TermStore;
 
 /**
- * <p>BulkEditorMarkerPreferenceComposite class.</p>
- *
  * @author p.ciardelli
  * @created 17.08.2009
  * @version 1.0
  */
-public class BulkEditorMarkerPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+public class BulkEditorMarkerPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
 
-       private Map<MarkerType, Boolean> markerTypeEditingMap = new HashMap<MarkerType, Boolean>();
 
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
-        */
        @Override
        public void init(IWorkbench workbench) {
                setPreferenceStore(PreferencesUtil.getPreferenceStore());
                if(!CdmStore.isActive()) {
             MessagingUtils.noDataSourceWarningDialog(null);
-               }else{
-                   markerTypeEditingMap = PreferencesUtil.getEditMarkerTypePreferences();
                }
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
-        */
-       @Override
-       protected Control createContents(Composite parent) {
-               Composite container = new Composite(parent, SWT.NULL);
-               container.setLayout(new GridLayout());
+    @Override
+    protected void createFieldEditors() {
         if(CdmStore.isActive()){
             for (final MarkerType markerType : TermStore.getTerms(MarkerType.class)) {
-                final Button button = new Button(container, SWT.CHECK);
-                button.setText(String.format("Edit '%s' markers", markerType.getLabel()));
-
-                button.addSelectionListener(new SelectionAdapter() {
-                    @Override
-                    public void widgetSelected(SelectionEvent e) {
-                        markerTypeEditingMap.put(markerType, button.getSelection());
-                    }
-                });
-
-                boolean edit = markerTypeEditingMap.get(markerType) == null ? true : markerTypeEditingMap.get(markerType);
-
-                button.setSelection(edit);
+                addField(new BooleanFieldEditor(IPreferenceKeys.EDIT_MARKER_TYPE_PREFIX
+                        + markerType.getClass().getName() + markerType.getLabel(), String.format("Edit '%s' markers",
+                        markerType.getLabel()), getFieldEditorParent()));
             }
         }
-               return container;
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#performOk()
-        */
-       @Override
-       public boolean performOk() {
-               PreferencesUtil.setEditMarkerTypePreferences(markerTypeEditingMap);
 
-               return super.performOk();
-       }
+    }
 }
index 8679d67..0e953be 100644 (file)
@@ -1,25 +1,18 @@
 // $Id$
 /**
  * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
 
 package eu.etaxonomy.taxeditor.preference;
 
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Text;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IntegerFieldEditor;
+import org.eclipse.jface.preference.StringFieldEditor;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
 
@@ -28,120 +21,28 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
  * @created Feb 4, 2011
  * @version 1.0
  */
-public class MobotOpenUrlPreferences extends PreferencePage implements
+public class MobotOpenUrlPreferences extends FieldEditorPreferencePage implements
                IWorkbenchPreferencePage {
 
-       private String openUrlServiceAccessPoint;
-       private String openUrlImageMaxWidth;
-       private String openUrlImageMaxHeight;
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see
-        * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
-        */
-       @Override
-       public void init(IWorkbench workbench) {
-               setPreferenceStore(PreferencesUtil.getPreferenceStore());
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see
-        * org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse
-        * .swt.widgets.Composite)
-        */
-       @Override
-       protected Control createContents(Composite parent) {
-               Composite container = new Composite(parent, SWT.NULL);
-               final GridLayout gridLayout = new GridLayout();
-               container.setLayout(gridLayout);
-
-               creatOpenUrlServiceAccessPoint(container);
-
-               createOpenUrlImageSize(container);
-
-               return container;
-       }
-
-       /**
-        * @param container
-        */
-       private void createOpenUrlImageSize(Composite container) {
-               openUrlImageMaxWidth = getPreferenceStore().getString(
-                               IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH);
-               openUrlImageMaxHeight = getPreferenceStore().getString(
-                               IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT);
-
-               Composite composite = new Composite(container, SWT.NULL);
-               final GridLayout gridLayout = new GridLayout(2, false);
-               composite.setLayout(gridLayout);
-
-               final CLabel labelWidth = new CLabel(composite, SWT.NULL);
-               labelWidth.setText("Image Maximum Width: ");
-
-               final Text textWidth = new Text(composite, SWT.BORDER);
-               textWidth.setText(openUrlImageMaxWidth);
-               textWidth.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
-
-               textWidth.addModifyListener(new ModifyListener() {
-
-                       public void modifyText(ModifyEvent e) {
-                               openUrlImageMaxWidth = textWidth.getText();
-                       }
-               });
-
-               final CLabel labelHeight = new CLabel(composite, SWT.NULL);
-               labelHeight.setText("Image Maximum Height: ");
-
-               final Text textHeight = new Text(composite, SWT.BORDER);
-               textHeight.setText(openUrlImageMaxHeight);
-               textHeight.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
-
-               textHeight.addModifyListener(new ModifyListener() {
-
-                       public void modifyText(ModifyEvent e) {
-                               openUrlImageMaxHeight = textHeight.getText();
-                       }
-               });
-       }
-
-       private void creatOpenUrlServiceAccessPoint(Composite composite) {
-               openUrlServiceAccessPoint = getPreferenceStore().getString(
-                               IPreferenceKeys.OPENURL_ACCESS_POINT);
-
-               final CLabel label = new CLabel(composite, SWT.NULL);
-               label.setText("Mobot Open Url Service Access Point:");
-
-               final Text text = new Text(composite, SWT.BORDER);
-               text.setText(openUrlServiceAccessPoint);
-               text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
-
-               text.addModifyListener(new ModifyListener() {
-
-                       public void modifyText(ModifyEvent e) {
-                               openUrlServiceAccessPoint = text.getText();
-                       }
-               });
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see org.eclipse.jface.preference.PreferencePage#performOk()
-        */
-       @Override
-       public boolean performOk() {
-               getPreferenceStore().setValue(IPreferenceKeys.OPENURL_ACCESS_POINT,
-                               openUrlServiceAccessPoint);
-               getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH,
-                               openUrlImageMaxWidth);
-               getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT,
-                               openUrlImageMaxHeight);
-
-               return super.performOk();
-       }
 
+    @Override
+    protected void createFieldEditors() {
+        addField(new StringFieldEditor(
+                IPreferenceKeys.OPENURL_ACCESS_POINT,
+                "Mobot Open Url Service Access Point:", getFieldEditorParent()));
+        addField(new IntegerFieldEditor(
+                IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH,
+                "Image Maximum Width:",
+                getFieldEditorParent()));
+        addField(new IntegerFieldEditor(
+                IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT,
+                "Image Maximum Height:",
+                getFieldEditorParent()));
+
+    }
+
+    @Override
+    public void init(IWorkbench workbench) {
+        setPreferenceStore(PreferencesUtil.getPreferenceStore());
+    }
 }