1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.ui.forms;
|
12
|
|
13
|
import org.eclipse.jface.wizard.WizardPage;
|
14
|
import org.eclipse.swt.graphics.Color;
|
15
|
import org.eclipse.swt.widgets.Composite;
|
16
|
import org.eclipse.ui.forms.widgets.ScrolledForm;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
19
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
20
|
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
|
21
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
22
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
23
|
|
24
|
/**
|
25
|
* <p>Abstract AbstractCdmEntityWizardPage class.</p>
|
26
|
*
|
27
|
* @author n.hoffmann
|
28
|
* @created Jun 1, 2010
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage implements IConversationEnabled {
|
32
|
|
33
|
protected CdmFormFactory formFactory;
|
34
|
protected T entity;
|
35
|
|
36
|
AbstractCdmDetailElement<T> detailElement;
|
37
|
private ConversationHolder conversation;
|
38
|
|
39
|
/**
|
40
|
* <p>Constructor for AbstractCdmEntityWizardPage.</p>
|
41
|
*
|
42
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
|
43
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
44
|
* @param entity a T object.
|
45
|
* @param <T> a T object.
|
46
|
*/
|
47
|
protected AbstractCdmEntityWizardPage(CdmFormFactory formFactory, ConversationHolder conversation, T entity) {
|
48
|
super("page");
|
49
|
this.formFactory = formFactory;
|
50
|
this.entity = entity;
|
51
|
this.conversation = conversation;
|
52
|
setDescription(getEntityTitle());
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* @return
|
57
|
*/
|
58
|
private String getEntityTitle() {
|
59
|
if(entity instanceof IIdentifiableEntity){
|
60
|
((IIdentifiableEntity) entity).getTitleCache();
|
61
|
}
|
62
|
return "";
|
63
|
}
|
64
|
|
65
|
/*
|
66
|
* (non-Javadoc)
|
67
|
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
|
68
|
*/
|
69
|
/** {@inheritDoc} */
|
70
|
public void createControl(Composite parent) {
|
71
|
ScrolledForm scrolledForm = formFactory.createScrolledForm(parent);
|
72
|
scrolledForm.getBody().setLayout(CdmFormFactory.LAYOUT());
|
73
|
|
74
|
Composite control = formFactory.createComposite(scrolledForm.getBody());
|
75
|
control.setLayoutData(CdmFormFactory.FILL());
|
76
|
|
77
|
control.setLayout(CdmFormFactory.LAYOUT(2, false));
|
78
|
WizardPageRootElement rootElement = new WizardPageRootElement(formFactory, control, getConversationHolder());
|
79
|
|
80
|
Color bgColor = getShell().getBackground();
|
81
|
|
82
|
detailElement = createElement(rootElement);
|
83
|
|
84
|
rootElement.setBackground(bgColor);
|
85
|
control.setBackground(bgColor);
|
86
|
scrolledForm.setBackground(bgColor);
|
87
|
|
88
|
setControl(scrolledForm);
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* <p>Getter for the field <code>entity</code>.</p>
|
93
|
*
|
94
|
* @return a T object.
|
95
|
*/
|
96
|
public T getEntity() {
|
97
|
return entity;
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* Creates the detail element for this wizard page
|
102
|
*
|
103
|
* @param rootElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
|
104
|
* @return a {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement} object.
|
105
|
*/
|
106
|
public abstract AbstractCdmDetailElement<T> createElement(ICdmFormElement rootElement);
|
107
|
|
108
|
protected class WizardPageRootElement extends RootElement implements IConversationEnabled{
|
109
|
|
110
|
private ConversationHolder conversation;
|
111
|
|
112
|
public WizardPageRootElement(CdmFormFactory formFactory,
|
113
|
Composite layoutComposite, ConversationHolder conversation) {
|
114
|
super(formFactory, layoutComposite);
|
115
|
this.conversation = conversation;
|
116
|
}
|
117
|
|
118
|
@Override
|
119
|
public void refresh() {
|
120
|
super.refresh();
|
121
|
this.removeElements();
|
122
|
detailElement = createElement(this);
|
123
|
((Composite) getControl()).layout();
|
124
|
}
|
125
|
|
126
|
public ConversationHolder getConversationHolder() {
|
127
|
return conversation;
|
128
|
}
|
129
|
|
130
|
public void update(CdmDataChangeMap changeEvents) {}
|
131
|
}
|
132
|
|
133
|
/**
|
134
|
* <p>getConversationHolder</p>
|
135
|
*
|
136
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
137
|
*/
|
138
|
public ConversationHolder getConversationHolder() {
|
139
|
return conversation;
|
140
|
}
|
141
|
|
142
|
/** {@inheritDoc} */
|
143
|
@Override
|
144
|
public void dispose() {
|
145
|
super.dispose();
|
146
|
if(detailElement != null){
|
147
|
detailElement.removeElements();
|
148
|
}
|
149
|
}
|
150
|
|
151
|
/**
|
152
|
* <p>Getter for the field <code>detailElement</code>.</p>
|
153
|
*
|
154
|
* @return a {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement} object.
|
155
|
*/
|
156
|
public AbstractCdmDetailElement<T> getDetailElement() {
|
157
|
return detailElement;
|
158
|
}
|
159
|
|
160
|
/** {@inheritDoc} */
|
161
|
public void update(CdmDataChangeMap changeEvents) {}
|
162
|
}
|