</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">
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+// $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;
+ }
+
+}
--- /dev/null
+// $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();
+ }
+
+}
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;
parentElement.addElement(element);
return element;
}
-
+
public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
TermVocabulary<?> termVocabulary,
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);
--- /dev/null
+// $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
--- /dev/null
+// $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();
+ }
+
+}