From 72c03cfb0a99897b8fe87d7b55e72dee8147f22b Mon Sep 17 00:00:00 2001 From: Patrick Plitzner Date: Thu, 22 Feb 2018 10:49:41 +0100 Subject: [PATCH] ref #6806 Add "Add child feature" to feature tree editor context menu --- eu.etaxonomy.taxeditor.store/fragment.e4xmi | 3 + .../e4/handler/AddChildFeatureHandler.java | 66 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddChildFeatureHandler.java diff --git a/eu.etaxonomy.taxeditor.store/fragment.e4xmi b/eu.etaxonomy.taxeditor.store/fragment.e4xmi index 140b78b11..aa37367de 100644 --- a/eu.etaxonomy.taxeditor.store/fragment.e4xmi +++ b/eu.etaxonomy.taxeditor.store/fragment.e4xmi @@ -12,8 +12,10 @@ + + @@ -118,6 +120,7 @@ + diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddChildFeatureHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddChildFeatureHandler.java new file mode 100644 index 000000000..3c31c7fc6 --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddChildFeatureHandler.java @@ -0,0 +1,66 @@ +/** +* Copyright (C) 2017 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.featuretree.e4.handler; + +import java.util.Collection; + +import javax.inject.Named; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Shell; + +import eu.etaxonomy.cdm.api.service.IFeatureNodeService; +import eu.etaxonomy.cdm.model.description.Feature; +import eu.etaxonomy.cdm.model.description.FeatureNode; +import eu.etaxonomy.taxeditor.featuretree.AvailableFeaturesWizard; +import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor; +import eu.etaxonomy.taxeditor.store.CdmStore; + +/** + * @author pplitzner + * @since Jul 12, 2017 + * + */ +public class AddChildFeatureHandler { + + @Execute + public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, + @Named(IServiceConstants.ACTIVE_PART)MPart thisPart, + @Named(IServiceConstants.ACTIVE_SELECTION)Object selection) { + FeatureTreeEditor editor = ((FeatureTreeEditor) thisPart.getObject()); + AvailableFeaturesWizard wizard = new AvailableFeaturesWizard(); + WizardDialog dialog = new WizardDialog(shell, wizard); + + if (dialog.open() == IStatus.OK && selection instanceof FeatureNode) { + FeatureNode parent = (FeatureNode)selection; + Collection additionalFeatures = wizard.getAdditionalFeatures(); + for (Feature feature : additionalFeatures) { + if (!editor.getSelectedFeatureTree().getDistinctFeatures().contains(feature)) { + CdmStore.getService(IFeatureNodeService.class).addChildFeatureNode(parent.getUuid(), feature.getUuid()); + } + } + thisPart.setDirty(true); + editor.getViewer().refresh(); + editor.getViewer().expandToLevel(parent, 1); + } + } + + @CanExecute + public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart, + @Named(IServiceConstants.ACTIVE_SELECTION)Object selection) { + return thisPart.getObject() instanceof FeatureTreeEditor + && ((FeatureTreeEditor) thisPart.getObject()).getSelectedFeatureTree()!=null + && selection instanceof FeatureNode; + } +} -- 2.34.1