Project

General

Profile

« Previous | Next » 

Revision 9e92b44f

Added by Patrick Plitzner over 6 years ago

ref #6932 Migrate marker type handler

View differences:

eu.etaxonomy.taxeditor.bulkeditor/fragment.e4xmi
14 14
    <elements xsi:type="commands:Command" xmi:id="_S8xR4JcNEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.delete" commandName="%command.label.4"/>
15 15
    <elements xsi:type="commands:Command" xmi:id="_jWkVYJcOEeeM745tzuPNCQ" elementId="taxeditor-bulkeditor.dynamicnewobjectcommand" commandName="%command.name.2"/>
16 16
    <elements xsi:type="commands:Command" xmi:id="_tLGKgJcOEeeM745tzuPNCQ" elementId="taxeditor-bulkeditor.dynamicdeleteobjectcommand" commandName="%command.name.3"/>
17
    <elements xsi:type="commands:Command" xmi:id="_Svo9oKK6EeeZb4PEjoRsuw" elementId="taxeditor-bulkeditor.command.setMarkerFlag" commandName="%command.name.6"/>
17 18
  </fragments>
18 19
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_l_8NMCQUEeelPNxAg-e3TA" featurename="children" parentElementId="eu.etaxonomy.taxeditor.workbench.menu.admin">
19 20
    <elements xsi:type="menu:MenuSeparator" xmi:id="_zph3kDF2Eee-JvlKXQGppA" elementId="eu.etaxonomy.taxeditor.bulkeditor.menuseparator.0"/>
......
52 53
      <handlers xmi:id="_a-U4EJcOEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMergeTargetHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMergeTargetHandlerE4" command="_GAm9cJcNEeeM745tzuPNCQ"/>
53 54
      <handlers xmi:id="_qPOPQJcOEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.annotatedlineeditor.e4.handler.NewObjectHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.annotatedlineeditor.e4.handler.NewObjectHandlerE4" command="_jWkVYJcOEeeM745tzuPNCQ"/>
54 55
      <handlers xmi:id="_vskBsJcOEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.annotatedlineeditor.e4.handler.DeleteObjectHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.annotatedlineeditor.e4.handler.DeleteObjectHandlerE4" command="_tLGKgJcOEeeM745tzuPNCQ"/>
56
      <handlers xmi:id="_c9ppwKK6EeeZb4PEjoRsuw" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMarkerFlagHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.handler.SetMarkerFlagHandlerE4" command="_Svo9oKK6EeeZb4PEjoRsuw"/>
55 57
      <menus xsi:type="menu:PopupMenu" xmi:id="_B6IFsJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor">
56 58
        <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_H83EMJcMEeeM745tzuPNCQ" coreExpressionId="isCdmStoreConnected"/>
57 59
        <children xsi:type="menu:DynamicMenuContribution" xmi:id="_Y49vAJfHEeeUB5KN7hGpYQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicNewObjectMenuE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicNewObjectMenuE4"/>
......
65 67
        <children xsi:type="menu:HandledMenuItem" xmi:id="_l6dgYJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.handledmenuitem.convertTeam2Person" label="%command.label.5" command="_PtZy4JcNEeeM745tzuPNCQ"/>
66 68
        <children xsi:type="menu:HandledMenuItem" xmi:id="_oKqBYJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.handledmenuitem.convertPerson2Team" label="%command.label.6" command="_RFEJYJcNEeeM745tzuPNCQ"/>
67 69
        <children xsi:type="menu:MenuSeparator" xmi:id="_p-7bYJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.menuseparator.3"/>
68
        <children xsi:type="menu:Menu" xmi:id="_saDaAJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.menu.chooseMarkerType" label="%menu.label.2"/>
70
        <children xsi:type="menu:DynamicMenuContribution" xmi:id="_MughoKK6EeeZb4PEjoRsuw" elementId="eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicMarkerTypeEditingMenuE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicMarkerTypeEditingMenuE4"/>
69 71
        <children xsi:type="menu:MenuSeparator" xmi:id="_x3rgUJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.menuseparator.4"/>
70 72
        <children xsi:type="menu:HandledMenuItem" xmi:id="_yt2TUJcMEeeM745tzuPNCQ" elementId="eu.etaxonomy.taxeditor.bulkeditor.handledmenuitem.delete" label="%command.label.4" command="_S8xR4JcNEeeM745tzuPNCQ"/>
71 73
      </menus>
eu.etaxonomy.taxeditor.bulkeditor/plugin.xml
20 20
            name="%editor.name.1">
21 21
      </editor>
22 22
   </extension>
23
   <extension
24
         point="org.eclipse.ui.menus">
25
      <menuContribution
26
            locationURI="popup:bulkeditor.editor">
