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
.ExpandableComposite
;
26 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
28 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
29 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
30 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
31 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
32 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
33 import eu
.etaxonomy
.taxeditor
.remoting
.CdmEagerLoadingException
;
34 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
36 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
37 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
38 import eu
.etaxonomy
.taxeditor
.ui
.element
.RootElement
;
39 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.EmptySection
;
40 import eu
.etaxonomy
.taxeditor
.view
.detail
.CdmSectionPart
;
48 public abstract class AbstractCdmDataViewerE4
extends Viewer
implements IConversationEnabled
{
50 private Logger logger
;
52 protected ManagedForm managedForm
;
54 protected CdmFormFactory formFactory
;
56 protected ScrolledForm scrolledForm
;
58 private Composite body
;
60 protected RootElement rootElement
;
63 protected IEclipseContext context
;
65 //TODO: create a super class for this?
68 protected IDirtyMarkable part
;
71 public AbstractCdmDataViewerE4() {
75 public void init(Composite parent
, IDirtyMarkable part
) {
78 managedForm
= new ManagedForm(parent
){
81 public void dirtyStateChanged() {
88 scrolledForm
= managedForm
.getForm();
90 body
= scrolledForm
.getBody();
92 body
.setLayout(LayoutConstants
.LAYOUT());
94 rootElement
= new RootElement(formFactory
, body
);
98 protected void createEmptySection(String message
, RootElement parent
) {
101 EmptySection emptySection
= formFactory
.createEmptySection(message
, formFactory
, parent
, SWT
.NONE
);
103 addPart(emptySection
);
106 public void showEmptyPage(String message
){
108 createEmptySection(message
, rootElement
);
111 protected void markViewPartDirty(){
115 protected void createFormFactory() {
116 if(formFactory
!= null){
117 formFactory
.dispose();
120 formFactory
= new CdmFormFactory(Display
.getCurrent(), this);
121 ContextInjectionFactory
.inject(formFactory
, context
);
126 public Control
getControl() {
128 if(body
.isDisposed()){
131 for(Control child
: body
.getChildren()){
141 public void setInput(Object input
) {
146 }catch(CdmEagerLoadingException e
){
154 public Object
getInput() {
160 public void refresh() {
164 managedForm
.setInput(input
);
167 managedForm
.refresh();
169 // managedForm.reflow(true);
172 public void layout(){
176 protected int getSectionStyle(Class
<?
extends AbstractFormSection
> clazz
){
177 return getSectionStyle(clazz
, false);
180 protected int getSectionStyle(Class
<?
extends AbstractFormSection
> clazz
, boolean initiallyExpanded
){
181 int style
= ExpandableComposite
.TWISTIE
;
182 String prefKey
= StoreUtil
.getPrefKey(clazz
, getInput());
183 if(PreferencesUtil
.contains(prefKey
)){
184 style
= PreferencesUtil
.getStringValue(prefKey
)==CdmSectionPart
.EXPANDED?style
|= ExpandableComposite
.EXPANDED
:style
;
187 style
= initiallyExpanded?style
|= ExpandableComposite
.EXPANDED
:style
;
192 protected abstract void showParts();
194 public void destroySections() {
195 for (IFormPart formPart
: managedForm
.getParts()){
196 removePart((CdmSectionPart
<?
>) formPart
);
199 managedForm
.setInput(null);
201 formFactory
.destroyElement(rootElement
);
205 rootElement
= new RootElement(formFactory
, body
);
207 for(Control control
: body
.getChildren()){
209 if (control
!= null && !control
.isDisposed()){
212 }catch(SWTException e
){
213 if (PreferencesUtil
.isShowUpWidgetIsDisposedMessages() && e
.getMessage().equals("Widget is disposed")){
214 MessagingUtils
.errorDialog("Widget is disposed",
216 MessagingUtils
.WIDGET_IS_DISPOSED_MESSAGE
,
227 public void setFocus(){
228 // we have to set focus to a control of this viewer
229 // otherwise, after opening a dialog from the details, the focus will not be
230 // given back to the details view but to the editor
231 for(Control child
: body
.getChildren()){
237 public void reflow(){
238 managedForm
.reflow(true);
241 protected void removePart(CdmSectionPart
<?
> sectionPart
){
242 managedForm
.removePart(sectionPart
);
243 formFactory
.removePropertyChangeListener(sectionPart
);
246 protected void addPart(AbstractFormSection
<?
> section
){
247 CdmSectionPart
<?
> sectionPart
= new CdmSectionPart
<>(section
);
248 managedForm
.addPart(sectionPart
);
249 formFactory
.addPropertyChangeListener(sectionPart
);
253 public ConversationHolder
getConversationHolder() {