1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.view.concept.handler;
|
5
|
|
6
|
import org.eclipse.jface.action.ContributionItem;
|
7
|
import org.eclipse.swt.events.SelectionEvent;
|
8
|
import org.eclipse.swt.events.SelectionListener;
|
9
|
import org.eclipse.swt.widgets.Event;
|
10
|
import org.eclipse.swt.widgets.Menu;
|
11
|
import org.eclipse.swt.widgets.MenuItem;
|
12
|
import org.eclipse.ui.handlers.IHandlerService;
|
13
|
|
14
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
15
|
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
|
16
|
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
|
17
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
18
|
|
19
|
/**
|
20
|
* <p>Abstract AbstractDynamicConceptRelationMenu class.</p>
|
21
|
*
|
22
|
* @author n.hoffmann
|
23
|
* @created 17.04.2009
|
24
|
* @version 1.0
|
25
|
*/
|
26
|
public abstract class AbstractDynamicConceptRelationMenu extends ContributionItem {
|
27
|
|
28
|
/*
|
29
|
* (non-Javadoc)
|
30
|
* @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, int)
|
31
|
*/
|
32
|
/** {@inheritDoc} */
|
33
|
@Override
|
34
|
public void fill(Menu menu, int index){
|
35
|
final IHandlerService handlerService = (IHandlerService) TaxeditorEditorPlugin.getDefault().getWorkbench().getService(IHandlerService.class);
|
36
|
|
37
|
for(final TaxonRelationshipTypeInverseContainer container : CdmStore.getTermManager().getRelationshipTypesWithInverses()){
|
38
|
MenuItem menuItem = new MenuItem(menu, -1);
|
39
|
menuItem.setText(container.getTitleCache());
|
40
|
menuItem.setData(container);
|
41
|
menuItem.addSelectionListener(new SelectionListener(){
|
42
|
|
43
|
public void widgetDefaultSelected(SelectionEvent e) {}
|
44
|
|
45
|
public void widgetSelected(SelectionEvent ev) {
|
46
|
Event event = new Event();
|
47
|
event.data = container;
|
48
|
try {
|
49
|
handlerService.executeCommand(getCommandName(), event);
|
50
|
} catch (Exception e) {
|
51
|
EditorUtil.error(getClass(), "Error executing command", e);
|
52
|
}
|
53
|
}
|
54
|
});
|
55
|
}
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* <p>getCommandName</p>
|
60
|
*
|
61
|
* @return a {@link java.lang.String} object.
|
62
|
*/
|
63
|
public abstract String getCommandName();
|
64
|
|
65
|
}
|