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 java
.util
.ArrayList
;
13 import java
.util
.Collection
;
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
.graphics
.Color
;
19 import org
.eclipse
.swt
.widgets
.Control
;
20 import org
.eclipse
.ui
.forms
.events
.ExpansionEvent
;
21 import org
.eclipse
.ui
.forms
.events
.IExpansionListener
;
22 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
23 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
25 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
26 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
27 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
30 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
31 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
32 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
33 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
36 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
38 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
41 * This class visualizes an CDM entity of type ENTITY.
43 * @param <ENTITY> A CDM entity which should be visualized by this section.
46 * @created Feb 26, 2010
48 public abstract class AbstractCdmDetailSection
<ENTITY
>
49 extends AbstractFormSection
<ENTITY
>
50 implements IEnableableFormElement
, IExpansionListener
{
52 protected AbstractCdmDetailElement
<ENTITY
> detailElement
;
54 public AbstractCdmDetailSection(CdmFormFactory formFactory
,
55 ConversationHolder conversation
, ICdmFormElement parentElement
,
56 ISelectionProvider selectionProvider
, int style
) {
57 this(formFactory
, null, conversation
, parentElement
, selectionProvider
, style
);
61 public AbstractCdmDetailSection(CdmFormFactory formFactory
, Class
<ENTITY
> clazz
,
62 ConversationHolder conversation
, ICdmFormElement parentElement
,
63 ISelectionProvider selectionProvider
, int style
) {
64 super(formFactory
, parentElement
, selectionProvider
,
65 ExpandableComposite
.CLIENT_INDENT
| style
);
67 setText(getHeading());
69 addExpansionListener(this);
72 createControls(this, style
);
75 createControlsByType(this, clazz
, SWT
.NULL
);
80 public void setText(String title
) {
81 super.setText(StoreUtil
.cleanTitleString(title
));
84 protected void createControlsByType(AbstractCdmDetailSection
<ENTITY
> formElement
, Class
<ENTITY
> entityClass
, int style
) {
85 TableWrapLayout layout
= (TableWrapLayout
) getLayoutComposite().getLayout();
86 layout
.topMargin
= 10;
87 layout
.numColumns
= DEFAULT_NUM_COLUMNS
;
89 getLayoutComposite().setLayout(layout
);
90 if(entityClass
==null){
91 detailElement
= createCdmDetailElement(formElement
, style
);
94 detailElement
= createCdmDetailElementByType(formElement
, entityClass
, style
);
98 protected void createControls(AbstractCdmDetailSection
<ENTITY
> formElement
, int style
) {
99 createControlsByType(formElement
, null, style
);
102 protected abstract AbstractCdmDetailElement
<ENTITY
> createCdmDetailElement(AbstractCdmDetailSection
<ENTITY
> parentElement
, int style
);
104 protected AbstractCdmDetailElement
<ENTITY
> createCdmDetailElementByType(AbstractCdmDetailSection
<ENTITY
> parentElement
, Class
<ENTITY
> entityClass
, int style
){
105 return createCdmDetailElement(parentElement
, style
);
108 public abstract String
getHeading();
112 public void dispose() {
113 if (detailElement
instanceof ISelectableElement
) {
114 ISelectableElement selectableElement
= (ISelectableElement
) detailElement
;
115 if (selectableElement
.getSelectionArbitrator() != null) {
116 formFactory
.destroySelectionArbitrator(selectableElement
117 .getSelectionArbitrator());
125 public void setBackground(Color color
) {
126 if (detailElement
!= null) {
127 // detailComposite.setBackground(color);
129 super.setBackground(color
);
133 public void setEntity(ENTITY entity
) {
134 if (detailElement
!= null) {
135 detailElement
.setEntity(entity
);
136 Collection
<Object
> except
= new ArrayList
<Object
>();
137 for(ICdmFormElement formElement
:detailElement
.getElements()){
138 if(formElement
instanceof IEnableableFormElement
&& !((IEnableableFormElement
) formElement
).isEnabled()){
139 except
.add(formElement
);
142 detailElement
.setEnabled(isEnabled(), except
);
144 super.setEntity(entity
);
150 protected void setSectionTitle() {
153 if (getEntity() != null && (getEntity() instanceof IdentifiableEntity
) && !(getEntity() instanceof SpecimenOrObservationBase
)) {
154 if (getEntity() instanceof DefinedTermBase
<?
> ){
155 label
= ((DefinedTermBase
<?
>)getEntity()).getLabel(PreferencesUtil
.getGlobalLanguage());
157 label
= ((DefinedTermBase
<?
>)getEntity()).getLabel();
159 } else if (getEntity() instanceof TextData
){
160 label
= ((TextData
)getEntity()).getLanguageText(PreferencesUtil
.getGlobalLanguage()).getText();
162 label
= ((TextData
)getEntity()).getLanguageText(Language
.DEFAULT()).getText();
165 if(CdmUtils
.isBlank(label
)){
166 label
= ((IdentifiableEntity
) getEntity()).getTitleCache();
168 if(CdmUtils
.isBlank(label
)){
169 label
= ((IdentifiableEntity
) getEntity()).generateTitle();
171 title
= ": " + label
;
173 this.setText(String
.format("%s%s", getHeading(), title
));
174 setTextClient(createToolbar());
177 protected Control
createToolbar() {
178 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
179 return toolBarManager
.createControl(this);
182 public void updateTitle() {
191 public void setIrrelevant(boolean irrelevant
) {
192 if (detailElement
!= null) {
194 detailElement
.setIrrelevant(irrelevant
);
200 public void expansionStateChanging(ExpansionEvent e
) {
201 // logger.warn("Expansion State Changing");
206 public void expansionStateChanged(ExpansionEvent e
) {
207 // logger.warn("Expansion State Changed");