Project

General

Profile

Revision 72eff2a6

ID72eff2a6079496f3cfa9f3fea6b0fd837d4a7db0
Parent 6ba01b22
Child d2c6c782

Added by Patrick Plitzner over 1 year ago

ref #6746 Add/adapt handlers for feature tree editor

View differences:

eu.etaxonomy.taxeditor.store/fragment.e4xmi
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 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"/>
16
      <handlers xmi:id="_Bb0TwCFeEeiVXriJfxPIuA" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureTreeHandlers" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureTreeHandler" command="_3mqzkCFdEeiVXriJfxPIuA"/>
16 17
      <menus xsi:type="menu:PopupMenu" xmi:id="__Jwh4GceEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.popupmenu.featureTreeEditor">
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"/>
19
        <children xsi:type="menu:HandledMenuItem" xmi:id="_Beb6QGcfEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.removeFeature" label="Remove Feature" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
20
        <children xsi:type="menu:HandledMenuItem" xmi:id="_7vaEcGcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.exportFeatureTree" label="Export Feature Tree" command="_I_yx4GcqEee0qLTtA2ZpVQ">
18
        <children xsi:type="menu:HandledMenuItem" xmi:id="_jr4E0Be0EeiXusClKZjycQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.addchildfeature" label="Add Child Feature" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/add.gif" command="_aPYxsBezEeiXusClKZjycQ"/>
19
        <children xsi:type="menu:HandledMenuItem" xmi:id="_eWBz0GcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.addFeature" label="Add Feature" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/add.gif" command="_oftL0GceEee0qLTtA2ZpVQ"/>
20
        <children xsi:type="menu:HandledMenuItem" xmi:id="_7vaEcGcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.exportFeatureTree" label="Export Feature Tree" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/export.gif" command="_I_yx4GcqEee0qLTtA2ZpVQ">
21 21
          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_-91IQGcqEee0qLTtA2ZpVQ" coreExpressionId="isShowExperimentalFeatures"/>
22 22
        </children>
23
        <children xsi:type="menu:MenuSeparator" xmi:id="_TFRL0CFgEeiVXriJfxPIuA" elementId="eu.etaxonomy.taxeditor.store.menuseparator.0"/>
24
        <children xsi:type="menu:HandledMenuItem" xmi:id="_Beb6QGcfEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.removeFeature" label="Remove Feature" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/delete.gif" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
25
        <children xsi:type="menu:HandledMenuItem" xmi:id="_pw1FICFdEeiVXriJfxPIuA" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.deletefeaturetree" label="Delete Feature Tree" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/delete.gif" command="_3mqzkCFdEeiVXriJfxPIuA"/>
23 26
      </menus>
24 27
    </elements>
25 28
    <elements xsi:type="basic:PartDescriptor" xmi:id="_zTXhUGvBEeeNmdqhxF1CnA" elementId="eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4" label="%view.name.4" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/accessories-text-editor.png" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4"/>
......
121 124
    <elements xsi:type="commands:Command" xmi:id="_dQ0swL-rEeegz7IDD8MJaw" elementId="eu.etaxonomy.taxeditor.store.open.InspectSessionsDialog" commandName="Inspect Session"/>
122 125
    <elements xsi:type="commands:Command" xmi:id="_jSJrsBWPEeiazYUJirF0Pw" elementId="eu.etaxonomy.taxeditor.store.command.update" commandName="Check for updates"/>
123 126
    <elements xsi:type="commands:Command" xmi:id="_aPYxsBezEeiXusClKZjycQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.addChildFeature" commandName="Add child feature"/>
127
    <elements xsi:type="commands:Command" xmi:id="_3mqzkCFdEeiVXriJfxPIuA" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.deleteFeatureTree" commandName="Delete feature tree"/>
124 128
  </fragments>
125 129
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_swGH0GhvEee3K4uKJljEYg" featurename="handlers" parentElementId="xpath:/">
126 130
    <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/FeatureTreeEditor.java
46 46
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
47 47
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
48 48
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
49
import eu.etaxonomy.taxeditor.model.AbstractUtility;
50 49
import eu.etaxonomy.taxeditor.model.IContextListener;
51 50
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
52 51
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
......
185 184
	@Override
186 185
	public void selectionChanged(SelectionChangedEvent event) {
187 186
		//propagate selection
188
		selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event));
187
		selService.setSelection(event.getSelection());
189 188
	}
