3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
13 import org
.eclipse
.jface
.action
.Action
;
14 import org
.eclipse
.jface
.action
.IAction
;
15 import org
.eclipse
.jface
.action
.ToolBarManager
;
16 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.widgets
.Control
;
20 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
21 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
22 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
23 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
24 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
27 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
28 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
30 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.NameSelectionDialog
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
36 import eu
.etaxonomy
.taxeditor
.ui
.section
.ITaxonBaseDetailSection
;
40 * @created May 20, 2010
43 public class NonViralNameDetailSection
extends AbstractCdmDetailSection
<NonViralName
>
44 implements ITaxonBaseDetailSection
{
46 private TaxonBase taxonBase
;
47 boolean nameChoosable
= false;
50 * <p>Constructor for NonViralNameDetailSection.</p>
52 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
53 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
54 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
55 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
56 * @param nameChoosable if <code>true</code> adds a button to choose the displayed name
59 public NonViralNameDetailSection(CdmFormFactory formFactory
, ConversationHolder conversation
,
60 ICdmFormElement parentElement
, ISelectionProvider selectionProvider
, boolean nameChoosable
, int style
) {
61 super(formFactory
, conversation
, parentElement
, selectionProvider
, style
);
62 this.nameChoosable
= nameChoosable
;
66 protected Control
createToolbar() {
67 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
71 Action chooseNameAction
= new Action("Choose Name", IAction
.AS_PUSH_BUTTON
){
74 TaxonNameBase taxonName
= NameSelectionDialog
.select(getShell(), getConversationHolder(), null);
76 if(taxonName
.isInstanceOf(NonViralName
.class)){
77 CdmStore
.getService(ITaxonNodeService
.class).list(TaxonNode
.class, null, null, null, null);
78 NonViralName nonViralName
= HibernateProxyHelper
.deproxy(taxonName
, NonViralName
.class);
79 taxonBase
.setName(nonViralName
);
80 // taxonBase.getTitleCache();
81 setEntity(nonViralName
);
82 firePropertyChangeEvent(NonViralNameDetailSection
.this);
85 MessagingUtils
.warningDialog("Invalid name", this, "The selected name can not be used for this taxon.");
90 chooseNameAction
.setToolTipText("Choose name for this taxon");
91 chooseNameAction
.setImageDescriptor(ImageResources
.getImageDescriptor(ImageResources
.BROWSE_ICON
));
93 toolBarManager
.add(chooseNameAction
);
97 if(getEntity() != null && checkForMultipleNameUsages(getEntity())){
99 Action cloneAction
= new Action("Clone", IAction
.AS_PUSH_BUTTON
){
102 boolean confirm
= MessagingUtils
.confirmDialog("Confirm cloning", "Do you really want to clone the name?");
105 NonViralName clonedName
;
106 clonedName
= (NonViralName
) getEntity().clone();
107 setEntity(clonedName
);
108 taxonBase
.setName(clonedName
);
109 taxonBase
.generateTitle();
110 firePropertyChangeEvent(new CdmPropertyChangeEvent(NonViralNameDetailSection
.this, null));
116 cloneAction
.setToolTipText("Clone the name if you do not want to edit the shared instance");
118 toolBarManager
.add(cloneAction
);
121 return toolBarManager
.createControl(this);
125 private boolean checkForMultipleNameUsages(NonViralName nonViralName
) {
126 return nonViralName
.getTaxonBases().size() != 1;
131 public String
getHeading() {
137 public void setTaxonBase(TaxonBase taxon
) {
139 NonViralName name
= (NonViralName
) HibernateProxyHelper
.deproxy(taxon
.getName());
144 public TaxonBase
getTaxonBase() {
149 protected AbstractCdmDetailElement
<NonViralName
> createCdmDetailElement(AbstractCdmDetailSection
<NonViralName
> parentElement
, int style
) {
150 return formFactory
.createNonViralNameDetailElement(parentElement
);