</annotation>
<complexType>
<sequence>
- <element ref="cdmViewer" minOccurs="1" maxOccurs="unbounded"/>
+ <element ref="cdmViewer" minOccurs="0" maxOccurs="unbounded"/>
+ <element ref="viewCommandMapping" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
</complexType>
</element>
+ <element name="viewCommandMapping">
+ <annotation>
+ <documentation>
+ Maps a viewing class, like editors or views, to a command which opens it.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="commandId" type="string" use="required">
+ <annotation>
+ <documentation>
+ The command which opens the viewer to show the selected object
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="identifier" basedOn="org.eclipse.ui.commands/command/@id"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ <attribute name="viewerName" type="string">
+ <annotation>
+ <documentation>
+ The name of the viewer which shows the selected element
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="selection" type="string" use="required">
+ <annotation>
+ <documentation>
+ The class of the selected element
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
<annotation>
<appInfo>
<meta.section type="since"/>
import java.util.Map;
import java.util.Map.Entry;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.CompoundContributionItem;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
/**
* Generic context menu for opening elements in the taxeditor.
new ContributionItem() {
@Override
public void fill(Menu menu, int index) {
+ final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ final ISelection selection = window.getActivePage().getSelection();
+
MenuItem addItem = new MenuItem(menu, SWT.CASCADE);
addItem.setText("Open in...");
Menu addMenu = new Menu(menu);
addItem.setMenu(addMenu);
- final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- final ISelection selection = window.getActivePage().getSelection();
if(selection instanceof IStructuredSelection){
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
- Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap = CdmViewerUtil.getNameViewerMap(firstElement);
- for(Entry<Entry<Class<?>, String>, ICdmViewer> entry:nameViewerMap.entrySet()){
- Entry<Class<?>, String> viewerClass = entry.getKey();
+ Map<String, String> availableViewers = CdmViewerUtil.getAvailableViewers(firstElement);
+ for(Entry<String, String> entry:availableViewers.entrySet()){
+ final String commandId = entry.getKey();
+ String viewerName = entry.getValue();
MenuItem menuItem = new MenuItem(addMenu, SWT.NONE);
- menuItem.setText(viewerClass.getValue());
- menuItem.addSelectionListener(new OpenInViewerListener(entry.getValue(), firstElement, viewerClass.getKey()));
+ menuItem.setText(viewerName);
+ menuItem.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
+
+ Command command = commandService.getCommand(commandId);
+ if(command.isEnabled()) {
+ IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
+ try {
+ handlerService.executeCommand(commandId, null);
+ } catch (NotDefinedException nde) {
+ throw new RuntimeException("Could not find open command: " + commandId);
+ } catch (Exception exception) {
+ MessagingUtils.error(getClass(), "An exception occured while trying execute "+commandId, exception);
+ }
+ }
+ }
+ }) ;
}
}
}
public static Map<Entry<Class<?>, String>, ICdmViewer> getNameViewerMap(Object input){
Map<Entry<Class<?>, String>, ICdmViewer> nameViewerMap = new HashMap<Entry<Class<?>, String>, ICdmViewer>();
-
+
IExtensionRegistry reg = Platform.getExtensionRegistry();
IConfigurationElement[] extensions = reg
.getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer");
return nameViewerMap;
}
+ public static Map<String, String> getAvailableViewers(Object input){
+ Map<String, String> commandViewerNameMap = new HashMap<String, String>();
+
+ IExtensionRegistry reg = Platform.getExtensionRegistry();
+ IConfigurationElement[] extensions = reg
+ .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer");
+ for (IConfigurationElement configElement : extensions) {
+ if(configElement.getName().equals("viewCommandMapping")){
+ String commandId = configElement.getAttribute("commandId");
+ String viewerName = configElement.getAttribute("viewerName");
+ try {
+ Object selectionObject = configElement.createExecutableExtension("selection");
+ System.out.println(selectionObject);
+ Class<? extends Object> selectionClass = selectionObject.getClass();
+ if(input.getClass().isAssignableFrom(selectionClass)){
+ commandViewerNameMap.put(commandId, viewerName);
+ }
+ } catch (CoreException e) {
+ MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e);
+ }
+ }
+ }
+ return commandViewerNameMap;
+ }
+
}