1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.view;
|
11
|
|
12
|
import org.eclipse.jface.viewers.StructuredSelection;
|
13
|
import org.eclipse.jface.viewers.Viewer;
|
14
|
import org.eclipse.swt.widgets.Composite;
|
15
|
import org.eclipse.swt.widgets.Control;
|
16
|
import org.eclipse.ui.forms.IFormPart;
|
17
|
import org.eclipse.ui.forms.ManagedForm;
|
18
|
import org.eclipse.ui.forms.widgets.ScrolledForm;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
21
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
25
|
import eu.etaxonomy.taxeditor.ui.element.RootElement;
|
26
|
import eu.etaxonomy.taxeditor.view.detail.CdmSectionPart;
|
27
|
|
28
|
/**
|
29
|
* @author n.hoffmann
|
30
|
* @created Feb 9, 2010
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public abstract class AbstractCdmDataViewer extends Viewer implements IConversationEnabled{
|
34
|
|
35
|
protected ManagedForm managedForm;
|
36
|
|
37
|
protected CdmFormFactory formFactory;
|
38
|
|
39
|
protected ScrolledForm scrolledForm;
|
40
|
|
41
|
private final Composite body;
|
42
|
|
43
|
protected RootElement rootElement;
|
44
|
|
45
|
//TODO: create a super class for this?
|
46
|
private Object input;
|
47
|
|
48
|
private final AbstractCdmViewPart viewPart;
|
49
|
|
50
|
|
51
|
public AbstractCdmDataViewer(Composite parent, AbstractCdmViewPart viewPart) {
|
52
|
this.viewPart = viewPart;
|
53
|
|
54
|
managedForm = new ManagedForm(parent){
|
55
|
|
56
|
@Override
|
57
|
public void dirtyStateChanged() {
|
58
|
markViewPartDirty();
|
59
|
}
|
60
|
};
|
61
|
|
62
|
createFormFactory();
|
63
|
|
64
|
scrolledForm = managedForm.getForm();
|
65
|
|
66
|
body = scrolledForm.getBody();
|
67
|
|
68
|
body.setLayout(LayoutConstants.LAYOUT());
|
69
|
|
70
|
rootElement = new RootElement(formFactory, body);
|
71
|
}
|
72
|
|
73
|
protected void createFormFactory() {
|
74
|
if(formFactory != null){
|
75
|
formFactory.dispose();
|
76
|
formFactory = null;
|
77
|
}
|
78
|
// formFactory = new CdmFormFactory(Display.getCurrent(), this);
|
79
|
}
|
80
|
|
81
|
protected void markViewPartDirty(){
|
82
|
viewPart.changed(input);
|
83
|
}
|
84
|
|
85
|
protected AbstractCdmViewPart getViewPart() {
|
86
|
return viewPart;
|
87
|
}
|
88
|
|
89
|
/** {@inheritDoc} */
|
90
|
@Override
|
91
|
public Control getControl() {
|
92
|
if(body.isDisposed()){
|
93
|
return null;
|
94
|
}
|
95
|
for(Control child : body.getChildren()){
|
96
|
return child;
|
97
|
}
|
98
|
|
99
|
return body;
|
100
|
}
|
101
|
|
102
|
/** {@inheritDoc} */
|
103
|
@Override
|
104
|
public void setInput(Object input) {
|
105
|
this.input = input;
|
106
|
// reset selection
|
107
|
setSelection(new StructuredSelection(input));
|
108
|
refresh();
|
109
|
}
|
110
|
|
111
|
/** {@inheritDoc} */
|
112
|
@Override
|
113
|
public Object getInput() {
|
114
|
return input;
|
115
|
}
|
116
|
|
117
|
/** {@inheritDoc} */
|
118
|
@Override
|
119
|
public void refresh() {
|
120
|
showParts();
|
121
|
|
122
|
managedForm.setInput(input);
|
123
|
|
124
|
managedForm.refresh();
|
125
|
|
126
|
managedForm.reflow(true);
|
127
|
}
|
128
|
|
129
|
public void layout(){
|
130
|
body.layout();
|
131
|
}
|
132
|
|
133
|
protected abstract void showParts();
|
134
|
|
135
|
protected void destroySections() {
|
136
|
for (IFormPart formPart : managedForm.getParts()){
|
137
|
removePart((CdmSectionPart<?>) formPart);
|
138
|
}
|
139
|
|
140
|
managedForm.setInput(null);
|
141
|
|
142
|
formFactory.destroyElement(rootElement);
|
143
|
|
144
|
createFormFactory();
|
145
|
|
146
|
rootElement = new RootElement(formFactory, body);
|
147
|
|
148
|
for(Control control : body.getChildren()){
|
149
|
control.dispose();
|
150
|
control = null;
|
151
|
}
|
152
|
}
|
153
|
|
154
|
public void setFocus(){
|
155
|
// we have to set focus to a control of this viewer
|
156
|
// otherwise, after opening a dialog from the details, the focus will not be
|
157
|
// given back to the details view but to the editor
|
158
|
for(Control child : body.getChildren()){
|
159
|
child.setFocus();
|
160
|
break;
|
161
|
}
|
162
|
}
|
163
|
|
164
|
public void reflow(){
|
165
|
managedForm.reflow(true);
|
166
|
}
|
167
|
|
168
|
protected void removePart(CdmSectionPart<?> sectionPart){
|
169
|
managedForm.removePart(sectionPart);
|
170
|
formFactory.removePropertyChangeListener(sectionPart);
|
171
|
}
|
172
|
|
173
|
protected void addPart(AbstractFormSection<?> section){
|
174
|
CdmSectionPart<?> sectionPart = new CdmSectionPart<>(section);
|
175
|
managedForm.addPart(sectionPart);
|
176
|
formFactory.addPropertyChangeListener(sectionPart);
|
177
|
}
|
178
|
|
179
|
@Override
|
180
|
public ConversationHolder getConversationHolder() {
|
181
|
return viewPart.getConversationHolder();
|
182
|
}
|
183
|
|
184
|
}
|