Project

General

Profile

« Previous | Next » 

Revision ff46c6ca

Added by Patrick Plitzner almost 7 years ago

ref #6806 Add context menu to feature tree editor

  • menu item for add, remove feature and export feature tree (experimental)

View differences:

eu.etaxonomy.taxeditor.store/fragment.e4xmi
9 9
    <elements xsi:type="basic:PartDescriptor" xmi:id="_J-3UEEqgEeeN-dEYnw7m3g" elementId="eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor" label="%partdescriptor.label.featureTreeEditor" allowMultiple="true" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor">
10 10
      <tags>nonRestore</tags>
11 11
      <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"/>
12
      <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"/>
13
      <handlers 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"/>
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
      <menus xsi:type="menu:PopupMenu" xmi:id="__Jwh4GceEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.popupmenu.featureTreeEditor">
16
        <children xsi:type="menu:HandledMenuItem" xmi:id="_Beb6QGcfEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.removeFeature" label="Remove Feature" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
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="_7vaEcGcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.exportFeatureTree" label="Export Feature Tree" command="_I_yx4GcqEee0qLTtA2ZpVQ">
19
          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_-91IQGcqEee0qLTtA2ZpVQ" coreExpressionId="isShowExperimentalFeatures"/>
20
        </children>
21
      </menus>
12 22
    </elements>
13 23
  </fragments>
14 24
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_3rW8wCXaEeex9MwMOgUeWw" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView" positionInList="after:bulkeditor.menus.openmenu">
......
32 42
      <parameters xmi:id="_BylIUCZzEeeQLpuomSmVoQ" elementId="eu.etaxonomy.taxeditor.store.showView.parameter.sessionView" name="eu.etaxonomy.taxeditor.workbench.commandparameter.partName" value="eu.etaxonomy.taxeditor.view.sessions.SessionsViewPart"/>
33 43
    </elements>
34 44
  </fragments>
45
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_mPdAcGceEee0qLTtA2ZpVQ" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
46
    <elements xsi:type="commands:Command" xmi:id="_oftL0GceEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.addFeature" commandName="Add Feature" description="Add a feature to the feature tree"/>
47
    <elements xsi:type="commands:Command" xmi:id="_fNBtQGcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.removeFeature" commandName="Remove Feature" description="Removes a feature from the feature tree"/>
48
    <elements xsi:type="commands:Command" xmi:id="_I_yx4GcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.exportTree" commandName="Export Feature Tree"/>
49
  </fragments>
35 50
</fragment:ModelFragments>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java
24 24
import org.eclipse.e4.ui.di.Focus;
25 25
import org.eclipse.e4.ui.di.Persist;
26 26
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
27
import org.eclipse.e4.ui.services.EMenuService;
27 28
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
28 29
import org.eclipse.jface.viewers.ISelectionChangedListener;
29 30
import org.eclipse.jface.viewers.IStructuredSelection;
30 31
import org.eclipse.jface.viewers.SelectionChangedEvent;
32
import org.eclipse.jface.viewers.TreeViewer;
31 33
import org.eclipse.jface.wizard.WizardDialog;
32 34
import org.eclipse.swt.SWT;
33 35
import org.eclipse.swt.events.ModifyEvent;
......
78 80

  
79 81
	/** {@inheritDoc} */
80 82
    @PostConstruct
81
    public void createControl(Composite parent){
83
    public void createControl(Composite parent, EMenuService menuService){
82 84
        if (CdmStore.isActive()){
83 85
            if(conversation == null){
84 86
                conversation = CdmStore.createConversation();
......
110 112
                        }
111 113
                    }
112 114
                }, new AddButtonListener(), new RemoveSelectionListener(), new FeatureTreeExportListener(composite.getDisplay().getActiveShell(), composite));
115

  
116
        //create context menu
117
        menuService.registerContextMenu(composite.getViewer().getControl(), "eu.etaxonomy.taxeditor.store.popupmenu.featureTreeEditor");
113 118
    }
114 119

  
115 120
	public void setDirty(boolean isDirty){
......
156 161
        }
157 162
	}
158 163

  
164
	public void refresh(){
165
	    composite.getViewer().refresh();
166
	}
167

  
168
	public TreeViewer getViewer(){
169
	    return composite.getViewer();
170
	}
171

  
159 172
	@Persist
160 173
	public void save(){
161 174
        if (!conversation.isBound()) {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddFeatureHandler.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.cdm.model.description.FeatureTree;
27
import eu.etaxonomy.taxeditor.featuretree.AvailableFeaturesWizard;
28
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30

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

  
38
    @Execute
39
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
40
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart) {
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) {
46
            FeatureNode parent = ((FeatureTree) editor.getViewer().getInput()).getRoot();
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
        return thisPart.getObject() instanceof FeatureTreeEditor && ((FeatureTreeEditor) thisPart.getObject()).getSelectedFeatureTree()!=null;
62
    }
63
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/FeatureTreeExportHandler.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.io.File;
12

  
13
import javax.inject.Named;
14

  
15
import org.eclipse.core.runtime.jobs.Job;
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.swt.widgets.DirectoryDialog;
21
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.ui.progress.IProgressConstants;
23

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

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

  
37
    @Execute
38
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
39
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
40
        FeatureTreeEditor editor = ((FeatureTreeEditor) thisPart.getObject());
41
        FeatureTree selectedFeatureTree = editor.getSelectedFeatureTree();
42
        if(selectedFeatureTree==null){
43
            MessagingUtils.informationDialog("Export not possible", "There is no feature tree selected.");
44
            return;
45
        }
46
        DirectoryDialog dialog = new DirectoryDialog(shell);
47
        String directoryString = dialog.open();
48
        if(directoryString!=null){
49
            // create job
50
            Job job = CdmStore.getExportManager().createIOServiceJob(OwlExportConfigurator.NewInstance(null, null, selectedFeatureTree), new File(directoryString+"/owl.owl"));
51
            // configure the job
52
            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
53
            job.setUser(true);
54
            // schedule job
55
            job.schedule();
56
        }
57
    }
58

  
59
    @CanExecute
60
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
61
        return thisPart.getObject() instanceof FeatureTreeEditor && ((FeatureTreeEditor) thisPart.getObject()).getSelectedFeatureTree()!=null;
62
    }
63

  
64
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/RemoveFeatureHandler.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 javax.inject.Named;
12

  
13
import org.eclipse.e4.core.di.annotations.CanExecute;
14
import org.eclipse.e4.core.di.annotations.Execute;
15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16
import org.eclipse.e4.ui.services.IServiceConstants;
17
import org.eclipse.jface.viewers.IStructuredSelection;
18

  
19
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
20
import eu.etaxonomy.cdm.api.service.config.FeatureNodeDeletionConfigurator;
21
import eu.etaxonomy.cdm.model.description.FeatureNode;
22
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

  
25
/**
26
 * @author pplitzner
27
 * @since Jul 12, 2017
28
 *
29
 */
30
public class RemoveFeatureHandler {
31

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

  
44
    @CanExecute
45
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
46
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
47
        return thisPart.getObject() instanceof FeatureTreeEditor && selection!=null && !selection.isEmpty();
48
    }
49

  
50
}

Also available in: Unified diff