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