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