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
.ui
.element
;
12 import org
.apache
.commons
.lang
.StringUtils
;
13 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
14 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
15 import org
.eclipse
.jface
.wizard
.WizardPage
;
16 import org
.eclipse
.swt
.graphics
.Color
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
19 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
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 TableWrapLayout layout
= LayoutConstants
.LAYOUT(2, false);
100 layout
.horizontalSpacing
= 5;
101 control
.setLayout(layout
);
102 WizardPageRootElement rootElement
= new WizardPageRootElement(
103 formFactory
, control
, getConversationHolder());
105 Color bgColor
= getShell().getBackground();
107 detailElement
= createElement(rootElement
);
109 rootElement
.setBackground(bgColor
);
110 control
.setBackground(bgColor
);
111 scrolledForm
.setBackground(bgColor
);
113 setControl(scrolledForm
);
118 * Getter for the field <code>entity</code>.
121 * @return a T object.
123 public T
getEntity() {
128 * Creates the detail element for this wizard page
131 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
134 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
137 public abstract AbstractCdmDetailElement
<T
> createElement(
138 ICdmFormElement rootElement
);
140 protected class WizardPageRootElement
extends RootElement
implements
141 IConversationEnabled
{
143 private final ConversationHolder conversation
;
145 public WizardPageRootElement(CdmFormFactory formFactory
,
146 Composite layoutComposite
, ConversationHolder conversation
) {
147 super(formFactory
, layoutComposite
);
148 this.conversation
= conversation
;
152 public void refresh() {
154 this.removeElements();
155 detailElement
= createElement(this);
156 ((Composite
) getControl()).layout();
160 public ConversationHolder
getConversationHolder() {
165 public void update(CdmDataChangeMap changeEvents
) {
170 public void propertyChange(PropertyChangeEvent event
) {
171 if (event
.getSource() == getDetailElement()) {
174 else if(event
.getSource() instanceof AbstractCdmDetailElement
){
175 //check if parent element is set as detail element
176 ICdmFormElement formElement
= (ICdmFormElement
) event
.getSource();
177 while(formElement
.getParentElement()!=null){
178 if(formElement
.getParentElement() == getDetailElement()){
182 formElement
= formElement
.getParentElement();
188 * Should check whether the wizard is complete in a sense that it contains
189 * sane data. Should setPageComplete to true if that is the case.
191 protected void checkComplete() {
192 setPageComplete(titleCacheIsNotEmpty());
195 private boolean titleCacheIsNotEmpty() {
196 if (getEntity() instanceof IIdentifiableEntity
) {
197 IIdentifiableEntity entity
= (IIdentifiableEntity
) getEntity();
198 return !StringUtils
.isEmpty(entity
.getTitleCache());
205 * getConversationHolder
208 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
212 public ConversationHolder
getConversationHolder() {
218 public void dispose() {
219 if (detailElement
!= null) {
220 detailElement
.removeElements();
222 formFactory
.removePropertyChangeListener(this);
228 * Getter for the field <code>detailElement</code>.
232 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
235 public AbstractCdmDetailElement
<T
> getDetailElement() {
236 return detailElement
;
241 public void update(CdmDataChangeMap changeEvents
) {