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.commands.operations.IOperationHistory;
|
16
|
import org.eclipse.core.runtime.IStatus;
|
17
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
18
|
import org.eclipse.jface.action.Action;
|
19
|
import org.eclipse.jface.action.IAction;
|
20
|
import org.eclipse.jface.action.ToolBarManager;
|
21
|
import org.eclipse.jface.resource.ImageDescriptor;
|
22
|
import org.eclipse.jface.wizard.WizardDialog;
|
23
|
import org.eclipse.swt.graphics.ImageData;
|
24
|
|
25
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
26
|
import eu.etaxonomy.cdm.api.service.INameService;
|
27
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
28
|
import eu.etaxonomy.cdm.api.service.name.TypeDesignationComparator;
|
29
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
30
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
31
|
import eu.etaxonomy.cdm.model.name.Rank;
|
32
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
33
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
34
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
35
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
36
|
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
|
37
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
38
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
39
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
40
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
41
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
42
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
43
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
44
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
45
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
46
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
47
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
48
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
|
49
|
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
|
50
|
import eu.etaxonomy.taxeditor.ui.section.name.operation.DeleteTypeDesignationOperation;
|
51
|
import eu.etaxonomy.taxeditor.ui.section.name.type.CloneTypeWizard;
|
52
|
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
|
53
|
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
|
54
|
|
55
|
/**
|
56
|
* @author n.hoffmann
|
57
|
* @created May 17, 2010
|
58
|
*/
|
59
|
public class TypeDesignationSection extends AbstractEntityCollectionSection<TaxonName, TypeDesignationBase> implements ITaxonBaseDetailSection {
|
60
|
|
61
|
private TaxonBase taxonBase;
|
62
|
|
63
|
public TypeDesignationSection(CdmFormFactory formFactory, ConversationHolder conversation,
|
64
|
ICdmFormElement parentElement, int style) {
|
65
|
super(formFactory, conversation, parentElement, Messages.TypeDesignationSection_TYPE_DESIGNATIONS, style);
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
protected void addAction(ToolBarManager toolBarManager) {
|
70
|
if(!isSpecimenType() ||
|
71
|
getEntity().getTypeDesignations().isEmpty()
|
72
|
|| getEntity().getTypeDesignations().stream().noneMatch(designation->designation instanceof SpecimenTypeDesignation)){
|
73
|
return;
|
74
|
}
|
75
|
Action cloneAction = new Action(Messages.TypeDesignationSection_CREATE_DUPLICATE, IAction.AS_PUSH_BUTTON){
|
76
|
@Override
|
77
|
public void run() {
|
78
|
DetailsPartE4 detailsView = AbstractUtility.getDetailsView(getFormFactory().getContext().get((EPartService.class)));
|
79
|
if(detailsView!=null
|
80
|
&& detailsView.getSelectionProvidingPart().getObject() instanceof IE4SavablePart
|
81
|
&& StoreUtil.promptCheckIsDirty(((IE4SavablePart)detailsView.getSelectionProvidingPart().getObject()))){
|
82
|
return;
|
83
|
}
|
84
|
CloneTypeWizard wizard = new CloneTypeWizard(getEntity());
|
85
|
WizardDialog dialog = new WizardDialog(getShell(), wizard);
|
86
|
|
87
|
if (dialog.open() == IStatus.OK) {
|
88
|
SpecimenTypeDesignation baseTypeDesignation = HibernateProxyHelper.deproxy(wizard.getBaseTypeDesignation());
|
89
|
UpdateResult result = CdmStore.getService(INameService.class).cloneTypeDesignation(
|
90
|
wizard.getTaxonName().getUuid(),
|
91
|
baseTypeDesignation,
|
92
|
wizard.getAccessionNumber(),
|
93
|
wizard.getBarcode(),
|
94
|
wizard.getCatalogNumber(),
|
95
|
wizard.getCollection().getUuid(),
|
96
|
wizard.getTypeStatus());
|
97
|
if(!result.isOk()){
|
98
|
MessagingUtils.warningDialog(Messages.TypeDesignationSection_DUPLICATE_FAILED, this, result.getExceptions().toString());
|
99
|
}
|
100
|
StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
|
101
|
internalUpdateSection(false);
|
102
|
}
|
103
|
}
|
104
|
};
|
105
|
cloneAction.setImageDescriptor(new ImageDescriptor() {
|
106
|
|
107
|
@Override
|
108
|
public ImageData getImageData() {
|
109
|
return ImageResources.getImage(ImageResources.COPY_ICON).getImageData();
|
110
|
}
|
111
|
});
|
112
|
cloneAction.setToolTipText(Messages.TypeDesignationSection_CREATE_DUPLICATE);
|
113
|
|
114
|
toolBarManager.add(cloneAction);
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public void addElement(TypeDesignationBase element) {
|
119
|
getEntity().addTypeDesignation(element, PreferencesUtil.getBooleanValue(IPreferenceKeys.ADD_TYPES_TO_ALL_NAMES));
|
120
|
updateToolbar();
|
121
|
}
|
122
|
|
123
|
@Override
|
124
|
public TypeDesignationBase createNewElement() {
|
125
|
if(isSpecimenType()){
|
126
|
return SpecimenTypeDesignation.NewInstance();
|
127
|
}else{
|
128
|
return NameTypeDesignation.NewInstance();
|
129
|
}
|
130
|
}
|
131
|
|
132
|
@Override
|
133
|
public Collection<TypeDesignationBase> getCollection(TaxonName entity) {
|
134
|
if (entity == null){
|
135
|
return null;
|
136
|
}
|
137
|
return entity.getTypeDesignations();
|
138
|
}
|
139
|
|
140
|
@Override
|
141
|
public Comparator<TypeDesignationBase> getComparator() {
|
142
|
return new TypeDesignationComparator();
|
143
|
}
|
144
|
|
145
|
@Override
|
146
|
public String getEmptyString() {
|
147
|
return Messages.TypeDesignationSection_NO_TYPES_YET;
|
148
|
}
|
149
|
|
150
|
@Override
|
151
|
protected String getTooltipString() {
|
152
|
return Messages.TypeDesignationSection_ADD_TYPE;
|
153
|
}
|
154
|
|
155
|
@Override
|
156
|
public void removeElement(TypeDesignationBase element) {
|
157
|
DetailsPartE4 detailsView = AbstractUtility.getDetailsView(getFormFactory().getContext().get((EPartService.class)));
|
158
|
if(detailsView!=null
|
159
|
&& detailsView.getSelectionProvidingPart().getObject() instanceof IE4SavablePart
|
160
|
&& StoreUtil.promptCheckIsDirty(((IE4SavablePart)detailsView.getSelectionProvidingPart().getObject()))){
|
161
|
return;
|
162
|
}
|
163
|
boolean removeTypeDesignationFromAllTypifiedNames = PreferencesUtil.getBooleanValue(IPreferenceKeys.ADD_TYPES_TO_ALL_NAMES);
|
164
|
TaxonName entity = removeTypeDesignationFromAllTypifiedNames ? null : getEntity();
|
165
|
if(!element.isPersited() && entity!=null){
|
166
|
entity.removeTypeDesignation(element);
|
167
|
}
|
168
|
else if(detailsView!=null
|
169
|
&& detailsView.getSelectionProvidingPart().getObject() instanceof ITaxonEditor
|
170
|
&& detailsView.getSelectionProvidingPart().getObject() instanceof IPostOperationEnabled) {
|
171
|
DeleteTypeDesignationOperation operation = new DeleteTypeDesignationOperation(
|
172
|
"Remove type designation",
|
173
|
IOperationHistory.GLOBAL_UNDO_CONTEXT,
|
174
|
entity,
|
175
|
element,
|
176
|
(IPostOperationEnabled) detailsView.getSelectionProvidingPart().getObject(),
|
177
|
null);
|
178
|
((ITaxonEditor) detailsView.getSelectionProvidingPart().getObject()).addOperation(operation);
|
179
|
if(entity!=null){
|
180
|
entity.removeTypeDesignation(element);
|
181
|
}
|
182
|
}
|
183
|
updateToolbar();
|
184
|
}
|
185
|
|
186
|
@Override
|
187
|
public void setTaxonBase(TaxonBase entity) {
|
188
|
this.taxonBase = entity;
|
189
|
TaxonName name = HibernateProxyHelper.deproxy(entity.getName());
|
190
|
setEntity(name);
|
191
|
}
|
192
|
|
193
|
private boolean isSpecimenType(){
|
194
|
Rank rank = getEntity().getRank();
|
195
|
if(rank==null){
|
196
|
return false;
|
197
|
}
|
198
|
return rank.isSpecies() || rank.isInfraSpecific();
|
199
|
}
|
200
|
|
201
|
@Override
|
202
|
public TaxonBase getTaxonBase() {
|
203
|
return taxonBase;
|
204
|
}
|
205
|
|
206
|
@Override
|
207
|
public TypeDesignationBase addExisting() {
|
208
|
return null;
|
209
|
}
|
210
|
|
211
|
@Override
|
212
|
public boolean allowAddExisting() {
|
213
|
return false;
|
214
|
}
|
215
|
}
|