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
.element
.AbstractFormSection
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
.DetailType
;
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 AbstractCdmDetailElement
<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 super(formFactory
, parentElement
, selectionProvider
,
70 ExpandableComposite
.CLIENT_INDENT
| style
);
72 setText(getHeading());
74 addExpansionListener(this);
76 createControls(this, SWT
.NULL
);
79 public AbstractCdmDetailSection(CdmFormFactory formFactory
, Class
<ENTITY
> clazz
,
80 ConversationHolder conversation
, ICdmFormElement parentElement
,
81 ISelectionProvider selectionProvider
, int style
) {
82 super(formFactory
, parentElement
, selectionProvider
,
83 ExpandableComposite
.CLIENT_INDENT
| style
);
85 setText(getHeading());
87 addExpansionListener(this);
89 createControlsByType(this, clazz
, SWT
.NULL
);
93 * @param abstractCdmDetailSection
94 * @param definedTermClass
97 protected void createControlsByType(AbstractCdmDetailSection
<ENTITY
> abstractCdmDetailSection
, Class
<ENTITY
> entityClass
, int style
) {
108 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection}
113 protected void createControls(AbstractCdmDetailSection
<ENTITY
> formElement
,
115 TableWrapLayout layout
= (TableWrapLayout
) getLayoutComposite()
117 layout
.topMargin
= 10;
118 layout
.numColumns
= 2;
120 getLayoutComposite().setLayout(layout
);
121 detailElement
= formFactory
.createCdmDetailElement(getDetailType(), formElement
, style
);
130 * {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType}
133 protected abstract DetailType
getDetailType();
140 * @return the heading for this section
142 public abstract String
getHeading();
146 public void dispose() {
147 if (detailElement
instanceof ISelectableElement
) {
148 ISelectableElement selectableElement
= (ISelectableElement
) detailElement
;
149 if (selectableElement
.getSelectionArbitrator() != null) {
150 formFactory
.destroySelectionArbitrator(selectableElement
151 .getSelectionArbitrator());
161 * eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground
162 * (org.eclipse.swt.graphics.Color)
166 public void setBackground(Color color
) {
167 if (detailElement
!= null) {
168 // detailComposite.setBackground(color);
170 super.setBackground(color
);
182 public void setEntity(ENTITY entity
) {
183 if (detailElement
!= null) {
184 detailElement
.setEntity(entity
);
186 super.setEntity(entity
);
196 protected void setSectionTitle() {
198 if (getEntity() != null && (getEntity() instanceof IdentifiableEntity
)) {
199 title
= ": " + ((IdentifiableEntity
) getEntity()).getTitleCache();
201 this.setText(String
.format("%s%s", getHeading(), title
));
202 setTextClient(createToolbar());
208 protected Control
createToolbar() {
209 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
210 return toolBarManager
.createControl(this);
218 public void updateTitle() {
227 public void setIrrelevant(boolean irrelevant
) {
228 if (detailElement
!= null) {
229 detailElement
.setIrrelevant(irrelevant
);
235 public void expansionStateChanging(ExpansionEvent e
) {
236 // logger.warn("Expansion State Changing");
241 public void expansionStateChanged(ExpansionEvent e
) {
242 // logger.warn("Expansion State Changed");