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