Revision 1de8f66a
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/DeleteObjectContributionItem.java | ||
---|---|---|
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.command; |
|
11 |
|
|
12 |
import org.apache.log4j.Logger; |
|
13 |
import org.eclipse.jface.action.IContributionItem; |
|
14 |
import org.eclipse.swt.SWT; |
|
15 |
import org.eclipse.ui.IEditorInput; |
|
16 |
import org.eclipse.ui.IWorkbenchWindow; |
|
17 |
import org.eclipse.ui.PlatformUI; |
|
18 |
import org.eclipse.ui.actions.CompoundContributionItem; |
|
19 |
import org.eclipse.ui.menus.CommandContributionItem; |
|
20 |
import org.eclipse.ui.menus.CommandContributionItemParameter; |
|
21 |
|
|
22 |
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants; |
|
23 |
import eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputType; |
|
24 |
|
|
25 |
/** |
|
26 |
* <p>DeleteObjectContributionItem class.</p> |
|
27 |
* |
|
28 |
* @author p.ciardelli |
|
29 |
* @created 25.08.2009 |
|
30 |
* @version 1.0 |
|
31 |
*/ |
|
32 |
public class DeleteObjectContributionItem extends CompoundContributionItem { |
|
33 |
private static final Logger logger = Logger |
|
34 |
.getLogger(DeleteObjectContributionItem.class); |
|
35 |
|
|
36 |
/** |
|
37 |
* <p>Constructor for DeleteObjectContributionItem.</p> |
|
38 |
*/ |
|
39 |
public DeleteObjectContributionItem() {} |
|
40 |
|
|
41 |
/** |
|
42 |
* <p>Constructor for DeleteObjectContributionItem.</p> |
|
43 |
* |
|
44 |
* @param id a {@link java.lang.String} object. |
|
45 |
*/ |
|
46 |
public DeleteObjectContributionItem(String id) { |
|
47 |
super(id); |
|
48 |
} |
|
49 |
|
|
50 |
/* (non-Javadoc) |
|
51 |
* @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems() |
|
52 |
*/ |
|
53 |
/** {@inheritDoc} */ |
|
54 |
@Override |
|
55 |
protected IContributionItem[] getContributionItems() { |
|
56 |
|
|
57 |
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
|
58 |
|
|
59 |
CommandContributionItemParameter parameter = |
|
60 |
new CommandContributionItemParameter( |
|
61 |
window, null, IBulkEditorConstants.DYNAMIC_DELETE_OBJECT_ID, SWT.NONE); |
|
62 |
|
|
63 |
parameter.label = "Delete " + getEditorInputLabel(window) + " in Current Line"; |
|
64 |
|
|
65 |
return new IContributionItem[] { |
|
66 |
new CommandContributionItem(parameter) |
|
67 |
}; |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* @param window |
|
72 |
* @return |
|
73 |
*/ |
|
74 |
private String getEditorInputLabel(IWorkbenchWindow window) { |
|
75 |
IEditorInput input = window.getActivePage().getActiveEditor().getEditorInput(); |
|
76 |
|
|
77 |
BulkEditorInputType inputType = BulkEditorInputType.getByInput(input); |
|
78 |
return (inputType != null) ? inputType.label : ""; |
|
79 |
} |
|
80 |
} |
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/DynamicMarkerTypeEditingMenu.java | ||
---|---|---|
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.command; |
|
11 |
|
|
12 |
import org.eclipse.core.commands.ExecutionException; |
|
13 |
import org.eclipse.core.commands.NotEnabledException; |
|
14 |
import org.eclipse.core.commands.NotHandledException; |
|
15 |
import org.eclipse.core.commands.common.NotDefinedException; |
|
16 |
import org.eclipse.jface.action.ContributionItem; |
|
17 |
import org.eclipse.jface.action.IContributionItem; |
|
18 |
import org.eclipse.swt.SWT; |
|
19 |
import org.eclipse.swt.events.SelectionAdapter; |
|
20 |
import org.eclipse.swt.events.SelectionEvent; |
|
21 |
import org.eclipse.swt.widgets.Event; |
|
22 |
import org.eclipse.swt.widgets.Menu; |
|
23 |
import org.eclipse.swt.widgets.MenuItem; |
|
24 |
import org.eclipse.ui.PlatformUI; |
|
25 |
import org.eclipse.ui.actions.CompoundContributionItem; |
|
26 |
import org.eclipse.ui.handlers.IHandlerService; |
|
27 |
|
|
28 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
29 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
30 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
31 |
|
|
32 |
/** |
|
33 |
* @author n.hoffmann |
|
34 |
* @created Dec 13, 2010 |
|
35 |
* @version 1.0 |
|
36 |
*/ |
|
37 |
public class DynamicMarkerTypeEditingMenu extends CompoundContributionItem { |
|
38 |
|
|
39 |
private IHandlerService handlerService = |
|
40 |
(IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); |
|
41 |
|
|
42 |
/* (non-Javadoc) |
|
43 |
* @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems() |
|
44 |
*/ |
|
45 |
@Override |
|
46 |
protected IContributionItem[] getContributionItems() { |
|
47 |
|
|
48 |
return new IContributionItem[] { |
|
49 |
new ContributionItem() { |
|
50 |
public void fill(Menu menu, int index){ |
|
51 |
for(MarkerType markerType : CdmStore.getTermManager().getPreferredTerms(MarkerType.class)){ |
|
52 |
createMenuItem(menu, markerType); |
|
53 |
} |
|
54 |
} |
|
55 |
} |
|
56 |
}; |
|
57 |
} |
|
58 |
|
|
59 |
private void createMenuItem(Menu menu, final MarkerType markerType) { |
|
60 |
|
|
61 |
MenuItem subMenuItem = new MenuItem(menu, SWT.CASCADE); |
|
62 |
subMenuItem.setText(String.format("Set Flag '%s'", markerType.getLabel())); |
|
63 |
|
|
64 |
Menu subMenu = new Menu(menu.getShell(), SWT.DROP_DOWN); |
|
65 |
subMenuItem.setMenu(subMenu); |
|
66 |
|
|
67 |
MenuItem trueItem = new MenuItem(subMenu, SWT.PUSH); |
|
68 |
trueItem.setText("Yes"); |
|
69 |
trueItem.addSelectionListener(new SelectionAdapter() { |
|
70 |
public void widgetSelected(SelectionEvent e) { |
|
71 |
doSetFlagCommand(markerType, true); |
|
72 |
} |
|
73 |
}); |
|
74 |
|
|
75 |
MenuItem falseItem = new MenuItem(subMenu, SWT.PUSH); |
|
76 |
falseItem.setText("No"); |
|
77 |
falseItem.addSelectionListener(new SelectionAdapter() { |
|
78 |
public void widgetSelected(SelectionEvent e) { |
|
79 |
doSetFlagCommand(markerType, false); |
|
80 |
} |
|
81 |
}); |
|
82 |
} |
|
83 |
|
|
84 |
private void doSetFlagCommand(MarkerType markerType, boolean flag) { |
|
85 |
try { |
|
86 |
Event event = new Event(); |
|
87 |
event.data = new Object[]{markerType, flag}; |
|
88 |
handlerService.executeCommand("taxeditor-bulkeditor.command.setMarkerFlag", event); |
|
89 |
} catch (ExecutionException e) { |
|
90 |
MessagingUtils.error(getClass(), e); |
|
91 |
} catch (NotDefinedException e) { |
|
92 |
MessagingUtils.error(getClass(), e); |
|
93 |
} catch (NotEnabledException e) { |
|
94 |
MessagingUtils.error(getClass(), e); |
|
95 |
} catch (NotHandledException e) { |
|
96 |
MessagingUtils.error(getClass(), e); |
|
97 |
} |
|
98 |
|
|
99 |
} |
|
100 |
|
|
101 |
} |
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/DynamicNewObjectMenu.java | ||
---|---|---|
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.command; |
|
11 |
|
|
12 |
import java.util.Collections; |
|
13 |
import java.util.Map; |
|
14 |
|
|
15 |
import org.apache.log4j.Logger; |
|
16 |
import org.eclipse.jface.action.ContributionItem; |
|
17 |
import org.eclipse.jface.action.IContributionItem; |
|
18 |
import org.eclipse.swt.events.SelectionEvent; |
|
19 |
import org.eclipse.swt.events.SelectionListener; |
|
20 |
import org.eclipse.swt.widgets.Event; |
|
21 |
import org.eclipse.swt.widgets.Menu; |
|
22 |
import org.eclipse.swt.widgets.MenuItem; |
|
23 |
import org.eclipse.ui.IEditorInput; |
|
24 |
import org.eclipse.ui.IEditorPart; |
|
25 |
import org.eclipse.ui.PlatformUI; |
|
26 |
import org.eclipse.ui.actions.CompoundContributionItem; |
|
27 |
import org.eclipse.ui.handlers.IHandlerService; |
|
28 |
|
|
29 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator; |
|
30 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil; |
|
31 |
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants; |
|
32 |
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput; |
|
33 |
|
|
34 |
/** |
|
35 |
* @author n.hoffmann |
|
36 |
* @created 17.04.2009 |
|
37 |
* @version 1.0 |
|
38 |
*/ |
|
39 |
public class DynamicNewObjectMenu extends CompoundContributionItem { |
|
40 |
private static final Logger logger = Logger |
|
41 |
.getLogger(DynamicNewObjectMenu.class); |
|
42 |
|
|
43 |
private final IHandlerService handlerService = (IHandlerService) BulkEditorUtil.getService(IHandlerService.class); |
|
44 |
private Map<? extends Object, String> classLabelPairs; |
|
45 |
|
|
46 |
/** {@inheritDoc} */ |
|
47 |
@Override |
|
48 |
protected IContributionItem[] getContributionItems() { |
|
49 |
|
|
50 |
classLabelPairs = getClassLabelPairs(); |
|
51 |
|
|
52 |
return new IContributionItem[] { |
|
53 |
new ContributionItem() { |
|
54 |
@Override |
|
55 |
public void fill(Menu menu, int index){ |
|
56 |
for(final Object key : classLabelPairs.keySet()){ |
|
57 |
createMenuItem(menu, key); |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
}; |
|
62 |
} |
|
63 |
|
|
64 |
private void createMenuItem(Menu menu, final Object key){ |
|
65 |
MenuItem menuItem = new MenuItem(menu, -1); |
|
66 |
menuItem.setText(classLabelPairs.get(key)); |
|
67 |
menuItem.addSelectionListener(new SelectionListener(){ |
|
68 |
|
|
69 |
@Override |
|
70 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
71 |
|
|
72 |
@Override |
|
73 |
public void widgetSelected(SelectionEvent ev) { |
|
74 |
Event event = new Event(); |
|
75 |
event.data = key; |
|
76 |
event.text = classLabelPairs.get(key); |
|
77 |
try { |
|
78 |
handlerService.executeCommand(IBulkEditorConstants.DYNAMIC_OPEN_OBJECT_ID, event); |
|
79 |
} catch (Exception e) { |
|
80 |
logger.error("Error executing command", e); |
|
81 |
throw new RuntimeException("Error executing command", e); |
|
82 |
} |
|
83 |
} |
|
84 |
}); |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Get class label pairs from Annotated Line Editor's entity creator. |
|
89 |
* @return |
|
90 |
*/ |
|
91 |
private Map<? extends Object, String> getClassLabelPairs() { |
|
92 |
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); |
|
93 |
if (editor != null){ |
|
94 |
IEditorInput input = editor.getEditorInput(); |
|
95 |
|
|
96 |
if(input instanceof AbstractBulkEditorInput){ |
|
97 |
IEntityCreator<?> entityCreator = ((AbstractBulkEditorInput) input).getEntityCreator(); |
|
98 |
if(entityCreator!=null){ |
|
99 |
return entityCreator.getKeyLabelPairs(); |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
return Collections.EMPTY_MAP; |
|
105 |
} |
|
106 |
} |
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/OpenBulkEditorContributionItem.java | ||
---|---|---|
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.command; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
import org.eclipse.jface.action.IContributionItem; |
|
16 |
import org.eclipse.jface.action.Separator; |
|
17 |
import org.eclipse.ui.actions.CompoundContributionItem; |
|
18 |
|
|
19 |
import eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputType; |
|
20 |
|
|
21 |
/** |
|
22 |
* |
|
23 |
* @author p.ciardelli |
|
24 |
* @created 19.08.2009 |
|
25 |
* @version 1.0 |
|
26 |
*/ |
|
27 |
public class OpenBulkEditorContributionItem extends CompoundContributionItem { |
|
28 |
|
|
29 |
public OpenBulkEditorContributionItem() { |
|
30 |
} |
|
31 |
|
|
32 |
public OpenBulkEditorContributionItem(String id) { |
|
33 |
super(id); |
|
34 |
} |
|
35 |
|
|
36 |
/** {@inheritDoc} */ |
|
37 |
@Override |
|
38 |
protected IContributionItem[] getContributionItems() { |
|
39 |
|
|
40 |
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); |
|
41 |
|
|
42 |
contributionItems.add(BulkEditorInputType.AGENT.createContributionItem()); |
|
43 |
contributionItems.add(BulkEditorInputType.REFERENCE.createContributionItem()); |
|
44 |
String groupName = "test"; |
|
45 |
contributionItems.add(new Separator(groupName)); |
|
46 |
contributionItems.add(BulkEditorInputType.NAME.createContributionItem()); |
|
47 |
contributionItems.add(BulkEditorInputType.TAXON.createContributionItem()); |
|
48 |
contributionItems.add(new Separator(groupName)); |
|
49 |
contributionItems.add(BulkEditorInputType.MEDIA.createContributionItem()); |
|
50 |
contributionItems.add(new Separator(groupName)); |
|
51 |
contributionItems.add(BulkEditorInputType.OCCURRENCE.createContributionItem()); |
|
52 |
return contributionItems.toArray(new IContributionItem[contributionItems.size()]); |
|
53 |
} |
|
54 |
|
|
55 |
} |
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/command/OpenBulkEditorContributionItemE4.java | ||
---|---|---|
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.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
import org.eclipse.jface.action.IContributionItem; |
|
16 |
import org.eclipse.jface.action.Separator; |
|
17 |
import org.eclipse.ui.actions.CompoundContributionItem; |
|
18 |
|
|
19 |
import eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputType; |
|
20 |
|
|
21 |
/** |
|
22 |
* |
|
23 |
* @author p.ciardelli |
|
24 |
* @created 19.08.2009 |
|
25 |
* @version 1.0 |
|
26 |
*/ |
|
27 |
public class OpenBulkEditorContributionItemE4 extends CompoundContributionItem { |
|
28 |
|
|
29 |
public OpenBulkEditorContributionItemE4() { |
|
30 |
} |
|
31 |
|
|
32 |
public OpenBulkEditorContributionItemE4(String id) { |
|
33 |
super(id); |
|
34 |
} |
|
35 |
|
|
36 |
/** {@inheritDoc} */ |
|
37 |
@Override |
|
38 |
protected IContributionItem[] getContributionItems() { |
|
39 |
|
|
40 |
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); |
|
41 |
|
|
42 |
contributionItems.add(BulkEditorInputType.AGENT.createContributionItem()); |
|
43 |
contributionItems.add(BulkEditorInputType.REFERENCE.createContributionItem()); |
|
44 |
String groupName = "test"; //$NON-NLS-1$ |
|
45 |
contributionItems.add(new Separator(groupName)); |
|
46 |
contributionItems.add(BulkEditorInputType.NAME.createContributionItem()); |
|
47 |
contributionItems.add(BulkEditorInputType.TAXON.createContributionItem()); |
|
48 |
contributionItems.add(new Separator(groupName)); |
|
49 |
contributionItems.add(BulkEditorInputType.MEDIA.createContributionItem()); |
|
50 |
contributionItems.add(new Separator(groupName)); |
|
51 |
contributionItems.add(BulkEditorInputType.OCCURRENCE.createContributionItem()); |
|
52 |
return contributionItems.toArray(new IContributionItem[contributionItems.size()]); |
|
53 |
} |
|
54 |
|
|
55 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.view; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Map; |
|
5 |
import java.util.Map.Entry; |
|
6 |
import java.util.UUID; |
|
7 |
|
|
8 |
import org.eclipse.core.commands.Command; |
|
9 |
import org.eclipse.core.commands.ParameterizedCommand; |
|
10 |
import org.eclipse.core.commands.common.NotDefinedException; |
|
11 |
import org.eclipse.jface.action.ContributionItem; |
|
12 |
import org.eclipse.jface.action.IContributionItem; |
|
13 |
import org.eclipse.jface.viewers.ISelection; |
|
14 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
15 |
import org.eclipse.jface.viewers.TreeNode; |
|
16 |
import org.eclipse.swt.SWT; |
|
17 |
import org.eclipse.swt.events.SelectionAdapter; |
|
18 |
import org.eclipse.swt.events.SelectionEvent; |
|
19 |
import org.eclipse.swt.widgets.Menu; |
|
20 |
import org.eclipse.swt.widgets.MenuItem; |
|
21 |
import org.eclipse.ui.IWorkbenchPage; |
|
22 |
import org.eclipse.ui.IWorkbenchWindow; |
|
23 |
import org.eclipse.ui.PlatformUI; |
|
24 |
import org.eclipse.ui.actions.CompoundContributionItem; |
|
25 |
import org.eclipse.ui.handlers.IHandlerService; |
|
26 |
|
|
27 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
28 |
import eu.etaxonomy.cdm.model.common.ICdmBase; |
|
29 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
30 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
|
31 |
import eu.etaxonomy.taxeditor.l10n.Messages; |
|
32 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
33 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
34 |
|
|
35 |
/** |
|
36 |
* Generic context menu for opening elements in the taxeditor. |
|
37 |
* |
|
38 |
*/ |
|
39 |
public class CdmViewerContextMenu extends CompoundContributionItem { |
|
40 |
|
|
41 |
@Override |
|
42 |
protected IContributionItem[] getContributionItems() { |
|
43 |
IContributionItem[] contributionItems = new IContributionItem[] { |
|
44 |
new ContributionItem() { |
|
45 |
@Override |
|
46 |
public void fill(Menu menu, int index) { |
|
47 |
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
|
48 |
IWorkbenchPage activePage = window.getActivePage(); |
|
49 |
if(activePage!=null){ |
|
50 |
final ISelection selection = activePage.getSelection(); |
|
51 |
if(selection instanceof IStructuredSelection){ |
|
52 |
Object firstElement = ((IStructuredSelection) selection).getFirstElement(); |
|
53 |
if (firstElement instanceof TaxonNode && !((TaxonNode)firstElement).hasTaxon()){ |
|
54 |
firstElement = ((TaxonNode)firstElement).getClassification(); |
|
55 |
} |
|
56 |
Map<Command, String> enabledCommands = CdmViewerUtil.getAvailableViewers(firstElement); |
|
57 |
|
|
58 |
//check if only one or multiple viewers/commands are available |
|
59 |
if(enabledCommands.size()==1){ |
|
60 |
Entry<Command, String> entry = enabledCommands.entrySet().iterator().next(); |
|
61 |
final Command command = entry.getKey(); |
|
62 |
String viewerName = entry.getValue(); |
|
63 |
|
|
64 |
MenuItem addItem = new MenuItem(menu, SWT.CASCADE); |
|
65 |
addItem.setText(String.format(Messages.CdmViewerContextMenu_OPEN, viewerName)); |
|
66 |
addItem.addSelectionListener(new CommandInvoker(command, firstElement)) ; |
|
67 |
} |
|
68 |
else if(enabledCommands.size()>1){ |
|
69 |
MenuItem addItem = new MenuItem(menu, SWT.CASCADE); |
|
70 |
addItem.setText(Messages.CdmViewerContextMenu_OPEN_IN); |
|
71 |
Menu addMenu = new Menu(menu); |
|
72 |
addItem.setMenu(addMenu); |
|
73 |
for(Entry<Command, String> entry:enabledCommands.entrySet()){ |
|
74 |
final Command command = entry.getKey(); |
|
75 |
String viewerName = entry.getValue(); |
|
76 |
|
|
77 |
MenuItem menuItem = new MenuItem(addMenu, SWT.NONE); |
|
78 |
menuItem.setText(viewerName); |
|
79 |
menuItem.addSelectionListener(new CommandInvoker(command, firstElement)) ; |
|
80 |
} |
|
81 |
} |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
} |
|
87 |
}; |
|
88 |
return contributionItems; |
|
89 |
} |
|
90 |
|
|
91 |
private final class CommandInvoker extends SelectionAdapter { |
|
92 |
private final Command command; |
|
93 |
private Object selectedObject; |
|
94 |
|
|
95 |
private CommandInvoker(Command command, Object selectedObject) { |
|
96 |
this.command = command; |
|
97 |
this.selectedObject = selectedObject; |
|
98 |
} |
|
99 |
|
|
100 |
@Override |
|
101 |
public void widgetSelected(SelectionEvent e) { |
|
102 |
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class); |
|
103 |
Map<String, UUID> params = new HashMap<String, UUID>(); |
|
104 |
//for generic UuidAndTitleCache objects try to load the object |
|
105 |
if (selectedObject instanceof UuidAndTitleCache){ |
|
106 |
selectedObject = CdmStore.getCommonService().find(CdmBase.class, ((UuidAndTitleCache)selectedObject).getUuid()); |
|
107 |
} |
|
108 |
//for tree nodes get the value resp. the object of the node |
|
109 |
else if (selectedObject instanceof TreeNode){ |
|
110 |
selectedObject = ((TreeNode) selectedObject).getValue(); |
|
111 |
} |
|
112 |
if (selectedObject instanceof TaxonNode && !((TaxonNode)selectedObject).hasTaxon()){ |
|
113 |
selectedObject = ((TaxonNode)selectedObject).getClassification(); |
|
114 |
} |
|
115 |
if(selectedObject instanceof ICdmBase){ |
|
116 |
params.put(command.getId()+".uuid", ((ICdmBase) selectedObject).getUuid()); //$NON-NLS-1$ |
|
117 |
} |
|
118 |
ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, params); |
|
119 |
try { |
|
120 |
if(parameterizedCommand!=null){ |
|
121 |
handlerService.executeCommand(parameterizedCommand, null); |
|
122 |
} |
|
123 |
else{ |
|
124 |
handlerService.executeCommand(command.getId(), null); |
|
125 |
} |
|
126 |
} catch (NotDefinedException nde) { |
|
127 |
throw new RuntimeException("Could not find open command: " + command.getId()); //$NON-NLS-1$ |
|
128 |
} catch (Exception exception) { |
|
129 |
MessagingUtils.error(getClass(), "An exception occurred while trying to execute "+command.getId(), exception); //$NON-NLS-1$ |
|
130 |
} |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
} |
Also available in: Unified diff
ref #6913 Remove e3 context menus