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
|
* <p>GroupBasionymContributionItem class.</p>
|
27
|
*
|
28
|
* @author p.ciardelli
|
29
|
* @version $Id: $
|
30
|
*/
|
31
|
public class GroupBasionymContributionItem extends CompoundContributionItem {
|
32
|
@SuppressWarnings("unused")
|
33
|
private static final Logger logger = Logger.getLogger(GroupBasionymContributionItem.class);
|
34
|
|
35
|
/**
|
36
|
* <p>Constructor for GroupBasionymContributionItem.</p>
|
37
|
*/
|
38
|
public GroupBasionymContributionItem() {}
|
39
|
|
40
|
/**
|
41
|
* <p>Constructor for GroupBasionymContributionItem.</p>
|
42
|
*
|
43
|
* @param id a {@link java.lang.String} object.
|
44
|
*/
|
45
|
public GroupBasionymContributionItem(String id) {
|
46
|
super(id);
|
47
|
}
|
48
|
|
49
|
|
50
|
/** {@inheritDoc} */
|
51
|
@Override
|
52
|
protected IContributionItem[] getContributionItems() {
|
53
|
|
54
|
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
55
|
|
56
|
ISelectionService selectionService = window.getSelectionService();
|
57
|
|
58
|
ISelection selection = selectionService.getSelection();
|
59
|
|
60
|
if(selection instanceof IStructuredSelection){
|
61
|
Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
|
62
|
|
63
|
if(selectedObject != null && selectedObject instanceof TaxonBase){
|
64
|
|
65
|
TaxonNameBase name = (TaxonNameBase) HibernateProxyHelper.deproxy(((TaxonBase) selectedObject).getName());
|
66
|
|
67
|
if(name != null && name.getHomotypicalGroup().getTypifiedNames().size() > 1){
|
68
|
|
69
|
CommandContributionItemParameter parameter =
|
70
|
new CommandContributionItemParameter(
|
71
|
window, null, getCommand(name), SWT.NONE);
|
72
|
|
73
|
parameter.label = getLabel(name);
|
74
|
|
75
|
return new IContributionItem[] {
|
76
|
new CommandContributionItem(parameter)
|
77
|
};
|
78
|
}
|
79
|
|
80
|
}
|
81
|
}
|
82
|
|
83
|
return new IContributionItem[]{};
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* @param name
|
88
|
* @return
|
89
|
*/
|
90
|
private String getCommand(TaxonNameBase name) {
|
91
|
if(name.isGroupsBasionym()){
|
92
|
return "eu.etaxonomy.taxeditor.editor.name.removeBasionym" ;
|
93
|
}
|
94
|
return "eu.etaxonomy.taxeditor.editor.name.setBasionym";
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* @param name
|
99
|
* @return
|
100
|
*/
|
101
|
private String getLabel(TaxonNameBase name) {
|
102
|
ILabelImageStrategy strategy = LabelImageProvider.getLabelStrategy(name);
|
103
|
LabelImageProvider labelProvider = new LabelImageProvider(strategy);
|
104
|
return (name.isGroupsBasionym() ? "Remove" : "Set")
|
105
|
+ " as " + labelProvider.getNameRelationTypeDescription(NameRelationshipType.BASIONYM()) + " for Homotypic Group";
|
106
|
}
|
107
|
}
|