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() {
163 managedForm
.setInput(input
);
165 managedForm
.refresh();
167 // managedForm.reflow(true);
170 public void layout(){
174 protected int getSectionStyle(Class
<?
extends AbstractFormSection
> clazz
){
175 int style
= ExpandableComposite
.TWISTIE
;
176 if(PreferencesUtil
.getPreferenceStore().getBoolean(StoreUtil
.getPrefKey(clazz
, getInput()))){
177 style
|= ExpandableComposite
.EXPANDED
;
182 protected abstract void showParts();
184 public void destroySections() {
185 for (IFormPart formPart
: managedForm
.getParts()){
186 removePart((CdmSectionPart
<?
>) formPart
);
189 managedForm
.setInput(null);
191 formFactory
.destroyElement(rootElement
);
195 rootElement
= new RootElement(formFactory
, body
);
197 for(Control control
: body
.getChildren()){
199 if (control
!= null && !control
.isDisposed()){
202 }catch(SWTException e
){
203 if (PreferencesUtil
.isShowUpWidgetIsDisposedMessages() && e
.getMessage().equals("Widget is disposed")){
204 MessagingUtils
.errorDialog("Widget is disposed",
206 MessagingUtils
.WIDGET_IS_DISPOSED_MESSAGE
,
217 public void setFocus(){
218 // we have to set focus to a control of this viewer
219 // otherwise, after opening a dialog from the details, the focus will not be
220 // given back to the details view but to the editor
221 for(Control child
: body
.getChildren()){
227 public void reflow(){
228 managedForm
.reflow(true);
231 protected void removePart(CdmSectionPart
<?
> sectionPart
){
232 managedForm
.removePart(sectionPart
);
233 formFactory
.removePropertyChangeListener(sectionPart
);
236 protected void addPart(AbstractFormSection
<?
> section
){
237 CdmSectionPart
<?
> sectionPart
= new CdmSectionPart
<>(section
);
238 managedForm
.addPart(sectionPart
);
239 formFactory
.addPropertyChangeListener(sectionPart
);
243 public ConversationHolder
getConversationHolder() {