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 org
.eclipse
.jface
.action
.Action
;
13 import org
.eclipse
.jface
.action
.IAction
;
14 import org
.eclipse
.jface
.action
.ToolBarManager
;
15 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.widgets
.Control
;
19 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
20 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
21 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
22 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
24 import eu
.etaxonomy
.taxeditor
.event
.EventUtility
;
25 import eu
.etaxonomy
.taxeditor
.event
.WorkbenchEventConstants
;
26 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
27 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
28 import eu
.etaxonomy
.taxeditor
.remoting
.CdmEagerLoadingException
;
29 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.NameSelectionDialog
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
35 import eu
.etaxonomy
.taxeditor
.ui
.section
.ITaxonBaseDetailSection
;
39 * @created May 20, 2010
41 public class NonViralNameDetailSection
extends AbstractCdmDetailSection
<TaxonName
>
42 implements ITaxonBaseDetailSection
{
44 private TaxonBase
<?
> taxonBase
;
45 boolean nameChoosable
= false;
48 * <p>Constructor for NonViralNameDetailSection.</p>
50 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
51 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
52 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
53 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
54 * @param nameChoosable if <code>true</code> adds a button to choose the displayed name
57 public NonViralNameDetailSection(CdmFormFactory formFactory
, ConversationHolder conversation
,
58 ICdmFormElement parentElement
, ISelectionProvider selectionProvider
, boolean nameChoosable
, int style
) {
59 super(formFactory
, conversation
, parentElement
, selectionProvider
, style
);
60 this.nameChoosable
= nameChoosable
;
64 protected Control
createToolbar() {
65 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
69 Action chooseNameAction
= new Action("Choose Name", IAction
.AS_PUSH_BUTTON
){
72 TaxonName taxonName
= NameSelectionDialog
.select(getShell(), //getConversationHolder(),
75 TaxonName nonViralName
= HibernateProxyHelper
.deproxy(taxonName
);
76 taxonBase
.setName(nonViralName
);
77 setEntity(nonViralName
);
79 firePropertyChangeEvent(NonViralNameDetailSection
.this);
80 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_DETAILS
, true);
81 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_SUPPLEMENTAL
, true);
85 chooseNameAction
.setToolTipText("Choose name for this taxon");
86 chooseNameAction
.setImageDescriptor(ImageResources
.getImageDescriptor(ImageResources
.BROWSE_ICON
));
88 toolBarManager
.add(chooseNameAction
);
92 if(getEntity() != null && checkForMultipleNameUsages(getEntity())){
94 Action cloneAction
= new Action("Clone", IAction
.AS_PUSH_BUTTON
){
97 boolean confirm
= MessagingUtils
.confirmDialog("Confirm cloning", "Do you really want to clone the name?");
100 TaxonName clonedName
;
101 clonedName
= (TaxonName
) getEntity().clone();
102 setEntity(clonedName
);
103 taxonBase
.setName(clonedName
);
104 taxonBase
.generateTitle();
105 firePropertyChangeEvent(new CdmPropertyChangeEvent(NonViralNameDetailSection
.this, null));
111 cloneAction
.setToolTipText("Clone the name if you do not want to edit the shared instance");
112 cloneAction
.setImageDescriptor(ImageResources
.getImageDescriptor(ImageResources
.COPY_ICON
));
113 toolBarManager
.add(cloneAction
);
116 return toolBarManager
.createControl(this);
119 private boolean checkForMultipleNameUsages(INonViralName nonViralName
) {
121 return nonViralName
.getTaxonBases().size() != 1;
122 }catch (CdmEagerLoadingException e
){
123 System
.out
.println(e
.getLocalizedMessage());
129 public String
getHeading() {
134 public void setTaxonBase(TaxonBase taxon
) {
136 TaxonName name
= HibernateProxyHelper
.deproxy(taxon
.getName());
141 public TaxonBase
getTaxonBase() {
146 protected AbstractCdmDetailElement
<TaxonName
> createCdmDetailElement(
147 AbstractCdmDetailSection
<TaxonName
> parentElement
, int style
) {
148 return formFactory
.createNonViralNameDetailElement(parentElement
);