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
|
}
|