(no commit message)
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / AbstractCdmDetailSection.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.ui.section;
12
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;
22
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.ICdmFormElement;
28 import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
29 import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
30 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType;
31
32 /**
33 * <p>
34 * Abstract AbstractCdmDetailSection class.
35 * </p>
36 *
37 * @author n.hoffmann
38 * @created Feb 26, 2010
39 * @version 1.0
40 */
41 public abstract class AbstractCdmDetailSection<ENTITY> extends
42 AbstractFormSection<ENTITY> implements IEnableableFormElement,
43 IExpansionListener {
44
45 protected AbstractCdmDetailElement<ENTITY> detailElement;
46
47 /**
48 * <p>
49 * Constructor for AbstractCdmDetailSection.
50 * </p>
51 *
52 * @param formFactory
53 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
54 * object.
55 * @param conversation
56 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
57 * object.
58 * @param parentElement
59 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
60 * object.
61 * @param selectionProvider
62 * a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
63 * @param style
64 * a int.
65 * @param <ENTITY>
66 * a ENTITY object.
67 */
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);
73
74 setText(getHeading());
75
76 addExpansionListener(this);
77
78 createControls(this, SWT.NULL);
79 }
80
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);
86
87 setText(getHeading());
88
89 addExpansionListener(this);
90
91 createControlsByType(this, clazz, SWT.NULL);
92 }
93
94 /**
95 * @param abstractCdmDetailSection
96 * @param definedTermClass
97 * @param null1
98 */
99 protected void createControlsByType(
100 AbstractCdmDetailSection<ENTITY> abstractCdmDetailSection,
101 Class<ENTITY> entityClass, int style) {
102 }
103
104
105 /**
106 * <p>
107 * createControls
108 * </p>
109 *
110 * @param formElement
111 * a
112 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection}
113 * object.
114 * @param style
115 * a int.
116 */
117 protected void createControls(AbstractCdmDetailSection<ENTITY> formElement,
118 int style) {
119 TableWrapLayout layout = (TableWrapLayout) getLayoutComposite()
120 .getLayout();
121 layout.topMargin = 10;
122 layout.numColumns = 2;
123
124 getLayoutComposite().setLayout(layout);
125 detailElement = formFactory.createCdmDetailElement(getDetailType(),
126 formElement, style);
127 }
128
129 /**
130 * <p>
131 * getDetailType
132 * </p>
133 *
134 * @return a
135 * {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType}
136 * object.
137 */
138 protected abstract DetailType getDetailType();
139
140 /**
141 * <p>
142 * getHeading
143 * </p>
144 *
145 * @return the heading for this section
146 */
147 public abstract String getHeading();
148
149 /** {@inheritDoc} */
150 @Override
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());
157 }
158 }
159 super.dispose();
160 }
161
162 /*
163 * (non-Javadoc)
164 *
165 * @see
166 * eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground
167 * (org.eclipse.swt.graphics.Color)
168 */
169 /** {@inheritDoc} */
170 @Override
171 public void setBackground(Color color) {
172 if (detailElement != null) {
173 // detailComposite.setBackground(color);
174 }
175 super.setBackground(color);
176 }
177
178 /**
179 * <p>
180 * setEntity
181 * </p>
182 *
183 * @param entity
184 * a ENTITY object.
185 */
186 @Override
187 public void setEntity(ENTITY entity) {
188 if (detailElement != null) {
189 detailElement.setEntity(entity);
190 }
191 super.setEntity(entity);
192 setSectionTitle();
193 layout();
194 }
195
196 /**
197 * <p>
198 * setSectionTitle
199 * </p>
200 */
201 protected void setSectionTitle() {
202 String title = "";
203 if (getEntity() != null && (getEntity() instanceof IdentifiableEntity)) {
204 title = ": " + ((IdentifiableEntity) getEntity()).getTitleCache();
205 }
206 this.setText(String.format("%s%s", getHeading(), title));
207 setTextClient(createToolbar());
208 }
209
210 /**
211 * @return
212 */
213 protected Control createToolbar() {
214 ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
215 return toolBarManager.createControl(this);
216 }
217
218 /**
219 * <p>
220 * updateTitle
221 * </p>
222 */
223 public void updateTitle() {
224 if (!isDisposed()) {
225 setSectionTitle();
226 layout();
227 }
228 }
229
230 /** {@inheritDoc} */
231 public void setIrrelevant(boolean irrelevant) {
232 if (detailElement != null) {
233 detailElement.setIrrelevant(irrelevant);
234 }
235 }
236
237 /** {@inheritDoc} */
238 public void expansionStateChanging(ExpansionEvent e) {
239 // logger.warn("Expansion State Changing");
240 }
241
242 /** {@inheritDoc} */
243 public void expansionStateChanged(ExpansionEvent e) {
244 // logger.warn("Expansion State Changed");
245 }
246 }