1 |
729887cf
|
n.hoffmann
|
// $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 |
2d9a13f7
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.editor.view;
|
12 |
729887cf
|
n.hoffmann
|
|
13 |
|
|
import org.apache.log4j.Logger;
|
14 |
|
|
import org.eclipse.jface.util.IPropertyChangeListener;
|
15 |
|
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
16 |
|
|
import org.eclipse.jface.viewers.ISelectionProvider;
|
17 |
|
|
import org.eclipse.jface.viewers.StructuredSelection;
|
18 |
|
|
import org.eclipse.jface.viewers.Viewer;
|
19 |
|
|
import org.eclipse.swt.widgets.Composite;
|
20 |
|
|
import org.eclipse.swt.widgets.Control;
|
21 |
|
|
import org.eclipse.swt.widgets.Display;
|
22 |
|
|
import org.eclipse.ui.forms.IFormPart;
|
23 |
|
|
import org.eclipse.ui.forms.ManagedForm;
|
24 |
2d9a13f7
|
n.hoffmann
|
import org.eclipse.ui.forms.events.IExpansionListener;
|
25 |
729887cf
|
n.hoffmann
|
import org.eclipse.ui.forms.widgets.ScrolledForm;
|
26 |
|
|
|
27 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
28 |
|
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
29 |
|
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
30 |
729887cf
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.forms.AbstractFormSection;
|
31 |
|
|
import eu.etaxonomy.taxeditor.forms.CdmFormFactory;
|
32 |
|
|
import eu.etaxonomy.taxeditor.forms.RootElement;
|
33 |
|
|
|
34 |
|
|
/**
|
35 |
|
|
* @author n.hoffmann
|
36 |
|
|
* @created Feb 9, 2010
|
37 |
|
|
* @version 1.0
|
38 |
|
|
*/
|
39 |
2d9a13f7
|
n.hoffmann
|
public abstract class AbstractCdmDataViewer extends Viewer implements IPropertyChangeListener, ISelectionProvider, IConversationEnabled{
|
40 |
729887cf
|
n.hoffmann
|
private static final Logger logger = Logger
|
41 |
2d9a13f7
|
n.hoffmann
|
.getLogger(AbstractCdmDataViewer.class);
|
42 |
729887cf
|
n.hoffmann
|
|
43 |
|
|
protected ManagedForm managedForm;
|
44 |
|
|
|
45 |
|
|
protected CdmFormFactory formFactory;
|
46 |
|
|
|
47 |
|
|
protected ScrolledForm scrolledForm;
|
48 |
|
|
|
49 |
|
|
private Composite body;
|
50 |
|
|
|
51 |
|
|
protected RootElement rootElement;
|
52 |
|
|
|
53 |
|
|
private Object input;
|
54 |
|
|
|
55 |
2d9a13f7
|
n.hoffmann
|
private AbstractCdmViewPart viewPart;
|
56 |
|
|
|
57 |
729887cf
|
n.hoffmann
|
|
58 |
|
|
/**
|
59 |
|
|
*
|
60 |
|
|
*/
|
61 |
2d9a13f7
|
n.hoffmann
|
public AbstractCdmDataViewer(Composite parent, AbstractCdmViewPart viewPart) {
|
62 |
|
|
this.viewPart = viewPart;
|
63 |
|
|
|
64 |
729887cf
|
n.hoffmann
|
managedForm = new ManagedForm(parent){
|
65 |
|
|
|
66 |
|
|
/* (non-Javadoc)
|
67 |
|
|
* @see org.eclipse.ui.forms.ManagedForm#dirtyStateChanged()
|
68 |
|
|
*/
|
69 |
|
|
@Override
|
70 |
|
|
public void dirtyStateChanged() {
|
71 |
2d9a13f7
|
n.hoffmann
|
markViewPartDirty();
|
72 |
729887cf
|
n.hoffmann
|
}
|
73 |
|
|
};
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
createFormFactory();
|
77 |
|
|
|
78 |
|
|
formFactory.addPropertyChangeListener(this);
|
79 |
|
|
|
80 |
|
|
scrolledForm = managedForm.getForm();
|
81 |
|
|
|
82 |
|
|
body = scrolledForm.getBody();
|
83 |
|
|
|
84 |
|
|
body.setLayout(CdmFormFactory.LAYOUT());
|
85 |
|
|
|
86 |
|
|
rootElement = new RootElement(formFactory, body);
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
protected void createFormFactory() {
|
90 |
|
|
if(formFactory != null){
|
91 |
|
|
formFactory.dispose();
|
92 |
|
|
formFactory = null;
|
93 |
|
|
}
|
94 |
|
|
formFactory = new CdmFormFactory(Display.getCurrent(), this);
|
95 |
|
|
}
|
96 |
|
|
|
97 |
2d9a13f7
|
n.hoffmann
|
private void markViewPartDirty(){
|
98 |
|
|
viewPart.dirtyStateChanged();
|
99 |
|
|
}
|
100 |
729887cf
|
n.hoffmann
|
|
101 |
|
|
|
102 |
|
|
/* (non-Javadoc)
|
103 |
|
|
* @see org.eclipse.jface.viewers.Viewer#getControl()
|
104 |
|
|
*/
|
105 |
|
|
@Override
|
106 |
|
|
public Control getControl() {
|
107 |
2d9a13f7
|
n.hoffmann
|
for(Control child : body.getChildren()){
|
108 |
|
|
return child;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
729887cf
|
n.hoffmann
|
return body;
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
/* (non-Javadoc)
|
115 |
|
|
* @see org.eclipse.jface.viewers.Viewer#setInput(java.lang.Object)
|
116 |
|
|
*/
|
117 |
|
|
@Override
|
118 |
|
|
public void setInput(Object input) {
|
119 |
|
|
this.input = input;
|
120 |
|
|
// reset selection
|
121 |
|
|
setSelection(new StructuredSelection(input));
|
122 |
|
|
refresh();
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
/* (non-Javadoc)
|
126 |
|
|
* @see org.eclipse.jface.viewers.Viewer#getInput()
|
127 |
|
|
*/
|
128 |
|
|
@Override
|
129 |
|
|
public Object getInput() {
|
130 |
|
|
return input;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
/* (non-Javadoc)
|
134 |
|
|
* @see org.eclipse.jface.viewers.Viewer#refresh()
|
135 |
|
|
*/
|
136 |
|
|
@Override
|
137 |
|
|
public void refresh() {
|
138 |
|
|
showParts();
|
139 |
|
|
|
140 |
|
|
managedForm.setInput(input);
|
141 |
|
|
|
142 |
|
|
managedForm.refresh();
|
143 |
|
|
|
144 |
|
|
managedForm.reflow(true);
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
public void layout(){
|
148 |
|
|
body.layout();
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
protected abstract void showParts();
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
protected void destroySections() {
|
155 |
|
|
for (IFormPart formPart : managedForm.getParts()){
|
156 |
|
|
removePart((CdmSectionPart) formPart);
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
managedForm.setInput(null);
|
160 |
|
|
|
161 |
|
|
formFactory.destroyElement(rootElement);
|
162 |
|
|
|
163 |
|
|
createFormFactory();
|
164 |
|
|
|
165 |
|
|
rootElement = new RootElement(formFactory, body);
|
166 |
|
|
|
167 |
|
|
for(Control control : body.getChildren()){
|
168 |
|
|
control.dispose();
|
169 |
|
|
control = null;
|
170 |
|
|
}
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
public void setFocus(){
|
175 |
|
|
// we have to set focus to a control of this viewer
|
176 |
|
|
// otherwise, after opening a dialog from the details, the focus will not be
|
177 |
|
|
// given back to the details view but to the editor
|
178 |
|
|
for(Control child : body.getChildren()){
|
179 |
|
|
child.setFocus();
|
180 |
|
|
break;
|
181 |
|
|
}
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
public void reflow(){
|
185 |
|
|
managedForm.reflow(true);
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
/* (non-Javadoc)
|
189 |
|
|
* @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
|
190 |
|
|
*/
|
191 |
|
|
public void propertyChange(PropertyChangeEvent event) {
|
192 |
|
|
logger.warn("Property changed: " + event);
|
193 |
|
|
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
protected void removePart(CdmSectionPart sectionPart){
|
197 |
|
|
managedForm.removePart(sectionPart);
|
198 |
|
|
formFactory.removePropertyChangeListener(sectionPart);
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
protected void addPart(AbstractFormSection section){
|
202 |
|
|
CdmSectionPart sectionPart = new CdmSectionPart(section);
|
203 |
|
|
managedForm.addPart(sectionPart);
|
204 |
|
|
formFactory.addPropertyChangeListener(sectionPart);
|
205 |
|
|
}
|
206 |
2d9a13f7
|
n.hoffmann
|
|
207 |
|
|
public ConversationHolder getConversationHolder() {
|
208 |
|
|
return viewPart.getConversationHolder();
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
public void update(CdmDataChangeMap changeEvents) {}
|
212 |
729887cf
|
n.hoffmann
|
}
|