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.cdm.model.occurrence.SpecimenOrObservationBase;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
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 ICdmDetailElement<ENTITY> detailElement;
|
44
|
|
45
|
public AbstractCdmDetailSection(CdmFormFactory formFactory,
|
46
|
ConversationHolder conversation, ICdmFormElement parentElement,
|
47
|
ISelectionProvider selectionProvider, int style) {
|
48
|
this(formFactory, null, conversation, parentElement, selectionProvider, style);
|
49
|
}
|
50
|
|
51
|
|
52
|
public AbstractCdmDetailSection(CdmFormFactory formFactory, Class<ENTITY> clazz,
|
53
|
ConversationHolder conversation, ICdmFormElement parentElement,
|
54
|
ISelectionProvider selectionProvider, int style) {
|
55
|
super(formFactory, parentElement, selectionProvider,
|
56
|
ExpandableComposite.CLIENT_INDENT | style);
|
57
|
|
58
|
setText(getHeading());
|
59
|
|
60
|
addExpansionListener(this);
|
61
|
|
62
|
if(clazz==null){
|
63
|
createControls(this, style);
|
64
|
}
|
65
|
else{
|
66
|
createControlsByType(this, clazz, SWT.NULL);
|
67
|
}
|
68
|
}
|
69
|
|
70
|
protected void createControlsByType(AbstractCdmDetailSection<ENTITY> formElement, Class<ENTITY> entityClass, int style) {
|
71
|
TableWrapLayout layout = (TableWrapLayout) getLayoutComposite().getLayout();
|
72
|
layout.topMargin = 10;
|
73
|
layout.numColumns = DEFAULT_NUM_COLUMNS;
|
74
|
|
75
|
getLayoutComposite().setLayout(layout);
|
76
|
if(entityClass==null){
|
77
|
detailElement = createCdmDetailElement(formElement, style);
|
78
|
}
|
79
|
else{
|
80
|
detailElement = createCdmDetailElementByType(formElement, entityClass, style);
|
81
|
}
|
82
|
}
|
83
|
|
84
|
protected void createControls(AbstractCdmDetailSection<ENTITY> formElement, int style) {
|
85
|
createControlsByType(formElement, null, style);
|
86
|
}
|
87
|
|
88
|
protected abstract ICdmDetailElement<ENTITY> createCdmDetailElement(AbstractCdmDetailSection<ENTITY> parentElement, int style);
|
89
|
|
90
|
protected ICdmDetailElement<ENTITY> createCdmDetailElementByType(AbstractCdmDetailSection<ENTITY> parentElement, Class<ENTITY> entityClass, int style){
|
91
|
return createCdmDetailElement(parentElement, style);
|
92
|
}
|
93
|
|
94
|
public abstract String getHeading();
|
95
|
|
96
|
/** {@inheritDoc} */
|
97
|
@Override
|
98
|
public void dispose() {
|
99
|
if (detailElement instanceof ISelectableElement) {
|
100
|
ISelectableElement selectableElement = (ISelectableElement) detailElement;
|
101
|
if (selectableElement.getSelectionArbitrator() != null) {
|
102
|
formFactory.destroySelectionArbitrator(selectableElement
|
103
|
.getSelectionArbitrator());
|
104
|
}
|
105
|
}
|
106
|
super.dispose();
|
107
|
}
|
108
|
|
109
|
/** {@inheritDoc} */
|
110
|
@Override
|
111
|
public void setBackground(Color color) {
|
112
|
if (detailElement != null) {
|
113
|
// detailComposite.setBackground(color);
|
114
|
}
|
115
|
super.setBackground(color);
|
116
|
}
|
117
|
|
118
|
@Override
|
119
|
public void setEntity(ENTITY entity) {
|
120
|
if (detailElement != null) {
|
121
|
detailElement.setEntity(entity);
|
122
|
}
|
123
|
super.setEntity(entity);
|
124
|
setSectionTitle();
|
125
|
layout();
|
126
|
}
|
127
|
|
128
|
protected void setSectionTitle() {
|
129
|
String title = "";
|
130
|
if (getEntity() != null && (getEntity() instanceof IdentifiableEntity) && !(getEntity() instanceof SpecimenOrObservationBase)) {
|
131
|
title = ": " + ((IdentifiableEntity) getEntity()).getTitleCache();
|
132
|
// we have to duplicate ampersands otherwise they are treated as
|
133
|
// mnenomic (see Label.setText() documentation)
|
134
|
// see also #4302
|
135
|
title = title.replace("&", "&&");
|
136
|
}
|
137
|
this.setText(String.format("%s%s", getHeading(), title));
|
138
|
setTextClient(createToolbar());
|
139
|
}
|
140
|
|
141
|
protected Control createToolbar() {
|
142
|
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
|
143
|
return toolBarManager.createControl(this);
|
144
|
}
|
145
|
|
146
|
public void updateTitle() {
|
147
|
if (!isDisposed()) {
|
148
|
setSectionTitle();
|
149
|
layout();
|
150
|
}
|
151
|
}
|
152
|
|
153
|
/** {@inheritDoc} */
|
154
|
@Override
|
155
|
public void setIrrelevant(boolean irrelevant) {
|
156
|
if (detailElement != null) {
|
157
|
detailElement.setIrrelevant(irrelevant);
|
158
|
}
|
159
|
}
|
160
|
|
161
|
/** {@inheritDoc} */
|
162
|
@Override
|
163
|
public void expansionStateChanging(ExpansionEvent e) {
|
164
|
// logger.warn("Expansion State Changing");
|
165
|
}
|
166
|
|
167
|
/** {@inheritDoc} */
|
168
|
@Override
|
169
|
public void expansionStateChanged(ExpansionEvent e) {
|
170
|
// logger.warn("Expansion State Changed");
|
171
|
}
|
172
|
}
|