From 32103a77f2254b12499008fd4873046fe2e13ac5 Mon Sep 17 00:00:00 2001 From: Alexander Oppermann Date: Wed, 18 Mar 2015 15:02:05 +0000 Subject: [PATCH 1/1] Added Create Hierarchy Service for Editor as a experimental feature --- .gitattributes | 1 + eu.etaxonomy.taxeditor.editor/plugin.xml | 9 +++ .../FixClassificationHierarchyHandler.java | 60 +++++++++++++++++++ eu.etaxonomy.taxeditor.navigation/plugin.xml | 32 ++++++++++ 4 files changed, 102 insertions(+) create mode 100644 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/FixClassificationHierarchyHandler.java diff --git a/.gitattributes b/.gitattributes index 292f101cf..f9fd22985 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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/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 diff --git a/eu.etaxonomy.taxeditor.editor/plugin.xml b/eu.etaxonomy.taxeditor.editor/plugin.xml index 53080cc47..f81c57b2c 100644 --- a/eu.etaxonomy.taxeditor.editor/plugin.xml +++ b/eu.etaxonomy.taxeditor.editor/plugin.xml @@ -1103,6 +1103,10 @@ class="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.ToggleShowOnlyIndividualAssociationsHandler" commandId="eu.etaxonomy.taxeditor.editor.handler.showOnlyIndividualAssociations"> + + + + 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 index 000000000..aeff573a8 --- /dev/null +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/FixClassificationHierarchyHandler.java @@ -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> 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; + } +} diff --git a/eu.etaxonomy.taxeditor.navigation/plugin.xml b/eu.etaxonomy.taxeditor.navigation/plugin.xml index 78ff843f3..74a06c5b4 100644 --- a/eu.etaxonomy.taxeditor.navigation/plugin.xml +++ b/eu.etaxonomy.taxeditor.navigation/plugin.xml @@ -127,6 +127,22 @@ + + + + + + + + + + @@ -670,6 +686,13 @@ properties="isCdmStoreConnected" type="org.eclipse.jface.viewers.IStructuredSelection"> + + @@ -727,5 +750,14 @@ + + + + + + -- 2.34.1