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
;
45 public AbstractCdmDetailSection(CdmFormFactory formFactory
,
46 ConversationHolder conversation
, ICdmFormElement parentElement
,
47 ISelectionProvider selectionProvider
, int style
) {
48 this(formFactory
, null, conversation
, parentElement
, selectionProvider
, style
);
52 public AbstractCdmDetailSection(CdmFormFactory formFactory
, Class
<ENTITY
> clazz
,
53 ConversationHolder conversation
, ICdmFormElement parentElement
,
54 ISelectionProvider selectionProvider
, int style
) {
55 super(formFactory
, parentElement
, selectionProvider
,
56 ExpandableComposite
.CLIENT_INDENT
| style
);
58 setText(getHeading());
60 addExpansionListener(this);
63 createControls(this, style
);
66 createControlsByType(this, clazz
, SWT
.NULL
);
70 protected void createControlsByType(AbstractCdmDetailSection
<ENTITY
> formElement
, Class
<ENTITY
> entityClass
, int style
) {
71 TableWrapLayout layout
= (TableWrapLayout
) getLayoutComposite().getLayout();
72 layout
.topMargin
= 10;
73 layout
.numColumns
= DEFAULT_NUM_COLUMNS
;
75 getLayoutComposite().setLayout(layout
);
76 if(entityClass
==null){
77 detailElement
= createCdmDetailElement(formElement
, style
);
80 detailElement
= createCdmDetailElementByType(formElement
, entityClass
, style
);
84 protected void createControls(AbstractCdmDetailSection
<ENTITY
> formElement
, int style
) {
85 createControlsByType(formElement
, null, style
);
88 protected abstract ICdmDetailElement
<ENTITY
> createCdmDetailElement(AbstractCdmDetailSection
<ENTITY
> parentElement
, int style
);
90 protected ICdmDetailElement
<ENTITY
> createCdmDetailElementByType(AbstractCdmDetailSection
<ENTITY
> parentElement
, Class
<ENTITY
> entityClass
, int style
){
91 return createCdmDetailElement(parentElement
, style
);
94 public abstract String
getHeading();
98 public void dispose() {
99 if (detailElement
instanceof ISelectableElement
) {
100 ISelectableElement selectableElement
= (ISelectableElement
) detailElement
;
101 if (selectableElement
.getSelectionArbitrator() != null) {
102 formFactory
.destroySelectionArbitrator(selectableElement
103 .getSelectionArbitrator());
111 public void setBackground(Color color
) {
112 if (detailElement
!= null) {
113 // detailComposite.setBackground(color);
115 super.setBackground(color
);
119 public void setEntity(ENTITY entity
) {
120 if (detailElement
!= null) {
121 detailElement
.setEntity(entity
);
123 super.setEntity(entity
);
128 protected void setSectionTitle() {
130 if (getEntity() != null && (getEntity() instanceof IdentifiableEntity
) && !(getEntity() instanceof SpecimenOrObservationBase
)) {
131 title
= ": " + ((IdentifiableEntity
) getEntity()).getTitleCache();
132 // we have to duplicate ampersands otherwise they are treated as
133 // mnenomic (see Label.setText() documentation)
135 title
= title
.replace("&", "&&");
137 this.setText(String
.format("%s%s", getHeading(), title
));
138 setTextClient(createToolbar());
141 protected Control
createToolbar() {
142 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
143 return toolBarManager
.createControl(this);
146 public void updateTitle() {
155 public void setIrrelevant(boolean irrelevant
) {
156 if (detailElement
!= null) {
157 detailElement
.setIrrelevant(irrelevant
);
163 public void expansionStateChanging(ExpansionEvent e
) {
164 // logger.warn("Expansion State Changing");
169 public void expansionStateChanged(ExpansionEvent e
) {
170 // logger.warn("Expansion State Changed");