3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.view
;
13 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
14 import org
.eclipse
.jface
.viewers
.Viewer
;
15 import org
.eclipse
.swt
.widgets
.Composite
;
16 import org
.eclipse
.swt
.widgets
.Control
;
17 import org
.eclipse
.swt
.widgets
.Display
;
18 import org
.eclipse
.ui
.forms
.IFormPart
;
19 import org
.eclipse
.ui
.forms
.ManagedForm
;
20 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
22 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
24 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.RootElement
;
29 import eu
.etaxonomy
.taxeditor
.view
.detail
.CdmSectionPart
;
32 * <p>Abstract AbstractCdmDataViewer class.</p>
35 * @created Feb 9, 2010
38 public abstract class AbstractCdmDataViewer
extends Viewer
implements IConversationEnabled
{
40 protected ManagedForm managedForm
;
42 protected CdmFormFactory formFactory
;
44 protected ScrolledForm scrolledForm
;
46 private final Composite body
;
48 protected RootElement rootElement
;
50 //TODO: create a super class for this?
53 private final AbstractCdmViewPart viewPart
;
57 * <p>Constructor for AbstractCdmDataViewer.</p>
59 * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
60 * @param viewPart a {@link eu.etaxonomy.taxeditor.view.AbstractCdmViewPart} object.
62 public AbstractCdmDataViewer(Composite parent
, AbstractCdmViewPart viewPart
) {
63 this.viewPart
= viewPart
;
65 managedForm
= new ManagedForm(parent
){
68 * @see org.eclipse.ui.forms.ManagedForm#dirtyStateChanged()
71 public void dirtyStateChanged() {
78 scrolledForm
= managedForm
.getForm();
80 body
= scrolledForm
.getBody();
82 body
.setLayout(LayoutConstants
.LAYOUT());
84 rootElement
= new RootElement(formFactory
, body
);
88 * <p>createFormFactory</p>
90 protected void createFormFactory() {
91 if(formFactory
!= null){
92 formFactory
.dispose();
95 formFactory
= new CdmFormFactory(Display
.getCurrent(), this);
98 protected void markViewPartDirty(){
99 viewPart
.changed(input
);
106 protected AbstractCdmViewPart
getViewPart() {
111 * @see org.eclipse.jface.viewers.Viewer#getControl()
115 public Control
getControl() {
116 for(Control child
: body
.getChildren()){
124 * @see org.eclipse.jface.viewers.Viewer#setInput(java.lang.Object)
128 public void setInput(Object input
) {
131 setSelection(new StructuredSelection(input
));
136 * @see org.eclipse.jface.viewers.Viewer#getInput()
140 public Object
getInput() {
145 * @see org.eclipse.jface.viewers.Viewer#refresh()
149 public void refresh() {
152 managedForm
.setInput(input
);
154 managedForm
.refresh();
156 managedForm
.reflow(true);
163 public void layout(){
170 protected abstract void showParts();
174 * <p>destroySections</p>
176 protected void destroySections() {
177 for (IFormPart formPart
: managedForm
.getParts()){
178 removePart((CdmSectionPart
) formPart
);
181 managedForm
.setInput(null);
183 formFactory
.destroyElement(rootElement
);
187 rootElement
= new RootElement(formFactory
, body
);
189 for(Control control
: body
.getChildren()){
199 public void setFocus(){
200 // we have to set focus to a control of this viewer
201 // otherwise, after opening a dialog from the details, the focus will not be
202 // given back to the details view but to the editor
203 for(Control child
: body
.getChildren()){
212 public void reflow(){
213 managedForm
.reflow(true);
219 * @param sectionPart a {@link eu.etaxonomy.taxeditor.view.detail.CdmSectionPart} object.
221 protected void removePart(CdmSectionPart sectionPart
){
222 managedForm
.removePart(sectionPart
);
223 formFactory
.removePropertyChangeListener(sectionPart
);
229 * @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
231 protected void addPart(AbstractFormSection section
){
232 CdmSectionPart sectionPart
= new CdmSectionPart(section
);
233 managedForm
.addPart(sectionPart
);
234 formFactory
.addPropertyChangeListener(sectionPart
);
238 * <p>getConversationHolder</p>
240 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
243 public ConversationHolder
getConversationHolder() {
244 return viewPart
.getConversationHolder();
249 public void update(CdmDataChangeMap changeEvents
) {}