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
.taxeditor
.ui
.campanula
.compatibility
.ICdmFormElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
32 * This class visualizes an CDM entity of type ENTITY.
34 * @param <ENTITY> A CDM entity which should be visualized by this section.
37 * @created Feb 26, 2010
40 public abstract class AbstractCdmDetailSection
<ENTITY
> extends AbstractFormSection
<ENTITY
> implements IEnableableFormElement
, IExpansionListener
{
42 protected ICdmDetailElement
<ENTITY
> detailElement
;
46 * Constructor for AbstractCdmDetailSection.
50 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
53 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
55 * @param parentElement
56 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
58 * @param selectionProvider
59 * a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
65 public AbstractCdmDetailSection(CdmFormFactory formFactory
,
66 ConversationHolder conversation
, ICdmFormElement parentElement
,
67 ISelectionProvider selectionProvider
, int style
) {
68 this(formFactory
, null, conversation
, parentElement
, selectionProvider
, style
);
72 public AbstractCdmDetailSection(CdmFormFactory formFactory
, Class
<ENTITY
> clazz
,
73 ConversationHolder conversation
, ICdmFormElement parentElement
,
74 ISelectionProvider selectionProvider
, int style
) {
75 super(formFactory
, parentElement
, selectionProvider
,
76 ExpandableComposite
.CLIENT_INDENT
| style
);
78 setText(getHeading());
80 addExpansionListener(this);
83 createControls(this, style
);
86 createControlsByType(this, clazz
, SWT
.NULL
);
91 * @param abstractCdmDetailSection
92 * @param definedTermClass
95 protected void createControlsByType(AbstractCdmDetailSection
<ENTITY
> formElement
, Class
<ENTITY
> entityClass
, int style
) {
96 TableWrapLayout layout
= (TableWrapLayout
) getLayoutComposite().getLayout();
97 layout
.topMargin
= 10;
98 layout
.numColumns
= 2;
100 getLayoutComposite().setLayout(layout
);
101 if(entityClass
==null){
102 detailElement
= createCdmDetailElement(formElement
, style
);
105 detailElement
= createCdmDetailElementByType(formElement
, entityClass
, style
);
117 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection}
122 protected void createControls(AbstractCdmDetailSection
<ENTITY
> formElement
, int style
) {
123 createControlsByType(formElement
, null, style
);
126 protected abstract ICdmDetailElement
<ENTITY
> createCdmDetailElement(AbstractCdmDetailSection
<ENTITY
> parentElement
, int style
);
128 protected ICdmDetailElement
<ENTITY
> createCdmDetailElementByType(AbstractCdmDetailSection
<ENTITY
> parentElement
, Class
<ENTITY
> entityClass
, int style
){
129 return createCdmDetailElement(parentElement
, style
);
137 * @return the heading for this section
139 public abstract String
getHeading();
143 public void dispose() {
144 if (detailElement
instanceof ISelectableElement
) {
145 ISelectableElement selectableElement
= (ISelectableElement
) detailElement
;
146 if (selectableElement
.getSelectionArbitrator() != null) {
147 formFactory
.destroySelectionArbitrator(selectableElement
148 .getSelectionArbitrator());
158 * eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground
159 * (org.eclipse.swt.graphics.Color)
163 public void setBackground(Color color
) {
164 if (detailElement
!= null) {
165 // detailComposite.setBackground(color);
167 super.setBackground(color
);
179 public void setEntity(ENTITY entity
) {
180 if (detailElement
!= null) {
181 detailElement
.setEntity(entity
);
183 super.setEntity(entity
);
193 protected void setSectionTitle() {
195 if (getEntity() != null && (getEntity() instanceof IdentifiableEntity
)) {
196 title
= ": " + ((IdentifiableEntity
) getEntity()).getTitleCache();
198 this.setText(String
.format("%s%s", getHeading(), title
));
199 setTextClient(createToolbar());
205 protected Control
createToolbar() {
206 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
207 return toolBarManager
.createControl(this);
215 public void updateTitle() {
224 public void setIrrelevant(boolean irrelevant
) {
225 if (detailElement
!= null) {
226 detailElement
.setIrrelevant(irrelevant
);
232 public void expansionStateChanging(ExpansionEvent e
) {
233 // logger.warn("Expansion State Changing");
238 public void expansionStateChanged(ExpansionEvent e
) {
239 // logger.warn("Expansion State Changed");