ref #5971: new main menu admin with cdm preference nomenclatural code and insert...
authorKatja Luther <k.luther@bgbm.org>
Fri, 18 Nov 2016 17:20:27 +0000 (18:20 +0100)
committerKatja Luther <k.luther@bgbm.org>
Fri, 18 Nov 2016 17:25:40 +0000 (18:25 +0100)
15 files changed:
eu.etaxonomy.taxeditor.application/plugin.xml
eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin.properties
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyEditorLabels.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/InsertNewNodeHandler.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/InsertPolytomousKeyNodeOperation.java [new file with mode: 0755]
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/databasePreferences/wizard/DatabasePreferencesPage.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databasePreferences/wizard/DatabasePreferencesWizard.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenDatabasePreferencesWizardHandler.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AdminNomenclaturalCode.java [deleted file]
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
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java

index ae74af849e0ff876087aa64776ee4fe35b24249c..3f377ea589c7ab3db4b1f1159e64cbf98d9330fa 100644 (file)
                id="org.eclipse.ui.main.menu.help"
                label="%menu.label.2">
          </menu>
+         <menu
+               id="org.eclipse.ui.main.menu.admin"
+               label="Admin">
+         </menu>
       </menuContribution>
       <menuContribution
             locationURI="menu:org.eclipse.ui.main.menu.file">
             </command>
          </toolbar>
       </menuContribution>
+            <menuContribution
+                  allPopups="false"
+                  locationURI="menu:org.eclipse.ui.main.menu.admin">
+               <command
+                     commandId="eu.etaxonomy.taxeditor.application.DatabaseSettings"
+                     label="Database Preferences"
+                     style="push">
+               </command>
+            </menuContribution>
    </extension>
    <extension
          id="product"
             id="eu.etaxonomy.taxeditor.install"
             name="%command.label.18">
       </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.handler.OpenDatabasePreferencesWizardHandler"
+            id="eu.etaxonomy.taxeditor.application.DatabaseSettings"
+            name="databaseSettings">
+            
+      </command>
    </extension>
    
    
index 14420cb28163f51b7a7e2fae548a0549a910adc4..24a5da7d1343fd4144a6dd3c5e6d3be00d1b20b4 100644 (file)
@@ -45,6 +45,7 @@ command.label.22 = Apply Layout
 command.label.23 = New Key Number\r
 command.label.24 = New Alternative\r
 command.label.25 = Refresh Nodes\r
+command.label.58 = Insert Node\r
 command.label.26 = Delete\r
 command.label.27 = New Factual Data\r
 menu.label.1 = New\r
@@ -105,6 +106,7 @@ category.name.5 = -- Polytomous Keys
 command.name.28 = New Child Node\r
 command.name.29 = New Sibling Node\r
 command.name.30 = Refresh Node Numbering\r
+command.name.58 = Insert New Node\r
 command.name.31 = Apply Layout\r
 category.name.6 = -- Concept Relations\r
 command.name.32 = Create Concept Relation\r
index d44bd77183832366df05898333172c42d3cb6315..ef0345253959952e95158510f4a3ba4caf50f939 100644 (file)
                label="%command.label.23"
                style="push">
          </command>
+         <command
+               commandId="eu.etaxonomy.taxeditor.key.polytomous.command.new.node"
+               label="%command.label.58"
+               style="push">
+         </command>
          <command
                commandId="eu.etaxonomy.taxeditor.key.polytomous.command.new.sibling"
                label="%command.label.24"
       <handler
             class="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.RemotingCreateChildPolytomousKeyNodeHandler"
             commandId="eu.etaxonomy.taxeditor.key.polytomous.command.new.child">
+        <activeWhen>
+            <reference
+                  definitionId="isRemoting">
+            </reference>
+         </activeWhen>
+      </handler>
+       <handler
+            class="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.InsertNewNodeHandler"
+            commandId="eu.etaxonomy.taxeditor.key.polytomous.command.new.node">
          <activeWhen>
             <reference
                   definitionId="isRemoting">
             id="eu.etaxonomy.taxeditor.editor.name.createMisapplication"
             name="%command.name.36">
       </command>
