Project

General

Profile

« Previous | Next » 

Revision 72c03cfb

Added by Patrick Plitzner over 4 years ago

ref #6806 Add "Add child feature" to feature tree editor context menu

View differences:

eu.etaxonomy.taxeditor.store/fragment.e4xmi
12 12
      <handlers xmi:id="_H_c_EEq2EeeN-dEYnw7m3g" elementId="eu.etaxonomy.taxeditor.featuretree.handler.SaveHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.SaveHandler" command="_LlbAMEq2EeeN-dEYnw7m3g"/>
13 13
      <handlers xmi:id="_3wq0cGceEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.AddFeatureHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.AddFeatureHandler" command="_oftL0GceEee0qLTtA2ZpVQ"/>
14 14
      <handlers xmi:id="_VSc2UGcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportHandler" command="_I_yx4GcqEee0qLTtA2ZpVQ"/>
15
      <handlers xmi:id="_hPTxMBezEeiXusClKZjycQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.AddChildFeatureHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.AddChildFeatureHandler" command="_aPYxsBezEeiXusClKZjycQ"/>
15 16
      <menus xsi:type="menu:PopupMenu" xmi:id="__Jwh4GceEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.popupmenu.featureTreeEditor">
16 17
        <children xsi:type="menu:HandledMenuItem" xmi:id="_eWBz0GcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.addFeature" label="Add Feature" command="_oftL0GceEee0qLTtA2ZpVQ"/>
18
        <children xsi:type="menu:HandledMenuItem" xmi:id="_jr4E0Be0EeiXusClKZjycQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.addchildfeature" label="Add Child Feature" command="_aPYxsBezEeiXusClKZjycQ"/>
17 19
        <children xsi:type="menu:HandledMenuItem" xmi:id="_Beb6QGcfEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.removeFeature" label="Remove Feature" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
18 20
        <children xsi:type="menu:HandledMenuItem" xmi:id="_7vaEcGcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.exportFeatureTree" label="Export Feature Tree" command="_I_yx4GcqEee0qLTtA2ZpVQ">
19 21
          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_-91IQGcqEee0qLTtA2ZpVQ" coreExpressionId="isShowExperimentalFeatures"/>
......
118 120
    <elements xsi:type="commands:Command" xmi:id="_SXZF8K2gEeeykrJkROy5EA" elementId="eu.etaxonomy.taxeditor.store.openPasswordWizzard" commandName="%command.name.10"/>
119 121
    <elements xsi:type="commands:Command" xmi:id="_dQ0swL-rEeegz7IDD8MJaw" elementId="eu.etaxonomy.taxeditor.store.open.InspectSessionsDialog" commandName="Inspect Session"/>
120 122
    <elements xsi:type="commands:Command" xmi:id="_jSJrsBWPEeiazYUJirF0Pw" elementId="eu.etaxonomy.taxeditor.store.command.update" commandName="Check for updates"/>
123
    <elements xsi:type="commands:Command" xmi:id="_aPYxsBezEeiXusClKZjycQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.addChildFeature" commandName="Add child feature"/>
121 124
  </fragments>
122 125
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_swGH0GhvEee3K4uKJljEYg" featurename="handlers" parentElementId="xpath:/">
123 126
    <elements xsi:type="commands:Handler" xmi:id="_rVEdIGcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddChildFeatureHandler.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.featuretree.e4.handler;
10

  
11
import java.util.Collection;
12

  
13
import javax.inject.Named;
14

  
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.e4.core.di.annotations.CanExecute;
17
import org.eclipse.e4.core.di.annotations.Execute;
18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.jface.wizard.WizardDialog;
21
import org.eclipse.swt.widgets.Shell;
22

  
23
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
24
import eu.etaxonomy.cdm.model.description.Feature;
25
import eu.etaxonomy.cdm.model.description.FeatureNode;
26
import eu.etaxonomy.taxeditor.featuretree.AvailableFeaturesWizard;
27
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

  
30
/**
31
 * @author pplitzner
32
 * @since Jul 12, 2017
33
 *
34
 */
35
public class AddChildFeatureHandler {
36

  
37
    @Execute
38
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
39
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
40
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection) {
41
        FeatureTreeEditor editor = ((FeatureTreeEditor) thisPart.getObject());
42
        AvailableFeaturesWizard wizard = new AvailableFeaturesWizard();
43
        WizardDialog dialog = new WizardDialog(shell, wizard);
44

  
45
        if (dialog.open() == IStatus.OK && selection instanceof FeatureNode) {
46
            FeatureNode parent = (FeatureNode)selection;
47
            Collection<Feature> additionalFeatures = wizard.getAdditionalFeatures();
48
            for (Feature feature : additionalFeatures) {
49
                if (!editor.getSelectedFeatureTree().getDistinctFeatures().contains(feature)) {
50
                    CdmStore.getService(IFeatureNodeService.class).addChildFeatureNode(parent.getUuid(), feature.getUuid());
51
                }
52
            }
53
            thisPart.setDirty(true);
54
            editor.getViewer().refresh();
55
            editor.getViewer().expandToLevel(parent, 1);
56
        }
57
    }
58

  
59
    @CanExecute
60
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
61
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection) {
62
        return thisPart.getObject() instanceof FeatureTreeEditor
63
                && ((FeatureTreeEditor) thisPart.getObject()).getSelectedFeatureTree()!=null
64
                && selection instanceof FeatureNode;
65
    }
66
}

Also available in: Unified diff