27
         <menu
28
               label="%menu.label.1">
29
            <dynamic
30
                  class="eu.etaxonomy.taxeditor.bulkeditor.command.DynamicNewObjectMenu"
31
                  id="eu.etaxonomy.taxeditor.bulkeditor.dynamicNewMenu">
32
               <visibleWhen
33
                     checkEnabled="false">
34
                  <reference
35
                        definitionId="isCdmStoreConnected">
36
                  </reference>
37
               </visibleWhen>
38
            </dynamic>
39
            <visibleWhen
40
                  checkEnabled="true">
41
               <reference
42
                     definitionId="isCdmStoreConnected">
43
               </reference>
44
            </visibleWhen>
45
         </menu>
46
         <separator
47
               name="taxeditor-bulkeditor.separator4"
48
               visible="true">
49
         </separator>
50
         <command
51
               commandId="bulkeditor.commands.setmergetarget"
52
               label="%command.label.0"
53
               style="push">
54
            <visibleWhen>
55
               <reference
56
                     definitionId="isMergeEnabled">
57
               </reference>
58
            </visibleWhen>
59
         </command>
60
         
61
         <command
62
               commandId="bulkeditor.commands.setmergecandidate"
63
               label="%command.label.1"
64
               style="push">
65
            <visibleWhen>
66
               <reference
67
                     definitionId="isMergeEnabled">
68
               </reference>
69
            </visibleWhen>
70
         </command>
71
         <command
72
               commandId="bulkeditor.commands.removemergecandidate"
73
               label="%command.label.2"
74
               style="push">
75
            <visibleWhen>
76
               <reference
77
                     definitionId="isMergeEnabled">
78
               </reference>
79
            </visibleWhen>
80
         </command>            
81
         <command
82
               commandId="bulkeditor.commands.mergegroup"
83
               label="%command.label.3"
84
               style="push">
85
            <visibleWhen>
86
               <reference
87
                     definitionId="isMergeEnabled">
88
               </reference>
89
            </visibleWhen>
90
         </command>
91
         <separator
92
               name="eu.etaxonomy.taxeditor.bulkeditor.separator1"
93
               visible="true">
94
         </separator>
95
         <command
96
               commandId="eu.etaxonomy.taxeditor.bulkeditor.convertTeam2Person"
97
               label="%command.label.5"
98
               style="push">
99
           	   <visibleWhen
100
           	   		checkEnabled="true">
101
               		<and>
102
               		<reference
103
                     	definitionId="isConvertEnabled">
104
               		</reference>
105
               		<reference 
106
               				definitionId="isTeam">
107
               		</reference>
108
            		</and>
109
           		</visibleWhen>
110
         </command>
111
         <command
112
               commandId="eu.etaxonomy.taxeditor.bulkeditor.convertPerson2Team"
113
               label="%command.label.6"
114
               style="push">
115
            	<visibleWhen 
116
            		checkEnabled="true">>
117
               		<and>
118
               		<reference
119
                     	definitionId="isConvertEnabled">
120
               		</reference>
121
               		<reference 
122
               			definitionId="isPerson">
123
               		</reference>
124
            		</and>
125
           		</visibleWhen>
126
         </command>
127
         <separator
128
               name="taxeditor-bulkeditor.separator2"
129
               visible="true">
130
         </separator>
131
         <menu
132
               label="%menu.label.2">
133
            <dynamic
134
                  class="eu.etaxonomy.taxeditor.bulkeditor.command.DynamicMarkerTypeEditingMenu"
135
                  id="eu.etaxonomy.taxeditor.bulkeditor.dynamicMarkerTypeEditingMenu">
136
            </dynamic>
137
            <visibleWhen
138
                  checkEnabled="true">
139
               <reference
140
                     definitionId="isCdmStoreConnected">
141
               </reference>
142
            </visibleWhen>
143
         </menu>
144
         <separator
145
               name="taxeditor-bulkeditor.separator3"
146
               visible="true">
147
         </separator>
148
         <command
149
               commandId="eu.etaxonomy.taxeditor.bulkeditor.delete"
150
               label="%command.label.4"
151
               style="push">
152
            <visibleWhen
153
                  checkEnabled="true">
154
               <reference
155
                     definitionId="isCdmStoreConnected">
156
               </reference>
157
            </visibleWhen>
158
         </command>
159
         <dynamic
160
               class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu"
161
               id="eu.etaxonomy.taxeditor.bulkeditor.cdmViewerContextMenu">
162
         </dynamic>
163
      <!--menuContribution
164
            locationURI="popup:org.eclipse.ui.popup.any"-->
165
      </menuContribution>
166
   </extension>
167 23
   <extension
168 24
         point="org.eclipse.ui.commands">
169
      <command