190 189

  
191 190
	@Focus
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddChildFeatureHandler.java
16 16
import org.eclipse.e4.core.di.annotations.CanExecute;
17 17
import org.eclipse.e4.core.di.annotations.Execute;
18 18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19 20
import org.eclipse.e4.ui.services.IServiceConstants;
21
import org.eclipse.jface.viewers.IStructuredSelection;
20 22
import org.eclipse.jface.wizard.WizardDialog;
21 23
import org.eclipse.swt.widgets.Shell;
22 24

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

  
56 58
    @CanExecute
57 59
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
58
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection) {
59
        return thisPart.getObject() instanceof FeatureTreeEditor
60
                && selection instanceof FeatureNode;
60
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
61
            MHandledMenuItem menuItem) {
62
        boolean canExecute = false;
63
        canExecute = thisPart.getObject() instanceof FeatureTreeEditor
64
                && selection.size()==1
65
                && selection.iterator().next() instanceof FeatureNode;
66
        menuItem.setVisible(canExecute);
67
        return canExecute;
61 68
    }
62 69
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddFeatureHandler.java
16 16
import org.eclipse.e4.core.di.annotations.CanExecute;
17 17
import org.eclipse.e4.core.di.annotations.Execute;
18 18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19 20
import org.eclipse.e4.ui.services.IServiceConstants;
21
import org.eclipse.jface.viewers.IStructuredSelection;
20 22
import org.eclipse.jface.wizard.WizardDialog;
21 23
import org.eclipse.swt.widgets.Shell;
22 24

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

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

  
45 47
        if (dialog.open() == IStatus.OK) {
46
            FeatureNode parent = ((FeatureTree) editor.getViewer().getInput()).getRoot();
48
            FeatureTree tree = (FeatureTree) selection.iterator().next();
47 49
            Collection<Feature> additionalFeatures = wizard.getAdditionalFeatures();
48 50
            for (Feature feature : additionalFeatures) {
49
                CdmStore.getService(IFeatureNodeService.class).addChildFeatureNode(parent.getUuid(), feature.getUuid());
51
                CdmStore.getService(IFeatureNodeService.class).addChildFeatureNode(tree.getUuid(), feature.getUuid());
50 52
            }
51 53
            editor.getViewer().refresh();
52
            editor.getViewer().expandToLevel(parent, 1);
54
            editor.getViewer().expandToLevel(selection, 1);
53 55
        }
54 56
    }
55 57

  
56 58
    @CanExecute
