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
;
13 import org
.eclipse
.jface
.action
.ToolBarManager
;
14 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.graphics
.Color
;
17 import org
.eclipse
.swt
.widgets
.Control
;
18 import org
.eclipse
.ui
.forms
.events
.ExpansionEvent
;
19 import org
.eclipse
.ui
.forms
.events
.IExpansionListener
;
20 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
21 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
24 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
25 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
26 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
27 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
28 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
29 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
37 * This class visualizes an CDM entity of type ENTITY.
39 * @param <ENTITY> A CDM entity which should be visualized by this section.
42 * @created Feb 26, 2010
45 public abstract class AbstractCdmDetailSection
<ENTITY
> extends AbstractFormSection
<ENTITY
> implements IEnableableFormElement
, IExpansionListener
{
47 protected ICdmDetailElement
<ENTITY
> detailElement
;
49 public AbstractCdmDetailSection(CdmFormFactory formFactory
,
50 ConversationHolder conversation
, ICdmFormElement parentElement
,
51 ISelectionProvider selectionProvider
, int style
) {
52 this(formFactory
, null, conversation
, parentElement
, selectionProvider
, style
);
56 public AbstractCdmDetailSection(CdmFormFactory formFactory
, Class
<ENTITY
> clazz
,
57 ConversationHolder conversation
, ICdmFormElement parentElement
,
58 ISelectionProvider selectionProvider
, int style
) {
59 super(formFactory
, parentElement
, selectionProvider
,
60 ExpandableComposite
.CLIENT_INDENT
| style
);
62 setText(getHeading());
64 addExpansionListener(this);
67 createControls(this, style
);
70 createControlsByType(this, clazz
, SWT
.NULL
);
74 protected void createControlsByType(AbstractCdmDetailSection
<ENTITY
> formElement
, Class
<ENTITY
> entityClass
, int style
) {
75 TableWrapLayout layout
= (TableWrapLayout
) getLayoutComposite().getLayout();
76 layout
.topMargin
= 10;
77 layout
.numColumns
= DEFAULT_NUM_COLUMNS
;
79 getLayoutComposite().setLayout(layout
);
80 if(entityClass
==null){
81 detailElement
= createCdmDetailElement(formElement
, style
);
84 detailElement
= createCdmDetailElementByType(formElement
, entityClass
, style
);
88 protected void createControls(AbstractCdmDetailSection
<ENTITY
> formElement
, int style
) {
89 createControlsByType(formElement
, null, style
);
92 protected abstract ICdmDetailElement
<ENTITY
> createCdmDetailElement(AbstractCdmDetailSection
<ENTITY
> parentElement
, int style
);
94 protected ICdmDetailElement
<ENTITY
> createCdmDetailElementByType(AbstractCdmDetailSection
<ENTITY
> parentElement
, Class
<ENTITY
> entityClass
, int style
){
95 return createCdmDetailElement(parentElement
, style
);
98 public abstract String
getHeading();
102 public void dispose() {
103 if (detailElement
instanceof ISelectableElement
) {
104 ISelectableElement selectableElement
= (ISelectableElement
) detailElement
;
105 if (selectableElement
.getSelectionArbitrator() != null) {
106 formFactory
.destroySelectionArbitrator(selectableElement
107 .getSelectionArbitrator());
115 public void setBackground(Color color
) {
116 if (detailElement
!= null) {
117 // detailComposite.setBackground(color);
119 super.setBackground(color
);
123 public void setEntity(ENTITY entity
) {
124 if (detailElement
!= null) {
125 detailElement
.setEntity(entity
);
127 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) {
177 detailElement
.setIrrelevant(irrelevant
);
183 public void expansionStateChanging(ExpansionEvent e
) {
184 // logger.warn("Expansion State Changing");
189 public void expansionStateChanged(ExpansionEvent e
) {
190 // logger.warn("Expansion State Changed");