Added Create Hierarchy Service for Editor as a experimental feature
authorAlexander Oppermann <a.oppermann@bgbm.org>
Wed, 18 Mar 2015 15:02:05 +0000 (15:02 +0000)
committerAlexander Oppermann <a.oppermann@bgbm.org>
Wed, 18 Mar 2015 15:02:05 +0000 (15:02 +0000)
.gitattributes
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/FixClassificationHierarchyHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/plugin.xml

index 292f101cf9512954698985d661e6b37aee591019..f9fd22985109d0ac0c8808770fa110b8f7c6fdac 100644 (file)
@@ -391,6 +391,7 @@ eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditorInput.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/handler/EditCdmAuthoritiesHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/EditNewTaxonHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditorInput.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/handler/EditCdmAuthoritiesHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/EditNewTaxonHandler.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/FixClassificationHierarchyHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenChecklistEditorHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenDerivateViewHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenParentHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenChecklistEditorHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenDerivateViewHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenParentHandler.java -text
index 53080cc47d69177e2a1509e581dcb603f1e19765..f81c57b2c1529f436b4082807478c167206e2a44 100644 (file)
             class="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.ToggleShowOnlyIndividualAssociationsHandler"
             commandId="eu.etaxonomy.taxeditor.editor.handler.showOnlyIndividualAssociations">
       </handler>
             class="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.ToggleShowOnlyIndividualAssociationsHandler"
             commandId="eu.etaxonomy.taxeditor.editor.handler.showOnlyIndividualAssociations">
       </handler>
+      <handler
+            class="eu.etaxonomy.taxeditor.editor.handler.FixClassificationHierarchyHandler"
+            commandId="eu.etaxonomy.taxeditor.editor.handler.FixClassificationHierarchyHandler">
+      </handler>
    </extension>
    <extension
          name="%extension.name"
    </extension>
    <extension
          name="%extension.name"
             id="eu.etaxonomy.taxeditor.editor.derivate.deepDelete"
             name="Deep Delete">
       </command>
             id="eu.etaxonomy.taxeditor.editor.derivate.deepDelete"
             name="Deep Delete">
       </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.editor.handler.FixClassificationHierarchyHandler"
+            id="eu.etaxonomy.taxeditor.editor.handler.OpenFixClassificationHierarchyHandler"
+            name="Fix Classification Hierarchy">
+      </command>
    </extension>
    <extension
          point="org.eclipse.core.expressions.definitions">
    </extension>
    <extension
          point="org.eclipse.core.expressions.definitions">
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/FixClassificationHierarchyHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/FixClassificationHierarchyHandler.java
new file mode 100644 (file)
index 0000000..aeff573
--- /dev/null
@@ -0,0 +1,60 @@
+package eu.etaxonomy.taxeditor.editor.handler;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+public class FixClassificationHierarchyHandler extends AbstractHandler {
+
+    private static final Logger logger = Logger.getLogger(FixClassificationHierarchyHandler.class);
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
+     * ExecutionEvent)
+     */
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        boolean isChecklistEditorActivated = PreferencesUtil.getPreferenceStore().getBoolean(
+                IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE);
+        if (isChecklistEditorActivated) {
+            ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+            if (currentSelection instanceof IStructuredSelection) {
+                Object selectedElement = ((IStructuredSelection) currentSelection).getFirstElement();
+                if (selectedElement instanceof Classification) {
+
+                    Classification classification = (Classification) selectedElement;
+                    try {
+                        IClassificationService service = CdmStore.getService(IClassificationService.class);
+
+                        // Map<String, List<TaxonNode>> sortedGenusList =
+                        // service.getSortedGenusList(classification.getAllNodes());
+
+                        Classification newClassification = service.createHierarchyInClassification(classification, null);
+
+                        MessagingUtils.messageDialog("Fix Hierarchy successful",
+                                FixClassificationHierarchyHandler.class, "Operation 'Fix Hierarchy' was successful. New classification is " + newClassification.getTitleCache());
+
+                    } catch (Exception e) {
+                        MessagingUtils.messageDialog("Failed to open Editor", FixClassificationHierarchyHandler.class,
+                                "Could not open ChecklistView. The hierarchy is corrupted!", e);
+                    }
+                }
+            }
+        }
+        return null;
+    }
+}
index 78ff843f3c5f4da5f134f8b7a0fad9adf118164c..74a06c5b4bebf9b977e4c3210a5ebb0f8e7f0c13 100644 (file)
               </and>
             </visibleWhen>
          </command>
               </and>
             </visibleWhen>
          </command>
+         <command
+               commandId="eu.etaxonomy.taxeditor.editor.handler.OpenFixClassificationHierarchyHandler"
+               label="Fix Classification Hierarchy"
+               style="push">
+            <visibleWhen
+                  checkEnabled="true">
+               <and>
+                  <reference
+                        definitionId="isShowExperimentalFeatures">
+                  </reference>
+                  <reference
+                        definitionId="isClassification">
+                  </reference>
+               </and>
+            </visibleWhen>
+         </command>
          <separator
                name="taxeditor-navigation.separator1"
                visible="true">
          <separator
                name="taxeditor-navigation.separator1"
                visible="true">
          properties="isCdmStoreConnected"
          type="org.eclipse.jface.viewers.IStructuredSelection">
    </propertyTester>
          properties="isCdmStoreConnected"
          type="org.eclipse.jface.viewers.IStructuredSelection">
    </propertyTester>
+   <propertyTester
+         class="eu.etaxonomy.taxeditor.preference.PreferencePropertyTester"
+         id="eu.etaxonomy.taxeditor.preferences.propertyTester"
+         namespace="eu.etaxonomy.taxeditor.preferences.propertyTester"
+         properties="isShowExperimentalFeatures"
+         type="org.eclipse.jface.viewers.IStructuredSelection">
+   </propertyTester>
    </extension>
    <extension
          point="org.eclipse.core.expressions.definitions">
    </extension>
    <extension
          point="org.eclipse.core.expressions.definitions">
             </test>
          </with>
       </definition>
             </test>
          </with>
       </definition>
+      <definition
+            id="isShowExperimentalFeatures">
+         <with
+               variable="selection">
+            <test
+                  property="eu.etaxonomy.taxeditor.preferences.propertyTester.isShowExperimentalFeatures">
+            </test>
+         </with>
+      </definition>
    </extension>
 </plugin>
    </extension>
 </plugin>