1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.ui.element;
|
11
|
|
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;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
|
22
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
23
|
|
24
|
/**
|
25
|
* @author n.hoffmann
|
26
|
* @created Jun 1, 2010
|
27
|
*/
|
28
|
public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
|
29
|
implements IPropertyChangeListener {
|
30
|
|
31
|
protected CdmFormFactory formFactory;
|
32
|
protected T entity;
|
33
|
|
34
|
AbstractCdmDetailElement<T> detailElement;
|
35
|
|
36
|
protected AbstractCdmEntityWizardPage(CdmFormFactory formFactory, T entity) {
|
37
|
super("page");
|
38
|
this.formFactory = formFactory;
|
39
|
this.entity = entity;
|
40
|
setDescription(getEntityTitle());
|
41
|
|
42
|
formFactory.addPropertyChangeListener(this);
|
43
|
setPageComplete(false);
|
44
|
}
|
45
|
|
46
|
|
47
|
private String getEntityTitle() {
|
48
|
if (entity instanceof IIdentifiableEntity) {
|
49
|
((IIdentifiableEntity) entity).getTitleCache();
|
50
|
}
|
51
|
return "";
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
public void createControl(Composite parent) {
|
56
|
ScrolledForm scrolledForm = formFactory.createScrolledForm(parent);
|
57
|
scrolledForm.getBody().setLayout(LayoutConstants.LAYOUT());
|
58
|
|
59
|
Composite control = formFactory.createComposite(scrolledForm.getBody());
|
60
|
control.setLayoutData(LayoutConstants.FILL());
|
61
|
|
62
|
TableWrapLayout layout = LayoutConstants.LAYOUT(2, false);
|
63
|
layout.horizontalSpacing = 5;
|
64
|
layout.bottomMargin = 25;
|
65
|
control.setLayout(layout);
|
66
|
WizardPageRootElement rootElement = new WizardPageRootElement(
|
67
|
formFactory, control);
|
68
|
|
69
|
Color bgColor = getShell().getBackground();
|
70
|
|
71
|
detailElement = createElement(rootElement);
|
72
|
|
73
|
rootElement.setBackground(bgColor);
|
74
|
control.setBackground(bgColor);
|
75
|
scrolledForm.setBackground(bgColor);
|
76
|
|
77
|
setControl(scrolledForm);
|
78
|
}
|
79
|
|
80
|
public T getEntity() {
|
81
|
return entity;
|
82
|
}
|
83
|
|
84
|
public abstract AbstractCdmDetailElement<T> createElement(
|
85
|
ICdmFormElement rootElement);
|
86
|
|
87
|
protected class WizardPageRootElement extends RootElement {
|
88
|
|
89
|
public WizardPageRootElement(CdmFormFactory formFactory, Composite layoutComposite) {
|
90
|
super(formFactory, layoutComposite);
|
91
|
}
|
92
|
|
93
|
@Override
|
94
|
public void refresh() {
|
95
|
super.refresh();
|
96
|
this.removeElements();
|
97
|
detailElement = createElement(this);
|
98
|
((Composite) getControl()).layout();
|
99
|
}
|
100
|
}
|
101
|
|
102
|
@Override
|
103
|
public void propertyChange(PropertyChangeEvent event) {
|
104
|
if (event.getSource() == getDetailElement()) {
|
105
|
checkComplete();
|
106
|
}
|
107
|
else if(event.getSource() instanceof AbstractCdmDetailElement){
|
108
|
//check if parent element is set as detail element
|
109
|
ICdmFormElement formElement = (ICdmFormElement) event.getSource();
|
110
|
while(formElement.getParentElement()!=null){
|
111
|
if(formElement.getParentElement() == getDetailElement()){
|
112
|
checkComplete();
|
113
|
return;
|
114
|
}
|
115
|
formElement = formElement.getParentElement();
|
116
|
}
|
117
|
}
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* Should check whether the wizard is complete in a sense that it contains
|
122
|
* sane data. Should setPageComplete to true if that is the case.
|
123
|
*/
|
124
|
protected void checkComplete() {
|
125
|
setPageComplete(titleCacheIsNotEmpty());
|
126
|
}
|
127
|
|
128
|
protected boolean titleCacheIsNotEmpty() {
|
129
|
if (getEntity() instanceof IIdentifiableEntity) {
|
130
|
IIdentifiableEntity entity = (IIdentifiableEntity) getEntity();
|
131
|
return !StringUtils.isEmpty(entity.getTitleCache());
|
132
|
}
|
133
|
return true;
|
134
|
}
|
135
|
|
136
|
@Override
|
137
|
public void dispose() {
|
138
|
if (detailElement != null) {
|
139
|
detailElement.removeElements();
|
140
|
}
|
141
|
formFactory.removePropertyChangeListener(this);
|
142
|
super.dispose();
|
143
|
}
|
144
|
|
145
|
public AbstractCdmDetailElement<T> getDetailElement() {
|
146
|
return detailElement;
|
147
|
}
|
148
|
}
|