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
.taxeditor
.ui
.element
.AbstractFormSection
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.RootElement
;
28 import eu
.etaxonomy
.taxeditor
.view
.detail
.CdmSectionPart
;
32 * @created Feb 9, 2010
35 public abstract class AbstractCdmDataViewer
extends Viewer
implements IConversationEnabled
{
37 protected ManagedForm managedForm
;
39 protected CdmFormFactory formFactory
;
41 protected ScrolledForm scrolledForm
;
43 private final Composite body
;
45 protected RootElement rootElement
;
47 //TODO: create a super class for this?
50 private final AbstractCdmViewPart viewPart
;
53 public AbstractCdmDataViewer(Composite parent
, AbstractCdmViewPart viewPart
) {
54 this.viewPart
= viewPart
;
56 managedForm
= new ManagedForm(parent
){
59 public void dirtyStateChanged() {
66 scrolledForm
= managedForm
.getForm();
68 body
= scrolledForm
.getBody();
70 body
.setLayout(LayoutConstants
.LAYOUT());
72 rootElement
= new RootElement(formFactory
, body
);
75 protected void createFormFactory() {
76 if(formFactory
!= null){
77 formFactory
.dispose();
80 formFactory
= new CdmFormFactory(Display
.getCurrent(), this);
83 protected void markViewPartDirty(){
84 viewPart
.changed(input
);
87 protected AbstractCdmViewPart
getViewPart() {
93 public Control
getControl() {
94 if(body
.isDisposed()){
97 for(Control child
: body
.getChildren()){
106 public void setInput(Object input
) {
109 setSelection(new StructuredSelection(input
));
115 public Object
getInput() {
121 public void refresh() {
124 managedForm
.setInput(input
);
126 managedForm
.refresh();
128 managedForm
.reflow(true);
131 public void layout(){
135 protected abstract void showParts();
137 protected void destroySections() {
138 for (IFormPart formPart
: managedForm
.getParts()){
139 removePart((CdmSectionPart
<?
>) formPart
);
142 managedForm
.setInput(null);
144 formFactory
.destroyElement(rootElement
);
148 rootElement
= new RootElement(formFactory
, body
);
150 for(Control control
: body
.getChildren()){
156 public void setFocus(){
157 // we have to set focus to a control of this viewer
158 // otherwise, after opening a dialog from the details, the focus will not be
159 // given back to the details view but to the editor
160 for(Control child
: body
.getChildren()){
166 public void reflow(){
167 managedForm
.reflow(true);
170 protected void removePart(CdmSectionPart
<?
> sectionPart
){
171 managedForm
.removePart(sectionPart
);
172 formFactory
.removePropertyChangeListener(sectionPart
);
175 protected void addPart(AbstractFormSection
<?
> section
){
176 CdmSectionPart
<?
> sectionPart
= new CdmSectionPart
<>(section
);
177 managedForm
.addPart(sectionPart
);
178 formFactory
.addPropertyChangeListener(sectionPart
);
182 public ConversationHolder
getConversationHolder() {
183 return viewPart
.getConversationHolder();