1 |
729887cf
|
n.hoffmann
|
// $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 |
f211dd28
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.ui.section;
|
12 |
729887cf
|
n.hoffmann
|
|
13 |
|
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
14 |
|
|
import org.eclipse.swt.SWT;
|
15 |
|
|
import org.eclipse.swt.events.SelectionEvent;
|
16 |
|
|
import org.eclipse.swt.events.SelectionListener;
|
17 |
|
|
import org.eclipse.swt.graphics.Color;
|
18 |
|
|
import org.eclipse.swt.widgets.Button;
|
19 |
|
|
import org.eclipse.swt.widgets.Composite;
|
20 |
|
|
import org.eclipse.swt.widgets.Layout;
|
21 |
|
|
import org.eclipse.ui.forms.widgets.TableWrapLayout;
|
22 |
|
|
|
23 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
24 |
|
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
25 |
|
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
26 |
729887cf
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
27 |
f211dd28
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.ui.forms.AbstractCdmFormElement;
|
28 |
|
|
import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
|
29 |
|
|
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
|
30 |
|
|
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
|
31 |
|
|
import eu.etaxonomy.taxeditor.ui.forms.IEntityElement;
|
32 |
|
|
import eu.etaxonomy.taxeditor.ui.forms.ISelectable;
|
33 |
729887cf
|
n.hoffmann
|
|
34 |
|
|
/**
|
35 |
3be6ef3e
|
n.hoffmann
|
* <p>Abstract AbstractEntityCollectionElement class.</p>
|
36 |
|
|
*
|
37 |
729887cf
|
n.hoffmann
|
* @author n.hoffmann
|
38 |
|
|
* @created Nov 16, 2009
|
39 |
|
|
* @version 1.0
|
40 |
|
|
*/
|
41 |
74b9f670
|
n.hoffmann
|
public abstract class AbstractEntityCollectionElement<ENTITY> extends AbstractCdmFormElement implements IEntityElement<ENTITY>, SelectionListener, IConversationEnabled{
|
42 |
729887cf
|
n.hoffmann
|
|
43 |
|
|
protected ENTITY entity;
|
44 |
|
|
|
45 |
|
|
private Composite container;
|
46 |
|
|
|
47 |
|
|
private Composite box;
|
48 |
|
|
|
49 |
|
|
private Button button_remove;
|
50 |
|
|
|
51 |
|
|
private Color backgroundColor;
|
52 |
|
|
|
53 |
|
|
/**
|
54 |
3be6ef3e
|
n.hoffmann
|
* <p>Constructor for AbstractEntityCollectionElement.</p>
|
55 |
|
|
*
|
56 |
|
|
* @param style a int.
|
57 |
f211dd28
|
n.hoffmann
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
|
58 |
|
|
* @param section a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection} object.
|
59 |
3be6ef3e
|
n.hoffmann
|
* @param entity a ENTITY object.
|
60 |
|
|
* @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
|
61 |
|
|
* @param <ENTITY> a ENTITY object.
|
62 |
729887cf
|
n.hoffmann
|
*/
|
63 |
|
|
public AbstractEntityCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, ENTITY entity, SelectionListener removeListener,
|
64 |
|
|
Color backgroundColor, int style) {
|
65 |
|
|
super(formFactory, (ICdmFormElement) section);
|
66 |
|
|
|
67 |
|
|
init();
|
68 |
|
|
|
69 |
|
|
formFactory.addPropertyChangeListener(this);
|
70 |
|
|
|
71 |
|
|
// section.getLayoutComposite().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN));
|
72 |
|
|
|
73 |
|
|
box = formFactory.createComposite(section.getLayoutComposite());
|
74 |
|
|
box.setBackgroundMode(SWT.INHERIT_DEFAULT);
|
75 |
|
|
addControl(box);
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
TableWrapLayout boxLayout = CdmFormFactory.LAYOUT(2, false);
|
79 |
|
|
boxLayout.topMargin = 4;
|
80 |
|
|
boxLayout.bottomMargin = 4;
|
81 |
|
|
box.setLayout(boxLayout);
|
82 |
|
|
|
83 |
|
|
box.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY());
|
84 |
|
|
|
85 |
|
|
// box.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
|
86 |
|
|
|
87 |
|
|
container = formFactory.createComposite(box);
|
88 |
|
|
container.setBackgroundMode(SWT.INHERIT_DEFAULT);
|
89 |
|
|
|
90 |
|
|
// container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
|
91 |
|
|
setLayoutComposite(container);
|
92 |
|
|
|
93 |
|
|
addControl(container);
|
94 |
|
|
Layout containerLayout = CdmFormFactory.LAYOUT(2, false);
|
95 |
|
|
|
96 |
|
|
container.setLayout(containerLayout);
|
97 |
|
|
container.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY());
|
98 |
|
|
|
99 |
|
|
if(removeListener != null){
|
100 |
|
|
button_remove = formFactory.createButton(box, null, SWT.PUSH);
|
101 |
|
|
addControl(button_remove);
|
102 |
|
|
button_remove.setLayoutData(CdmFormFactory.RIGHT());
|
103 |
|
|
button_remove.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
|
104 |
|
|
button_remove.setToolTipText("Remove");
|
105 |
|
|
|
106 |
|
|
button_remove.addSelectionListener(removeListener);
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
createControls(this, style);
|
111 |
|
|
|
112 |
|
|
setEntity(entity);
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
/**
|
116 |
|
|
* Init gets executed before any other setup of the section takes place
|
117 |
3be6ef3e
|
n.hoffmann
|
*
|
118 |
729887cf
|
n.hoffmann
|
* Implement this if you want to configure the section
|
119 |
|
|
*/
|
120 |
|
|
public void init() {
|
121 |
|
|
// default implementation is empty
|
122 |
|
|
}
|
123 |
|
|
|
124 |
3be6ef3e
|
n.hoffmann
|
/**
|
125 |
|
|
* <p>Setter for the field <code>entity</code>.</p>
|
126 |
|
|
*
|
127 |
|
|
* @param entity a ENTITY object.
|
128 |
|
|
*/
|
129 |
729887cf
|
n.hoffmann
|
public abstract void setEntity(ENTITY entity);
|
130 |
|
|
|
131 |
3be6ef3e
|
n.hoffmann
|
/**
|
132 |
|
|
* <p>Getter for the field <code>entity</code>.</p>
|
133 |
|
|
*
|
134 |
|
|
* @return a ENTITY object.
|
135 |
|
|
*/
|
136 |
729887cf
|
n.hoffmann
|
public ENTITY getEntity(){
|
137 |
|
|
return entity;
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
/**
|
141 |
3be6ef3e
|
n.hoffmann
|
* <p>createControls</p>
|
142 |
|
|
*
|
143 |
f211dd28
|
n.hoffmann
|
* @param element a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
|
144 |
3be6ef3e
|
n.hoffmann
|
* @param style a int.
|
145 |
729887cf
|
n.hoffmann
|
*/
|
146 |
|
|
public abstract void createControls(ICdmFormElement element, int style);
|
147 |
|
|
|
148 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
149 |
729887cf
|
n.hoffmann
|
public void setSelected(boolean selected) {
|
150 |
|
|
for(ICdmFormElement element : getElements()){
|
151 |
|
|
if(element instanceof ISelectable){
|
152 |
|
|
((ISelectable)element).setSelected(selected);
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
|
|
this.setBackground(getColor(selected));
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
/*
|
159 |
|
|
* (non-Javadoc)
|
160 |
|
|
* @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
|
161 |
|
|
*/
|
162 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
163 |
729887cf
|
n.hoffmann
|
@Override
|
164 |
|
|
public void propertyChange(PropertyChangeEvent event) {
|
165 |
|
|
if(event == null){
|
166 |
|
|
return;
|
167 |
|
|
}
|
168 |
|
|
Object eventSource = event.getSource();
|
169 |
|
|
if(getElements().contains(eventSource)){
|
170 |
|
|
handleEvent(eventSource);
|
171 |
|
|
}
|
172 |
|
|
}
|
173 |
|
|
|
174 |
3be6ef3e
|
n.hoffmann
|
/**
|
175 |
|
|
* <p>handleEvent</p>
|
176 |
|
|
*
|
177 |
|
|
* @param eventSource a {@link java.lang.Object} object.
|
178 |
|
|
*/
|
179 |
729887cf
|
n.hoffmann
|
public abstract void handleEvent(Object eventSource);
|
180 |
|
|
|
181 |
|
|
/*
|
182 |
|
|
* (non-Javadoc)
|
183 |
|
|
* @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#getColor(boolean)
|
184 |
|
|
*/
|
185 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
186 |
729887cf
|
n.hoffmann
|
@Override
|
187 |
|
|
public Color getColor(boolean selected) {
|
188 |
|
|
return selected ? SELECTED : backgroundColor;
|
189 |
|
|
}
|
190 |
|
|
|
191 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
192 |
cfcb0ce6
|
n.hoffmann
|
public void setBackground(Color color){
|
193 |
729887cf
|
n.hoffmann
|
container.setBackground(color);
|
194 |
|
|
box.setBackground(color);
|
195 |
cfcb0ce6
|
n.hoffmann
|
for(ICdmFormElement element : getElements()){
|
196 |
|
|
element.setBackground(color);
|
197 |
|
|
}
|
198 |
729887cf
|
n.hoffmann
|
}
|
199 |
|
|
|
200 |
|
|
/**
|
201 |
3be6ef3e
|
n.hoffmann
|
* {@inheritDoc}
|
202 |
|
|
*
|
203 |
729887cf
|
n.hoffmann
|
* React when selection occurs
|
204 |
|
|
*/
|
205 |
|
|
public void widgetSelected(SelectionEvent e) {
|
206 |
|
|
|
207 |
|
|
}
|
208 |
|
|
|
209 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
210 |
729887cf
|
n.hoffmann
|
public void widgetDefaultSelected(SelectionEvent e) {}
|
211 |
|
|
|
212 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
213 |
729887cf
|
n.hoffmann
|
@Override
|
214 |
|
|
public Composite getLayoutComposite() {
|
215 |
|
|
return container;
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
/**
|
219 |
3be6ef3e
|
n.hoffmann
|
* <p>Setter for the field <code>backgroundColor</code>.</p>
|
220 |
|
|
*
|
221 |
729887cf
|
n.hoffmann
|
* @param backgroundColor the backgroundColor to set
|
222 |
|
|
*/
|
223 |
|
|
public void setBackgroundColor(Color backgroundColor) {
|
224 |
|
|
this.backgroundColor = backgroundColor;
|
225 |
|
|
getLayoutComposite().setBackground(backgroundColor);
|
226 |
|
|
setBackground(backgroundColor);
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
/**
|
230 |
3be6ef3e
|
n.hoffmann
|
* <p>Getter for the field <code>backgroundColor</code>.</p>
|
231 |
|
|
*
|
232 |
729887cf
|
n.hoffmann
|
* @return the backgroundColor
|
233 |
|
|
*/
|
234 |
|
|
public Color getBackgroundColor() {
|
235 |
|
|
return backgroundColor;
|
236 |
|
|
}
|
237 |
2d9a13f7
|
n.hoffmann
|
|
238 |
3be6ef3e
|
n.hoffmann
|
/**
|
239 |
|
|
* <p>getConversationHolder</p>
|
240 |
|
|
*
|
241 |
|
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
242 |
|
|
*/
|
243 |
2d9a13f7
|
n.hoffmann
|
public ConversationHolder getConversationHolder() {
|
244 |
|
|
if(getParentElement() instanceof IConversationEnabled){
|
245 |
|
|
return ((IConversationEnabled) getParentElement()).getConversationHolder();
|
246 |
|
|
}
|
247 |
|
|
throw new IllegalArgumentException("Parent element should be IConversationEnabled");
|
248 |
|
|
}
|
249 |
|
|
|
250 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
251 |
2d9a13f7
|
n.hoffmann
|
public void update(CdmDataChangeMap changeEvents) {}
|
252 |
729887cf
|
n.hoffmann
|
}
|