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.
9 package eu
.etaxonomy
.taxeditor
.view
.e4
;
11 import javax
.inject
.Inject
;
13 import org
.apache
.logging
.log4j
.LogManager
;
14 import org
.apache
.logging
.log4j
.Logger
;
15 import org
.eclipse
.e4
.core
.contexts
.ContextInjectionFactory
;
16 import org
.eclipse
.e4
.core
.contexts
.IEclipseContext
;
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
.taxeditor
.model
.IDirtyMarkable
;
28 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
29 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
30 import eu
.etaxonomy
.taxeditor
.remoting
.CdmEagerLoadingException
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.RootElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.EmptySection
;
36 import eu
.etaxonomy
.taxeditor
.view
.detail
.CdmSectionPart
;
42 public abstract class AbstractCdmDataViewer
extends Viewer
{
44 private static final Logger logger
= LogManager
.getLogger();
46 protected ManagedForm managedForm
;
48 protected CdmFormFactory formFactory
;
50 protected ScrolledForm scrolledForm
;
52 private Composite body
;
54 protected RootElement rootElement
;
57 protected IEclipseContext context
;
59 //TODO: create a super class for this?
62 protected IDirtyMarkable part
;
65 public AbstractCdmDataViewer() {
68 public void init(Composite parent
, IDirtyMarkable part
) {
71 managedForm
= new ManagedForm(parent
){
74 public void dirtyStateChanged() {
81 scrolledForm
= managedForm
.getForm();
83 body
= scrolledForm
.getBody();
85 body
.setLayout(LayoutConstants
.LAYOUT());
87 rootElement
= new RootElement(formFactory
, body
);
90 protected void createEmptySection(String message
, RootElement parent
) {
93 EmptySection emptySection
= formFactory
.createEmptySection(message
, formFactory
, parent
, SWT
.NONE
);
95 addPart(emptySection
);
98 public void showEmptyPage(String message
){
100 createEmptySection(message
, rootElement
);
103 protected void markViewPartDirty(){
107 protected void createFormFactory() {
108 if(formFactory
!= null){
109 formFactory
.dispose();
112 formFactory
= new CdmFormFactory(Display
.getCurrent(), this);
113 ContextInjectionFactory
.inject(formFactory
, context
);
117 public Control
getControl() {
119 if(body
.isDisposed()){
122 for(Control child
: body
.getChildren()){
131 public void setInput(Object input
) {
136 }catch(CdmEagerLoadingException e
){
143 public Object
getInput() {
148 public void refresh() {
152 managedForm
.setInput(input
);
155 managedForm
.refresh();
157 // managedForm.reflow(true);
160 public void layout(){
164 protected abstract void showParts();
166 public void destroySections() {
167 for (IFormPart formPart
: managedForm
.getParts()){
168 removePart((CdmSectionPart
<?
>) formPart
);
171 managedForm
.setInput(null);
173 formFactory
.destroyElement(rootElement
);
174 }catch (SWTException e
){
175 if (PreferencesUtil
.isShowUpWidgetIsDisposedMessages() && e
.getMessage().equals("Widget is disposed")){
176 MessagingUtils
.errorDialog("Widget is disposed",
178 MessagingUtils
.WIDGET_IS_DISPOSED_MESSAGE
,
187 rootElement
= new RootElement(formFactory
, body
);
189 for(Control control
: body
.getChildren()){
191 if (control
!= null && !control
.isDisposed()){
194 }catch(SWTException e
){
195 if (PreferencesUtil
.isShowUpWidgetIsDisposedMessages() && e
.getMessage().equals("Widget is disposed")){
196 MessagingUtils
.errorDialog("Widget is disposed",
198 MessagingUtils
.WIDGET_IS_DISPOSED_MESSAGE
,
208 public void setFocus(){
209 // we have to set focus to a control of this viewer
210 // otherwise, after opening a dialog from the details, the focus will not be
211 // given back to the details view but to the editor
212 for(Control child
: body
.getChildren()){
218 public void reflow(){
219 managedForm
.reflow(true);
222 protected void removePart(CdmSectionPart
<?
> sectionPart
){
223 managedForm
.removePart(sectionPart
);
224 formFactory
.removePropertyChangeListener(sectionPart
);
227 protected void addPart(AbstractFormSection
<?
> section
){
228 CdmSectionPart
<?
> sectionPart
= new CdmSectionPart
<>(section
);
229 managedForm
.addPart(sectionPart
);
230 formFactory
.addPropertyChangeListener(sectionPart
);