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
.e4
.details
;
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
.model
.IDirtyMarkable
;
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
;
36 public abstract class AbstractCdmDataViewerE4
extends Viewer
implements IConversationEnabled
{
38 protected ManagedForm managedForm
;
40 protected CdmFormFactory formFactory
;
42 protected ScrolledForm scrolledForm
;
44 private final Composite body
;
46 protected RootElement rootElement
;
48 //TODO: create a super class for this?
51 private final IDirtyMarkable part
;
54 public AbstractCdmDataViewerE4(Composite parent
, IDirtyMarkable part
) {
57 managedForm
= new ManagedForm(parent
){
60 public void dirtyStateChanged() {
67 scrolledForm
= managedForm
.getForm();
69 body
= scrolledForm
.getBody();
71 body
.setLayout(LayoutConstants
.LAYOUT());
73 rootElement
= new RootElement(formFactory
, body
);
76 protected void markViewPartDirty(){
80 protected void createFormFactory() {
81 if(formFactory
!= null){
82 formFactory
.dispose();
85 formFactory
= new CdmFormFactory(Display
.getCurrent(), this);
90 public Control
getControl() {
91 if(body
.isDisposed()){
94 for(Control child
: body
.getChildren()){
103 public void setInput(Object input
) {
106 setSelection(new StructuredSelection(input
));
112 public Object
getInput() {
118 public void refresh() {
121 managedForm
.setInput(input
);
123 managedForm
.refresh();
125 managedForm
.reflow(true);
128 public void layout(){
132 protected abstract void showParts();
134 protected void destroySections() {
135 for (IFormPart formPart
: managedForm
.getParts()){
136 removePart((CdmSectionPart
<?
>) formPart
);
139 managedForm
.setInput(null);
141 formFactory
.destroyElement(rootElement
);
145 rootElement
= new RootElement(formFactory
, body
);
147 for(Control control
: body
.getChildren()){
153 public void setFocus(){
154 // we have to set focus to a control of this viewer
155 // otherwise, after opening a dialog from the details, the focus will not be
156 // given back to the details view but to the editor
157 for(Control child
: body
.getChildren()){
163 public void reflow(){
164 managedForm
.reflow(true);
167 protected void removePart(CdmSectionPart
<?
> sectionPart
){
168 managedForm
.removePart(sectionPart
);
169 formFactory
.removePropertyChangeListener(sectionPart
);
172 protected void addPart(AbstractFormSection
<?
> section
){
173 CdmSectionPart
<?
> sectionPart
= new CdmSectionPart
<>(section
);
174 managedForm
.addPart(sectionPart
);
175 formFactory
.addPropertyChangeListener(sectionPart
);
179 public ConversationHolder
getConversationHolder() {