1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.name.handler;
|
5
|
|
6
|
import org.apache.log4j.Logger;
|
7
|
import org.eclipse.jface.action.IContributionItem;
|
8
|
import org.eclipse.jface.viewers.ISelection;
|
9
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
10
|
import org.eclipse.swt.SWT;
|
11
|
import org.eclipse.ui.ISelectionService;
|
12
|
import org.eclipse.ui.IWorkbenchWindow;
|
13
|
import org.eclipse.ui.PlatformUI;
|
14
|
import org.eclipse.ui.actions.CompoundContributionItem;
|
15
|
import org.eclipse.ui.menus.CommandContributionItem;
|
16
|
import org.eclipse.ui.menus.CommandContributionItemParameter;
|
17
|
|
18
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
19
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
20
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
22
|
import eu.etaxonomy.taxeditor.labels.ILabelImageStrategy;
|
23
|
import eu.etaxonomy.taxeditor.labels.LabelImageProvider;
|
24
|
|
25
|
/**
|
26
|
* @author p.ciardelli
|
27
|
*
|
28
|
*/
|
29
|
public class GroupBasionymContributionItem extends CompoundContributionItem {
|
30
|
private static final Logger logger = Logger.getLogger(GroupBasionymContributionItem.class);
|
31
|
|
32
|
/**
|
33
|
*
|
34
|
*/
|
35
|
public GroupBasionymContributionItem() {}
|
36
|
|
37
|
/**
|
38
|
* @param id
|
39
|
*/
|
40
|
public GroupBasionymContributionItem(String id) {
|
41
|
super(id);
|
42
|
}
|
43
|
|
44
|
|
45
|
/* (non-Javadoc)
|
46
|
* @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
|
47
|
*/
|
48
|
@Override
|
49
|
protected IContributionItem[] getContributionItems() {
|
50
|
|
51
|
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
52
|
|
53
|
ISelectionService selectionService = window.getSelectionService();
|
54
|
|
55
|
ISelection selection = selectionService.getSelection();
|
56
|
|
57
|
if(selection instanceof IStructuredSelection){
|
58
|
Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
|
59
|
|
60
|
if(selectedObject != null && selectedObject instanceof TaxonBase){
|
61
|
|
62
|
TaxonNameBase name = (TaxonNameBase) HibernateProxyHelper.deproxy(((TaxonBase) selectedObject).getName());
|
63
|
|
64
|
if(name.getHomotypicalGroup().getTypifiedNames().size() > 1){
|
65
|
|
66
|
CommandContributionItemParameter parameter =
|
67
|
new CommandContributionItemParameter(
|
68
|
window, null, getCommand(name), SWT.NONE);
|
69
|
|
70
|
parameter.label = getLabel(name);
|
71
|
|
72
|
return new IContributionItem[] {
|
73
|
new CommandContributionItem(parameter)
|
74
|
};
|
75
|
}
|
76
|
|
77
|
}
|
78
|
}
|
79
|
|
80
|
return new IContributionItem[]{};
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* @param name
|
85
|
* @return
|
86
|
*/
|
87
|
private String getCommand(TaxonNameBase name) {
|
88
|
if(name.isGroupsBasionym()){
|
89
|
return "eu.etaxonomy.taxeditor.editor.name.removeBasionym" ;
|
90
|
}
|
91
|
return "eu.etaxonomy.taxeditor.editor.name.setBasionym";
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* @param name
|
96
|
* @return
|
97
|
*/
|
98
|
private String getLabel(TaxonNameBase name) {
|
99
|
ILabelImageStrategy strategy = LabelImageProvider.getLabelStrategy(name);
|
100
|
LabelImageProvider labelProvider = new LabelImageProvider(strategy);
|
101
|
return (name.isGroupsBasionym() ? "Remove" : "Set")
|
102
|
+ " as " + labelProvider.getNameRelationTypeDescription(NameRelationshipType.BASIONYM()) + " for Group";
|
103
|
}
|
104
|
}
|