3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.ui
.element
;
13 import org
.apache
.commons
.lang
.StringUtils
;
14 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
15 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
16 import org
.eclipse
.jface
.wizard
.WizardPage
;
17 import org
.eclipse
.swt
.graphics
.Color
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
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
.cdm
.model
.common
.IIdentifiableEntity
;
24 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
29 * Abstract AbstractCdmEntityWizardPage class.
33 * @created Jun 1, 2010
36 public abstract class AbstractCdmEntityWizardPage
<T
> extends WizardPage
37 implements IConversationEnabled
, IPropertyChangeListener
{
39 protected CdmFormFactory formFactory
;
42 AbstractCdmDetailElement
<T
> detailElement
;
43 private final ConversationHolder conversation
;
47 * Constructor for AbstractCdmEntityWizardPage.
51 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
54 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
61 protected AbstractCdmEntityWizardPage(CdmFormFactory formFactory
,
62 ConversationHolder conversation
, T entity
) {
64 this.formFactory
= formFactory
;
66 this.conversation
= conversation
;
67 setDescription(getEntityTitle());
69 formFactory
.addPropertyChangeListener(this);
70 setPageComplete(false);
76 private String
getEntityTitle() {
77 if (entity
instanceof IIdentifiableEntity
) {
78 ((IIdentifiableEntity
) entity
).getTitleCache();
87 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
92 public void createControl(Composite parent
) {
93 ScrolledForm scrolledForm
= formFactory
.createScrolledForm(parent
);
94 scrolledForm
.getBody().setLayout(LayoutConstants
.LAYOUT());
96 Composite control
= formFactory
.createComposite(scrolledForm
.getBody());
97 control
.setLayoutData(LayoutConstants
.FILL());
99 control
.setLayout(LayoutConstants
.LAYOUT(2, false));
100 WizardPageRootElement rootElement
= new WizardPageRootElement(
101 formFactory
, control
, getConversationHolder());
103 Color bgColor
= getShell().getBackground();
105 detailElement
= createElement(rootElement
);
107 rootElement
.setBackground(bgColor
);
108 control
.setBackground(bgColor
);
109 scrolledForm
.setBackground(bgColor
);
111 setControl(scrolledForm
);
116 * Getter for the field <code>entity</code>.
119 * @return a T object.
121 public T
getEntity() {
126 * Creates the detail element for this wizard page
129 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
132 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
135 public abstract AbstractCdmDetailElement
<T
> createElement(
136 ICdmFormElement rootElement
);
138 protected class WizardPageRootElement
extends RootElement
implements
139 IConversationEnabled
{
141 private final ConversationHolder conversation
;
143 public WizardPageRootElement(CdmFormFactory formFactory
,
144 Composite layoutComposite
, ConversationHolder conversation
) {
145 super(formFactory
, layoutComposite
);
146 this.conversation
= conversation
;
150 public void refresh() {
152 this.removeElements();
153 detailElement
= createElement(this);
154 ((Composite
) getControl()).layout();
158 public ConversationHolder
getConversationHolder() {
163 public void update(CdmDataChangeMap changeEvents
) {
168 public void propertyChange(PropertyChangeEvent event
) {
169 if (event
.getSource() == getDetailElement()) {
175 * Should check whether the wizard is complete in a sense that it contains
176 * sane data. Should setPageComplete to true if that is the case.
178 protected void checkComplete() {
179 setPageComplete(titleCacheIsNotEmpty());
182 private boolean titleCacheIsNotEmpty() {
183 if (getEntity() instanceof IIdentifiableEntity
) {
184 IIdentifiableEntity entity
= (IIdentifiableEntity
) getEntity();
185 return !StringUtils
.isEmpty(entity
.getTitleCache());
192 * getConversationHolder
195 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
199 public ConversationHolder
getConversationHolder() {
205 public void dispose() {
206 if (detailElement
!= null) {
207 detailElement
.removeElements();
209 formFactory
.removePropertyChangeListener(this);
215 * Getter for the field <code>detailElement</code>.
219 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
222 public AbstractCdmDetailElement
<T
> getDetailElement() {
223 return detailElement
;
228 public void update(CdmDataChangeMap changeEvents
) {