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
.campanula
.compatibility
.ICdmFormElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
30 * Abstract AbstractCdmEntityWizardPage class.
34 * @created Jun 1, 2010
37 public abstract class AbstractCdmEntityWizardPage
<T
> extends WizardPage
38 implements IConversationEnabled
, IPropertyChangeListener
{
40 protected CdmFormFactory formFactory
;
43 AbstractCdmDetailElement
<T
> detailElement
;
44 private final ConversationHolder conversation
;
48 * Constructor for AbstractCdmEntityWizardPage.
52 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
55 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
62 protected AbstractCdmEntityWizardPage(CdmFormFactory formFactory
,
63 ConversationHolder conversation
, T entity
) {
65 this.formFactory
= formFactory
;
67 this.conversation
= conversation
;
68 setDescription(getEntityTitle());
70 formFactory
.addPropertyChangeListener(this);
71 setPageComplete(false);
77 private String
getEntityTitle() {
78 if (entity
instanceof IIdentifiableEntity
) {
79 ((IIdentifiableEntity
) entity
).getTitleCache();
88 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
93 public void createControl(Composite parent
) {
94 ScrolledForm scrolledForm
= formFactory
.createScrolledForm(parent
);
95 scrolledForm
.getBody().setLayout(LayoutConstants
.LAYOUT());
97 Composite control
= formFactory
.createComposite(scrolledForm
.getBody());
98 control
.setLayoutData(LayoutConstants
.FILL());
100 control
.setLayout(LayoutConstants
.LAYOUT(2, false));
101 WizardPageRootElement rootElement
= new WizardPageRootElement(
102 formFactory
, control
, getConversationHolder());
104 Color bgColor
= getShell().getBackground();
106 detailElement
= createElement(rootElement
);
108 rootElement
.setBackground(bgColor
);
109 control
.setBackground(bgColor
);
110 scrolledForm
.setBackground(bgColor
);
112 setControl(scrolledForm
);
117 * Getter for the field <code>entity</code>.
120 * @return a T object.
122 public T
getEntity() {
127 * Creates the detail element for this wizard page
130 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
133 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
136 public abstract AbstractCdmDetailElement
<T
> createElement(
137 ICdmFormElement rootElement
);
139 protected class WizardPageRootElement
extends RootElement
implements
140 IConversationEnabled
{
142 private final ConversationHolder conversation
;
144 public WizardPageRootElement(CdmFormFactory formFactory
,
145 Composite layoutComposite
, ConversationHolder conversation
) {
146 super(formFactory
, layoutComposite
);
147 this.conversation
= conversation
;
151 public void refresh() {
153 this.removeElements();
154 detailElement
= createElement(this);
155 ((Composite
) getControl()).layout();
159 public ConversationHolder
getConversationHolder() {
164 public void update(CdmDataChangeMap changeEvents
) {
169 public void propertyChange(PropertyChangeEvent event
) {
170 if (event
.getSource() == getDetailElement()) {
176 * Should check whether the wizard is complete in a sense that it contains
177 * sane data. Should setPageComplete to true if that is the case.
179 protected void checkComplete() {
180 setPageComplete(titleCacheIsNotEmpty());
183 private boolean titleCacheIsNotEmpty() {
184 if (getEntity() instanceof IIdentifiableEntity
) {
185 IIdentifiableEntity entity
= (IIdentifiableEntity
) getEntity();
186 return !StringUtils
.isEmpty(entity
.getTitleCache());
193 * getConversationHolder
196 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
200 public ConversationHolder
getConversationHolder() {
206 public void dispose() {
207 if (detailElement
!= null) {
208 detailElement
.removeElements();
210 formFactory
.removePropertyChangeListener(this);
216 * Getter for the field <code>detailElement</code>.
220 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
223 public AbstractCdmDetailElement
<T
> getDetailElement() {
224 return detailElement
;
229 public void update(CdmDataChangeMap changeEvents
) {