2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.view
;
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
.swt
.widgets
.Display
;
17 import org
.eclipse
.ui
.forms
.IFormPart
;
18 import org
.eclipse
.ui
.forms
.ManagedForm
;
19 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
21 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
22 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.RootElement
;
27 import eu
.etaxonomy
.taxeditor
.view
.detail
.CdmSectionPart
;
31 * @created Feb 9, 2010
34 public abstract class AbstractCdmDataViewer
extends Viewer
implements IConversationEnabled
{
36 protected ManagedForm managedForm
;
38 protected CdmFormFactory formFactory
;
40 protected ScrolledForm scrolledForm
;
42 private final Composite body
;
44 protected RootElement rootElement
;
46 //TODO: create a super class for this?
49 private final AbstractCdmViewPart viewPart
;
52 public AbstractCdmDataViewer(Composite parent
, AbstractCdmViewPart viewPart
) {
53 this.viewPart
= viewPart
;
55 managedForm
= new ManagedForm(parent
){
58 public void dirtyStateChanged() {
65 scrolledForm
= managedForm
.getForm();
67 body
= scrolledForm
.getBody();
69 body
.setLayout(LayoutConstants
.LAYOUT());
71 rootElement
= new RootElement(formFactory
, body
);
74 protected void createFormFactory() {
75 if(formFactory
!= null){
76 formFactory
.dispose();
79 formFactory
= new CdmFormFactory(Display
.getCurrent(), this);
82 protected void markViewPartDirty(){
83 viewPart
.changed(input
);
86 protected AbstractCdmViewPart
getViewPart() {
92 public Control
getControl() {
93 if(body
.isDisposed()){
96 for(Control child
: body
.getChildren()){
105 public void setInput(Object input
) {
108 setSelection(new StructuredSelection(input
));
114 public Object
getInput() {
120 public void refresh() {
123 managedForm
.setInput(input
);
125 managedForm
.refresh();
127 managedForm
.reflow(true);
130 public void layout(){
134 protected abstract void showParts();
136 protected void destroySections() {
137 for (IFormPart formPart
: managedForm
.getParts()){
138 removePart((CdmSectionPart
<?
>) formPart
);
141 managedForm
.setInput(null);
143 formFactory
.destroyElement(rootElement
);
147 rootElement
= new RootElement(formFactory
, body
);
149 for(Control control
: body
.getChildren()){
155 public void setFocus(){
156 // we have to set focus to a control of this viewer
157 // otherwise, after opening a dialog from the details, the focus will not be
158 // given back to the details view but to the editor
159 for(Control child
: body
.getChildren()){
165 public void reflow(){
166 managedForm
.reflow(true);
169 protected void removePart(CdmSectionPart
<?
> sectionPart
){
170 managedForm
.removePart(sectionPart
);
171 formFactory
.removePropertyChangeListener(sectionPart
);
174 protected void addPart(AbstractFormSection
<?
> section
){
175 CdmSectionPart
<?
> sectionPart
= new CdmSectionPart
<>(section
);
176 managedForm
.addPart(sectionPart
);
177 formFactory
.addPropertyChangeListener(sectionPart
);
181 public ConversationHolder
getConversationHolder() {
182 return viewPart
.getConversationHolder();