1 |
98b82274
|
Andreas Müller
|
/**
|
2 |
|
|
* Copyright (C) 2015 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 |
fcff8863
|
Patrick Plitzner
|
package eu.etaxonomy.taxeditor.view;
|
10 |
|
|
|
11 |
|
|
import java.util.List;
|
12 |
|
|
import java.util.Map;
|
13 |
|
|
import java.util.Map.Entry;
|
14 |
|
|
|
15 |
|
|
import javax.inject.Inject;
|
16 |
|
|
import javax.inject.Named;
|
17 |
|
|
|
18 |
|
|
import org.eclipse.core.commands.Command;
|
19 |
|
|
import org.eclipse.core.commands.common.NotDefinedException;
|
20 |
|
|
import org.eclipse.e4.core.commands.ECommandService;
|
21 |
|
|
import org.eclipse.e4.core.commands.EHandlerService;
|
22 |
|
|
import org.eclipse.e4.ui.di.AboutToShow;
|
23 |
|
|
import org.eclipse.e4.ui.model.application.commands.MCommand;
|
24 |
|
|
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
|
25 |
|
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
26 |
|
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
|
27 |
|
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
|
28 |
|
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
|
29 |
|
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
30 |
|
|
|
31 |
963170aa
|
Katja Luther
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
32 |
|
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
33 |
fcff8863
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
34 |
|
|
|
35 |
|
|
/**
|
36 |
|
|
* Generic context menu for opening elements in the taxeditor.
|
37 |
|
|
*/
|
38 |
|
|
public class CdmViewerContextMenuE4 {
|
39 |
|
|
|
40 |
|
|
@Inject
|
41 |
|
|
private EHandlerService handlerService;
|
42 |
|
|
|
43 |
|
|
@Inject
|
44 |
|
|
private ECommandService commandService;
|
45 |
|
|
|
46 |
|
|
@AboutToShow
|
47 |
|
|
public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) Object selectedObject) {
|
48 |
74389de2
|
Katja Luther
|
|
49 |
880f5390
|
Andreas Müller
|
if (selectedObject == null){
|
50 |
|
|
return;
|
51 |
fcff8863
|
Patrick Plitzner
|
}
|
52 |
74389de2
|
Katja Luther
|
|
53 |
bbae6889
|
Katja Luther
|
List<UuidAndTitleCache<? extends ICdmBase>> uuidTypes = CdmViewerUtil.transformSelectionToUuidAndTitleCacheList(selectedObject);
|
54 |
1c7218c8
|
Katja Luther
|
|
55 |
bbae6889
|
Katja Luther
|
Map<Command, String> enabledCommands = CdmViewerUtil.getAvailableViewers(uuidTypes, commandService, handlerService);
|
56 |
fcff8863
|
Patrick Plitzner
|
|
57 |
|
|
//check if only one or multiple viewers/commands are available
|
58 |
880f5390
|
Andreas Müller
|
if (!enabledCommands.isEmpty()){
|
59 |
fcff8863
|
Patrick Plitzner
|
MMenu menu = MMenuFactory.INSTANCE.createMenu();
|
60 |
|
|
menu.setLabel(Messages.CdmViewerContextMenu_OPEN_IN);
|
61 |
|
|
items.add(menu);
|
62 |
880f5390
|
Andreas Müller
|
for(Entry<Command, String> entry: enabledCommands.entrySet()){
|
63 |
fcff8863
|
Patrick Plitzner
|
String viewerName = entry.getValue();
|
64 |
|
|
Command command = entry.getKey();
|
65 |
880f5390
|
Andreas Müller
|
menu.getChildren().add(addCommand(uuidTypes, command, viewerName));
|
66 |
fcff8863
|
Patrick Plitzner
|
}
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
|
70 |
880f5390
|
Andreas Müller
|
|
71 |
|
|
public MHandledMenuItem addCommand(List<UuidAndTitleCache<? extends ICdmBase>> selectedUuids, Command command, String commandLabel) {
|
72 |
fcff8863
|
Patrick Plitzner
|
MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem();
|
73 |
|
|
menuItem.setLabel(commandLabel);
|
74 |
|
|
MCommand mCommand = MCommandsFactory.INSTANCE.createCommand();
|
75 |
|
|
mCommand.setElementId(command.getId());
|
76 |
|
|
mCommand.setCommandName(commandLabel);
|
77 |
|
|
try {
|
78 |
|
|
mCommand.setCommandName(command.getName());
|
79 |
|
|
} catch (NotDefinedException e) {
|
80 |
|
|
e.printStackTrace();
|
81 |
|
|
}
|
82 |
|
|
//set params
|
83 |
1c7218c8
|
Katja Luther
|
|
84 |
880f5390
|
Andreas Müller
|
menuItem.getTransientData().put(command.getId()+".uuid", selectedUuids);
|
85 |
1c7218c8
|
Katja Luther
|
|
86 |
fcff8863
|
Patrick Plitzner
|
// MParameter parameter = MCommandsFactory.INSTANCE.createParameter();
|
87 |
|
|
// parameter.setElementId(command.getId()+".uuid");
|
88 |
|
|
// parameter.setValue(uuid.toString());
|
89 |
|
|
// menuItem.getParameters().add(parameter);
|
90 |
|
|
|
91 |
|
|
menuItem.setCommand(mCommand);
|
92 |
|
|
return menuItem;
|
93 |
|
|
}
|
94 |
69dc5be6
|
Andreas Müller
|
}
|