1 |
729887cf
|
n.hoffmann
|
/**
|
2 |
86d58314
|
n.hoffmann
|
* Copyright (C) 2007 EDIT
|
3 |
eaa9ba52
|
Patrick Plitzner
|
* European Distributed Institute of Taxonomy
|
4 |
86d58314
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
eaa9ba52
|
Patrick Plitzner
|
*
|
6 |
86d58314
|
n.hoffmann
|
* 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.
|
8 |
|
|
*/
|
9 |
729887cf
|
n.hoffmann
|
|
10 |
78222507
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.ui.element;
|
11 |
729887cf
|
n.hoffmann
|
|
12 |
86d58314
|
n.hoffmann
|
import org.apache.commons.lang.StringUtils;
|
13 |
|
|
import org.eclipse.jface.util.IPropertyChangeListener;
|
14 |
|
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
15 |
729887cf
|
n.hoffmann
|
import org.eclipse.jface.wizard.WizardPage;
|
16 |
1d9ed6ce
|
n.hoffmann
|
import org.eclipse.swt.graphics.Color;
|
17 |
729887cf
|
n.hoffmann
|
import org.eclipse.swt.widgets.Composite;
|
18 |
e53963de
|
n.hoffmann
|
import org.eclipse.ui.forms.widgets.ScrolledForm;
|
19 |
3257fc1d
|
Patrick Plitzner
|
import org.eclipse.ui.forms.widgets.TableWrapLayout;
|
20 |
729887cf
|
n.hoffmann
|
|
21 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
22 |
|
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
23 |
27b59ab1
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
|
24 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
25 |
f211dd28
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
26 |
729887cf
|
n.hoffmann
|
|
27 |
|
|
/**
|
28 |
86d58314
|
n.hoffmann
|
* <p>
|
29 |
|
|
* Abstract AbstractCdmEntityWizardPage class.
|
30 |
|
|
* </p>
|
31 |
eaa9ba52
|
Patrick Plitzner
|
*
|
32 |
729887cf
|
n.hoffmann
|
* @author n.hoffmann
|
33 |
|
|
* @created Jun 1, 2010
|
34 |
|
|
* @version 1.0
|
35 |
|
|
*/
|
36 |
86d58314
|
n.hoffmann
|
public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
|
37 |
|
|
implements IConversationEnabled, IPropertyChangeListener {
|
38 |
729887cf
|
n.hoffmann
|
|
39 |
|
|
protected CdmFormFactory formFactory;
|
40 |
|
|
protected T entity;
|
41 |
|
|
|
42 |
cfcb0ce6
|
n.hoffmann
|
AbstractCdmDetailElement<T> detailElement;
|
43 |
86d58314
|
n.hoffmann
|
private final ConversationHolder conversation;
|
44 |
|
|
|
45 |
3be6ef3e
|
n.hoffmann
|
/**
|
46 |
86d58314
|
n.hoffmann
|
* <p>
|
47 |
|
|
* Constructor for AbstractCdmEntityWizardPage.
|
48 |
|
|
* </p>
|
49 |
eaa9ba52
|
Patrick Plitzner
|
*
|
50 |
86d58314
|
n.hoffmann
|
* @param formFactory
|
51 |
78222507
|
n.hoffmann
|
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
|
52 |
86d58314
|
n.hoffmann
|
* object.
|
53 |
|
|
* @param conversation
|
54 |
|
|
* a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
|
55 |
|
|
* object.
|
56 |
|
|
* @param entity
|
57 |
|
|
* a T object.
|
58 |
|
|
* @param <T>
|
59 |
|
|
* a T object.
|
60 |
3be6ef3e
|
n.hoffmann
|
*/
|
61 |
86d58314
|
n.hoffmann
|
protected AbstractCdmEntityWizardPage(CdmFormFactory formFactory,
|
62 |
|
|
ConversationHolder conversation, T entity) {
|
63 |
729887cf
|
n.hoffmann
|
super("page");
|
64 |
|
|
this.formFactory = formFactory;
|
65 |
|
|
this.entity = entity;
|
66 |
2d9a13f7
|
n.hoffmann
|
this.conversation = conversation;
|
67 |
27b59ab1
|
n.hoffmann
|
setDescription(getEntityTitle());
|
68 |
86d58314
|
n.hoffmann
|
|
69 |
|
|
formFactory.addPropertyChangeListener(this);
|
70 |
|
|
setPageComplete(false);
|
71 |
729887cf
|
n.hoffmann
|
}
|
72 |
86d58314
|
n.hoffmann
|
|
73 |
27b59ab1
|
n.hoffmann
|
/**
|
74 |
|
|
* @return
|
75 |
|
|
*/
|
76 |
|
|
private String getEntityTitle() {
|
77 |
86d58314
|
n.hoffmann
|
if (entity instanceof IIdentifiableEntity) {
|
78 |
27b59ab1
|
n.hoffmann
|
((IIdentifiableEntity) entity).getTitleCache();
|
79 |
|
|
}
|
80 |
|
|
return "";
|
81 |
|
|
}
|
82 |
|
|
|
83 |
729887cf
|
n.hoffmann
|
/*
|
84 |
|
|
* (non-Javadoc)
|
85 |
eaa9ba52
|
Patrick Plitzner
|
*
|
86 |
86d58314
|
n.hoffmann
|
* @see
|
87 |
|
|
* org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
|
88 |
|
|
* .Composite)
|
89 |
729887cf
|
n.hoffmann
|
*/
|
90 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
91 |
86d58314
|
n.hoffmann
|
@Override
|
92 |
729887cf
|
n.hoffmann
|
public void createControl(Composite parent) {
|
93 |
86d58314
|
n.hoffmann
|
ScrolledForm scrolledForm = formFactory.createScrolledForm(parent);
|
94 |
23783f7a
|
n.hoffmann
|
scrolledForm.getBody().setLayout(LayoutConstants.LAYOUT());
|
95 |
86d58314
|
n.hoffmann
|
|
96 |
e53963de
|
n.hoffmann
|
Composite control = formFactory.createComposite(scrolledForm.getBody());
|
97 |
23783f7a
|
n.hoffmann
|
control.setLayoutData(LayoutConstants.FILL());
|
98 |
86d58314
|
n.hoffmann
|
|
99 |
3257fc1d
|
Patrick Plitzner
|
TableWrapLayout layout = LayoutConstants.LAYOUT(2, false);
|
100 |
|
|
layout.horizontalSpacing = 5;
|
101 |
|
|
control.setLayout(layout);
|
102 |
86d58314
|
n.hoffmann
|
WizardPageRootElement rootElement = new WizardPageRootElement(
|
103 |
|
|
formFactory, control, getConversationHolder());
|
104 |
|
|
|
105 |
1d9ed6ce
|
n.hoffmann
|
Color bgColor = getShell().getBackground();
|
106 |
86d58314
|
n.hoffmann
|
|
107 |
729887cf
|
n.hoffmann
|
detailElement = createElement(rootElement);
|
108 |
1a18702c
|
Katja Luther
|
|
109 |
1d9ed6ce
|
n.hoffmann
|
rootElement.setBackground(bgColor);
|
110 |
|
|
control.setBackground(bgColor);
|
111 |
e53963de
|
n.hoffmann
|
scrolledForm.setBackground(bgColor);
|
112 |
86d58314
|
n.hoffmann
|
|
113 |
e53963de
|
n.hoffmann
|
setControl(scrolledForm);
|
114 |
729887cf
|
n.hoffmann
|
}
|
115 |
86d58314
|
n.hoffmann
|
|
116 |
3be6ef3e
|
n.hoffmann
|
/**
|
117 |
86d58314
|
n.hoffmann
|
* <p>
|
118 |
|
|
* Getter for the field <code>entity</code>.
|
119 |
|
|
* </p>
|
120 |
eaa9ba52
|
Patrick Plitzner
|
*
|
121 |
3be6ef3e
|
n.hoffmann
|
* @return a T object.
|
122 |
|
|
*/
|
123 |
729887cf
|
n.hoffmann
|
public T getEntity() {
|
124 |
|
|
return entity;
|
125 |
|
|
}
|
126 |
86d58314
|
n.hoffmann
|
|
127 |
729887cf
|
n.hoffmann
|
/**
|
128 |
|
|
* Creates the detail element for this wizard page
|
129 |
eaa9ba52
|
Patrick Plitzner
|
*
|
130 |
86d58314
|
n.hoffmann
|
* @param rootElement
|
131 |
78222507
|
n.hoffmann
|
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
|
132 |
86d58314
|
n.hoffmann
|
* object.
|
133 |
|
|
* @return a
|
134 |
|
|
* {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
|
135 |
|
|
* object.
|
136 |
729887cf
|
n.hoffmann
|
*/
|
137 |
86d58314
|
n.hoffmann
|
public abstract AbstractCdmDetailElement<T> createElement(
|
138 |
|
|
ICdmFormElement rootElement);
|
139 |
|
|
|
140 |
|
|
protected class WizardPageRootElement extends RootElement implements
|
141 |
|
|
IConversationEnabled {
|
142 |
|
|
|
143 |
|
|
private final ConversationHolder conversation;
|
144 |
729887cf
|
n.hoffmann
|
|
145 |
86d58314
|
n.hoffmann
|
public WizardPageRootElement(CdmFormFactory formFactory,
|
146 |
2d9a13f7
|
n.hoffmann
|
Composite layoutComposite, ConversationHolder conversation) {
|
147 |
729887cf
|
n.hoffmann
|
super(formFactory, layoutComposite);
|
148 |
2d9a13f7
|
n.hoffmann
|
this.conversation = conversation;
|
149 |
729887cf
|
n.hoffmann
|
}
|
150 |
86d58314
|
n.hoffmann
|
|
151 |
729887cf
|
n.hoffmann
|
@Override
|
152 |
|
|
public void refresh() {
|
153 |
|
|
super.refresh();
|
154 |
|
|
this.removeElements();
|
155 |
|
|
detailElement = createElement(this);
|
156 |
1d9ed6ce
|
n.hoffmann
|
((Composite) getControl()).layout();
|
157 |
729887cf
|
n.hoffmann
|
}
|
158 |
86d58314
|
n.hoffmann
|
|
159 |
|
|
@Override
|
160 |
2d9a13f7
|
n.hoffmann
|
public ConversationHolder getConversationHolder() {
|
161 |
|
|
return conversation;
|
162 |
|
|
}
|
163 |
86d58314
|
n.hoffmann
|
|
164 |
|
|
@Override
|
165 |
|
|
public void update(CdmDataChangeMap changeEvents) {
|
166 |
|
|
}
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
@Override
|
170 |
|
|
public void propertyChange(PropertyChangeEvent event) {
|
171 |
|
|
if (event.getSource() == getDetailElement()) {
|
172 |
|
|
checkComplete();
|
173 |
|
|
}
|
174 |
eaa9ba52
|
Patrick Plitzner
|
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()){
|
179 |
|
|
checkComplete();
|
180 |
|
|
return;
|
181 |
|
|
}
|
182 |
|
|
formElement = formElement.getParentElement();
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
729887cf
|
n.hoffmann
|
}
|
186 |
86d58314
|
n.hoffmann
|
|
187 |
3be6ef3e
|
n.hoffmann
|
/**
|
188 |
86d58314
|
n.hoffmann
|
* 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.
|
190 |
3be6ef3e
|
n.hoffmann
|
*/
|
191 |
86d58314
|
n.hoffmann
|
protected void checkComplete() {
|
192 |
|
|
setPageComplete(titleCacheIsNotEmpty());
|
193 |
|
|
}
|
194 |
|
|
|
195 |
1a18702c
|
Katja Luther
|
protected boolean titleCacheIsNotEmpty() {
|
196 |
86d58314
|
n.hoffmann
|
if (getEntity() instanceof IIdentifiableEntity) {
|
197 |
|
|
IIdentifiableEntity entity = (IIdentifiableEntity) getEntity();
|
198 |
|
|
return !StringUtils.isEmpty(entity.getTitleCache());
|
199 |
|
|
}
|
200 |
|
|
return true;
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
/**
|
204 |
|
|
* <p>
|
205 |
|
|
* getConversationHolder
|
206 |
|
|
* </p>
|
207 |
eaa9ba52
|
Patrick Plitzner
|
*
|
208 |
86d58314
|
n.hoffmann
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
|
209 |
|
|
* object.
|
210 |
|
|
*/
|
211 |
|
|
@Override
|
212 |
2d9a13f7
|
n.hoffmann
|
public ConversationHolder getConversationHolder() {
|
213 |
|
|
return conversation;
|
214 |
|
|
}
|
215 |
86d58314
|
n.hoffmann
|
|
216 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
217 |
3fb05254
|
n.hoffmann
|
@Override
|
218 |
|
|
public void dispose() {
|
219 |
86d58314
|
n.hoffmann
|
if (detailElement != null) {
|
220 |
a60842d7
|
n.hoffmann
|
detailElement.removeElements();
|
221 |
|
|
}
|
222 |
86d58314
|
n.hoffmann
|
formFactory.removePropertyChangeListener(this);
|
223 |
5400463f
|
n.hoffmann
|
super.dispose();
|
224 |
3fb05254
|
n.hoffmann
|
}
|
225 |
86d58314
|
n.hoffmann
|
|
226 |
3be6ef3e
|
n.hoffmann
|
/**
|
227 |
86d58314
|
n.hoffmann
|
* <p>
|
228 |
|
|
* Getter for the field <code>detailElement</code>.
|
229 |
|
|
* </p>
|
230 |
eaa9ba52
|
Patrick Plitzner
|
*
|
231 |
86d58314
|
n.hoffmann
|
* @return a
|
232 |
|
|
* {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
|
233 |
|
|
* object.
|
234 |
3be6ef3e
|
n.hoffmann
|
*/
|
235 |
cfcb0ce6
|
n.hoffmann
|
public AbstractCdmDetailElement<T> getDetailElement() {
|
236 |
|
|
return detailElement;
|
237 |
|
|
}
|
238 |
86d58314
|
n.hoffmann
|
|
239 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
240 |
86d58314
|
n.hoffmann
|
@Override
|
241 |
|
|
public void update(CdmDataChangeMap changeEvents) {
|
242 |
|
|
}
|
243 |
729887cf
|
n.hoffmann
|
}
|