ref #4867 Implement "Clone Classification" functionality
authorPatrick Plitzner <p.plitzner@bgbm.org>
Sun, 6 Nov 2016 13:21:10 +0000 (14:21 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Sun, 6 Nov 2016 13:21:10 +0000 (14:21 +0100)
 - availabel via context menu in taxon navigator
 - parameters available: classification name, taxon relation from cloned
taxa to original taxa
 - sec reference

eu.etaxonomy.taxeditor.navigation/plugin.xml
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/CloneClassificationHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CloneClassificationOperation.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/CloneClassificationDetailElement.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/CloneClassificationWizard.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/CloneClassificationWizardPage.java [new file with mode: 0644]

index be4c61af80e4f663d7ba7a28cf6902b6c7466f29..4b6e4e62117585791021a05d366a69ef57303bfc 100644 (file)
                </and>
             </visibleWhen>
          </command>
+         <command
+               commandId="eu.etaxonomy.taxeditor.navigation.cloneClassification"
+               label="Clone Classification"
+               style="push">
+            <visibleWhen
+                  checkEnabled="true">
+               <and>
+                  <reference
+                        definitionId="isShowExperimentalFeatures">
+                  </reference>
+                  <reference
+                        definitionId="isClassification">
+                  </reference>
+               </and>
+            </visibleWhen>
+         </command>
          <separator
                name="taxeditor-navigation.separator1"
                visible="true">
             id="eu.etaxonomy.taxeditor.navigation.key.polytomous.command.delete"
             name="%command.name.11">
       </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.navigation.navigator.handler.CloneClassificationHandler"
+            id="eu.etaxonomy.taxeditor.navigation.cloneClassification"
+            name="Clone Classification">
+      </command>
    </extension>
    <extension
          point="org.eclipse.ui.handlers">
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 (file)
index 0000000..8152bae
--- /dev/null
@@ -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 (file)
index 0000000..cd335ea
--- /dev/null
@@ -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 (file)
index 0000000..957e4ed
--- /dev/null
@@ -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<Classification>{
+
+    private TextWithLabelElement txtClassificationName;
+    private TermComboElement<TaxonRelationshipType> comboRelationType;
+    private EntitySelectionElement<Reference> 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();
+    }
+
+}
index 12f8a0af70c009be2d4ce584ca40748179034b1a..13033b4e6fbb5cc62f0e633290c1e2ceb460d8a9 100644 (file)
@@ -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 <T extends DefinedTermBase> TermComboElement<T> 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 (file)
index 0000000..4b9e65d
--- /dev/null
@@ -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 (file)
index 0000000..5935d5a
--- /dev/null
@@ -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<Classification> {
+
+       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();
+    }
+
+}