ref #7793: add cdm preference to disable multi classification functionality
authorKatja Luther <k.luther@bgbm.org>
Thu, 18 Oct 2018 20:28:36 +0000 (22:28 +0200)
committerKatja Luther <k.luther@bgbm.org>
Thu, 18 Oct 2018 20:32:13 +0000 (22:32 +0200)
eu.etaxonomy.taxeditor.navigation/fragment.e4xmi
eu.etaxonomy.taxeditor.navigation/plugin.xml
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodePropertyTester.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/CloneClassificationHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/CreateClassificationHierarchyHandlerE4.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/NewClassificationHandlerE4.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java

index 947aab9938db2817d5a555e7adde289a76c10307..87fb52873882feb9ba4deca634b34bc210327ec7 100644 (file)
@@ -48,7 +48,9 @@
         <children xsi:type="menu:Menu" xmi:id="_yzFmYJIvEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.menu.new" label="%menu.label">
           <children xsi:type="menu:HandledMenuItem" xmi:id="_wzftMJIvEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.menu.new.taxon" label="%command.label.2" command="_Nx06MJIvEeeJAdt8ZUxyaw"/>
           <children xsi:type="menu:MenuSeparator" xmi:id="_33c4IJIvEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.menuseparator.0"/>
-          <children xsi:type="menu:HandledMenuItem" xmi:id="_4dTXMJIvEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.menu.new.classification" label="%command.label.3" command="_Vco-4JIxEeeJAdt8ZUxyaw"/>
+          <children xsi:type="menu:HandledMenuItem" xmi:id="_4dTXMJIvEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.menu.new.classification" label="%command.label.3" command="_Vco-4JIxEeeJAdt8ZUxyaw">
+            <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_wlrJYNMPEeiXranio7VdMQ" coreExpressionId="noClassificationExists"/>
+          </children>
         </children>
         <children xsi:type="menu:MenuSeparator" xmi:id="_24NMMJIwEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.menuseparator.5"/>
         <children xsi:type="menu:DynamicMenuContribution" xmi:id="_3d1BwJIwEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.dynamicmenucontribution.openInCdmViewer" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.CdmViewerContextMenuE4"/>
index 51afdea223962612db89de8ce3408bcf59aea7de..e042b30380114480948c45f136d52bfe7219e752 100644 (file)
@@ -46,7 +46,7 @@
             class="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodePropertyTester"
             id="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester"
             namespace="eu.etaxonomy.taxeditor.navigation.navigator.navigatorPropertyTester"
-            properties="hasSynonyms,isClassification,isUnplaced,isExcluded"
+            properties="hasSynonyms,isClassification,isUnplaced,isExcluded,noClassificationExists"
             type="java.lang.Object">
       </propertyTester>
       
                property="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodePropertyTester.isExcluded">
          </test>
       </definition>
+       <definition
+             id="noClassificationExists">
+          <test
+                property="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodePropertyTester.noClassificationExists">
+          </test>
+       </definition>
    </extension>
+   <definition
+            id="noClassificationExists">
+         <not>
+            <reference 
+               definitionId="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodePropertyTester.noClassificationExists">
+            </reference>
+         </not>
+      </definition>
    <extension
          id="eu.etaxonomy.taxeditor.navigation.workbench.model"
          name="Navigation Workbench Model"
index fe6a1a273ae09138b6656e7d9cbf7efd1d3ec934..bb3caec055b5b5075418ae5c353ecb545dcc2e17 100644 (file)
@@ -11,9 +11,12 @@ import java.util.Collection;
 
 import org.eclipse.core.expressions.PropertyTester;
 
+import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 public class TaxonNodePropertyTester extends PropertyTester {
 
        private static final Object HAS_SYNONYMS = "hasSynonyms"; //$NON-NLS-1$
@@ -21,6 +24,7 @@ public class TaxonNodePropertyTester extends PropertyTester {
        private static final Object IS_CLASSIFICATION = "isClassification"; //$NON-NLS-1$
        private static final Object IS_UNPLACED = "isUnplaced";
        private static final Object IS_EXCLUDED = "isExcluded";
+    private static final Object NO_CLASSIFICATION_EXIST = "noClassificationExist";
        /** {@inheritDoc} */
        @Override
     public boolean test(Object receiver, String property, Object[] args,
@@ -57,7 +61,15 @@ public class TaxonNodePropertyTester extends PropertyTester {
             TaxonNodeDto node = (TaxonNodeDto) receiver;
             return node.isExcluded();
         }
+               if (NO_CLASSIFICATION_EXIST.equals(property)) {
+           return 0 == CdmStore.getService(IClassificationService.class).count(Classification.class);
+        }
 
                return false;
        }
+
+       public static boolean noClassifiactionExists(){
+           int count = CdmStore.getService(IClassificationService.class).count(Classification.class);
+           return 0 == count;
+       }
 }
index 14d98d72cbb9826b7eb027eb6ad871558890fd22..9e0df5b51beecffadfa1f55d46b849b56fa86bbb 100644 (file)
@@ -73,7 +73,8 @@ public class CloneClassificationHandlerE4 {
         canExecute = selection.size()==1
                 && selection.getFirstElement() instanceof TaxonNode
                 && ((TaxonNode) selection.getFirstElement()).getTaxon()==null
-                && PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES);
+                && PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES)
+                && !PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DISABLE_MULTI_CLASSIFICATION);
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index 569f1596b339984f65f2082e8475cd721a929576..07a20d7647635c29bb8740efd7d8ea2ee90e8ef8 100644 (file)
@@ -56,7 +56,8 @@ public class CreateClassificationHierarchyHandlerE4 {
         canExecute = selection.size()==1
                 && selection.getFirstElement() instanceof TaxonNode
                 && ((TaxonNode) selection.getFirstElement()).getTaxon()==null
-                && PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES);
+                && PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES)
+                && !PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DISABLE_MULTI_CLASSIFICATION);
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index 19e6cef007e405f0e971e3dcf9d7b9bac347891d..c5947195cc030cd785acc70857313922bb796b0f 100644 (file)
@@ -11,14 +11,19 @@ package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
 
 import javax.inject.Named;
 
