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.e4.container;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
16
|
import org.eclipse.swt.SWT;
|
17
|
import org.eclipse.swt.dnd.DND;
|
18
|
import org.eclipse.swt.dnd.DropTarget;
|
19
|
import org.eclipse.swt.dnd.DropTargetListener;
|
20
|
import org.eclipse.swt.dnd.Transfer;
|
21
|
import org.eclipse.swt.graphics.Color;
|
22
|
import org.eclipse.swt.widgets.Composite;
|
23
|
import org.eclipse.swt.widgets.Display;
|
24
|
import org.eclipse.ui.forms.widgets.TableWrapData;
|
25
|
import org.eclipse.ui.forms.widgets.TableWrapLayout;
|
26
|
|
27
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
28
|
import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
|
29
|
import eu.etaxonomy.taxeditor.editor.name.e4.IDropTargetableE4;
|
30
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
31
|
import eu.etaxonomy.taxeditor.editor.name.e4.dnd.NameEditorDropTargetEffect;
|
32
|
import eu.etaxonomy.taxeditor.editor.name.e4.dnd.NameEditorDropTargetListenerE4;
|
33
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
34
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
35
|
|
36
|
/**
|
37
|
*
|
38
|
* @author pplitzner
|
39
|
* @date Aug 24, 2017
|
40
|
*
|
41
|
*/
|
42
|
public abstract class AbstractGroupE4 implements IDropTargetableE4{
|
43
|
|
44
|
private Composite control;
|
45
|
|
46
|
private IEclipseContext context;
|
47
|
|
48
|
private final List<AbstractGroupedContainerE4> groupedContainers = new ArrayList<>();
|
49
|
|
50
|
protected TaxonNameEditorE4 editor;
|
51
|
|
52
|
private DropTarget target;
|
53
|
private DropTargetListener dropListener;
|
54
|
|
55
|
public AbstractGroupE4(TaxonNameEditorE4 editor){
|
56
|
this.editor = editor;
|
57
|
this.context = editor.getContext();
|
58
|
}
|
59
|
|
60
|
protected void createContent(){
|
61
|
createControl();
|
62
|
|
63
|
createContainers();
|
64
|
|
65
|
// Drop functionality
|
66
|
this.setDroppable(true);
|
67
|
|
68
|
editor.getManagedForm().reflow(true);
|
69
|
}
|
70
|
|
71
|
protected void createControl() {
|
72
|
control = editor.getToolkit().createComposite(editor.getControl());
|
73
|
|
74
|
control.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
|
75
|
TableWrapLayout layout = new TableWrapLayout();
|
76
|
|
77
|
layout.topMargin = 0;
|
78
|
layout.rightMargin = 0;
|
79
|
layout.bottomMargin = 1;
|
80
|
layout.leftMargin = 0;
|
81
|
|
82
|
layout.verticalSpacing = 0;
|
83
|
layout.horizontalSpacing = 0;
|
84
|
control.setLayout(layout);
|
85
|
|
86
|
control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
|
87
|
}
|
88
|
|
89
|
public void add(AbstractGroupedContainerE4 groupedContainer){
|
90
|
groupedContainers.add(groupedContainer);
|
91
|
}
|
92
|
|
93
|
public void remove(AbstractGroupedContainerE4 groupedContainer){
|
94
|
groupedContainer.dispose();
|
95
|
groupedContainers.remove(groupedContainer);
|
96
|
|
97
|
if(!(this instanceof AcceptedGroupE4) && groupedContainers.isEmpty()){
|
98
|
getEditor().removeGroup(this);
|
99
|
}
|
100
|
}
|
101
|
|
102
|
public List<AbstractGroupedContainerE4> getGroupedContainers(){
|
103
|
return groupedContainers;
|
104
|
}
|
105
|
|
106
|
|
107
|
public void setDroppable(boolean droppable) {
|
108
|
if (droppable) {
|
109
|
Transfer[] types = new Transfer[] {CdmDataTransfer.getInstance()};
|
110
|
int operations = DND.DROP_MOVE;
|
111
|
target = new DropTarget(control, operations);
|
112
|
target.setTransfer(types);
|
113
|
dropListener = new NameEditorDropTargetListenerE4(this);
|
114
|
target.addDropListener(dropListener);
|
115
|
|
116
|
target.setDropTargetEffect(new NameEditorDropTargetEffect(control));
|
117
|
|
118
|
} else {
|
119
|
if (dropListener != null) {
|
120
|
target.removeDropListener(dropListener);
|
121
|
}
|
122
|
}
|
123
|
}
|
124
|
|
125
|
@Override
|
126
|
public IEclipseContext getContext() {
|
127
|
return context;
|
128
|
}
|
129
|
|
130
|
@Override
|
131
|
public TaxonNameEditorE4 getEditor() {
|
132
|
return editor;
|
133
|
}
|
134
|
|
135
|
@Override
|
136
|
public void dragEntered() {
|
137
|
Color color = AbstractUtility.getColor(Resources.COLOR_DRAG_ENTER);
|
138
|
|
139
|
for(AbstractGroupedContainerE4 container : groupedContainers){
|
140
|
container.setBackground(color);
|
141
|
}
|
142
|
}
|
143
|
|
144
|
@Override
|
145
|
public void dragLeft() {
|
146
|
for(AbstractGroupedContainerE4 container : groupedContainers){
|
147
|
container.restoreColor();
|
148
|
}
|
149
|
}
|
150
|
|
151
|
/** {@inheritDoc} */
|
152
|
@Override
|
153
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
154
|
editor.changed(objectAffectedByOperation);
|
155
|
redraw();
|
156
|
return true;
|
157
|
}
|
158
|
|
159
|
public void redraw(){
|
160
|
emptyGroup();
|
161
|
createContainers();
|
162
|
}
|
163
|
|
164
|
protected abstract void createContainers();
|
165
|
|
166
|
@Override
|
167
|
public Composite getControl() {
|
168
|
return control;
|
169
|
}
|
170
|
|
171
|
@Override
|
172
|
public boolean onComplete() {
|
173
|
return true;
|
174
|
}
|
175
|
|
176
|
public void dispose(){
|
177
|
if(getControl() != null){
|
178
|
for(AbstractGroupedContainerE4 container : getGroupedContainers()){
|
179
|
container.dispose();
|
180
|
}
|
181
|
getControl().setMenu(null);
|
182
|
getControl().dispose();
|
183
|
}
|
184
|
}
|
185
|
|
186
|
protected void emptyGroup(){
|
187
|
for(AbstractGroupedContainerE4 container : groupedContainers){
|
188
|
container.dispose();
|
189
|
}
|
190
|
groupedContainers.clear();
|
191
|
}
|
192
|
}
|