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
.IdentifiableEntity
;
25 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
33 * This class visualizes an CDM entity of type ENTITY.
35 * @param <ENTITY> A CDM entity which should be visualized by this section.
38 * @created Feb 26, 2010
41 public abstract class AbstractCdmDetailSection
<ENTITY
> extends AbstractFormSection
<ENTITY
> implements IEnableableFormElement
, IExpansionListener
{
43 protected ICdmDetailElement
<ENTITY
> detailElement
;
47 * Constructor for AbstractCdmDetailSection.
51 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
54 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
56 * @param parentElement
57 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
59 * @param selectionProvider
60 * a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
66 public AbstractCdmDetailSection(CdmFormFactory formFactory
,
67 ConversationHolder conversation
, ICdmFormElement parentElement
,
68 ISelectionProvider selectionProvider
, int style
) {
69 this(formFactory
, null, conversation
, parentElement
, selectionProvider
, style
);
73 public AbstractCdmDetailSection(CdmFormFactory formFactory
, Class
<ENTITY
> clazz
,
74 ConversationHolder conversation
, ICdmFormElement parentElement
,
75 ISelectionProvider selectionProvider
, int style
) {
76 super(formFactory
, parentElement
, selectionProvider
,
77 ExpandableComposite
.CLIENT_INDENT
| style
);
79 setText(getHeading());
81 addExpansionListener(this);
84 createControls(this, style
);
87 createControlsByType(this, clazz
, SWT
.NULL
);
92 * @param abstractCdmDetailSection
93 * @param definedTermClass
96 protected void createControlsByType(AbstractCdmDetailSection
<ENTITY
> formElement
, Class
<ENTITY
> entityClass
, int style
) {
97 TableWrapLayout layout
= (TableWrapLayout
) getLayoutComposite().getLayout();
98 layout
.topMargin
= 10;
99 layout
.numColumns
= 2;
101 getLayoutComposite().setLayout(layout
);
102 if(entityClass
==null){
103 detailElement
= createCdmDetailElement(formElement
, style
);
106 detailElement
= createCdmDetailElementByType(formElement
, entityClass
, style
);
118 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection}
123 protected void createControls(AbstractCdmDetailSection
<ENTITY
> formElement
, int style
) {
124 createControlsByType(formElement
, null, style
);
127 protected abstract ICdmDetailElement
<ENTITY
> createCdmDetailElement(AbstractCdmDetailSection
<ENTITY
> parentElement
, int style
);
129 protected ICdmDetailElement
<ENTITY
> createCdmDetailElementByType(AbstractCdmDetailSection
<ENTITY
> parentElement
, Class
<ENTITY
> entityClass
, int style
){
130 return createCdmDetailElement(parentElement
, style
);
138 * @return the heading for this section
140 public abstract String
getHeading();
144 public void dispose() {
145 if (detailElement
instanceof ISelectableElement
) {
146 ISelectableElement selectableElement
= (ISelectableElement
) detailElement
;
147 if (selectableElement
.getSelectionArbitrator() != null) {
148 formFactory
.destroySelectionArbitrator(selectableElement
149 .getSelectionArbitrator());
159 * eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground
160 * (org.eclipse.swt.graphics.Color)
164 public void setBackground(Color color
) {
165 if (detailElement
!= null) {
166 // detailComposite.setBackground(color);
168 super.setBackground(color
);
180 public void setEntity(ENTITY entity
) {
181 if (detailElement
!= null) {
182 detailElement
.setEntity(entity
);
184 super.setEntity(entity
);
194 protected void setSectionTitle() {
196 if (getEntity() != null && (getEntity() instanceof IdentifiableEntity
) && !(getEntity() instanceof SpecimenOrObservationBase
)) {
197 title
= ": " + ((IdentifiableEntity
) getEntity()).getTitleCache();
199 this.setText(String
.format("%s%s", getHeading(), title
));
200 setTextClient(createToolbar());
206 protected Control
createToolbar() {
207 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
208 return toolBarManager
.createControl(this);
216 public void updateTitle() {
225 public void setIrrelevant(boolean irrelevant
) {
226 if (detailElement
!= null) {
227 detailElement
.setIrrelevant(irrelevant
);
233 public void expansionStateChanging(ExpansionEvent e
) {
234 // logger.warn("Expansion State Changing");
239 public void expansionStateChanged(ExpansionEvent e
) {
240 // logger.warn("Expansion State Changed");