2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
12 import java
.util
.Collection
;
13 import java
.util
.Comparator
;
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
;
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
.TextualTypeDesignation
;
35 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
37 import eu
.etaxonomy
.taxeditor
.editor
.ITaxonEditor
;
38 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
39 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
40 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
41 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
42 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
43 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
44 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
45 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
46 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
47 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
48 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
49 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractEntityCollectionSection
;
50 import eu
.etaxonomy
.taxeditor
.ui
.section
.ITaxonBaseDetailSection
;
51 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.operation
.DeleteTypeDesignationOperation
;
52 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.type
.CloneTypeWizard
;
53 import eu
.etaxonomy
.taxeditor
.view
.e4
.details
.DetailsPartE4
;
54 import eu
.etaxonomy
.taxeditor
.workbench
.part
.IE4SavablePart
;
58 * @created May 17, 2010
60 public class TypeDesignationSection
extends AbstractEntityCollectionSection
<TaxonName
, TypeDesignationBase
> implements ITaxonBaseDetailSection
{
62 private TaxonBase
<?
> taxonBase
;
64 public TypeDesignationSection(CdmFormFactory formFactory
, ConversationHolder conversation
,
65 ICdmFormElement parentElement
, int style
) {
66 super(formFactory
, conversation
, parentElement
, Messages
.TypeDesignationSection_TYPE_DESIGNATIONS
, style
);
70 protected void addAction(ToolBarManager toolBarManager
) {
72 // add textual type designation button
73 Action addTextualTypeDesignationAction
= new Action("Add", IAction
.AS_PUSH_BUTTON
){
76 TextualTypeDesignation textualTypeDesignation
= TextualTypeDesignation
.NewInstance();
77 addElement(textualTypeDesignation
);
78 if(! getSection().isExpanded()) {
79 getSection().setExpanded(true);
81 internalUpdateSection(true);
84 addTextualTypeDesignationAction
.setImageDescriptor(new ImageDescriptor() {
87 public ImageData
getImageData() {
88 return ImageResources
.getImage(ImageResources
.ADD_TEXT
).getImageData();
91 addTextualTypeDesignationAction
.setToolTipText("Add textual type designation");
92 toolBarManager
.add(addTextualTypeDesignationAction
);
95 if(!isSpecimenType() ||
96 getEntity().getTypeDesignations().isEmpty()
97 || getEntity().getTypeDesignations().stream().noneMatch(designation
->designation
instanceof SpecimenTypeDesignation
)){
100 Action cloneAction
= new Action(Messages
.TypeDesignationSection_CREATE_DUPLICATE
, IAction
.AS_PUSH_BUTTON
){
103 DetailsPartE4 detailsView
= AbstractUtility
.getDetailsView(getFormFactory().getContext().get((EPartService
.class)));
105 && detailsView
.getSelectionProvidingPart().getObject() instanceof IE4SavablePart
106 && StoreUtil
.promptCheckIsDirty(((IE4SavablePart
)detailsView
.getSelectionProvidingPart().getObject()))){
109 CloneTypeWizard wizard
= new CloneTypeWizard(getEntity());
110 WizardDialog dialog
= new WizardDialog(getShell(), wizard
);
112 if (dialog
.open() == IStatus
.OK
) {
113 SpecimenTypeDesignation baseTypeDesignation
= HibernateProxyHelper
.deproxy(wizard
.getBaseTypeDesignation());
114 UpdateResult result
= CdmStore
.getService(INameService
.class).cloneTypeDesignation(
115 wizard
.getTaxonName().getUuid(),
117 wizard
.getAccessionNumber(),
119 wizard
.getCatalogNumber(),
120 wizard
.getCollection().getUuid(),
121 wizard
.getTypeStatus());
123 MessagingUtils
.warningDialog(Messages
.TypeDesignationSection_DUPLICATE_FAILED
, this, result
.getExceptions().toString());
125 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
126 internalUpdateSection(false);
130 cloneAction
.setImageDescriptor(new ImageDescriptor() {
133 public ImageData
getImageData() {
134 return ImageResources
.getImage(ImageResources
.ADD_DOUBLE
).getImageData();
137 cloneAction
.setToolTipText(Messages
.TypeDesignationSection_CREATE_DUPLICATE
);
139 toolBarManager
.add(cloneAction
);
143 public void addElement(TypeDesignationBase element
) {
144 getEntity().addTypeDesignation(element
, PreferencesUtil
.getBooleanValue(IPreferenceKeys
.ADD_TYPES_TO_ALL_NAMES
));
149 public TypeDesignationBase
createNewElement() {
150 if(isSpecimenType()){
151 return SpecimenTypeDesignation
.NewInstance();
153 return NameTypeDesignation
.NewInstance();
158 public Collection
<TypeDesignationBase
> getCollection(TaxonName entity
) {
162 return entity
.getTypeDesignations();
166 public Comparator
<TypeDesignationBase
> getComparator() {
167 return new TypeDesignationComparator();
171 public String
getEmptyString() {
172 return Messages
.TypeDesignationSection_NO_TYPES_YET
;
176 protected String
getTooltipString() {
177 return Messages
.TypeDesignationSection_ADD_TYPE
;
181 public void removeElement(TypeDesignationBase element
) {
182 DetailsPartE4 detailsView
= AbstractUtility
.getDetailsView(getFormFactory().getContext().get((EPartService
.class)));
184 && detailsView
.getSelectionProvidingPart().getObject() instanceof IE4SavablePart
185 && StoreUtil
.promptCheckIsDirty(((IE4SavablePart
)detailsView
.getSelectionProvidingPart().getObject()))){
188 boolean removeTypeDesignationFromAllTypifiedNames
= PreferencesUtil
.getBooleanValue(IPreferenceKeys
.ADD_TYPES_TO_ALL_NAMES
);
189 TaxonName entity
= removeTypeDesignationFromAllTypifiedNames ?
null : getEntity();
190 if(!element
.isPersited() && entity
!=null){
191 entity
.removeTypeDesignation(element
);
193 else if(detailsView
!=null
194 && detailsView
.getSelectionProvidingPart().getObject() instanceof ITaxonEditor
195 && detailsView
.getSelectionProvidingPart().getObject() instanceof IPostOperationEnabled
) {
196 DeleteTypeDesignationOperation operation
= new DeleteTypeDesignationOperation(
197 "Remove type designation",
198 IOperationHistory
.GLOBAL_UNDO_CONTEXT
,
201 (IPostOperationEnabled
) detailsView
.getSelectionProvidingPart().getObject(),
203 ((ITaxonEditor
) detailsView
.getSelectionProvidingPart().getObject()).addOperation(operation
);
205 entity
.removeTypeDesignation(element
);
212 public void setTaxonBase(TaxonBase entity
) {
213 this.taxonBase
= entity
;
214 TaxonName name
= HibernateProxyHelper
.deproxy(entity
.getName());
218 private boolean isSpecimenType(){
219 Rank rank
= getEntity() == null ?
null : getEntity().getRank();
223 return rank
.isSpecies() || rank
.isInfraSpecific();
227 public TaxonBase
getTaxonBase() {
232 public TypeDesignationBase
addExisting() {
237 public boolean allowAddExisting() {