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.editor.name.container;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.eclipse.swt.SWT;
|
16
|
import org.eclipse.swt.dnd.DND;
|
17
|
import org.eclipse.swt.dnd.DropTarget;
|
18
|
import org.eclipse.swt.dnd.DropTargetListener;
|
19
|
import org.eclipse.swt.dnd.Transfer;
|
20
|
import org.eclipse.swt.graphics.Color;
|
21
|
import org.eclipse.swt.widgets.Composite;
|
22
|
import org.eclipse.swt.widgets.Menu;
|
23
|
import org.eclipse.ui.forms.widgets.TableWrapData;
|
24
|
import org.eclipse.ui.forms.widgets.TableWrapLayout;
|
25
|
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
|
28
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
29
|
import eu.etaxonomy.taxeditor.editor.IDropTargetable;
|
30
|
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
|
31
|
import eu.etaxonomy.taxeditor.editor.name.dnd.NameEditorDropTargetEffect;
|
32
|
import eu.etaxonomy.taxeditor.editor.name.dnd.NameEditorDropTargetListener;
|
33
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
34
|
import eu.etaxonomy.taxeditor.store.singlesource.widget.DisplayProxy;
|
35
|
|
36
|
/**
|
37
|
* <p>Abstract AbstractGroup class.</p>
|
38
|
*
|
39
|
* @author p.ciardelli
|
40
|
* @author n.hoffmann
|
41
|
* @created 25.06.2008
|
42
|
* @version 1.0
|
43
|
*/
|
44
|
public abstract class AbstractGroup implements IDropTargetable{
|
45
|
|
46
|
private Composite control;
|
47
|
|
48
|
private List<AbstractGroupedContainer> groupedContainers = new ArrayList<AbstractGroupedContainer>();
|
49
|
|
50
|
protected TaxonNameEditor editor;
|
51
|
|
52
|
private DropTarget target;
|
53
|
private DropTargetListener dropListener;
|
54
|
|
55
|
/**
|
56
|
* <p>Constructor for AbstractGroup.</p>
|
57
|
*
|
58
|
* @param editor a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object.
|
59
|
* @param <T> a T object.
|
60
|
*/
|
61
|
public AbstractGroup(TaxonNameEditor editor){
|
62
|
this.editor = editor;
|
63
|
}
|
64
|
|
65
|
protected void createContent(){
|
66
|
createControl();
|
67
|
|
68
|
createContainers();
|
69
|
|
70
|
// Drop functionality
|
71
|
this.setDroppable(true);
|
72
|
|
73
|
editor.getManagedForm().reflow(true);
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* <p>createControl</p>
|
78
|
*/
|
79
|
protected void createControl() {
|
80
|
control = editor.getToolkit().createComposite(editor.getControl());
|
81
|
|
82
|
control.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
|
83
|
TableWrapLayout layout = new TableWrapLayout();
|
84
|
|
85
|
layout.topMargin = 0;
|
86
|
layout.rightMargin = 0;
|
87
|
layout.bottomMargin = 1;
|
88
|
layout.leftMargin = 0;
|
89
|
|
90
|
layout.verticalSpacing = 0;
|
91
|
layout.horizontalSpacing = 0;
|
92
|
control.setLayout(layout);
|
93
|
|
94
|
control.setBackground(DisplayProxy.getDefault().getSystemColor(SWT.COLOR_GRAY));
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* <p>add</p>
|
99
|
*
|
100
|
* @param groupedContainer a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer} object.
|
101
|
*/
|
102
|
public void add(AbstractGroupedContainer groupedContainer){
|
103
|
groupedContainers.add(groupedContainer);
|
104
|
groupedContainer.setGroup(this);
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* <p>remove</p>
|
109
|
*
|
110
|
* @param groupedContainer a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer} object.
|
111
|
*/
|
112
|
public void remove(AbstractGroupedContainer groupedContainer){
|
113
|
groupedContainer.dispose();
|
114
|
groupedContainers.remove(groupedContainer);
|
115
|
|
116
|
if(!(this instanceof AcceptedGroup) && groupedContainers.isEmpty()){
|
117
|
getEditor().removeGroup(this);
|
118
|
}
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* <p>Getter for the field <code>groupedContainers</code>.</p>
|
123
|
*
|
124
|
* @return a {@link java.util.List} object.
|
125
|
*/
|
126
|
public List<AbstractGroupedContainer> getGroupedContainers(){
|
127
|
return groupedContainers;
|
128
|
}
|
129
|
|
130
|
|
131
|
/**
|
132
|
* <p>setDroppable</p>
|
133
|
*
|
134
|
* @param droppable a boolean.
|
135
|
*/
|
136
|
public void setDroppable(boolean droppable) {
|
137
|
if (droppable) {
|
138
|
Transfer[] types = new Transfer[] {CdmDataTransfer.getInstance()};
|
139
|
int operations = DND.DROP_MOVE;
|
140
|
target = new DropTarget(control, operations);
|
141
|
target.setTransfer(types);
|
142
|
dropListener = new NameEditorDropTargetListener(this);
|
143
|
target.addDropListener(dropListener);
|
144
|
|
145
|
target.setDropTargetEffect(new NameEditorDropTargetEffect(control));
|
146
|
|
147
|
} else {
|
148
|
if (dropListener != null) {
|
149
|
target.removeDropListener(dropListener);
|
150
|
}
|
151
|
}
|
152
|
}
|
153
|
|
154
|
/**
|
155
|
* <p>getNameEditor</p>
|
156
|
*
|
157
|
* @return a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object.
|
158
|
*/
|
159
|
public TaxonNameEditor getEditor() {
|
160
|
return editor;
|
161
|
}
|
162
|
|
163
|
/**
|
164
|
* <p>dragEntered</p>
|
165
|
*/
|
166
|
public void dragEntered() {
|
167
|
Color color = EditorUtil.getColor(Resources.COLOR_DRAG_ENTER);
|
168
|
|
169
|
for(AbstractGroupedContainer container : groupedContainers){
|
170
|
container.setBackground(color);
|
171
|
}
|
172
|
}
|
173
|
|
174
|
/**
|
175
|
* <p>dragLeft</p>
|
176
|
*/
|
177
|
public void dragLeft() {
|
178
|
for(AbstractGroupedContainer container : groupedContainers){
|
179
|
container.restoreColor();
|
180
|
}
|
181
|
}
|
182
|
|
183
|
/** {@inheritDoc} */
|
184
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
185
|
editor.getMultiPageTaxonEditor().changed(null);
|
186
|
redraw();
|
187
|
return true;
|
188
|
}
|
189
|
|
190
|
/**
|
191
|
* <p>redraw</p>
|
192
|
*/
|
193
|
public void redraw(){
|
194
|
emptyGroup();
|
195
|
createContainers();
|
196
|
}
|
197
|
|
198
|
protected abstract void createContainers();
|
199
|
|
200
|
/* (non-Javadoc)
|
201
|
* @see eu.etaxonomy.taxeditor.editor.IDropTargetable#getControl()
|
202
|
*/
|
203
|
@Override
|
204
|
public Composite getControl() {
|
205
|
return control;
|
206
|
}
|
207
|
|
208
|
/* (non-Javadoc)
|
209
|
* @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#onComplete()
|
210
|
*/
|
211
|
@Override
|
212
|
public boolean onComplete() {
|
213
|
return true;
|
214
|
}
|
215
|
|
216
|
public void dispose(){
|
217
|
if(getControl() != null){
|
218
|
for(AbstractGroupedContainer container : getGroupedContainers()){
|
219
|
container.dispose();
|
220
|
}
|
221
|
getControl().setMenu(null);
|
222
|
getControl().dispose();
|
223
|
}
|
224
|
}
|
225
|
|
226
|
/**
|
227
|
* @param object
|
228
|
*/
|
229
|
public void setMenu(Menu menu) {
|
230
|
getControl().setMenu(menu);
|
231
|
for(AbstractGroupedContainer container : getGroupedContainers()){
|
232
|
container.setMenu(menu);
|
233
|
}
|
234
|
|
235
|
}
|
236
|
|
237
|
protected void emptyGroup(){
|
238
|
for(AbstractGroupedContainer container : groupedContainers){
|
239
|
container.dispose();
|
240
|
}
|
241
|
groupedContainers.clear();
|
242
|
}
|
243
|
}
|