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.ui.section.name;
|
11
|
|
12
|
import java.util.Collection;
|
13
|
import java.util.Comparator;
|
14
|
|
15
|
import org.eclipse.core.runtime.IStatus;
|
16
|
import org.eclipse.jface.action.Action;
|
17
|
import org.eclipse.jface.action.IAction;
|
18
|
import org.eclipse.jface.action.ToolBarManager;
|
19
|
import org.eclipse.jface.resource.ImageDescriptor;
|
20
|
import org.eclipse.jface.wizard.WizardDialog;
|
21
|
import org.eclipse.swt.graphics.ImageData;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
24
|
import eu.etaxonomy.cdm.api.service.INameService;
|
25
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
26
|
import eu.etaxonomy.cdm.api.service.name.TypeDesignationComparator;
|
27
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
28
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
29
|
import eu.etaxonomy.cdm.model.name.Rank;
|
30
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
31
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
32
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
33
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
34
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
35
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
36
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
37
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
38
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
39
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
40
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
41
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
42
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
|
43
|
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
|
44
|
import eu.etaxonomy.taxeditor.ui.section.name.type.CloneTypeWizard;
|
45
|
|
46
|
/**
|
47
|
* @author n.hoffmann
|
48
|
* @created May 17, 2010
|
49
|
*/
|
50
|
public class TypeDesignationSection extends AbstractEntityCollectionSection<TaxonName, TypeDesignationBase> implements ITaxonBaseDetailSection {
|
51
|
|
52
|
private TaxonBase taxonBase;
|
53
|
|
54
|
public TypeDesignationSection(CdmFormFactory formFactory, ConversationHolder conversation,
|
55
|
ICdmFormElement parentElement, int style) {
|
56
|
super(formFactory, conversation, parentElement, "Type Designations", style);
|
57
|
}
|
58
|
|
59
|
@Override
|
60
|
protected void addAction(ToolBarManager toolBarManager) {
|
61
|
if(!isSpecimenType() ||
|
62
|
getEntity().getTypeDesignations().isEmpty()
|
63
|
|| getEntity().getTypeDesignations().stream().noneMatch(designation->designation instanceof SpecimenTypeDesignation)){
|
64
|
return;
|
65
|
}
|
66
|
Action addAction = new Action("Create type duplicate", IAction.AS_PUSH_BUTTON){
|
67
|
@Override
|
68
|
public void run() {
|
69
|
CloneTypeWizard wizard = new CloneTypeWizard(getEntity());
|
70
|
WizardDialog dialog = new WizardDialog(getShell(), wizard);
|
71
|
|
72
|
if (dialog.open() == IStatus.OK) {
|
73
|
SpecimenTypeDesignation baseTypeDesignation = HibernateProxyHelper.deproxy(wizard.getBaseTypeDesignation());
|
74
|
UpdateResult result = CdmStore.getService(INameService.class).cloneTypeDesignation(
|
75
|
wizard.getTaxonName(),
|
76
|
baseTypeDesignation,
|
77
|
wizard.getAccessionNumber(),
|
78
|
wizard.getCollection(),
|
79
|
wizard.getTypeStatus());
|
80
|
if(!result.isOk()){
|
81
|
MessagingUtils.warningDialog("Duplicating type failed", this, result.getExceptions().toString());
|
82
|
}
|
83
|
StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
|
84
|
internalUpdateSection(true);
|
85
|
}
|
86
|
}
|
87
|
};
|
88
|
addAction.setImageDescriptor(new ImageDescriptor() {
|
89
|
|
90
|
@Override
|
91
|
public ImageData getImageData() {
|
92
|
return ImageResources.getImage(ImageResources.COPY_ICON).getImageData();
|
93
|
}
|
94
|
});
|
95
|
addAction.setToolTipText("Create type duplicate");
|
96
|
|
97
|
toolBarManager.add(addAction);
|
98
|
}
|
99
|
|
100
|
@Override
|
101
|
public void addElement(TypeDesignationBase element) {
|
102
|
getEntity().addTypeDesignation(element, PreferencesUtil.getBooleanValue(IPreferenceKeys.ADD_TYPES_TO_ALL_NAMES));
|
103
|
}
|
104
|
|
105
|
@Override
|
106
|
public TypeDesignationBase createNewElement() {
|
107
|
if(isSpecimenType()){
|
108
|
return SpecimenTypeDesignation.NewInstance();
|
109
|
}else{
|
110
|
return NameTypeDesignation.NewInstance();
|
111
|
}
|
112
|
}
|
113
|
|
114
|
@Override
|
115
|
public Collection<TypeDesignationBase> getCollection(TaxonName entity) {
|
116
|
if (entity == null){
|
117
|
return null;
|
118
|
}
|
119
|
return entity.getTypeDesignations();
|
120
|
}
|
121
|
|
122
|
@Override
|
123
|
public Comparator<TypeDesignationBase> getComparator() {
|
124
|
return new TypeDesignationComparator();
|
125
|
}
|
126
|
|
127
|
@Override
|
128
|
public String getEmptyString() {
|
129
|
return "No type designations yet.";
|
130
|
}
|
131
|
|
132
|
@Override
|
133
|
protected String getTooltipString() {
|
134
|
return "Add a type designation";
|
135
|
}
|
136
|
|
137
|
@Override
|
138
|
public void removeElement(TypeDesignationBase element) {
|
139
|
boolean removeTypeDesignationFromAllTypifiedNames = PreferencesUtil.getBooleanValue(IPreferenceKeys.ADD_TYPES_TO_ALL_NAMES);
|
140
|
TaxonName entity = removeTypeDesignationFromAllTypifiedNames ? null : getEntity();
|
141
|
CdmStore.getService(INameService.class).deleteTypeDesignation(entity.getUuid(), element.getUuid());
|
142
|
}
|
143
|
|
144
|
@Override
|
145
|
public void setTaxonBase(TaxonBase entity) {
|
146
|
this.taxonBase = entity;
|
147
|
TaxonName name = HibernateProxyHelper.deproxy(entity.getName());
|
148
|
setEntity(name);
|
149
|
}
|
150
|
|
151
|
private boolean isSpecimenType(){
|
152
|
Rank rank = getEntity().getRank();
|
153
|
if(rank==null){
|
154
|
return false;
|
155
|
}
|
156
|
return rank.isSpecies() || rank.isInfraSpecific();
|
157
|
}
|
158
|
|
159
|
@Override
|
160
|
public TaxonBase getTaxonBase() {
|
161
|
return taxonBase;
|
162
|
}
|
163
|
|
164
|
@Override
|
165
|
public TypeDesignationBase addExisting() {
|
166
|
return null;
|
167
|
}
|
168
|
|
169
|
@Override
|
170
|
public boolean allowAddExisting() {
|
171
|
return false;
|
172
|
}
|
173
|
}
|