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
, int style
) {
114 TableWrapLayout layout
= (TableWrapLayout
) getLayoutComposite().getLayout();
115 layout
.topMargin
= 10;
116 layout
.numColumns
= 2;
118 getLayoutComposite().setLayout(layout
);
119 detailElement
= createCdmDetailElement(formElement
, style
);
122 //TODO: when all detail type enums are removed this can be abstract
123 protected AbstractCdmDetailElement
<ENTITY
> createCdmDetailElement(AbstractCdmDetailSection
<ENTITY
> parentElement
, int style
){
124 return formFactory
.createCdmDetailElement(getDetailType(), parentElement
, style
);
133 * {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType}
136 protected abstract DetailType
getDetailType();
143 * @return the heading for this section
145 public abstract String
getHeading();
149 public void dispose() {
150 if (detailElement
instanceof ISelectableElement
) {
151 ISelectableElement selectableElement
= (ISelectableElement
) detailElement
;
152 if (selectableElement
.getSelectionArbitrator() != null) {
153 formFactory
.destroySelectionArbitrator(selectableElement
154 .getSelectionArbitrator());
164 * eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground
165 * (org.eclipse.swt.graphics.Color)
169 public void setBackground(Color color
) {
170 if (detailElement
!= null) {
171 // detailComposite.setBackground(color);
173 super.setBackground(color
);
185 public void setEntity(ENTITY entity
) {
186 if (detailElement
!= null) {
187 detailElement
.setEntity(entity
);
189 super.setEntity(entity
);
199 protected void setSectionTitle() {
201 if (getEntity() != null && (getEntity() instanceof IdentifiableEntity
)) {
202 title
= ": " + ((IdentifiableEntity
) getEntity()).getTitleCache();
204 this.setText(String
.format("%s%s", getHeading(), title
));
205 setTextClient(createToolbar());
211 protected Control
createToolbar() {
212 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
213 return toolBarManager
.createControl(this);
221 public void updateTitle() {
230 public void setIrrelevant(boolean irrelevant
) {
231 if (detailElement
!= null) {
232 detailElement
.setIrrelevant(irrelevant
);
238 public void expansionStateChanging(ExpansionEvent e
) {
239 // logger.warn("Expansion State Changing");
244 public void expansionStateChanged(ExpansionEvent e
) {
245 // logger.warn("Expansion State Changed");