From: Patrick Plitzner
Date: Sun, 6 Nov 2016 13:21:10 +0000 (+0100)
Subject: ref #4867 Implement "Clone Classification" functionality
X-Git-Tag: 4.4.0^2~66
X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/5d3fd02f9b2c89750b32d616f847cbf1bdce4673?hp=08a29cf3c005e270c1290aa5aba0ae7053b51564
ref #4867 Implement "Clone Classification" functionality
- availabel via context menu in taxon navigator
- parameters available: classification name, taxon relation from cloned
taxa to original taxa
- sec reference
---
diff --git a/eu.etaxonomy.taxeditor.navigation/plugin.xml b/eu.etaxonomy.taxeditor.navigation/plugin.xml
index be4c61af8..4b6e4e621 100644
--- a/eu.etaxonomy.taxeditor.navigation/plugin.xml
+++ b/eu.etaxonomy.taxeditor.navigation/plugin.xml
@@ -150,6 +150,22 @@
+
+
+
+
+
+
+
+
+
+
@@ -451,6 +467,11 @@
id="eu.etaxonomy.taxeditor.navigation.key.polytomous.command.delete"
name="%command.name.11">
+
+
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/CloneClassificationHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/CloneClassificationHandler.java
new file mode 100644
index 000000000..8152bae9e
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/CloneClassificationHandler.java
@@ -0,0 +1,55 @@
+package eu.etaxonomy.taxeditor.navigation.navigator.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.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
+import eu.etaxonomy.taxeditor.navigation.operation.CloneClassificationOperation;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
+import eu.etaxonomy.taxeditor.ui.section.classification.CloneClassificationWizard;
+
+public class CloneClassificationHandler extends AbstractHandler {
+
+ @SuppressWarnings("unused")
+ private static final Logger logger = Logger.getLogger(CloneClassificationHandler.class);
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+ if (currentSelection instanceof IStructuredSelection) {
+ Object selectedElement = ((IStructuredSelection) currentSelection).getFirstElement();
+ if (selectedElement instanceof Classification) {
+ Classification classification = (Classification) selectedElement;
+ TaxonNavigator taxonNavigator = (TaxonNavigator)AbstractUtility.showView(TaxonNavigator.ID);
+ CloneClassificationWizard wizard = new CloneClassificationWizard(classification);
+ WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
+ dialog.open();
+
+ String classificationName = wizard.getClassificationName();
+ TaxonRelationshipType relationType = wizard.getRelationType();
+ Reference reference = wizard.getReference();
+
+ CloneClassificationOperation operation = new CloneClassificationOperation("Clone classification",
+ StoreUtil.getUndoContext(), classification, classificationName, reference, relationType,
+ NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false));
+
+ AbstractUtility.executeOperation(operation);
+ taxonNavigator.refresh();
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CloneClassificationOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CloneClassificationOperation.java
new file mode 100644
index 000000000..cd335ea56
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CloneClassificationOperation.java
@@ -0,0 +1,76 @@
+// $Id$
+/**
+* Copyright (C) 2015 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.navigation.operation;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
+import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ *
+ * @author pplitzner
+ *
+ */
+public class CloneClassificationOperation extends AbstractPersistentPostOperation {
+
+ private final Classification classification;
+
+ private final IClassificationService service;
+
+ private String classificationName;
+
+ private Reference sec;
+
+ private TaxonRelationshipType relationType;
+
+ public CloneClassificationOperation(String label, IUndoContext undoContext, Classification classification,
+ String classificationName, Reference sec, TaxonRelationshipType relationType,
+ IPostOperationEnabled postOperationEnabled,
+ IConversationEnabled conversationEnabled) {
+ super(label, undoContext, postOperationEnabled, conversationEnabled);
+
+ this.classification = classification;
+ this.classificationName = classificationName;
+ this.sec = sec;
+ this.relationType = relationType;
+ this.service = CdmStore.getService(IClassificationService.class);
+
+ }
+
+ @Override
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ UpdateResult result = service.cloneClassification(classification.getUuid(), classificationName, sec, relationType);
+ return postExecute(result.getCdmEntity());
+ }
+
+ @Override
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ return null;
+ }
+
+ @Override
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ return null;
+ }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/CloneClassificationDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/CloneClassificationDetailElement.java
new file mode 100644
index 000000000..957e4ed34
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/CloneClassificationDetailElement.java
@@ -0,0 +1,62 @@
+// $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.ui.dialog;
+
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
+import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
+
+/**
+ * @author pplitzner
+ * @date Nov 6, 2016
+ *
+ */
+public class CloneClassificationDetailElement extends
+AbstractCdmDetailElement{
+
+ private TextWithLabelElement txtClassificationName;
+ private TermComboElement comboRelationType;
+ private EntitySelectionElement selectReference;
+
+ public CloneClassificationDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
+ super(formFactory, formElement);
+ }
+
+ @Override
+ protected void createControls(ICdmFormElement formElement, Classification entity, int style) {
+ txtClassificationName = formFactory.createTextWithLabelElement(formElement, "Classification name", null, style);
+ comboRelationType = formFactory.createDefinedTermComboElement(TermType.TaxonRelationshipType, formElement, "Taxon relation", null, style);
+ selectReference = formFactory.createSelectionElement(Reference.class, getConversationHolder(), formElement, "Reference", null, EntitySelectionElement.SELECTABLE, style);
+ }
+
+ @Override
+ public void handleEvent(Object eventSource) {
+ }
+
+ public String getClassificationName(){
+ return txtClassificationName.getText();
+ }
+
+ public TaxonRelationshipType getRelationType(){
+ return comboRelationType.getSelection();
+ }
+
+ public Reference getReference(){
+ return selectReference.getSelection();
+ }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
index 12f8a0af7..13033b4e6 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
@@ -110,6 +110,7 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
import eu.etaxonomy.taxeditor.ui.combo.VocabularyComboElement;
+import eu.etaxonomy.taxeditor.ui.dialog.CloneClassificationDetailElement;
import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection.UnitType;
import eu.etaxonomy.taxeditor.ui.mvc.element.DateElement;
import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
@@ -944,7 +945,7 @@ public class CdmFormFactory extends FormToolkit {
parentElement.addElement(element);
return element;
}
-
+
public TermComboElement createDefinedTermComboElement(
TermVocabulary> termVocabulary,
@@ -2050,6 +2051,12 @@ public class CdmFormFactory extends FormToolkit {
return element;
}
+ public CloneClassificationDetailElement createCloneClassificationDetailElement(ICdmFormElement parentElement){
+ CloneClassificationDetailElement element = new CloneClassificationDetailElement(this, parentElement);
+ addAndAdaptElement(parentElement, element);
+ return element;
+ }
+
public FeatureDistributionDetailElement createFeatureDistributionDetailElement(ICdmFormElement parentElement){
FeatureDistributionDetailElement element = new FeatureDistributionDetailElement(this, parentElement);
addAndAdaptElement(parentElement, element);
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/CloneClassificationWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/CloneClassificationWizard.java
new file mode 100644
index 000000000..4b9e65d4e
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/CloneClassificationWizard.java
@@ -0,0 +1,81 @@
+// $Id$
+/**
+* Copyright (C) 2007 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.ui.section.classification;
+
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.widgets.Display;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+
+/**
+ *
+ * @author pplitzner
+ * @date Nov 6, 2016
+ *
+ */
+
+public class CloneClassificationWizard extends Wizard{
+
+ private CloneClassificationWizardPage cloneClassificationWizardPage;
+
+ private ConversationHolder conversationHolder;
+
+ private CdmFormFactory formFactory;
+
+ private String classificationName;
+
+ private TaxonRelationshipType relationType;
+
+ private Reference reference;
+
+ public CloneClassificationWizard(Classification classification) {
+ super();
+ conversationHolder = CdmStore.createConversation();
+ formFactory = new CdmFormFactory(Display.getCurrent(), null);
+ cloneClassificationWizardPage = new CloneClassificationWizardPage(formFactory, conversationHolder, classification);
+ addPage(cloneClassificationWizardPage);
+ }
+
+
+ @Override
+ public boolean canFinish() {
+ return cloneClassificationWizardPage.getClassificationName()!=null
+ && cloneClassificationWizardPage.getRelationType()!=null &&
+ cloneClassificationWizardPage.getReference()!=null;
+ }
+
+ @Override
+ public boolean performFinish() {
+ classificationName = cloneClassificationWizardPage.getClassificationName();
+ relationType = cloneClassificationWizardPage.getRelationType();
+ reference = cloneClassificationWizardPage.getReference();
+ return true;
+ }
+
+
+ public String getClassificationName(){
+ return classificationName;
+ }
+
+ public TaxonRelationshipType getRelationType(){
+ return relationType;
+ }
+
+ public Reference getReference(){
+ return reference;
+ }
+
+}
\ No newline at end of file
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/CloneClassificationWizardPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/CloneClassificationWizardPage.java
new file mode 100644
index 000000000..5935d5a1f
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/CloneClassificationWizardPage.java
@@ -0,0 +1,59 @@
+// $Id$
+/**
+ * Copyright (C) 2007 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.ui.section.classification;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
+import eu.etaxonomy.taxeditor.ui.dialog.CloneClassificationDetailElement;
+import eu.etaxonomy.taxeditor.ui.element.AbstractCdmEntityWizardPage;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+
+/**
+ *
+ * @author pplitzner
+ * @date Nov 6, 2016
+ *
+ */
+public class CloneClassificationWizardPage extends
+ AbstractCdmEntityWizardPage {
+
+ private CloneClassificationDetailElement detailElement;
+
+ public CloneClassificationWizardPage(CdmFormFactory formFactory,
+ ConversationHolder conversation, Classification entity) {
+ super(formFactory, conversation, entity);
+ setTitle("Clone Classification");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public CloneClassificationDetailElement createElement(ICdmFormElement rootElement) {
+ detailElement = formFactory.createCloneClassificationDetailElement(rootElement);
+ detailElement.setEntity(getEntity());
+ return detailElement;
+ }
+
+ public String getClassificationName(){
+ return detailElement.getClassificationName();
+ }
+
+ public TaxonRelationshipType getRelationType(){
+ return detailElement.getRelationType();
+ }
+
+ public Reference getReference(){
+ return detailElement.getReference();
+ }
+
+}