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
.Section
;
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
.forms
.AbstractFormSection
;
26 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.DetailType
;
28 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ICdmFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.forms
.IEnableableFormElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ISelectableElement
;
34 * Abstract AbstractCdmDetailSection class.
38 * @created Feb 26, 2010
41 public abstract class AbstractCdmDetailSection
<ENTITY
> extends
42 AbstractFormSection
<ENTITY
> implements IEnableableFormElement
,
45 protected AbstractCdmDetailElement
<ENTITY
> detailElement
;
49 * Constructor for AbstractCdmDetailSection.
53 * a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
56 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
58 * @param parentElement
59 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
61 * @param selectionProvider
62 * a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
68 public AbstractCdmDetailSection(CdmFormFactory formFactory
,
69 ConversationHolder conversation
, ICdmFormElement parentElement
,
70 ISelectionProvider selectionProvider
, int style
) {
71 super(formFactory
, parentElement
, selectionProvider
,
72 Section
.CLIENT_INDENT
| style
);
74 setText(getHeading());
76 addExpansionListener(this);
78 createControls(this, SWT
.NULL
);
81 public AbstractCdmDetailSection(CdmFormFactory formFactory
, Class
<ENTITY
> clazz
,
82 ConversationHolder conversation
, ICdmFormElement parentElement
,
83 ISelectionProvider selectionProvider
, int style
) {
84 super(formFactory
, parentElement
, selectionProvider
,
85 Section
.CLIENT_INDENT
| style
);
87 setText(getHeading());
89 addExpansionListener(this);
91 createControlsByType(this, clazz
, SWT
.NULL
);
95 * @param abstractCdmDetailSection
96 * @param definedTermClass
99 protected void createControlsByType(
100 AbstractCdmDetailSection
<ENTITY
> abstractCdmDetailSection
,
101 Class
<ENTITY
> entityClass
, int style
) {
112 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection}
117 protected void createControls(AbstractCdmDetailSection
<ENTITY
> formElement
,
119 TableWrapLayout layout
= (TableWrapLayout
) getLayoutComposite()
121 layout
.topMargin
= 10;
122 layout
.numColumns
= 2;
124 getLayoutComposite().setLayout(layout
);
125 detailElement
= formFactory
.createCdmDetailElement(getDetailType(),
135 * {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType}
138 protected abstract DetailType
getDetailType();
145 * @return the heading for this section
147 public abstract String
getHeading();
151 public void dispose() {
152 if (detailElement
instanceof ISelectableElement
) {
153 ISelectableElement selectableElement
= (ISelectableElement
) detailElement
;
154 if (selectableElement
.getSelectionArbitrator() != null) {
155 formFactory
.destroySelectionArbitrator(selectableElement
156 .getSelectionArbitrator());
166 * eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground
167 * (org.eclipse.swt.graphics.Color)
171 public void setBackground(Color color
) {
172 if (detailElement
!= null) {
173 // detailComposite.setBackground(color);
175 super.setBackground(color
);
187 public void setEntity(ENTITY entity
) {
188 if (detailElement
!= null) {
189 detailElement
.setEntity(entity
);
191 super.setEntity(entity
);
201 protected void setSectionTitle() {
203 if (getEntity() != null && (getEntity() instanceof IdentifiableEntity
)) {
204 title
= ": " + ((IdentifiableEntity
) getEntity()).getTitleCache();
206 this.setText(String
.format("%s%s", getHeading(), title
));
207 setTextClient(createToolbar());
213 protected Control
createToolbar() {
214 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
215 return toolBarManager
.createControl(this);
223 public void updateTitle() {
231 public void setIrrelevant(boolean irrelevant
) {
232 if (detailElement
!= null) {
233 detailElement
.setIrrelevant(irrelevant
);
238 public void expansionStateChanging(ExpansionEvent e
) {
239 // logger.warn("Expansion State Changing");
243 public void expansionStateChanged(ExpansionEvent e
) {
244 // logger.warn("Expansion State Changed");