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
;
12 import javax
.inject
.Inject
;
14 import org
.eclipse
.e4
.core
.contexts
.ContextInjectionFactory
;
15 import org
.eclipse
.e4
.core
.contexts
.IEclipseContext
;
16 import org
.eclipse
.e4
.core
.services
.log
.Logger
;
17 import org
.eclipse
.jface
.viewers
.Viewer
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.SWTException
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Control
;
22 import org
.eclipse
.swt
.widgets
.Display
;
23 import org
.eclipse
.ui
.forms
.IFormPart
;
24 import org
.eclipse
.ui
.forms
.ManagedForm
;
25 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
27 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
28 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
29 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
30 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
32 import eu
.etaxonomy
.taxeditor
.remoting
.CdmEagerLoadingException
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
36 import eu
.etaxonomy
.taxeditor
.ui
.element
.RootElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.EmptySection
;
38 import eu
.etaxonomy
.taxeditor
.view
.detail
.CdmSectionPart
;
46 public abstract class AbstractCdmDataViewerE4
extends Viewer
implements IConversationEnabled
{
48 private Logger logger
;
50 protected ManagedForm managedForm
;
52 protected CdmFormFactory formFactory
;
54 protected ScrolledForm scrolledForm
;
56 private Composite body
;
58 protected RootElement rootElement
;
61 protected IEclipseContext context
;
63 //TODO: create a super class for this?
66 protected IDirtyMarkable part
;
69 public AbstractCdmDataViewerE4() {
73 public void init(Composite parent
, IDirtyMarkable part
) {
76 managedForm
= new ManagedForm(parent
){
79 public void dirtyStateChanged() {
86 scrolledForm
= managedForm
.getForm();
88 body
= scrolledForm
.getBody();
90 body
.setLayout(LayoutConstants
.LAYOUT());
92 rootElement
= new RootElement(formFactory
, body
);
96 protected void createEmptySection(RootElement parent
) {
99 EmptySection emptySection
= formFactory
.createEmptySection(formFactory
, parent
, SWT
.NONE
);
101 addPart(emptySection
);
104 public void showEmptyPage(){
106 createEmptySection(rootElement
);
109 protected void markViewPartDirty(){
113 protected void createFormFactory() {
114 if(formFactory
!= null){
115 formFactory
.dispose();
118 formFactory
= new CdmFormFactory(Display
.getCurrent(), this);
119 ContextInjectionFactory
.inject(formFactory
, context
);
124 public Control
getControl() {
126 if(body
.isDisposed()){
129 for(Control child
: body
.getChildren()){
139 public void setInput(Object input
) {
144 }catch(CdmEagerLoadingException e
){
152 public Object
getInput() {
158 public void refresh() {
161 managedForm
.setInput(input
);
163 managedForm
.refresh();
165 managedForm
.reflow(true);
168 public void layout(){
172 protected abstract void showParts();
174 public void destroySections() {
175 for (IFormPart formPart
: managedForm
.getParts()){
176 removePart((CdmSectionPart
<?
>) formPart
);
179 managedForm
.setInput(null);
181 formFactory
.destroyElement(rootElement
);
185 rootElement
= new RootElement(formFactory
, body
);
187 for(Control control
: body
.getChildren()){
189 if (control
!= null && !control
.isDisposed()){
192 }catch(SWTException e
){
193 if (PreferencesUtil
.isShowUpWidgetIsDisposedMessages() && e
.getMessage().equals("Widget is disposed")){
194 MessagingUtils
.errorDialog("Widget is disposed",
196 MessagingUtils
.WIDGET_IS_DISPOSED_MESSAGE
,
207 public void setFocus(){
208 // we have to set focus to a control of this viewer
209 // otherwise, after opening a dialog from the details, the focus will not be
210 // given back to the details view but to the editor
211 for(Control child
: body
.getChildren()){
217 public void reflow(){
218 managedForm
.reflow(true);
221 protected void removePart(CdmSectionPart
<?
> sectionPart
){
222 managedForm
.removePart(sectionPart
);
223 formFactory
.removePropertyChangeListener(sectionPart
);
226 protected void addPart(AbstractFormSection
<?
> section
){
227 CdmSectionPart
<?
> sectionPart
= new CdmSectionPart
<>(section
);
228 managedForm
.addPart(sectionPart
);
229 formFactory
.addPropertyChangeListener(sectionPart
);
233 public ConversationHolder
getConversationHolder() {