170
            defaultHandler="eu.etaxonomy.taxeditor.bulkeditor.handler.SetMarkerFlagHandler"
171
            id="taxeditor-bulkeditor.command.setMarkerFlag"
172
            name="%command.name.6">
173
      </command>
174 25
      <command
175 26
            id="eu.etaxonomy.taxeditor.openReferencingObjectsView"
176 27
            name="%command.name.OPEN_REFERENCING_OBJECTS_VIEW">
......
185 36
               typeId="eu.etaxonomy.taxeditor.uuidParameterType">
186 37
         </commandParameter>
187 38
      </command>
188
      <command
189
            defaultHandler="eu.etaxonomy.taxeditor.handler.defaultHandler.OpenReferencingObjectsView"
190
            id="eu.etaxonomy.taxeditor.openReferencingObjectsViewFromMenu"
191
            name="%command.name.OPEN_REFERENCING_OBJECTS_VIEW">
192
      </command>
193 39
      <!--command
194 40
            defaultHandler="eu.etaxonomy.taxeditor.bulkeditor.handler.NewEntityHandler"
195 41
            id="eu.etaxonomy.taxeditor.bulkeditor.command.new"
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/command/DynamicMarkerTypeEditingMenuE4.java
1
/**
2
* Copyright (C) 2007 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

  
10
package eu.etaxonomy.taxeditor.bulkeditor.e4.command;
11

  
12
import java.util.List;
13

  
14
import javax.inject.Named;
15

  
16
import org.eclipse.e4.ui.di.AboutToShow;
17
import org.eclipse.e4.ui.model.application.commands.MCommand;
18
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
19
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
20
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
21
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
22
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
23
import org.eclipse.e4.ui.services.IServiceConstants;
24

  
25
import eu.etaxonomy.cdm.model.common.MarkerType;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27

  
28
/**
29
 *
30
 * @author pplitzner
31
 * @date 26.09.2017
32
 *
33
 */
34
public class DynamicMarkerTypeEditingMenuE4 {
35

  
36
    public static final String COMMAND_ID = "taxeditor-bulkeditor.command.setMarkerFlag";
37
    public static final String COMMAND_PARAMETER_MARKER_TYPE = COMMAND_ID+".markerType";
38
    public static final String COMMAND_PARAMETER_MARKER_STATE = COMMAND_ID+".markerState";
39

  
40
	/** {@inheritDoc} */
41
    @AboutToShow
42
    public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION)Object selection) {
43
        if(selection==null){
44
            return;
45
        }
46
        MMenu menu = MMenuFactory.INSTANCE.createMenu();
47
        menu.setLabel("Choose marker type");
48
        items.add(menu);
49
        for(MarkerType markerType : CdmStore.getTermManager().getPreferredTerms(MarkerType.class)){
50
            createMenuItem(menu, markerType);
51
        }
52
    }
53

  
54
	private void createMenuItem(MMenu menu, final MarkerType markerType) {
55

  
56
	    MMenu subMenu = MMenuFactory.INSTANCE.createMenu();
57
	    subMenu.setLabel(String.format("Set Flag '%s'", markerType.getLabel()));
58
	    menu.getChildren().add(subMenu);
59

  
60
	    MHandledMenuItem subMenuItemYes = MMenuFactory.INSTANCE.createHandledMenuItem();
61
	    subMenuItemYes.setLabel("Yes");
62
	    MCommand mCommandYes = MCommandsFactory.INSTANCE.createCommand();
63
	    mCommandYes.setElementId(COMMAND_ID);
64
	    //set params
65
	    subMenuItemYes.getTransientData().put(COMMAND_PARAMETER_MARKER_TYPE, markerType);
66
	    subMenuItemYes.getTransientData().put(COMMAND_PARAMETER_MARKER_STATE, true);
67
	    subMenuItemYes.setCommand(mCommandYes);
68
	    subMenu.getChildren().add(subMenuItemYes);
69

  
70
	    MHandledMenuItem subMenuItemNo = MMenuFactory.INSTANCE.createHandledMenuItem();
71
	    subMenuItemNo.setLabel("No");
72
	    MCommand mCommandNo = MCommandsFactory.INSTANCE.createCommand();
73
	    mCommandNo.setElementId(COMMAND_ID);
74
	    //set params
75
	    subMenuItemNo.getTransientData().put(COMMAND_PARAMETER_MARKER_TYPE, markerType);
76
	    subMenuItemNo.getTransientData().put(COMMAND_PARAMETER_MARKER_STATE, false);
77
	    subMenuItemNo.setCommand(mCommandNo);
78
	    subMenu.getChildren().add(subMenuItemNo);
79
	}