+import org.eclipse.e4.core.di.annotations.CanExecute;
 import org.eclipse.e4.core.di.annotations.Execute;
 import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
 import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.viewers.ITreeSelection;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.widgets.Shell;
 
+import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodePropertyTester;
 import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 
 /**
  *
@@ -37,4 +42,13 @@ public class NewClassificationHandlerE4 {
                dialog.open();
 
        }
+
+    @CanExecute
+    private boolean canExecute(MHandledMenuItem menuItem){
+        boolean canExecute = false;
+
+        canExecute = TaxonNodePropertyTester.noClassifiactionExists() || !PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DISABLE_MULTI_CLASSIFICATION);
+        menuItem.setVisible(canExecute);
+        return canExecute;
+    }
 }
index b72b4b342af3e159a4d664bdd937a0141e2b4f46..82f64da5cd5f1ce3e16af6a542a1c887ab7c435d 100644 (file)
@@ -252,6 +252,11 @@ public interface IPreferenceKeys {
     public static final String SHOW_TAXONNODE_WIZARD = "eu.etaxonomy.taxeditor.menu.showTaxonNodeWizard";
     public static final String IS_SEARCH_FOR_IDENTIFIER_AS_DEFAULT = "eu.etaxonomy.taxeditor.search.reference.defaultIdentifier";
     public static final String SEARCH_FOR_IDENTIFIER_AND_TITLECACHE = "eu.etaxonomy.taxeditor.search.reference.identifierAndTitleCache";
+    public static final String DISABLE_MULTI_CLASSIFICATION = "eu.etaxonomy.taxeditor.classification.multi";
+
+    public static final String SHOW_ID_IN_SOURCE = "eu.etaxonomy.taxeditor.source.detail.IdInSource";
+    public static final String SHOW_NAME_IN_SOURCE = "eu.etaxonomy.taxeditor.source.detail.nameInSource";
+
 
 
 
index 5198de1bfa5751974318490483ee35b342d1186d..7b077f2f4c0c6a1339399b7c9f481860fea3e89e 100644 (file)
@@ -606,7 +606,10 @@ public class PreferencesUtil implements IPreferenceKeys {
 
                getPreferenceStore().setDefault(FILTER_COMMON_NAME_REFERENCES, false);
                getPreferenceStore().setDefault(SHOW_SPECIMEN, true);
-               getPreferenceStore().setDefault(SHOW_TAXONNODE_WIZARD, false);
+               getPreferenceStore().setDefault(SHOW_TAXONNODE_WIZARD, true);
+               getPreferenceStore().setDefault(SHOW_NAME_IN_SOURCE, true);
+               getPreferenceStore().setDefault(SHOW_ID_IN_SOURCE, true);
+               getPreferenceStore().setDefault(DISABLE_MULTI_CLASSIFICATION, false);
 
        }
 
@@ -1732,6 +1735,14 @@ public static void updateDBPreferences() {
         }
     }
 
+    preference = getPreferenceFromDB(PreferencePredicate.UseOnlyReferencesWithCommonNameMarker);
+    if (preference != null){
+        if (!prefStore.getBoolean(FILTER_COMMON_NAME_REFERENCES) ||  !preference.isAllowOverride()){
+            prefStore.setValue(FILTER_COMMON_NAME_REFERENCES, preference.getValue());
+        }
+    }
+
+
     preference = getPreferenceFromDB(PreferencePredicate.ShowTaxonNodeWizard);
     if (preference != null){
         if (!prefStore.getBoolean(SHOW_TAXONNODE_WIZARD) ||  !preference.isAllowOverride()){
@@ -1739,6 +1750,27 @@ public static void updateDBPreferences() {
         }
     }
 
+    preference = getPreferenceFromDB(PreferencePredicate.ShowIdInSource);
+    if (preference != null){
+        if (!prefStore.getBoolean(SHOW_ID_IN_SOURCE) ||  !preference.isAllowOverride()){
+            prefStore.setValue(SHOW_ID_IN_SOURCE, preference.getValue());
+        }
+    }
+
+    preference = getPreferenceFromDB(PreferencePredicate.ShowNameInSource);
+    if (preference != null){
+        if (!prefStore.getBoolean(SHOW_NAME_IN_SOURCE) ||  !preference.isAllowOverride()){
+            prefStore.setValue(SHOW_NAME_IN_SOURCE, preference.getValue());
+        }
+    }
+
+    preference = getPreferenceFromDB(PreferencePredicate.DisableMultiClassification);
+    if (preference != null){
+        if (!prefStore.getBoolean(DISABLE_MULTI_CLASSIFICATION) ||  !preference.isAllowOverride()){
+            prefStore.setValue(DISABLE_MULTI_CLASSIFICATION, preference.getValue());
+        }
+    }
+
 }