Revision fcff8863
Added by Patrick Plitzner almost 5 years ago
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/defaultHandler/OpenBulkEditorForIdentifiableEntityE4.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.bulkeditor.handler.defaultHandler; |
|
2 |
|
|
3 |
import java.util.UUID; |
|
4 |
|
|
5 |
import org.eclipse.ui.PartInitException; |
|
6 |
|
|
7 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
8 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil; |
|
9 |
import eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenHandlerBaseE4; |
|
10 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
11 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
12 |
|
|
13 |
public class OpenBulkEditorForIdentifiableEntityE4 extends DefaultOpenHandlerBaseE4<IdentifiableEntity> { |
|
14 |
|
|
15 |
@Override |
|
16 |
protected IdentifiableEntity getEntity(UUID uuid) { |
|
17 |
return CdmStore.getCommonService().find(IdentifiableEntity.class, uuid); |
|
18 |
} |
|
19 |
|
|
20 |
@Override |
|
21 |
protected void open(IdentifiableEntity entity) { |
|
22 |
try { |
|
23 |
BulkEditorUtil.openEditor(entity); |
|
24 |
} catch (PartInitException e) { |
|
25 |
MessagingUtils.error(this.getClass(), "Bulk Editor could not be opened for "+entity, e); |
|
26 |
} |
|
27 |
} |
|
28 |
|
|
29 |
|
|
30 |
} |
eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF | ||
---|---|---|
30 | 30 |
eu.etaxonomy.taxeditor.cdmlib, |
31 | 31 |
org.eclipse.ui.ide, |
32 | 32 |
org.eclipse.e4.ui.workbench, |
33 |
org.eclipse.e4.core.di |
|
33 |
org.eclipse.e4.core.di, |
|
34 |
org.eclipse.e4.ui.model.workbench, |
|
35 |
org.eclipse.e4.ui.di |
|
34 | 36 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 |
35 | 37 |
Bundle-ActivationPolicy: lazy |
36 | 38 |
Import-Package: javax.inject;version="1.0.0", |
eu.etaxonomy.taxeditor.editor/fragment.e4xmi | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="ASCII"?> |
2 | 2 |
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/descriptor/basic" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmlns:ui="http://www.eclipse.org/ui/2010/UIModel/application/ui" xmi:id="_OhwnQCTfEeeiN5lBIuqN3g"> |
3 | 3 |
<imports xsi:type="commands:Command" xmi:id="_WPjpoDSnEeek0dKsFNy--Q" elementId="eu.etaxonomy.taxeditor.command.openPart"/> |
4 |
<imports xsi:type="commands:Command" xmi:id="_Qz6EMD62EeekvPZafWEv7w" elementId="eu.etaxonomy.taxeditor.bulkeditor.openBulkEditorForIdentifiableEntity"/> |
|
4 | 5 |
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_gSpRsDQDEeeTNOFVGI4q2w" featurename="descriptors" parentElementId="xpath:/"> |
5 | 6 |
<elements xsi:type="basic:PartDescriptor" xmi:id="_gSpRsTQDEeeTNOFVGI4q2w" elementId="eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView" label="%command.label.DERIVATIVE_EDITOR" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.editor/icons/derivate_view-16x16-32.png" tooltip="" allowMultiple="true" category="Sample Category" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"> |
6 | 7 |
<tags>View</tags> |
... | ... | |
19 | 20 |
<handlers xmi:id="_bAGysDumEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.view.derivate.handler.SingleReadHandler.reuseSingleRead" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.derivate.handler.SingleReadReuseHandler" command="_HmerkDumEeeOtqC_3qh40A"/> |
20 | 21 |
<handlers xmi:id="_ed9ZoDumEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.view.derivate.handler.SingleReadHandler.removeSingleRead" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.derivate.handler.SingleReadRemoveHandler" command="_K4DxEDumEeeOtqC_3qh40A"/> |
21 | 22 |
<handlers xmi:id="_CQjyIDvaEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.view.derivate.handler.DeleteDerivateHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.derivate.handler.DeleteDerivateHandler" command="_YPp1wDvREeeOtqC_3qh40A"/> |
23 |
<handlers xmi:id="_OJK8QD62EeekvPZafWEv7w" elementId="eu.etaxonomy.taxeditor.bulkeditor.handler.defaultHandler.OpenBulkEditorForIdentifiableEntityE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.bulkeditor/eu.etaxonomy.taxeditor.bulkeditor.handler.defaultHandler.OpenBulkEditorForIdentifiableEntityE4" command="_Qz6EMD62EeekvPZafWEv7w"/> |
|
22 | 24 |
<menus xsi:type="menu:PopupMenu" xmi:id="_CYXZ0DQEEeeTNOFVGI4q2w" elementId="eu.etaxonomy.taxeditor.editor.popupmenu.specimeneditor"> |
23 | 25 |
<children xsi:type="menu:Menu" xmi:id="_cdjzEDmAEeeOos_QXKSXcA" elementId="eu.etaxonomy.taxeditor.editor.menu.add" label="%menu.label.5"> |
24 | 26 |
<visibleWhen xsi:type="ui:CoreExpression" xmi:id="_ASKmMDpCEeecM-jyCkToYw" coreExpressionId="isAddDerivateAllowed"/> |
... | ... | |
35 | 37 |
<children xsi:type="menu:HandledMenuItem" xmi:id="_Z-LKEDmBEeeOos_QXKSXcA" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.singleread" label="%handledmenuitem.label.7" command="_LTuN8DooEeecLdI14WMq7w"/> |
36 | 38 |
</children> |
37 | 39 |
<children xsi:type="menu:MenuSeparator" xmi:id="_O4ujcDuhEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.1"/> |
40 |
<children xsi:type="menu:DynamicMenuContribution" xmi:id="_yz9M4DxrEeeqBMqdgjGMrQ" elementId="eu.etaxonomy.taxeditor.editor.specimeneditor.dynamicmenucontribution.cdmViewer" label="Open in..." contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.CdmViewerContextMenuE4"/> |
|
41 |
<children xsi:type="menu:MenuSeparator" xmi:id="_sp6BoDy8EeeqBMqdgjGMrQ" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.5"/> |
|
38 | 42 |
<children xsi:type="menu:HandledMenuItem" xmi:id="_um1oYDVpEee_b7RlBzTDRw" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.create_field_unit_for_taxon" label="%handledmenuitem.label.8" command="_BjF3ADVqEee_b7RlBzTDRw"/> |
39 | 43 |
<children xsi:type="menu:HandledMenuItem" xmi:id="_5GMRcDWQEeeNfoZ3nN0K8Q" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.createfieldunit" label="%handledmenuitem.label.9" command="_BjF3ADVqEee_b7RlBzTDRw"/> |
40 | 44 |
<children xsi:type="menu:MenuSeparator" xmi:id="_QoiUMDuhEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.2"/> |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/DeleteDerivateHandler.java | ||
---|---|---|
18 | 18 |
import org.eclipse.e4.core.di.annotations.Execute; |
19 | 19 |
import org.eclipse.e4.core.di.annotations.Optional; |
20 | 20 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
21 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
21 | 22 |
import org.eclipse.e4.ui.services.IServiceConstants; |
22 | 23 |
import org.eclipse.jface.viewers.TreeNode; |
23 | 24 |
|
... | ... | |
125 | 126 |
} |
126 | 127 |
|
127 | 128 |
@CanExecute |
128 |
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode node){ |
|
129 |
return node !=null; |
|
129 |
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode node, |
|
130 |
MHandledMenuItem menuItem){ |
|
131 |
boolean canExecute = node !=null; |
|
132 |
menuItem.setVisible(canExecute); |
|
133 |
return canExecute; |
|
130 | 134 |
} |
131 | 135 |
|
132 | 136 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenHandlerBaseE4.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.handler.defaultHandler; |
|
2 |
|
|
3 |
import java.util.UUID; |
|
4 |
|
|
5 |
import org.eclipse.e4.core.di.annotations.Execute; |
|
6 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
7 |
|
|
8 |
public abstract class DefaultOpenHandlerBaseE4 <T> { |
|
9 |
|
|
10 |
@Execute |
|
11 |
public Object execute(MHandledMenuItem menuItem){ |
|
12 |
String commandId = menuItem.getCommand().getElementId(); |
|
13 |
UUID uuid = (UUID) menuItem.getTransientData().get(commandId+".uuid"); |
|
14 |
//check if uuid parameter is set |
|
15 |
if(uuid!=null){ |
|
16 |
T entity = getEntity(uuid); |
|
17 |
open(entity); |
|
18 |
} |
|
19 |
return null; |
|
20 |
} |
|
21 |
|
|
22 |
|
|
23 |
protected abstract T getEntity(UUID uuid); |
|
24 |
|
|
25 |
protected abstract void open(T entity); |
|
26 |
|
|
27 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenuE4.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.view; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.Map; |
|
5 |
import java.util.Map.Entry; |
|
6 |
import java.util.UUID; |
|
7 |
|
|
8 |
import javax.inject.Inject; |
|
9 |
import javax.inject.Named; |
|
10 |
|
|
11 |
import org.eclipse.core.commands.Command; |
|
12 |
import org.eclipse.core.commands.common.NotDefinedException; |
|
13 |
import org.eclipse.e4.core.commands.ECommandService; |
|
14 |
import org.eclipse.e4.core.commands.EHandlerService; |
|
15 |
import org.eclipse.e4.ui.di.AboutToShow; |
|
16 |
import org.eclipse.e4.ui.model.application.commands.MCommand; |
|
17 |
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory; |
|
18 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
19 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenu; |
|
20 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; |
|
21 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory; |
|
22 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
23 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
24 |
import org.eclipse.jface.viewers.TreeNode; |
|
25 |
|
|
26 |
import eu.etaxonomy.cdm.model.common.ICdmBase; |
|
27 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
|
28 |
import eu.etaxonomy.taxeditor.l10n.Messages; |
|
29 |
|
|
30 |
/** |
|
31 |
* Generic context menu for opening elements in the taxeditor. |
|
32 |
* |
|
33 |
*/ |
|
34 |
public class CdmViewerContextMenuE4 { |
|
35 |
|
|
36 |
@Inject |
|
37 |
private EHandlerService handlerService; |
|
38 |
|
|
39 |
@Inject |
|
40 |
private ECommandService commandService; |
|
41 |
|
|
42 |
@AboutToShow |
|
43 |
public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) Object selectedObject) { |
|
44 |
if(selectedObject instanceof IStructuredSelection){ |
|
45 |
selectedObject = ((IStructuredSelection) selectedObject).getFirstElement(); |
|
46 |
} |
|
47 |
if(selectedObject instanceof TreeNode){ |
|
48 |
selectedObject = ((TreeNode) selectedObject).getValue(); |
|
49 |
} |
|
50 |
Map<Command, String> enabledCommands = CdmViewerUtilE4.getAvailableViewers(selectedObject, commandService, handlerService); |
|
51 |
|
|
52 |
//get UUID |
|
53 |
UUID uuid = null; |
|
54 |
//for generic UuidAndTitleCache objects try to load the object |
|
55 |
if (selectedObject instanceof UuidAndTitleCache){ |
|
56 |
uuid = ((UuidAndTitleCache)selectedObject).getUuid(); |
|
57 |
} |
|
58 |
if(selectedObject instanceof ICdmBase){ |
|
59 |
uuid = ((ICdmBase) selectedObject).getUuid(); |
|
60 |
} |
|
61 |
|
|
62 |
//check if only one or multiple viewers/commands are available |
|
63 |
if(enabledCommands.size()==1){ |
|
64 |
Entry<Command, String> entry = enabledCommands.entrySet().iterator().next(); |
|
65 |
final Command command = entry.getKey(); |
|
66 |
String viewerName = entry.getValue(); |
|
67 |
addCommand(uuid, command, String.format(Messages.CdmViewerContextMenu_OPEN, viewerName), items); |
|
68 |
} |
|
69 |
else if(enabledCommands.size()>1){ |
|
70 |
MMenu menu = MMenuFactory.INSTANCE.createMenu(); |
|
71 |
menu.setLabel(Messages.CdmViewerContextMenu_OPEN_IN); |
|
72 |
items.add(menu); |
|
73 |
for(Entry<Command, String> entry:enabledCommands.entrySet()){ |
|
74 |
String viewerName = entry.getValue(); |
|
75 |
Command command = entry.getKey(); |
|
76 |
menu.getChildren().add(addCommand(uuid, command, viewerName, items)); |
|
77 |
} |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
public MHandledMenuItem addCommand(UUID uuid, Command command, String commandLabel, List<MMenuElement> items) { |
|
82 |
MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem(); |
|
83 |
menuItem.setLabel(commandLabel); |
|
84 |
MCommand mCommand = MCommandsFactory.INSTANCE.createCommand(); |
|
85 |
mCommand.setElementId(command.getId()); |
|
86 |
mCommand.setCommandName(commandLabel); |
|
87 |
try { |
|
88 |
mCommand.setCommandName(command.getName()); |
|
89 |
} catch (NotDefinedException e) { |
|
90 |
e.printStackTrace(); |
|
91 |
} |
|
92 |
//set params |
|
93 |
menuItem.getTransientData().put(command.getId()+".uuid", uuid); |
|
94 |
// MParameter parameter = MCommandsFactory.INSTANCE.createParameter(); |
|
95 |
// parameter.setElementId(command.getId()+".uuid"); |
|
96 |
// parameter.setValue(uuid.toString()); |
|
97 |
// menuItem.getParameters().add(parameter); |
|
98 |
|
|
99 |
menuItem.setCommand(mCommand); |
|
100 |
return menuItem; |
|
101 |
} |
|
102 |
|
|
103 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtilE4.java | ||
---|---|---|
1 |
/** |
|
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 |
package eu.etaxonomy.taxeditor.view; |
|
10 |
|
|
11 |
import java.util.HashMap; |
|
12 |
import java.util.Map; |
|
13 |
|
|
14 |
import org.eclipse.core.commands.Command; |
|
15 |
import org.eclipse.core.runtime.IConfigurationElement; |
|
16 |
import org.eclipse.core.runtime.IExtensionRegistry; |
|
17 |
import org.eclipse.core.runtime.Platform; |
|
18 |
import org.eclipse.e4.core.commands.ECommandService; |
|
19 |
import org.eclipse.e4.core.commands.EHandlerService; |
|
20 |
import org.eclipse.jface.viewers.TreeNode; |
|
21 |
|
|
22 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
|
23 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
24 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
25 |
|
|
26 |
/** |
|
27 |
* Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point. |
|
28 |
* @author pplitzner |
|
29 |
* @date Jul 7, 2015 |
|
30 |
* |
|
31 |
*/ |
|
32 |
public class CdmViewerUtilE4 { |
|
33 |
|
|
34 |
/** |
|
35 |
* Returns a map of available commands to open the given input. Keys are the |
|
36 |
* command IDs and values are their string representations. |
|
37 |
* |
|
38 |
* @param input |
|
39 |
* the object which should be handled by the available commands |
|
40 |
* @return a key-value map of available commands and their string |
|
41 |
* representation |
|
42 |
*/ |
|
43 |
public static Map<Command, String> getAvailableViewers(Object input, ECommandService commandService, |
|
44 |
EHandlerService handlerService){ |
|
45 |
Map<Command, String> commandViewerNameMap = new HashMap<>(); |
|
46 |
|
|
47 |
if(input!=null){ |
|
48 |
//for generic UuidAndTitleCache objects try to load the object |
|
49 |
if (input instanceof UuidAndTitleCache){ |
|
50 |
UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache)input; |
|
51 |
input = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid()); |
|
52 |
} |
|
53 |
//for tree nodes get the value resp. the object of the node |
|
54 |
else if (input instanceof TreeNode){ |
|
55 |
TreeNode treeNode = (TreeNode)input; |
|
56 |
input = treeNode.getValue(); |
|
57 |
} |
|
58 |
|
|
59 |
IExtensionRegistry reg = Platform.getExtensionRegistry(); |
|
60 |
IConfigurationElement[] extensions = reg |
|
61 |
.getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$ |
|
62 |
for (IConfigurationElement configElement : extensions) { |
|
63 |
try { |
|
64 |
if(configElement.getName().equals("viewCommandMapping")){ //$NON-NLS-1$ |
|
65 |
String commandId = configElement.getAttribute("commandId"); //$NON-NLS-1$ |
|
66 |
String viewerName = configElement.getAttribute("viewerName"); //$NON-NLS-1$ |
|
67 |
Class<?> selectionClass = Class.forName(configElement.getAttribute("selection")); //$NON-NLS-1$ |
|
68 |
if(selectionClass.isAssignableFrom(input.getClass())){ |
|
69 |
Command command = commandService.getCommand(commandId); |
|
70 |
commandViewerNameMap.put(command, viewerName); |
|
71 |
} |
|
72 |
} |
|
73 |
} catch (ClassNotFoundException e) { |
|
74 |
MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e); //$NON-NLS-1$ |
|
75 |
} |
|
76 |
} |
|
77 |
} |
|
78 |
return commandViewerNameMap; |
|
79 |
} |
|
80 |
|
|
81 |
} |
Also available in: Unified diff
ref #6566 Migrate "Open in.." context menu items for specimen editor