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
.lang3
.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
35 public abstract class AbstractCdmEntityWizardPage
<T
> extends WizardPage
36 implements IConversationEnabled
, IPropertyChangeListener
{
38 protected CdmFormFactory formFactory
;
41 AbstractCdmDetailElement
<T
> detailElement
;
42 private final ConversationHolder conversation
;
46 * Constructor for AbstractCdmEntityWizardPage.
50 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
53 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
60 protected AbstractCdmEntityWizardPage(CdmFormFactory formFactory
,
61 ConversationHolder conversation
, T entity
) {
63 this.formFactory
= formFactory
;
65 this.conversation
= conversation
;
66 setDescription(getEntityTitle());
68 formFactory
.addPropertyChangeListener(this);
69 setPageComplete(false);
75 private String
getEntityTitle() {
76 if (entity
instanceof IIdentifiableEntity
) {
77 ((IIdentifiableEntity
) entity
).getTitleCache();
84 public void createControl(Composite parent
) {
85 ScrolledForm scrolledForm
= formFactory
.createScrolledForm(parent
);
86 scrolledForm
.getBody().setLayout(LayoutConstants
.LAYOUT());
88 Composite control
= formFactory
.createComposite(scrolledForm
.getBody());
89 control
.setLayoutData(LayoutConstants
.FILL());
91 TableWrapLayout layout
= LayoutConstants
.LAYOUT(2, false);
92 layout
.horizontalSpacing
= 5;
93 layout
.bottomMargin
= 25;
94 control
.setLayout(layout
);
95 WizardPageRootElement rootElement
= new WizardPageRootElement(
96 formFactory
, control
, getConversationHolder());
98 Color bgColor
= getShell().getBackground();
100 detailElement
= createElement(rootElement
);
102 rootElement
.setBackground(bgColor
);
103 control
.setBackground(bgColor
);
104 scrolledForm
.setBackground(bgColor
);
106 setControl(scrolledForm
);
111 * Getter for the field <code>entity</code>.
114 * @return a T object.
116 public T
getEntity() {
121 * Creates the detail element for this wizard page
124 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
127 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
130 public abstract AbstractCdmDetailElement
<T
> createElement(
131 ICdmFormElement rootElement
);
133 protected class WizardPageRootElement
extends RootElement
implements
134 IConversationEnabled
{
136 private final ConversationHolder conversation
;
138 public WizardPageRootElement(CdmFormFactory formFactory
,
139 Composite layoutComposite
, ConversationHolder conversation
) {
140 super(formFactory
, layoutComposite
);
141 this.conversation
= conversation
;
145 public void refresh() {
147 this.removeElements();
148 detailElement
= createElement(this);
149 ((Composite
) getControl()).layout();
153 public ConversationHolder
getConversationHolder() {
158 public void update(CdmDataChangeMap changeEvents
) {
163 public void propertyChange(PropertyChangeEvent event
) {
164 if (event
.getSource() == getDetailElement()) {
167 else if(event
.getSource() instanceof AbstractCdmDetailElement
){
168 //check if parent element is set as detail element
169 ICdmFormElement formElement
= (ICdmFormElement
) event
.getSource();
170 while(formElement
.getParentElement()!=null){
171 if(formElement
.getParentElement() == getDetailElement()){
175 formElement
= formElement
.getParentElement();
181 * Should check whether the wizard is complete in a sense that it contains
182 * sane data. Should setPageComplete to true if that is the case.
184 protected void checkComplete() {
185 setPageComplete(titleCacheIsNotEmpty());
188 protected boolean titleCacheIsNotEmpty() {
189 if (getEntity() instanceof IIdentifiableEntity
) {
190 IIdentifiableEntity entity
= (IIdentifiableEntity
) getEntity();
191 return !StringUtils
.isEmpty(entity
.getTitleCache());
198 * getConversationHolder
201 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
205 public ConversationHolder
getConversationHolder() {
211 public void dispose() {
212 if (detailElement
!= null) {
213 detailElement
.removeElements();
215 formFactory
.removePropertyChangeListener(this);
221 * Getter for the field <code>detailElement</code>.
225 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
228 public AbstractCdmDetailElement
<T
> getDetailElement() {
229 return detailElement
;
234 public void update(CdmDataChangeMap changeEvents
) {