Project

General

Profile

Download (5.59 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.ui.element;
2

    
3
import org.eclipse.jface.resource.ResourceManager;
4
import org.eclipse.jface.util.PropertyChangeEvent;
5
import org.eclipse.swt.SWT;
6
import org.eclipse.swt.events.SelectionEvent;
7
import org.eclipse.swt.events.SelectionListener;
8
import org.eclipse.swt.graphics.Color;
9
import org.eclipse.swt.widgets.Button;
10
import org.eclipse.swt.widgets.Composite;
11
import org.eclipse.swt.widgets.Layout;
12
import org.eclipse.ui.forms.widgets.FormToolkit;
13
import org.eclipse.ui.forms.widgets.TableWrapLayout;
14

    
15
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
16
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
17
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
18

    
19
public abstract class AbstractEntityCollectionElementComposite<ENTITY>
20
	extends AbstractCdmFormElementComposite
21
	implements IEntityElement<ENTITY>, SelectionListener, IConversationEnabled {
22

    
23
	protected ENTITY entity;
24

    
25
	private final Composite container;
26

    
27
	private final Composite box;
28

    
29
	private final Button button_remove;
30

    
31
	private Color backgroundColor;
32

    
33
    /**
34
     * Create the composite.
35
     *
36
     * @param parent
37
     * @param style
38
     */
39
    public AbstractEntityCollectionElementComposite(Composite parent, ICdmFormElement parentFormElement, FormToolkit formFactory, ENTITY entity, SelectionListener removeListener, int style) {
40
        super(parent, parentFormElement, style);
41

    
42
        box = formFactory.createComposite(parent);
43
        box.setBackgroundMode(SWT.INHERIT_DEFAULT);
44
        addControl(box);
45

    
46
        TableWrapLayout boxLayout = LayoutConstants.LAYOUT(2, false);
47
        boxLayout.topMargin = 4;
48
        boxLayout.bottomMargin = 4;
49
        box.setLayout(boxLayout);
50

    
51
        box.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
52

    
53
        container = formFactory.createComposite(box);
54
        container.setBackgroundMode(SWT.INHERIT_DEFAULT);
55

    
56
        setLayoutComposite(container);
57

    
58
        addControl(container);
59
        Layout containerLayout = LayoutConstants.LAYOUT(2, false);
60

    
61
        container.setLayout(containerLayout);
62
        container.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
63

    
64
        // if (removeListener != null) {
65
        button_remove = formFactory.createButton(box, null, SWT.PUSH);
66
        addControl(button_remove);
67
        button_remove.setLayoutData(LayoutConstants.RIGHT());
68
        button_remove.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
69
        button_remove.setToolTipText("Remove");
70
//        button_remove.addSelectionListener(removeListener);
71
        // }
72

    
73
        createControls(this, style);
74
        setEntity(entity);
75

    
76
    }
77

    
78
	/**
79
	 * Init gets executed before any other setup of the section takes place
80
	 *
81
	 * Implement this if you want to configure the section
82
	 */
83
	public void init() {
84
		// default implementation is empty
85
	}
86

    
87
	/**
88
	 * <p>
89
	 * Setter for the field <code>entity</code>.
90
	 * </p>
91
	 *
92
	 * @param entity
93
	 *            a ENTITY object.
94
	 */
95
	public abstract void setEntity(ENTITY entity);
96

    
97
	/**
98
	 * <p>
99
	 * Getter for the field <code>entity</code>.
100
	 * </p>
101
	 *
102
	 * @return a ENTITY object.
103
	 */
104
	@Override
105
    public ENTITY getEntity() {
106
		return entity;
107
	}
108

    
109
	/**
110
	 * <p>
111
	 * createControls
112
	 * </p>
113
	 *
114
	 * @param element
115
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
116
	 *            object.
117
	 * @param style
118
	 *            a int.
119
	 */
120
	public abstract void createControls(ICdmFormElement element, int style);
121

    
122
	/**
123
	 * Mark <code>this</code> element as selected.
124
	 */
125
	@Override
126
    public void setSelected(boolean selected) {
127

    
128
		for (ICdmFormElement element : getElements()) {
129
			if (element instanceof ISelectable) {
130
				((ISelectable) element).setSelected(selected);
131
			}
132
		}
133
		setBackground(selected ? SELECTED : getPersistentBackground());
134
	}
135

    
136
	/*
137
	 * (non-Javadoc)
138
	 *
139
	 * @see
140
	 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
141
	 * .eclipse.jface.util.PropertyChangeEvent)
142
	 */
143
	/** {@inheritDoc} */
144
	@Override
145
	public void propertyChange(PropertyChangeEvent event) {
146
		if (event == null) {
147
			return;
148
		}
149
		Object eventSource = event.getSource();
150
		if (getElements().contains(eventSource)) {
151
			handleEvent(eventSource);
152
		}
153
	}
154

    
155
	/**
156
	 * <p>
157
	 * handleEvent
158
	 * </p>
159
	 *
160
	 * @param eventSource
161
	 *            a {@link java.lang.Object} object.
162
	 */
163
	public abstract void handleEvent(Object eventSource);
164

    
165
	/** {@inheritDoc} */
166
	@Override
167
    public void setBackground(Color color) {
168
		backgroundColor = color;
169
		super.setBackground(backgroundColor);
170
		box.setBackground(backgroundColor);
171
		container.setBackground(backgroundColor);
172
	}
173

    
174
	/**
175
	 * {@inheritDoc}
176
	 *
177
	 * React when selection occurs
178
	 */
179
	@Override
180
    public void widgetSelected(SelectionEvent e) {
181

    
182
	}
183

    
184
	/** {@inheritDoc} */
185
	@Override
186
    public void widgetDefaultSelected(SelectionEvent e) {
187
	}
188

    
189
	/** {@inheritDoc} */
190
	@Override
191
	public Composite getLayoutComposite() {
192
		return container;
193
	}
194

    
195
	/**
196
	 * <p>
197
	 * Getter for the field <code>backgroundColor</code>.
198
	 * </p>
199
	 *
200
	 * @return the backgroundColor
201
	 */
202
	public Color getBackgroundColor() {
203
		return backgroundColor;
204
	}
205

    
206
	/**
207
	 * <p>
208
	 * getConversationHolder
209
	 * </p>
210
	 *
211
	 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
212
	 *         object.
213
	 */
214
	@Override
215
    public ConversationHolder getConversationHolder() {
216
		if (getParentElement() instanceof IConversationEnabled) {
217
			return ((IConversationEnabled) getParentElement())
218
					.getConversationHolder();
219
		}
220
		throw new IllegalArgumentException(
221
				"Parent element should be IConversationEnabled");
222
	}
223

    
224
	/** {@inheritDoc} */
225
	@Override
226
    public void update(CdmDataChangeMap changeEvents) {
227
	}
228

    
229
}
(5-5/40)