80

  
81
}
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMarkerFlagHandlerE4.java
1 1
/**
2
* Copyright (C) 2007 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
*/
2
 * Copyright (C) 2007 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 9

  
10 10
package eu.etaxonomy.taxeditor.bulkeditor.e4.handler;
11 11

  
12
import java.util.HashSet;
13
import java.util.Iterator;
14
import java.util.Set;
12
import java.util.Collections;
13

  
14
import javax.inject.Named;
15 15

  
16
import org.eclipse.core.commands.AbstractHandler;
17
import org.eclipse.core.commands.ExecutionEvent;
18
import org.eclipse.core.commands.ExecutionException;
19
import org.eclipse.jface.text.TextSelection;
20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.ui.IEditorPart;
23
import org.eclipse.ui.handlers.HandlerUtil;
16
import org.eclipse.e4.core.di.annotations.CanExecute;
17
import org.eclipse.e4.core.di.annotations.Execute;
18
import org.eclipse.e4.core.di.annotations.Optional;
19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
21
import org.eclipse.e4.ui.services.IServiceConstants;
24 22

  
25 23
import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
26 24
import eu.etaxonomy.cdm.model.common.MarkerType;
27
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
28
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
29
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
30 25
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
26
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
27
import eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicMarkerTypeEditingMenuE4;
28
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
31 29
import eu.etaxonomy.taxeditor.bulkeditor.operation.SetMarkerFlagOperation;
32 30
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
33 31

  
34 32
/**
35
 * <p>SetMarkerFlagTrueHandler class.</p>
36 33
 *
37
 * @author p.ciardelli
38
 * @created 20.10.2009
39
 * @version 1.0
34
 * @author pplitzner
35
 * @date 26.09.2017
36
 *
40 37
 */
41
public class SetMarkerFlagHandlerE4 extends AbstractHandler {
38
public class SetMarkerFlagHandlerE4 {
39

  
40
    @Execute
41
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)IAnnotatableEntity selection,
42
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
43
            MHandledMenuItem menuItem) {
44

  
45
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
46
        AbstractBulkEditorInput input = editor.getEditorInput();
47
        MarkerType markerType = (MarkerType) menuItem.getTransientData().get(DynamicMarkerTypeEditingMenuE4.COMMAND_PARAMETER_MARKER_TYPE);
48
        boolean markerState = (boolean) menuItem.getTransientData().get(DynamicMarkerTypeEditingMenuE4.COMMAND_PARAMETER_MARKER_STATE);
49

  
50

  
51
        AbstractPostOperation operation = new SetMarkerFlagOperation("Set Marker", BulkEditorUtil.getUndoContext(), Collections.singleton(selection), markerType, markerState, editor);
52
        BulkEditorUtil.executeOperation(operation);
53
    }
54

  
42 55

  
43
	/* (non-Javadoc)
44
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
45
	 */
46
	/** {@inheritDoc} */
47
	public Object execute(ExecutionEvent event) throws ExecutionException {
48
		
49
		ISelection selection = HandlerUtil.getCurrentSelection(event);
50
		
51
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
52
		
53
		Object[] data = (Object[]) ((Event) event.getTrigger()).data;
54
		
55
		if (selection instanceof TextSelection 
56
					&& editor instanceof BulkEditor) {
57
			TextSelection textSelection = (TextSelection) selection;
58
			BulkEditor bulkEditor = (BulkEditor) editor;
59
			
60
			LineAnnotationModel model = (LineAnnotationModel) bulkEditor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
61
			if (model != null) {
62
				Iterator iter = model.getAnnotationIterator(textSelection.getOffset(), textSelection.getLength(), true, true);
63
				
64
				Set<IAnnotatableEntity> annotatableEntities = new HashSet<IAnnotatableEntity>();
65
				while (iter.hasNext()) {
66
					Object next = iter.next();
67
					if (next instanceof LineAnnotation) {
68
						Object entity = ((LineAnnotation) next).getEntity();
69
						
70
						if(entity instanceof IAnnotatableEntity){
71
							annotatableEntities.add((IAnnotatableEntity) entity);
72
						}
73
					}
74
				}
75
								
76
				AbstractPostOperation operation = new SetMarkerFlagOperation("Set Marker", BulkEditorUtil.getUndoContext(), annotatableEntities, (MarkerType) data[0], (Boolean) data[1], bulkEditor);
77
				BulkEditorUtil.executeOperation(operation);
78
			}
79
		}
80
		return null;
81
	}
56
    @CanExecute
57
    public boolean canExecute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
58
            MHandledMenuItem menuItem){
59
        boolean canExecute = false;
60
        canExecute = selection instanceof IAnnotatableEntity;
61
        menuItem.setVisible(canExecute);
62
        return canExecute;
63
    }
82 64
}

Also available in: Unified diff