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
;
12 import org
.eclipse
.jface
.action
.ToolBarManager
;
13 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.graphics
.Color
;
16 import org
.eclipse
.swt
.widgets
.Control
;
17 import org
.eclipse
.ui
.forms
.events
.ExpansionEvent
;
18 import org
.eclipse
.ui
.forms
.events
.IExpansionListener
;
19 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
20 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
22 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
23 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
24 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
25 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
26 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
27 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
28 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
36 * This class visualizes an CDM entity of type ENTITY.
38 * @param <ENTITY> A CDM entity which should be visualized by this section.
41 * @created Feb 26, 2010
44 public abstract class AbstractCdmDetailSection
<ENTITY
> extends AbstractFormSection
<ENTITY
> implements IEnableableFormElement
, IExpansionListener
{
46 protected ICdmDetailElement
<ENTITY
> detailElement
;
48 public AbstractCdmDetailSection(CdmFormFactory formFactory
,
49 ConversationHolder conversation
, ICdmFormElement parentElement
,
50 ISelectionProvider selectionProvider
, int style
) {
51 this(formFactory
, null, conversation
, parentElement
, selectionProvider
, style
);
55 public AbstractCdmDetailSection(CdmFormFactory formFactory
, Class
<ENTITY
> clazz
,
56 ConversationHolder conversation
, ICdmFormElement parentElement
,
57 ISelectionProvider selectionProvider
, int style
) {
58 super(formFactory
, parentElement
, selectionProvider
,
59 ExpandableComposite
.CLIENT_INDENT
| style
);
61 setText(getHeading());
63 addExpansionListener(this);
66 createControls(this, style
);
69 createControlsByType(this, clazz
, SWT
.NULL
);
73 protected void createControlsByType(AbstractCdmDetailSection
<ENTITY
> formElement
, Class
<ENTITY
> entityClass
, int style
) {
74 TableWrapLayout layout
= (TableWrapLayout
) getLayoutComposite().getLayout();
75 layout
.topMargin
= 10;
76 layout
.numColumns
= DEFAULT_NUM_COLUMNS
;
78 getLayoutComposite().setLayout(layout
);
79 if(entityClass
==null){
80 detailElement
= createCdmDetailElement(formElement
, style
);
83 detailElement
= createCdmDetailElementByType(formElement
, entityClass
, style
);
87 protected void createControls(AbstractCdmDetailSection
<ENTITY
> formElement
, int style
) {
88 createControlsByType(formElement
, null, style
);
91 protected abstract ICdmDetailElement
<ENTITY
> createCdmDetailElement(AbstractCdmDetailSection
<ENTITY
> parentElement
, int style
);
93 protected ICdmDetailElement
<ENTITY
> createCdmDetailElementByType(AbstractCdmDetailSection
<ENTITY
> parentElement
, Class
<ENTITY
> entityClass
, int style
){
94 return createCdmDetailElement(parentElement
, style
);
97 public abstract String
getHeading();
101 public void dispose() {
102 if (detailElement
instanceof ISelectableElement
) {
103 ISelectableElement selectableElement
= (ISelectableElement
) detailElement
;
104 if (selectableElement
.getSelectionArbitrator() != null) {
105 formFactory
.destroySelectionArbitrator(selectableElement
106 .getSelectionArbitrator());
114 public void setBackground(Color color
) {
115 if (detailElement
!= null) {
116 // detailComposite.setBackground(color);
118 super.setBackground(color
);
122 public void setEntity(ENTITY entity
) {
123 if (detailElement
!= null) {
124 detailElement
.setEntity(entity
);
126 super.setEntity(entity
);
132 protected void setSectionTitle() {
135 if (getEntity() != null && (getEntity() instanceof IdentifiableEntity
) && !(getEntity() instanceof SpecimenOrObservationBase
)) {
136 if (getEntity() instanceof DefinedTermBase
<?
> ){
137 label
= ((DefinedTermBase
<?
>)getEntity()).getLabel(PreferencesUtil
.getGlobalLanguage());
139 label
= ((DefinedTermBase
<?
>)getEntity()).getLabel();
142 } else if (getEntity() instanceof TextData
){
143 label
= ((TextData
)getEntity()).getLanguageText(PreferencesUtil
.getGlobalLanguage()).getText();
145 label
= ((TextData
)getEntity()).getLanguageText(Language
.DEFAULT()).getText();
148 label
=((IdentifiableEntity
) getEntity()).getTitleCache();
150 title
= ": " + label
;
152 // we have to duplicate ampersands otherwise they are treated as
153 // mnenomic (see Label.setText() documentation)
155 title
= title
.replace("&", "&&");
157 this.setText(String
.format("%s%s", getHeading(), title
));
158 setTextClient(createToolbar());
161 protected Control
createToolbar() {
162 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
163 return toolBarManager
.createControl(this);
166 public void updateTitle() {
175 public void setIrrelevant(boolean irrelevant
) {
176 if (detailElement
!= null) {
178 detailElement
.setIrrelevant(irrelevant
);
184 public void expansionStateChanging(ExpansionEvent e
) {
185 // logger.warn("Expansion State Changing");
190 public void expansionStateChanged(ExpansionEvent e
) {
191 // logger.warn("Expansion State Changed");