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 if(body
.isDisposed()){
119 for(Control child
: body
.getChildren()){
127 * @see org.eclipse.jface.viewers.Viewer#setInput(java.lang.Object)
131 public void setInput(Object input
) {
134 setSelection(new StructuredSelection(input
));
139 * @see org.eclipse.jface.viewers.Viewer#getInput()
143 public Object
getInput() {
148 * @see org.eclipse.jface.viewers.Viewer#refresh()
152 public void refresh() {
155 managedForm
.setInput(input
);
157 managedForm
.refresh();
159 managedForm
.reflow(true);
166 public void layout(){
173 protected abstract void showParts();
177 * <p>destroySections</p>
179 protected void destroySections() {
180 for (IFormPart formPart
: managedForm
.getParts()){
181 removePart((CdmSectionPart
) formPart
);
184 managedForm
.setInput(null);
186 formFactory
.destroyElement(rootElement
);
190 rootElement
= new RootElement(formFactory
, body
);
192 for(Control control
: body
.getChildren()){
202 public void setFocus(){
203 // we have to set focus to a control of this viewer
204 // otherwise, after opening a dialog from the details, the focus will not be
205 // given back to the details view but to the editor
206 for(Control child
: body
.getChildren()){
215 public void reflow(){
216 managedForm
.reflow(true);
222 * @param sectionPart a {@link eu.etaxonomy.taxeditor.view.detail.CdmSectionPart} object.
224 protected void removePart(CdmSectionPart sectionPart
){
225 managedForm
.removePart(sectionPart
);
226 formFactory
.removePropertyChangeListener(sectionPart
);
232 * @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
234 protected void addPart(AbstractFormSection section
){
235 CdmSectionPart sectionPart
= new CdmSectionPart(section
);
236 managedForm
.addPart(sectionPart
);
237 formFactory
.addPropertyChangeListener(sectionPart
);
241 * <p>getConversationHolder</p>
243 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
246 public ConversationHolder
getConversationHolder() {
247 return viewPart
.getConversationHolder();
252 public void update(CdmDataChangeMap changeEvents
) {}