57
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
58
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection) {
59
        return thisPart.getObject() instanceof FeatureTreeEditor
60
                && selection instanceof FeatureTree;
59
    public boolean canExecute(
60
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
61
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
62
            MHandledMenuItem menuItem) {
63
        boolean canExecute = false;
64
        canExecute = selection.size()==1
65
                && selection.iterator().next() instanceof FeatureTree
66
                && thisPart.getObject() instanceof FeatureTreeEditor;
67
        menuItem.setVisible(canExecute);
68
        return canExecute;
61 69
    }
62 70
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/FeatureTreeExportHandler.java
15 15
import org.eclipse.core.runtime.jobs.Job;
16 16
import org.eclipse.e4.core.di.annotations.CanExecute;
17 17
import org.eclipse.e4.core.di.annotations.Execute;
18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19 19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.jface.viewers.IStructuredSelection;
20 21
import org.eclipse.swt.widgets.DirectoryDialog;
21 22
import org.eclipse.swt.widgets.Shell;
22 23
import org.eclipse.ui.progress.IProgressConstants;
23 24

  
24 25
import eu.etaxonomy.cdm.io.descriptive.owl.out.OwlExportConfigurator;
25 26
import eu.etaxonomy.cdm.model.description.FeatureTree;
26
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
27
import eu.etaxonomy.taxeditor.model.MessagingUtils;
28 27
import eu.etaxonomy.taxeditor.store.CdmStore;
29 28

  
30 29
/**
......
36 35

  
37 36
    @Execute
38 37
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
39
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
40
            @Named(IServiceConstants.ACTIVE_SELECTION)FeatureTree selection){
41
        FeatureTree selectedFeatureTree = selection;
42
        if(selectedFeatureTree==null){
43
            MessagingUtils.informationDialog("Export not possible", "There is no feature tree selected.");
44
            return;
45
        }
38
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection){
39
        FeatureTree selectedFeatureTree = (FeatureTree) selection.iterator().next();
46 40
        DirectoryDialog dialog = new DirectoryDialog(shell);
47 41
        String directoryString = dialog.open();
48 42
        if(directoryString!=null){
......
57 51
    }
58 52

  
59 53
    @CanExecute
60
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
61
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection){
62
        return thisPart.getObject() instanceof FeatureTreeEditor && selection instanceof FeatureTree;
54
    public boolean canExecute(
55
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
56
            MHandledMenuItem menuItem) {
57
        boolean canExecute = false;
58
        canExecute = selection.size()==1 && selection.iterator().next() instanceof FeatureTree;
59
        menuItem.setVisible(canExecute);
60
        return canExecute;
63 61
    }
64 62

  
65 63
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/RemoveFeatureHandler.java
13 13
import org.eclipse.e4.core.di.annotations.CanExecute;
14 14
import org.eclipse.e4.core.di.annotations.Execute;
15 15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
16 17
import org.eclipse.e4.ui.services.IServiceConstants;
17 18
import org.eclipse.jface.viewers.IStructuredSelection;
18 19

  
19 20
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
20 21
import eu.etaxonomy.cdm.api.service.config.FeatureNodeDeletionConfigurator;
21 22
import eu.etaxonomy.cdm.model.description.FeatureNode;
22
import eu.etaxonomy.cdm.model.description.FeatureTree;
23 23
import eu.etaxonomy.taxeditor.store.CdmStore;
24 24
import eu.etaxonomy.taxeditor.workbench.part.IE4ViewerPart;
25 25

  
......
31 31
public class RemoveFeatureHandler {
32 32

  
33 33
    @Execute
34
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
35
        if(thisPart.getObject() instanceof IE4ViewerPart){
36
            IE4ViewerPart editor = (IE4ViewerPart) thisPart.getObject();
37
            IStructuredSelection selection = editor.getSelection();
38
            for (Object selectedObject : selection.toArray()) {
39
                FeatureNode featureNode = (FeatureNode) selectedObject;
40
                CdmStore.getService(IFeatureNodeService.class).deleteFeatureNode(featureNode.getUuid(), new FeatureNodeDeletionConfigurator());
41
            }
42
            editor.refresh();
34
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
35
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection){
36
        for (Object selectedObject : selection.toArray()) {
37
            FeatureNode featureNode = (FeatureNode) selectedObject;
38
            CdmStore.getService(IFeatureNodeService.class).deleteFeatureNode(featureNode.getUuid(), new FeatureNodeDeletionConfigurator());
43 39
        }
40
        IE4ViewerPart editor = (IE4ViewerPart) thisPart.getObject();
41
        editor.refresh();
44 42
    }
45 43

  
46 44
    @CanExecute
47
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
48
        if(thisPart.getObject() instanceof IE4ViewerPart){
49
            IE4ViewerPart viewerPart = (IE4ViewerPart)thisPart.getObject();
50
            return viewerPart.getSelection() instanceof FeatureTree;
45
    public boolean canExecute(
46
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
47
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
48
            MHandledMenuItem menuItem) {
49
        boolean canExecute = !selection.isEmpty();
50
        for(Object object:selection.toArray()){
51
            canExecute &= object instanceof FeatureNode;
51 52
        }
52
        return false;
53
        canExecute &= thisPart.getObject() instanceof IE4ViewerPart;
54
        menuItem.setVisible(canExecute);
55
        return canExecute;
53 56
    }
54 57

  
55 58
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/RemoveFeatureTreeHandler.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.List;
12

  
13
import javax.inject.Named;
14

  
15
import org.eclipse.e4.core.di.annotations.CanExecute;
16
import org.eclipse.e4.core.di.annotations.Execute;
17
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21

  
22
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
23
import eu.etaxonomy.cdm.model.description.FeatureTree;
24
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

  
27
/**
28
 * @author pplitzner
29
 * @since Jul 12, 2017
30
 *
31
 */
32
public class RemoveFeatureTreeHandler {
33

  
34
    @Execute
35
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
36
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection){
37
        for (Object selectedObject : selection.toArray()) {
38
            FeatureTree featureTree = (FeatureTree) selectedObject;
39
            CdmStore.getService(IFeatureTreeService.class).delete(featureTree.getUuid());
40
        }
41
        FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
42
        List<FeatureTree> trees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
43
        editor.getViewer().setInput(trees);
44
    }
45

  
46
    @CanExecute
47
    public boolean canExecute(
48
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
49
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
50
            MHandledMenuItem menuItem) {
51
        boolean canExecute = !selection.isEmpty();
52
        for(Object object:selection.toArray()){
53
            canExecute &= object instanceof FeatureTree;
54
        }
55
        canExecute &= thisPart.getObject() instanceof FeatureTreeEditor;
56
        menuItem.setVisible(canExecute);
57
        return canExecute;
58
    }
59

  
60
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)