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.core.di.annotations.CanExecute;
|
17
|
import org.eclipse.e4.ui.di.AboutToShow;
|
18
|
import org.eclipse.e4.ui.model.application.commands.MCommand;
|
19
|
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
|
20
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
21
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
22
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
|
23
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
|
24
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
|
25
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
26
|
import org.eclipse.jface.viewers.StructuredSelection;
|
27
|
|
28
|
import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
|
29
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
30
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
|
31
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
32
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33
|
|
34
|
/**
|
35
|
*
|
36
|
* @author pplitzner
|
37
|
* @date 26.09.2017
|
38
|
*
|
39
|
*/
|
40
|
public class DynamicMarkerTypeEditingMenuE4 {
|
41
|
|
42
|
public static final String COMMAND_ID = "taxeditor-bulkeditor.command.setMarkerFlag"; //$NON-NLS-1$
|
43
|
public static final String COMMAND_PARAMETER_MARKER_TYPE = COMMAND_ID+".markerType"; //$NON-NLS-1$
|
44
|
public static final String COMMAND_PARAMETER_MARKER_STATE = COMMAND_ID+".markerState"; //$NON-NLS-1$
|
45
|
|
46
|
/** {@inheritDoc} */
|
47
|
@AboutToShow
|
48
|
public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION)Object selection) {
|
49
|
if(selection instanceof StructuredSelection && ((StructuredSelection)selection).isEmpty()){
|
50
|
return;
|
51
|
}
|
52
|
MMenu menu = MMenuFactory.INSTANCE.createMenu();
|
53
|
menu.setLabel(Messages.DynamicMarkerTypeEditingMenuE4_CHOOSE_MARKER_TYPE);
|
54
|
items.add(menu);
|
55
|
for(MarkerType markerType : CdmStore.getTermManager().getPreferredTerms(MarkerType.class)){
|
56
|
createMenuItem(menu, markerType);
|
57
|
}
|
58
|
}
|
59
|
|
60
|
private void createMenuItem(MMenu menu, final MarkerType markerType) {
|
61
|
|
62
|
MMenu subMenu = MMenuFactory.INSTANCE.createMenu();
|
63
|
subMenu.setLabel(String.format(Messages.DynamicMarkerTypeEditingMenuE4_SET_FLAG, markerType.getLabel()));
|
64
|
menu.getChildren().add(subMenu);
|
65
|
|
66
|
MHandledMenuItem subMenuItemYes = MMenuFactory.INSTANCE.createHandledMenuItem();
|
67
|
subMenuItemYes.setLabel(Messages.DynamicMarkerTypeEditingMenuE4_YES);
|
68
|
MCommand mCommandYes = MCommandsFactory.INSTANCE.createCommand();
|
69
|
mCommandYes.setElementId(COMMAND_ID);
|
70
|
//set params
|
71
|
subMenuItemYes.getTransientData().put(COMMAND_PARAMETER_MARKER_TYPE, markerType);
|
72
|
subMenuItemYes.getTransientData().put(COMMAND_PARAMETER_MARKER_STATE, true);
|
73
|
subMenuItemYes.setCommand(mCommandYes);
|
74
|
subMenu.getChildren().add(subMenuItemYes);
|
75
|
|
76
|
MHandledMenuItem subMenuItemNo = MMenuFactory.INSTANCE.createHandledMenuItem();
|
77
|
subMenuItemNo.setLabel(Messages.DynamicMarkerTypeEditingMenuE4_NO);
|
78
|
MCommand mCommandNo = MCommandsFactory.INSTANCE.createCommand();
|
79
|
mCommandNo.setElementId(COMMAND_ID);
|
80
|
//set params
|
81
|
subMenuItemNo.getTransientData().put(COMMAND_PARAMETER_MARKER_TYPE, markerType);
|
82
|
subMenuItemNo.getTransientData().put(COMMAND_PARAMETER_MARKER_STATE, false);
|
83
|
subMenuItemNo.setCommand(mCommandNo);
|
84
|
subMenu.getChildren().add(subMenuItemNo);
|
85
|
}
|
86
|
|
87
|
@CanExecute
|
88
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
89
|
MHandledMenuItem menuItem){
|
90
|
boolean canExecute = false;
|
91
|
StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
|
92
|
canExecute = !selection.isEmpty() && selection.getFirstElement() instanceof IAnnotatableEntity;
|
93
|
menuItem.setVisible(canExecute);
|
94
|
return canExecute;
|
95
|
}
|
96
|
|
97
|
}
|