-      <!--command
+    <!--  <command
             defaultHandler="eu.etaxonomy.taxeditor.editor.handler.MoveTaxonHandler"
             id="eu.etaxonomy.taxeditor.editor.name.moveTaxon"
             name="Move Taxon">
-      </command-->
+      </command>-->
       <command
             categoryId="eu.etaxonomy.taxeditor.editor.taxon.name.command.category"
             defaultHandler="eu.etaxonomy.taxeditor.editor.name.handler.ChangeToSynonymHandler"
             defaultHandler="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.CreateChildNodeHandler"
             id="eu.etaxonomy.taxeditor.key.polytomous.command.new.child"
             name="%command.name.28">
+      </command>
+       <command
+            categoryId="eu.etaxonomy.taxeditor.editor.key.category"
+            defaultHandler="eu.etaxonomy.taxeditor.editor.key.polytomous.handler.InsertNewNodeHandler"
+            id="eu.etaxonomy.taxeditor.key.polytomous.command.new.node"
+            name="%command.name.58">
       </command>
       <command
             categoryId="eu.etaxonomy.taxeditor.editor.key.category"
index 82ee611fa483e4dc9644f88f4047b852c17a663b..1a7036b7e625d6a8c5c4c20d4bbcbb41b9bc87bb 100644 (file)
@@ -18,7 +18,9 @@ public interface PolytomousKeyEditorLabels {
 
     public static final String CREATE_CHILD_POLYTOMOUS_KEY_NODE_LABEL = "Create Child Polytomous Key Node";
     public static final String CREATE_SIBLING_POLYTOMOUS_KEY_NODE_LABEL = "Create Sibling Polytomous Key Node";
+    public static final String INSERT_NODE_POLYTOMOUS_KEY_NODE_LABEL = "Insert Node Polytomous Key Node";
 
     public static final String NO_KEY_NODE_FOR_CHILD_SELECTED_MESSAGE = "No Key Node Selected.Please right-click on a specific key node to create a new child key node.";
     public static final String NO_KEY_NODE_FOR_SIBLING_SELECTED_MESSAGE = "No Key Node Selected.Please right-click on a specific key node to create a new sibling key node.";
-}
+    public static final String NO_KEY_NODE_FOR_INSERT_NODE_SELECTED_MESSAGE = "No Key Node Selected.Please right-click on a specific key node to create a new key node.";
+    }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/InsertNewNodeHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/InsertNewNodeHandler.java
new file mode 100755 (executable)
index 0000000..67328f0
--- /dev/null
@@ -0,0 +1,91 @@
+/**
+* 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.editor.key.polytomous.handler;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.model.description.PolytomousKey;
+import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
+import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
+import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
+import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
+import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
+import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.InsertPolytomousKeyNodeOperation;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
+
+/**
+ * @author k.luther
+ * @date 17.11.2016
+ *
+ */
+public class InsertNewNodeHandler extends RemotingCdmHandler{
+
+    private PolytomousKeyNode parentNode ;
+
+    public InsertNewNodeHandler() {
+        super(PolytomousKeyEditorLabels.INSERT_NODE_POLYTOMOUS_KEY_NODE_LABEL);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IStatus allowOperations(ExecutionEvent event) {
+        IEditorPart editor = HandlerUtil.getActiveEditor(event);
+
+        if (editor instanceof KeyEditor) {
+            IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
+                    .getActiveEditor();
+
+            if (editorPage instanceof PolytomousKeyListEditor) {
+                PolytomousKeyListEditor klEditor = (PolytomousKeyListEditor) editorPage;
+                if(klEditor.getTableItemCount() == 0) {
+                    PolytomousKey pk = klEditor.getViewerInputKey();
+                    parentNode = pk.getRoot();
+
+                } else {
+                    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
+                    if (selection.getFirstElement() instanceof PolytomousKeyNode) {
+                        parentNode = ((PolytomousKeyNode) selection.getFirstElement()).getParent();
+                    } else {
+                        return new Status(IStatus.ERROR,
+                                "unknown",
+                                PolytomousKeyEditorLabels.NO_KEY_NODE_FOR_CHILD_SELECTED_MESSAGE);
+                    }
+                }
+            }
+        }
+        return Status.OK_STATUS;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public AbstractOperation prepareOperation(ExecutionEvent event) {
+        return new InsertPolytomousKeyNodeOperation(event.getTrigger(), false, parentNode);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onComplete() {
+        // TODO Auto-generated method stub
+
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/InsertPolytomousKeyNodeOperation.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/InsertPolytomousKeyNodeOperation.java
new file mode 100755 (executable)
index 0000000..e2e00c2
--- /dev/null
@@ -0,0 +1,65 @@
+/**
+* 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.editor.key.polytomous.operation;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmDefaultOperation;
+
+/**
+ * @author k.luther
+ * @date 17.11.2016
+ *
+ */
+public class InsertPolytomousKeyNodeOperation extends RemotingCdmDefaultOperation  {
+
+    private final PolytomousKeyNode parentNode;
+
+    private final static String LABEL = "Insert new polytomous key node";
+
+    /**
+     * @param label
+     * @param action
+     * @param source
+     * @param async
+     */
+    public InsertPolytomousKeyNodeOperation(Object source,
+            boolean async,
+            PolytomousKeyNode parentNode) {
+        super(LABEL, Action.Create, source, async);
+        this.parentNode = parentNode;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected CdmBase doSimpleExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
+        PolytomousKeyNode childNode = PolytomousKeyNode.NewInstance();
+        List<PolytomousKeyNode> newChildren = parentNode.getChildren();
+        List<PolytomousKeyNode> copy = new ArrayList<PolytomousKeyNode>();
+        for (PolytomousKeyNode node: newChildren) {
+            copy.add(node);
+        }
+        parentNode.addChild(childNode, 0);
+        for (PolytomousKeyNode node: copy){
+           childNode.addChild(node);
+        }
+
+        return childNode;
+    }
+
+}
index 4a7869277369ac3f0261e5df31859aab3ad2b0b4..dedac2a210fbff52c32fb6448eeeb1cdaf6bbd25 100644 (file)
@@ -4,7 +4,7 @@ page.name.0 = Faktendaten
 page.name.1 = Merkmal
 page.name.2 = Verbreitungsstatus
 page.name.3 = Taxonomisch
-page.name.4 = Nomenklaturcode
+page.name.4 = Nomenklatur-Code
 page.name.5 = R\u00e4nge
 page.name.6 = Nomenklatorischer Status
 page.name.7 = Namensbeziehungen
@@ -29,7 +29,7 @@ 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
+page.name.39 = Nomenklatur-Code
 view.name = Datenquelle
 view.name.0 = Fortschritt
 view.name.1 = Nachrichten
index 32beeab3356edc2e9d839f7aed5661ce4a97f450..0a6cfe0a1685bafd3ed2a524e9c1268bb2a9b016 100755 (executable)
@@ -8,12 +8,6 @@
             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"
@@ -23,7 +17,7 @@
       </page>-->
        <page
             category="eu.etaxonomy.taxeditor.preferences.admin"
-            class="eu.etaxonomy.taxeditor.preference.AdminNomenclaturalCode"
+            class="eu.etaxonomy.taxeditor.databasePreferences.AdminNomenclaturalCode"
             id="eu.etaxonomy.taxeditor.preferences.adminNomenclaturalCode"
             name="%page.name.39">
       </page>
             </reference>
          </activeWhen>
       </handler>
+      <handler
+            class="eu.etaxonomy.taxeditor.handler.OpenDatabasePreferencesWizardHandler"
+            commandId="eu.etaxonomy.taxeditor.store.open.OpenDatabasePreferencesWizardHandler">
+      </handler>
       <handler
             class="eu.etaxonomy.taxeditor.handler.SwitchUserHandler"
             commandId="eu.etaxonomy.taxeditor.store.operations.showLoginWindow">
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databasePreferences/wizard/DatabasePreferencesPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databasePreferences/wizard/DatabasePreferencesPage.java
new file mode 100755 (executable)
index 0000000..8add565
--- /dev/null
@@ -0,0 +1,223 @@
+// $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.databasePreferences.wizard;
+
+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.jface.preference.IPreferenceStore;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.IWizardPage;
+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.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+
+/**
+ * @author k.luther
+ * @date 01.11.2016
+ *
+ */
+public class DatabasePreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage, IWizardPage {
+
+    /**
+     * The wizard to which this page belongs; <code>null</code>
+     * if this page has yet to be added to a wizard.
+     */
+    private IWizard wizard = null;
+
+    /**
+     * Indicates whether this page is complete.
+     */
+    private boolean isPageComplete = true;
+
+    /**
+     * The page that was shown right before this page became visible;
+     * <code>null</code> if none.
+     */
+    private IWizardPage previousPage = null;
+
+    CdmPreference preferedNomenclaturalCode;
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+     */
+    @Override
+    public void init(IWorkbench workbench) {
+        setPreferenceStore(TaxeditorStorePlugin.getDefault()
+                .getPreferenceStore());
+
+        preferedNomenclaturalCode = PreferencesUtil.setPreferredNomenclaturalCode(null, false);
+        if (super.getPreferenceStore()== null){
+            setPreferenceStore(PreferencesUtil.getPreferenceStore());
+        }
+
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
+     */
+    @Override
+    protected void createFieldEditors() {
+        setMessage("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified.");
+        ComboFieldEditor nomenclaturalCode = new ComboFieldEditor(
+                IPreferenceKeys.CDM_NOMENCLATURAL_CODE_KEY,
+                "Available Codes", getLabelAndValues(),
+                getFieldEditorParent());
+        nomenclaturalCode.setPreferenceStore(PreferencesUtil.getPreferenceStore());
+        addField(nomenclaturalCode);
+        BooleanFieldEditor allowOverride = new BooleanFieldEditor(
+                IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY,
+                "allow to use local preference",
+                getFieldEditorParent());
+        allowOverride.setPreferenceStore(PreferencesUtil.getPreferenceStore());
+        addField(allowOverride);
+
+
+    }
+
+    /**
+     * Returns the preference store of this preference page.
+     * <p>
+     * This is a framework hook method for subclasses to return a
+     * page-specific preference store. The default implementation
+     * returns <code>null</code>.
+     * </p>
+     *
+     * @return the preference store, or <code>null</code> if none
+     */
+    @Override
+    protected IPreferenceStore doGetPreferenceStore() {
+        return PreferencesUtil.getPreferenceStore();
+    }
+
+    /**
+     * @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() {
+       if (super.getPreferenceStore()== null){
+           setPreferenceStore(PreferencesUtil.getPreferenceStore());
+       }
+       boolean result = super.performOk();
+       if (result){
+           String value =getPreferenceStore().getString(IPreferenceKeys.CDM_NOMENCLATURAL_CODE_KEY);
+           boolean allowOverride =  getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY);
+           CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.NomenclaturalCode, value);
+           pref.setAllowOverride(allowOverride);
+           ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
+           if (controller == null){
+               return false;
+           }
+           IPreferenceService service = controller.getPreferenceService();
+           service.set(pref);
+       }
+       return result;
+   }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean canFlipToNextPage() {
+        // TODO Auto-generated method stub
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getName() {
+
+        return "Database Preferences";
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IWizardPage getNextPage() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IWizardPage getPreviousPage() {
+
+        return previousPage;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IWizard getWizard() {
+
+        return wizard;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isPageComplete() {
+
+        return isPageComplete;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setPreviousPage(IWizardPage page) {
+        this.previousPage = page;
+
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setWizard(IWizard newWizard) {
+        this.wizard = newWizard;
+
+    }
+
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databasePreferences/wizard/DatabasePreferencesWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databasePreferences/wizard/DatabasePreferencesWizard.java
new file mode 100755 (executable)
index 0000000..f848887
--- /dev/null
@@ -0,0 +1,59 @@
+/**
+* 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.databasePreferences.wizard;
+
+import org.eclipse.jface.wizard.Wizard;
+
+/**
+ * @author k.luther
+ * @date 18.11.2016
+ *
+ */
+public class DatabasePreferencesWizard extends Wizard {
+
+
+    private final DatabasePreferencesPage preferencePage;
+
+
+    public DatabasePreferencesWizard() {
+        setWindowTitle("Database Preferences Wizard");
+
+        preferencePage = new DatabasePreferencesPage();
+       // preferencePage.setDescription("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified.");
+       // preferencePage.init(PlatformUI.getWorkbench());
+    }
+
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean performFinish() {
+        if (preferencePage.isPageComplete()){
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * @return the preferencePage
+     */
+    public DatabasePreferencesPage getPreferencePage() {
+        return preferencePage;
+    }
+
+    @Override
+    public void addPages() {
+        addPage(preferencePage);
+    }
+
+
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenDatabasePreferencesWizardHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenDatabasePreferencesWizardHandler.java
new file mode 100755 (executable)
index 0000000..8b46da5
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+* 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.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.wizard.WizardDialog;
+
+import eu.etaxonomy.taxeditor.databasePreferences.wizard.DatabasePreferencesWizard;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
+
+/**
+ * @author k.luther
+ * @date 18.11.2016
+ *
+ */
+public class OpenDatabasePreferencesWizardHandler  extends AbstractHandler{
+
+    String commandID = "eu.etaxonomy.taxeditor.store.open.OpenDatabasePreferencesWizardHandler";
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        DatabasePreferencesWizard databasePreferencesWizard = new DatabasePreferencesWizard();
+        WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
+                databasePreferencesWizard);
+
+        dialog.open();
+
+        return null;
+    }
+
+}
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
deleted file mode 100755 (executable)
index 40ec6fb..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-// $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);
-           String allowOverride =  getPreferenceStore().getString(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY);
-           CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.NomenclaturalCode, value);
-           pref.setAllowOverride(Boolean.parseBoolean(allowOverride));
-           ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
-           if (controller == null){
-               return false;
-           }
-           IPreferenceService service = controller.getPreferenceService();
-           service.set(pref);
-       }
-       return result;
-   }
-
-
-}
index 521a6a304faf6bbc57f54f744330ab90e8030e97..212cb992dbcc65f3b5ac0768aba663ee019c1dcb 100644 (file)
@@ -16,8 +16,15 @@ 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.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;
 
 /**
@@ -41,6 +48,7 @@ public class NomenclaturalCodePreferences extends FieldEditorPreferencePage
         */
        @Override
        protected void createFieldEditors() {
+           PreferencesUtil.setPreferredNomenclaturalCode(null, false);
            if (getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY)) {
                addField(new ComboFieldEditor(
                                IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY,
@@ -84,12 +92,19 @@ public class NomenclaturalCodePreferences extends FieldEditorPreferencePage
                setPreferenceStore(TaxeditorStorePlugin.getDefault()
                                .getPreferenceStore());
 
+             ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
+          if (controller != null){
+              IPreferenceService service = controller.getPreferenceService();
+              PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
+              CdmPreference pref = service.find(key);
+              getPreferenceStore().setValue(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, pref.isAllowOverride());
+          }
+
            if (getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY)) {
                setDescription("Choose which nomenclatural code you would like to use in your local application for scientific names unless otherwise specified.");
            }else{
                setDescription("The CDM settings don't allow to set the nomenclatural code locally. If you need to make local settings, please ask an administrator.");
 
-               //PreferencesUtil.setPreferredNomenclaturalCode(null, true);
            }
        }
 
index 44662fe1699dc645538aed240925776d70aa96df..c17c9e4afcbdc494683a6733b858e824deed706d 100644 (file)
@@ -107,7 +107,7 @@ public class PreferencesUtil implements IPreferenceKeys {
         *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
         *            object.
         */
-       public static NomenclaturalCode setPreferredNomenclaturalCode(
+       public static CdmPreference setPreferredNomenclaturalCode(
                        NomenclaturalCode preferredCode, boolean local) {
            if (local){
                getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
@@ -129,7 +129,11 @@ public class PreferencesUtil implements IPreferenceKeys {
                                int index = StringUtils.lastIndexOf(preference.getValue(), ".");
                                UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
                                preferredCode = NomenclaturalCode.getByUuid(uuid);
-                               return preferredCode;
+
+                               getPreferenceStore().setValue(CDM_NOMENCLATURAL_CODE_KEY,
+                           getPreferenceKey(preferredCode));
+                               getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY,preference.isAllowOverride());
+                               return preference;
                        }
                } else{
                        preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferredCode.getKey());
@@ -137,7 +141,7 @@ public class PreferencesUtil implements IPreferenceKeys {
 
                }
            }
-        return preferredCode;
+        return null;
 
 
 
@@ -486,28 +490,36 @@ public class PreferencesUtil implements IPreferenceKeys {
 
                if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
                        PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP, true);
-                       /*
-
-                       StoreUtil.info("No nomencatural code set.");
-
-                       Shell shell = StoreUtil.getShell();
-
-                Query user re: preferred nom. code
-                       Dialog dialog = new InitNomenclaturalCodePrefDialog(shell);
-                       dialog.open();
-
-                       // Short message confirming user's choice
-                       NomenclaturalCode code = PreferencesUtil
-                                       .getPreferredNomenclaturalCode();
-                       MessageDialog
-                                       .openInformation(
-                                                       shell,
-                                                       "Nomenclatural code set",
-                                                       "The following has been set as your preferred nomenclatural code:\n\n\t"
-                                                                       + NomenclaturalCodeHelper
-                                                                                       .getDescription(code)
-                                                                       + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");*/
                }
+
+
+
+       }
+       public static void setNomenclaturalCodePreferences(){
+       ICdmApplicationConfiguration controller;
+        controller = CdmStore.getCurrentApplicationConfiguration();
+        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
+        CdmPreference preference = null;
+        if (controller == null){
+            return ;
+        }
+        preference = controller.getPreferenceService().find(key);
+        if (preference == null){
+            return;
+        }
+        getPreferenceStore().setValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
+
+        int index = StringUtils.lastIndexOf(preference.getValue(), ".");
+        UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
+        NomenclaturalCode preferredCode = NomenclaturalCode.getByUuid(uuid);
+
+        getPreferenceStore().setValue(CDM_NOMENCLATURAL_CODE_KEY,
+                getPreferenceKey(preferredCode));
+
+        if (!preference.isAllowOverride()){
+            getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
+                    getPreferenceKey(preferredCode));
+        }
        }
 
        public static void checkDefaultLanguage(){
index fe8fefb0e692af14122945f30c82e9238426764b..f7bef1fee62072f95f2ad1949a6ebc20886d5cd5 100644 (file)
@@ -479,6 +479,7 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
                        startManagedServer();
                } else {
                        connect();
+                       PreferencesUtil.setNomenclaturalCodePreferences();
                }
        }