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.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;
|
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.forms.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.forms.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, conversation, parentElement, selectionProvider,
|
72
|
Section.CLIENT_INDENT | style);
|
73
|
|
74
|
setText(getHeading());
|
75
|
|
76
|
addExpansionListener(this);
|
77
|
|
78
|
createControls(this, SWT.NULL);
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* <p>
|
83
|
* createControls
|
84
|
* </p>
|
85
|
*
|
86
|
* @param formElement
|
87
|
* a
|
88
|
* {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection}
|
89
|
* object.
|
90
|
* @param style
|
91
|
* a int.
|
92
|
*/
|
93
|
protected void createControls(AbstractCdmDetailSection<ENTITY> formElement,
|
94
|
int style) {
|
95
|
TableWrapLayout layout = (TableWrapLayout) getLayoutComposite()
|
96
|
.getLayout();
|
97
|
layout.topMargin = 10;
|
98
|
layout.numColumns = 2;
|
99
|
|
100
|
getLayoutComposite().setLayout(layout);
|
101
|
detailElement = formFactory.createCdmDetailElement(getDetailType(),
|
102
|
formElement, style);
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* <p>
|
107
|
* getDetailType
|
108
|
* </p>
|
109
|
*
|
110
|
* @return a
|
111
|
* {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType}
|
112
|
* object.
|
113
|
*/
|
114
|
protected abstract DetailType getDetailType();
|
115
|
|
116
|
/**
|
117
|
* <p>
|
118
|
* getHeading
|
119
|
* </p>
|
120
|
*
|
121
|
* @return the heading for this section
|
122
|
*/
|
123
|
public abstract String getHeading();
|
124
|
|
125
|
/** {@inheritDoc} */
|
126
|
@Override
|
127
|
public void dispose() {
|
128
|
if (detailElement instanceof ISelectableElement) {
|
129
|
ISelectableElement selectableElement = (ISelectableElement) detailElement;
|
130
|
if (selectableElement.getSelectionArbitrator() != null) {
|
131
|
formFactory.destroySelectionArbitrator(selectableElement
|
132
|
.getSelectionArbitrator());
|
133
|
}
|
134
|
}
|
135
|
super.dispose();
|
136
|
}
|
137
|
|
138
|
/*
|
139
|
* (non-Javadoc)
|
140
|
*
|
141
|
* @see
|
142
|
* eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground
|
143
|
* (org.eclipse.swt.graphics.Color)
|
144
|
*/
|
145
|
/** {@inheritDoc} */
|
146
|
@Override
|
147
|
public void setBackground(Color color) {
|
148
|
if (detailElement != null) {
|
149
|
// detailComposite.setBackground(color);
|
150
|
}
|
151
|
super.setBackground(color);
|
152
|
}
|
153
|
|
154
|
/**
|
155
|
* <p>
|
156
|
* setEntity
|
157
|
* </p>
|
158
|
*
|
159
|
* @param entity
|
160
|
* a ENTITY object.
|
161
|
*/
|
162
|
@Override
|
163
|
public void setEntity(ENTITY entity) {
|
164
|
if (detailElement != null) {
|
165
|
detailElement.setEntity(entity);
|
166
|
}
|
167
|
super.setEntity(entity);
|
168
|
setSectionTitle();
|
169
|
layout();
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* <p>
|
174
|
* setSectionTitle
|
175
|
* </p>
|
176
|
*/
|
177
|
protected void setSectionTitle() {
|
178
|
String title = "";
|
179
|
if (getEntity() != null && (getEntity() instanceof IdentifiableEntity)) {
|
180
|
title = ": " + ((IdentifiableEntity) getEntity()).getTitleCache();
|
181
|
}
|
182
|
this.setText(String.format("%s%s", getHeading(), title));
|
183
|
setTextClient(createToolbar());
|
184
|
}
|
185
|
|
186
|
/**
|
187
|
* @return
|
188
|
*/
|
189
|
protected Control createToolbar() {
|
190
|
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
|
191
|
return toolBarManager.createControl(this);
|
192
|
}
|
193
|
|
194
|
/**
|
195
|
* <p>
|
196
|
* updateTitle
|
197
|
* </p>
|
198
|
*/
|
199
|
public void updateTitle() {
|
200
|
if (!isDisposed()) {
|
201
|
setSectionTitle();
|
202
|
layout();
|
203
|
}
|
204
|
}
|
205
|
|
206
|
/** {@inheritDoc} */
|
207
|
public void setIrrelevant(boolean irrelevant) {
|
208
|
if (detailElement != null) {
|
209
|
detailElement.setIrrelevant(irrelevant);
|
210
|
}
|
211
|
}
|
212
|
|
213
|
/** {@inheritDoc} */
|
214
|
public void expansionStateChanging(ExpansionEvent e) {
|
215
|
// logger.warn("Expansion State Changing");
|
216
|
}
|
217
|
|
218
|
/** {@inheritDoc} */
|
219
|
public void expansionStateChanged(ExpansionEvent e) {
|
220
|
// logger.warn("Expansion State Changed");
|
221
|
}
|
222
|
}
|