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
;
20 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
22 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
24 import eu
.etaxonomy
.cdm
.model
.common
.IIdentifiableEntity
;
25 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
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 TableWrapLayout layout
= LayoutConstants
.LAYOUT(2, false);
101 layout
.horizontalSpacing
= 5;
102 control
.setLayout(layout
);
103 WizardPageRootElement rootElement
= new WizardPageRootElement(
104 formFactory
, control
, getConversationHolder());
106 Color bgColor
= getShell().getBackground();
108 detailElement
= createElement(rootElement
);
110 rootElement
.setBackground(bgColor
);
111 control
.setBackground(bgColor
);
112 scrolledForm
.setBackground(bgColor
);
114 setControl(scrolledForm
);
119 * Getter for the field <code>entity</code>.
122 * @return a T object.
124 public T
getEntity() {
129 * Creates the detail element for this wizard page
132 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
135 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
138 public abstract AbstractCdmDetailElement
<T
> createElement(
139 ICdmFormElement rootElement
);
141 protected class WizardPageRootElement
extends RootElement
implements
142 IConversationEnabled
{
144 private final ConversationHolder conversation
;
146 public WizardPageRootElement(CdmFormFactory formFactory
,
147 Composite layoutComposite
, ConversationHolder conversation
) {
148 super(formFactory
, layoutComposite
);
149 this.conversation
= conversation
;
153 public void refresh() {
155 this.removeElements();
156 detailElement
= createElement(this);
157 ((Composite
) getControl()).layout();
161 public ConversationHolder
getConversationHolder() {
166 public void update(CdmDataChangeMap changeEvents
) {
171 public void propertyChange(PropertyChangeEvent event
) {
172 if (event
.getSource() == getDetailElement()) {
175 else if(event
.getSource() instanceof AbstractCdmDetailElement
){
176 //check if parent element is set as detail element
177 ICdmFormElement formElement
= (ICdmFormElement
) event
.getSource();
178 while(formElement
.getParentElement()!=null){
179 if(formElement
.getParentElement() == getDetailElement()){
183 formElement
= formElement
.getParentElement();
189 * Should check whether the wizard is complete in a sense that it contains
190 * sane data. Should setPageComplete to true if that is the case.
192 protected void checkComplete() {
193 setPageComplete(titleCacheIsNotEmpty());
196 private boolean titleCacheIsNotEmpty() {
197 if (getEntity() instanceof IIdentifiableEntity
) {
198 IIdentifiableEntity entity
= (IIdentifiableEntity
) getEntity();
199 return !StringUtils
.isEmpty(entity
.getTitleCache());
206 * getConversationHolder
209 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
213 public ConversationHolder
getConversationHolder() {
219 public void dispose() {
220 if (detailElement
!= null) {
221 detailElement
.removeElements();
223 formFactory
.removePropertyChangeListener(this);
229 * Getter for the field <code>detailElement</code>.
233 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
236 public AbstractCdmDetailElement
<T
> getDetailElement() {
237 return detailElement
;
242 public void update(CdmDataChangeMap changeEvents
) {