Convert MobotOpenUrlPreferences and BulkEditorPreferencePage to
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / MobotOpenUrlPreferences.java
index 8679d677e2085a5b284a3badd90519dfa28ab269..0e953be686a7ec469e07958c8b830186ec5c8ea6 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());
+    }
 }