--- /dev/null
+package eu.etaxonomy.taxeditor.bulkeditor.handler.defaultHandler;
+
+import java.util.UUID;
+
+import org.eclipse.ui.PartInitException;
+
+import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
+import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
+import eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenHandlerBaseE4;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+public class OpenBulkEditorForIdentifiableEntityE4 extends DefaultOpenHandlerBaseE4<IdentifiableEntity> {
+
+ @Override
+ protected IdentifiableEntity getEntity(UUID uuid) {
+ return CdmStore.getCommonService().find(IdentifiableEntity.class, uuid);
+ }
+
+ @Override
+ protected void open(IdentifiableEntity entity) {
+ try {
+ BulkEditorUtil.openEditor(entity);
+ } catch (PartInitException e) {
+ MessagingUtils.error(this.getClass(), "Bulk Editor could not be opened for "+entity, e);
+ }
+ }
+
+
+}
eu.etaxonomy.taxeditor.cdmlib,
org.eclipse.ui.ide,
org.eclipse.e4.ui.workbench,
- org.eclipse.e4.core.di
+ org.eclipse.e4.core.di,
+ org.eclipse.e4.ui.model.workbench,
+ org.eclipse.e4.ui.di
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: javax.inject;version="1.0.0",
<?xml version="1.0" encoding="ASCII"?>
<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">
<imports xsi:type="commands:Command" xmi:id="_WPjpoDSnEeek0dKsFNy--Q" elementId="eu.etaxonomy.taxeditor.command.openPart"/>
+ <imports xsi:type="commands:Command" xmi:id="_Qz6EMD62EeekvPZafWEv7w" elementId="eu.etaxonomy.taxeditor.bulkeditor.openBulkEditorForIdentifiableEntity"/>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_gSpRsDQDEeeTNOFVGI4q2w" featurename="descriptors" parentElementId="xpath:/">
<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">
<tags>View</tags>
<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"/>
<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"/>
<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"/>
+ <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"/>
<menus xsi:type="menu:PopupMenu" xmi:id="_CYXZ0DQEEeeTNOFVGI4q2w" elementId="eu.etaxonomy.taxeditor.editor.popupmenu.specimeneditor">
<children xsi:type="menu:Menu" xmi:id="_cdjzEDmAEeeOos_QXKSXcA" elementId="eu.etaxonomy.taxeditor.editor.menu.add" label="%menu.label.5">
<visibleWhen xsi:type="ui:CoreExpression" xmi:id="_ASKmMDpCEeecM-jyCkToYw" coreExpressionId="isAddDerivateAllowed"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_Z-LKEDmBEeeOos_QXKSXcA" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.singleread" label="%handledmenuitem.label.7" command="_LTuN8DooEeecLdI14WMq7w"/>
</children>
<children xsi:type="menu:MenuSeparator" xmi:id="_O4ujcDuhEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.1"/>
+ <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"/>
+ <children xsi:type="menu:MenuSeparator" xmi:id="_sp6BoDy8EeeqBMqdgjGMrQ" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.5"/>
<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"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_5GMRcDWQEeeNfoZ3nN0K8Q" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.createfieldunit" label="%handledmenuitem.label.9" command="_BjF3ADVqEee_b7RlBzTDRw"/>
<children xsi:type="menu:MenuSeparator" xmi:id="_QoiUMDuhEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.2"/>
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.viewers.TreeNode;
}
@CanExecute
- public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode node){
- return node !=null;
+ public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode node,
+ MHandledMenuItem menuItem){
+ boolean canExecute = node !=null;
+ menuItem.setVisible(canExecute);
+ return canExecute;
}
}
--- /dev/null
+package eu.etaxonomy.taxeditor.handler.defaultHandler;
+
+import java.util.UUID;
+
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
+
+public abstract class DefaultOpenHandlerBaseE4 <T> {
+
+ @Execute
+ public Object execute(MHandledMenuItem menuItem){
+ String commandId = menuItem.getCommand().getElementId();
+ UUID uuid = (UUID) menuItem.getTransientData().get(commandId+".uuid");
+ //check if uuid parameter is set
+ if(uuid!=null){
+ T entity = getEntity(uuid);
+ open(entity);
+ }
+ return null;
+ }
+
+
+ protected abstract T getEntity(UUID uuid);
+
+ protected abstract void open(T entity);
+
+}
--- /dev/null
+package eu.etaxonomy.taxeditor.view;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.UUID;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.e4.core.commands.ECommandService;
+import org.eclipse.e4.core.commands.EHandlerService;
+import org.eclipse.e4.ui.di.AboutToShow;
+import org.eclipse.e4.ui.model.application.commands.MCommand;
+import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeNode;
+
+import eu.etaxonomy.cdm.model.common.ICdmBase;
+import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
+import eu.etaxonomy.taxeditor.l10n.Messages;
+
+/**
+ * Generic context menu for opening elements in the taxeditor.
+ *
+ */
+public class CdmViewerContextMenuE4 {
+
+ @Inject
+ private EHandlerService handlerService;
+
+ @Inject
+ private ECommandService commandService;
+
+ @AboutToShow
+ public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) Object selectedObject) {
+ if(selectedObject instanceof IStructuredSelection){
+ selectedObject = ((IStructuredSelection) selectedObject).getFirstElement();
+ }
+ if(selectedObject instanceof TreeNode){
+ selectedObject = ((TreeNode) selectedObject).getValue();
+ }
+ Map<Command, String> enabledCommands = CdmViewerUtilE4.getAvailableViewers(selectedObject, commandService, handlerService);
+
+ //get UUID
+ UUID uuid = null;
+ //for generic UuidAndTitleCache objects try to load the object
+ if (selectedObject instanceof UuidAndTitleCache){
+ uuid = ((UuidAndTitleCache)selectedObject).getUuid();
+ }
+ if(selectedObject instanceof ICdmBase){
+ uuid = ((ICdmBase) selectedObject).getUuid();
+ }
+
+ //check if only one or multiple viewers/commands are available
+ if(enabledCommands.size()==1){
+ Entry<Command, String> entry = enabledCommands.entrySet().iterator().next();
+ final Command command = entry.getKey();
+ String viewerName = entry.getValue();
+ addCommand(uuid, command, String.format(Messages.CdmViewerContextMenu_OPEN, viewerName), items);
+ }
+ else if(enabledCommands.size()>1){
+ MMenu menu = MMenuFactory.INSTANCE.createMenu();
+ menu.setLabel(Messages.CdmViewerContextMenu_OPEN_IN);
+ items.add(menu);
+ for(Entry<Command, String> entry:enabledCommands.entrySet()){
+ String viewerName = entry.getValue();
+ Command command = entry.getKey();
+ menu.getChildren().add(addCommand(uuid, command, viewerName, items));
+ }
+ }
+ }
+
+ public MHandledMenuItem addCommand(UUID uuid, Command command, String commandLabel, List<MMenuElement> items) {
+ MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem();
+ menuItem.setLabel(commandLabel);
+ MCommand mCommand = MCommandsFactory.INSTANCE.createCommand();
+ mCommand.setElementId(command.getId());
+ mCommand.setCommandName(commandLabel);
+ try {
+ mCommand.setCommandName(command.getName());
+ } catch (NotDefinedException e) {
+ e.printStackTrace();
+ }
+ //set params
+ menuItem.getTransientData().put(command.getId()+".uuid", uuid);
+// MParameter parameter = MCommandsFactory.INSTANCE.createParameter();
+// parameter.setElementId(command.getId()+".uuid");
+// parameter.setValue(uuid.toString());
+// menuItem.getParameters().add(parameter);
+
+ menuItem.setCommand(mCommand);
+ return menuItem;
+ }
+
+}
--- /dev/null
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.e4.core.commands.ECommandService;
+import org.eclipse.e4.core.commands.EHandlerService;
+import org.eclipse.jface.viewers.TreeNode;
+
+import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point.
+ * @author pplitzner
+ * @date Jul 7, 2015
+ *
+ */
+public class CdmViewerUtilE4 {
+
+ /**
+ * Returns a map of available commands to open the given input. Keys are the
+ * command IDs and values are their string representations.
+ *
+ * @param input
+ * the object which should be handled by the available commands
+ * @return a key-value map of available commands and their string
+ * representation
+ */
+ public static Map<Command, String> getAvailableViewers(Object input, ECommandService commandService,
+ EHandlerService handlerService){
+ Map<Command, String> commandViewerNameMap = new HashMap<>();
+
+ if(input!=null){
+ //for generic UuidAndTitleCache objects try to load the object
+ if (input instanceof UuidAndTitleCache){
+ UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache)input;
+ input = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
+ }
+ //for tree nodes get the value resp. the object of the node
+ else if (input instanceof TreeNode){
+ TreeNode treeNode = (TreeNode)input;
+ input = treeNode.getValue();
+ }
+
+ IExtensionRegistry reg = Platform.getExtensionRegistry();
+ IConfigurationElement[] extensions = reg
+ .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$
+ for (IConfigurationElement configElement : extensions) {
+ try {
+ if(configElement.getName().equals("viewCommandMapping")){ //$NON-NLS-1$
+ String commandId = configElement.getAttribute("commandId"); //$NON-NLS-1$
+ String viewerName = configElement.getAttribute("viewerName"); //$NON-NLS-1$
+ Class<?> selectionClass = Class.forName(configElement.getAttribute("selection")); //$NON-NLS-1$
+ if(selectionClass.isAssignableFrom(input.getClass())){
+ Command command = commandService.getCommand(commandId);
+ commandViewerNameMap.put(command, viewerName);
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e); //$NON-NLS-1$
+ }
+ }
+ }
+ return commandViewerNameMap;
+ }
+
+}