ref #5971: add an admin page to the prefs and add cdm pref nomenclatural code
authorKatja Luther <k.luther@bgbm.org>
Tue, 1 Nov 2016 11:16:51 +0000 (12:16 +0100)
committerKatja Luther <k.luther@bgbm.org>
Tue, 1 Nov 2016 11:16:51 +0000 (12:16 +0100)
eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle.properties
eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle_de.properties
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/CdmDataSourceRepository.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AdminGeneralPreferences.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AdminNomenclaturalCode.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AdminPreferencesPage.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/InitNomenclaturalCodePrefDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalCodePreferences.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java

index bec383a23d8ba0945ac574b8ca5cbe902b80980a..3d5878ca8b7d33518dc3d2e1c6f3152809d39d02 100644 (file)
@@ -26,6 +26,10 @@ page.name.22 = Default Feature Trees
 page.name.23 = Representation\r
 page.name.24 = Mobot Open Url\r
 page.name.25 = Type Designations\r
+page.name.36 = Name Details View\r
+page.name.37 = Cdm Preferences\r
+page.name.38 = General Preferences\r
+page.name.39 = Nomenclatural Code\r
 view.name = Datasource\r
 view.name.0 = Progress\r
 view.name.1 = Message\r
index 13c9fe5720d04bbfbe99c8b8f50b57130765aadf..4a7869277369ac3f0261e5df31859aab3ad2b0b4 100644 (file)
@@ -26,6 +26,10 @@ page.name.22 = Standard Merkmalsbaum
 page.name.23 = Repr\u00e4sentation
 page.name.24 = Mobot Open Url
 page.name.25 = Typus
+page.name.36 = Namensdetails
+page.name.37 = CDM Präferenzen
+page.name.38 = allgemeine CDM Präferenzen
+page.name.39 = Nomenklatorischer Code
 view.name = Datenquelle
 view.name.0 = Fortschritt
 view.name.1 = Nachrichten
index 9b1bca568878beeab76bfa94667b9618857fb6df..32beeab3356edc2e9d839f7aed5661ce4a97f450 100755 (executable)
@@ -8,6 +8,30 @@
             class="eu.etaxonomy.taxeditor.preference.TaxonomicEditorGeneralPreferences"
             id="eu.etaxonomy.taxeditor.preferences.general"
             name="%page.name">
+      </page>
+       <page
+            category="eu.etaxonomy.taxeditor.preferences.general"
+            class="eu.etaxonomy.taxeditor.preference.AdminPreferencesPage"
+            id="eu.etaxonomy.taxeditor.preferences.admin"
+            name="%page.name.37">
+      </page>
+      <!-- <page
+            category="eu.etaxonomy.taxeditor.preferences.admin"
+            class="eu.etaxonomy.taxeditor.preference.AdminGeneralPreferences"
+            id="eu.etaxonomy.taxeditor.preferences.adminGeneral"
+            name="%page.name.38">
+      </page>-->
+       <page
+            category="eu.etaxonomy.taxeditor.preferences.admin"
+            class="eu.etaxonomy.taxeditor.preference.AdminNomenclaturalCode"
+            id="eu.etaxonomy.taxeditor.preferences.adminNomenclaturalCode"
+            name="%page.name.39">
+      </page>
+      <page
+                       category="eu.etaxonomy.taxeditor.preferences.general"
+            class="eu.etaxonomy.taxeditor.preference.NameDetailsViewConfiguration"
+            id="eu.etaxonomy.taxeditor.preferences.nameDetails"
+            name="%page.name.36">
       </page>
       <page
             category="eu.etaxonomy.taxeditor.preferences.general"
             id="eu.etaxonomy.taxeditor.preference.TaxonNavigator"
             name="%page.name.32">
       </page>
-       <page
+      <page
             category="eu.etaxonomy.taxeditor.preferences.general"
             class="eu.etaxonomy.taxeditor.preference.DebugPreferences"
             id="eu.etaxonomy.taxeditor.preferences.debug"
index ccdd5e28591f67096c51dc5d77fa3b63f7914fc8..53f077581ec4e9189d82ea9e4b8a5b00aef19438 100644 (file)
@@ -30,7 +30,6 @@ import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
 import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
 import eu.etaxonomy.cdm.database.ICdmDataSource;
 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
-
 import eu.etaxonomy.taxeditor.model.MementoHelper;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
@@ -191,7 +190,7 @@ public class CdmDataSourceRepository{
                NomenclaturalCode applicationNomenclaturalCode = PreferencesUtil.getPreferredNomenclaturalCode(true);
 
                if( dataSourceNomenclaturalCode != null && ! dataSourceNomenclaturalCode.equals(applicationNomenclaturalCode)){
-                       PreferencesUtil.setPreferredNomenclaturalCode(dataSourceNomenclaturalCode);
+                       PreferencesUtil.setPreferredNomenclaturalCode(dataSourceNomenclaturalCode, true);
                        MessagingUtils.informationDialog("Nomenclatural Code Change", "The Datasource that was just " +
                                        "loaded has a different nomenclatural code than the one stored in Preferences. " +
                                        "The nomenclatural code was changed in the application.");
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AdminGeneralPreferences.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AdminGeneralPreferences.java
new file mode 100755 (executable)
index 0000000..c1abee4
--- /dev/null
@@ -0,0 +1,51 @@
+// $Id$
+/**
+* Copyright (C) 2016 EDIT
+* 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.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * @author k.luther
+ * @date 01.11.2016
+ *
+ */
+public class AdminGeneralPreferences extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+    /* (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.FieldEditorPreferencePage#createFieldEditors()
+     */
+    @Override
+    protected void createFieldEditors() {
+        addField(new BooleanFieldEditor(IPreferenceKeys.IS_SHOW_UP_WIDGET_IS_DISPOSED,
+                "Show up widget is disposed error messages.",
+                getFieldEditorParent()));
+        addField(new BooleanFieldEditor(IPreferenceKeys.DISABLE_SERVICES_API_TIMESTAMP_CHECK,
+                "Disable services api timestamp check",
+                getFieldEditorParent()));
+        addField(new BooleanFieldEditor(
+                IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES,
+                "Show experimental features", getFieldEditorParent()));
+
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AdminNomenclaturalCode.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AdminNomenclaturalCode.java
new file mode 100755 (executable)
index 0000000..d87a9d8
--- /dev/null
@@ -0,0 +1,99 @@
+// $Id$
+/**
+* Copyright (C) 2016 EDIT
+* 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 java.util.List;
+
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.ComboFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
+import eu.etaxonomy.cdm.api.service.IPreferenceService;
+import eu.etaxonomy.cdm.model.metadata.CdmPreference;
+import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+
+/**
+ * @author k.luther
+ * @date 01.11.2016
+ *
+ */
+public class AdminNomenclaturalCode extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+     */
+    @Override
+    public void init(IWorkbench workbench) {
+        setPreferenceStore(TaxeditorStorePlugin.getDefault()
+                .getPreferenceStore());
+        setDescription("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified. \nATTENTION, this preference is stored in DB!");
+        PreferencesUtil.setPreferredNomenclaturalCode(null, false);
+
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
+     */
+    @Override
+    protected void createFieldEditors() {
+        addField(new ComboFieldEditor(
+                IPreferenceKeys.CDM_NOMENCLATURAL_CODE_KEY,
+                "Available Codes", getLabelAndValues(),
+                getFieldEditorParent()));
+        addField(new BooleanFieldEditor(
+                IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY,
+                "allow to use local preference",
+                getFieldEditorParent()));
+
+
+    }
+
+    /**
+     * @return
+     */
+    private String[][] getLabelAndValues() {
+        List<NomenclaturalCode> supportedCodes = NomenclaturalCodeHelper
+                .getSupportedCodes();
+        String[][] labelAndValues = new String[supportedCodes.size()][2];
+        for (int i = 0; i < supportedCodes.size(); i++) {
+            labelAndValues[i][0] = NomenclaturalCodeHelper
+                    .getDescription(supportedCodes.get(i));
+            labelAndValues[i][1] = PreferencesUtil
+                    .getPreferenceKey(supportedCodes.get(i));
+        }
+        return labelAndValues;
+    }
+    @Override
+    public boolean performOk() {
+
+       boolean result = super.performOk();
+       if (result){
+           String value = getPreferenceStore().getString(IPreferenceKeys.CDM_NOMENCLATURAL_CODE_KEY);
+           CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.NomenclaturalCode, value);
+           ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
+           if (controller == null){
+               return false;
+           }
+           IPreferenceService service = controller.getPreferenceService();
+           service.set(pref);
+       }
+       return result;
+   }
+
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AdminPreferencesPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AdminPreferencesPage.java
new file mode 100755 (executable)
index 0000000..dcc7287
--- /dev/null
@@ -0,0 +1,40 @@
+// $Id$
+/**
+* Copyright (C) 2016 EDIT
+* 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.FieldEditorPreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * @author k.luther
+ * @date 01.11.2016
+ *
+ */
+public class AdminPreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+     */
+    @Override
+    public void init(IWorkbench workbench) {
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
+     */
+    @Override
+    protected void createFieldEditors() {
+
+    }
+
+
+}
index ccbc6b96e654b40120ebbd1757791bb19b69d809..1f92bf6c3104376cf8c9ea43565bd8fe889a7ce0 100644 (file)
@@ -24,7 +24,9 @@ public interface IPreferenceKeys {
         *
         */
        public static final String PREFERRED_NOMENCLATURAL_CODE_KEY = "eu.etaxonomy.taxeditor.nomenclaturalCode";
-
+    public static final String OVERRIDE_NOMENCLATURAL_CODE_KEY = "eu.etaxonomy.taxeditor.nomenclaturalCode.override";
+    public static final String ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY = "eu.etaxonomy.taxeditor.nomenclaturalCode.allow_override";
+    public static final String CDM_NOMENCLATURAL_CODE_KEY = "eu.etaxonomy.taxeditor.cdm.nomenclaturalCode";
        /**
         *
         */
@@ -171,7 +173,7 @@ public interface IPreferenceKeys {
     public static final String SHOW_NAME_DETAILS_SECTION_NAME_RELATIONSHIP = "eu.etaxonomy.taxeditor.name.showNameNameRelationship";
        public static final String SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE = "eu.etaxonomy.taxeditor.name.showNameAppendedPhrase";
        public static final String SHOW_NAME_DETAILS_SECTION_CACHE = "eu.etaxonomy.taxeditor.name.showNameCache";
-       
+
     public static final String PROMPT_FOR_OPEN_SPECIMEN_IN_EDITOR = "eu.etaxonomy.taxeditor.specimen.promptForOpenSpecimenInEditor";
 
     // TODO RL
@@ -186,7 +188,10 @@ public interface IPreferenceKeys {
      */
     public static final String P2_REPOSITORY_LIST = "eu.etaxonomy.taxeditor.p2.repositories";
 
-       
+
+
+
+
 
 
 
index 291c80ffdf1ed8fac71d8d3405e48a6dd87bc656..ae03356050a4166904c701827a869a0d475d4c56 100644 (file)
@@ -1,8 +1,8 @@
 /**
 * 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.
 */
@@ -33,7 +33,7 @@ import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
  * @version 1.0
  */
 public class InitNomenclaturalCodePrefDialog extends Dialog {
-       
+
        /**
         * If the user makes no change, or cancels, preferred nom. code will be set to the default
         */
@@ -47,7 +47,7 @@ public class InitNomenclaturalCodePrefDialog extends Dialog {
        public InitNomenclaturalCodePrefDialog(Shell parentShell) {
                super(parentShell);
        }
-       
+
        /**
         * {@inheritDoc}
         *
@@ -71,23 +71,24 @@ public class InitNomenclaturalCodePrefDialog extends Dialog {
                buttonsComposite.setLayout(new GridLayout());
 
                NomenclaturalCode defaultCode = NomenclaturalCodeHelper.getDefaultCode();
-               
+
                for (final NomenclaturalCode code : NomenclaturalCodeHelper.getSupportedCodes()) {
                        Button button = new Button(buttonsComposite, SWT.RADIO);
                        button.setText(NomenclaturalCodeHelper.getDescription(code));
                        button.setSelection(defaultCode.equals(code));
                        button.addSelectionListener(new SelectionAdapter() {
-                               public void widgetSelected(SelectionEvent e) {
+                               @Override
+                public void widgetSelected(SelectionEvent e) {
                                        setPreferredCode(code);
                                }
                        });
                }
-                       
+
                // More dialog text
                String defaultCodeDescription = NomenclaturalCodeHelper.getDescription(defaultCode);
                final Label chooseANomenclaturalLabel_1 = new Label(container, SWT.WRAP);
                chooseANomenclaturalLabel_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-               chooseANomenclaturalLabel_1.setText("If you hit \"Cancel\", " + defaultCodeDescription + 
+               chooseANomenclaturalLabel_1.setText("If you hit \"Cancel\", " + defaultCodeDescription +
                                                                                                " will be set as your default nomenclatural code.\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");
                //
                return container;
@@ -111,25 +112,27 @@ public class InitNomenclaturalCodePrefDialog extends Dialog {
        protected Point getInitialSize() {
                return new Point(500, 375);
        }
-       
+
        /** {@inheritDoc} */
-       protected void configureShell(Shell newShell) {
+       @Override
+    protected void configureShell(Shell newShell) {
                super.configureShell(newShell);
                newShell.setText("Choose a nomenclatural code");
        }
-               
+
        /**
         * <p>close</p>
         *
         * @return a boolean.
         */
-       public boolean close() {
-               
+       @Override
+    public boolean close() {
+
                // Save preferred nomenclatural code before closing
-               PreferencesUtil.setPreferredNomenclaturalCode(preferredCode);
-               
+               PreferencesUtil.setPreferredNomenclaturalCode(preferredCode, true);
+
                return super.close();
        }
-       
-       
+
+
 }
index 16b326ca836f6e8ffbc0858a9015e2f689f6d4e9..126909a5b08d4a4c736738809721efd610d88cf6 100644 (file)
@@ -1,39 +1,30 @@
 /**
  * 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 java.util.Iterator;
 import java.util.List;
 
-import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.ComboFieldEditor;
 import org.eclipse.jface.preference.FieldEditorPreferencePage;
-import org.eclipse.jface.preference.RadioGroupFieldEditor;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
 
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
-import eu.etaxonomy.cdm.api.service.IClassificationService;
-import eu.etaxonomy.cdm.api.service.IPreferenceService;
-import eu.etaxonomy.cdm.model.metadata.CdmPreference;
-import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
-import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
-import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
 import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
-import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 
 /**
  * <p>
  * NomenclaturalCodePreferences class.
  * </p>
- * 
+ *
  * @author p.ciardelli
  * @created 16.09.2008
  * @version 1.0
@@ -43,7 +34,7 @@ public class NomenclaturalCodePreferences extends FieldEditorPreferencePage
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see
         * org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors
         * ()
@@ -51,10 +42,14 @@ public class NomenclaturalCodePreferences extends FieldEditorPreferencePage
        @Override
        protected void createFieldEditors() {
 
-               addField(new RadioGroupFieldEditor(
+               addField(new ComboFieldEditor(
                                IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY,
-                               "Available Codes", 1, getLabelAndValues(),
-                               getFieldEditorParent(), true));
+                               "Available Codes", getLabelAndValues(),
+                               getFieldEditorParent()));
+               addField(new BooleanFieldEditor(
+                IPreferenceKeys.OVERRIDE_NOMENCLATURAL_CODE_KEY,
+                "Use local nomenclatural code",
+                getFieldEditorParent()));
 
        }
 
@@ -76,33 +71,34 @@ public class NomenclaturalCodePreferences extends FieldEditorPreferencePage
 
        /**
         * {@inheritDoc}
-        * 
+        *
         * Initialize the preference page
         */
-       public void init(IWorkbench workbench) {
+       @Override
+    public void init(IWorkbench workbench) {
                setPreferenceStore(TaxeditorStorePlugin.getDefault()
                                .getPreferenceStore());
-               setDescription("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified. \nATTENTION, this preference is stored in DB!");
-               PreferencesUtil.setPreferredNomenclaturalCode(null);
+               setDescription("Choose which nomenclatural code you would like to use in your local application for scientific names unless otherwise specified.");
+               //PreferencesUtil.setPreferredNomenclaturalCode(null, true);
        }
-       
+
        @Override
         public boolean performOk() {
-               
+
                boolean result = super.performOk();
-               if (result){
-                       String value = getPreferenceStore().getString(IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY);
-                       CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.NomenclaturalCode, value);
-                       ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
-                       if (controller == null){
-                               return false;
-                       }
-                       IPreferenceService service = controller.getPreferenceService();
-                       service.set(pref);
-               }
+//             if (result){
+//                     String value = getPreferenceStore().getString(IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY);
+//                     CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.NomenclaturalCode, value);
+//                     ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
+//                     if (controller == null){
+//                             return false;
+//                     }
+//                     IPreferenceService service = controller.getPreferenceService();
+//                     service.set(pref);
+//             }
         return result;
     }
-       
-       
+
+
 
 }
index 0dd68af2e2d410f485d2e20b4e36bff430864f8a..f4f32c9b217c4c1405f8e058b4ba09c6aa05791d 100644 (file)
@@ -37,7 +37,6 @@ import org.eclipse.ui.PlatformUI;
 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
 import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
-import eu.etaxonomy.cdm.api.service.IPreferenceService;
 import eu.etaxonomy.cdm.api.service.ITermService;
 import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
 import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
@@ -108,38 +107,50 @@ public class PreferencesUtil implements IPreferenceKeys {
         *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
         *            object.
         */
-       public static void setPreferredNomenclaturalCode(
-                       NomenclaturalCode preferredCode) {
-               ICdmApplicationConfiguration controller;
-               controller = CdmStore.getCurrentApplicationConfiguration();
-               PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
-               CdmPreference preference = null;
-               if (controller == null){
-                       return;
-               }
-               if (preferredCode == null){
-                       preference = controller.getPreferenceService().find(key);
-                       if (preference == null){
-                               return;
-                       } else{
-                               int index = StringUtils.lastIndexOf(preference.getValue(), ".");
-                               UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
-                               preferredCode = NomenclaturalCode.getByUuid(uuid);
-                       }
-               } else{
-                       preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferredCode.getKey());
-                       controller.getPreferenceService().set(preference);
-               }
-                
-           
-               getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
-                               getPreferenceKey(preferredCode));
+       public static NomenclaturalCode setPreferredNomenclaturalCode(
+                       NomenclaturalCode preferredCode, boolean local) {
+           if (local){
+               getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
+                    getPreferenceKey(preferredCode));
+           }
+           else{
+               ICdmApplicationConfiguration controller;
+               controller = CdmStore.getCurrentApplicationConfiguration();
+               PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
+               CdmPreference preference = null;
+               if (controller == null){
+                       return null;
+               }
+               if (preferredCode == null){
+                       preference = controller.getPreferenceService().find(key);
+                       if (preference == null){
+                               return null;
+                       } else{
+                               int index = StringUtils.lastIndexOf(preference.getValue(), ".");
+                               UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
+                               preferredCode = NomenclaturalCode.getByUuid(uuid);
+                               return preferredCode;
+                       }
+               } else{
+                       preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferredCode.getKey());
+                       controller.getPreferenceService().set(preference);
+
+               }
+           }
+        return preferredCode;
+
+
+
        }
 
        public static NomenclaturalCode getPreferredNomenclaturalCode(){
-               return getPreferredNomenclaturalCode(false);
+           if (getPreferenceStore().getBoolean(OVERRIDE_NOMENCLATURAL_CODE_KEY)) {
+            return getPreferredNomenclaturalCode(true);
+        } else{
+            return getPreferredNomenclaturalCode(false);
+        }
        }
-       
+
        /**
         * <p>
         * getPreferredNomenclaturalCode
@@ -147,10 +158,10 @@ public class PreferencesUtil implements IPreferenceKeys {
         *
         * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
         */
-       public static NomenclaturalCode getPreferredNomenclaturalCode(boolean preConnected) {
+       public static NomenclaturalCode getPreferredNomenclaturalCode(boolean useLocal) {
                ICdmApplicationConfiguration controller;
                CdmPreference pref = null;
-               if (!preConnected){
+               if (!useLocal){
                        try{
                                controller = CdmStore.getCurrentApplicationConfiguration();
                                PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
@@ -159,7 +170,7 @@ public class PreferencesUtil implements IPreferenceKeys {
                                e.printStackTrace();
                        }
                }
-               
+
            String preferredCode;
            if(pref == null){
                preferredCode = getPreferenceStore().getString(
@@ -167,10 +178,8 @@ public class PreferencesUtil implements IPreferenceKeys {
            }else{
                preferredCode = pref.getValue();
            }
-           
+
                for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
-//                     String preferredCode = getPreferenceStore().getString(
-//                                     PREFERRED_NOMENCLATURAL_CODE_KEY);
                        if (getPreferenceKey(code).equals(preferredCode)) {
                                return code;
                        }
@@ -475,7 +484,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
 
                if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
-                       PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP);
+                       PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP, true);
                        /*
 
                        StoreUtil.info("No nomencatural code set.");