2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.container
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
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
.Display
;
23 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
24 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.taxeditor
.editor
.CdmDataTransfer
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.IDropTargetableE4
;
29 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
30 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.dnd
.NameEditorDropTargetEffect
;
31 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.dnd
.NameEditorDropTargetListenerE4
;
32 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
33 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
41 public abstract class AbstractGroupE4
implements IDropTargetableE4
{
43 private Composite control
;
45 private final List
<AbstractGroupedContainerE4
> groupedContainers
= new ArrayList
<>();
47 protected TaxonNameEditorE4 editor
;
49 private DropTarget target
;
50 private DropTargetListener dropListener
;
52 public AbstractGroupE4(TaxonNameEditorE4 editor
){
56 protected void createContent(){
62 this.setDroppable(true);
64 editor
.getManagedForm().reflow(true);
67 protected void createControl() {
68 control
= editor
.getToolkit().createComposite(editor
.getControl());
70 control
.setLayoutData(new TableWrapData(TableWrapData
.FILL_GRAB
));
71 TableWrapLayout layout
= new TableWrapLayout();
74 layout
.rightMargin
= 0;
75 layout
.bottomMargin
= 1;
76 layout
.leftMargin
= 0;
78 layout
.verticalSpacing
= 0;
79 layout
.horizontalSpacing
= 0;
80 control
.setLayout(layout
);
82 control
.setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_GRAY
));
85 public void add(AbstractGroupedContainerE4 groupedContainer
){
86 groupedContainers
.add(groupedContainer
);
87 groupedContainer
.setGroup(this);
90 public void remove(AbstractGroupedContainerE4 groupedContainer
){
91 groupedContainer
.dispose();
92 groupedContainers
.remove(groupedContainer
);
94 if(!(this instanceof AcceptedGroupE4
) && groupedContainers
.isEmpty()){
95 getEditor().removeGroup(this);
99 public List
<AbstractGroupedContainerE4
> getGroupedContainers(){
100 return groupedContainers
;
104 public void setDroppable(boolean droppable
) {
106 Transfer
[] types
= new Transfer
[] {CdmDataTransfer
.getInstance()};
107 int operations
= DND
.DROP_MOVE
;
108 target
= new DropTarget(control
, operations
);
109 target
.setTransfer(types
);
110 dropListener
= new NameEditorDropTargetListenerE4(this);
111 target
.addDropListener(dropListener
);
113 target
.setDropTargetEffect(new NameEditorDropTargetEffect(control
));
116 if (dropListener
!= null) {
117 target
.removeDropListener(dropListener
);
123 public TaxonNameEditorE4
getEditor() {
128 public void dragEntered() {
129 Color color
= AbstractUtility
.getColor(Resources
.COLOR_DRAG_ENTER
);
131 for(AbstractGroupedContainerE4 container
: groupedContainers
){
132 container
.setBackground(color
);
137 public void dragLeft() {
138 for(AbstractGroupedContainerE4 container
: groupedContainers
){
139 container
.restoreColor();
145 public boolean postOperation(CdmBase objectAffectedByOperation
) {
146 editor
.changed(objectAffectedByOperation
);
151 public void redraw(){
156 protected abstract void createContainers();
159 public Composite
getControl() {
164 public boolean onComplete() {
168 public void dispose(){
169 if(getControl() != null){
170 for(AbstractGroupedContainerE4 container
: getGroupedContainers()){
173 getControl().setMenu(null);
174 getControl().dispose();
178 protected void emptyGroup(){
179 for(AbstractGroupedContainerE4 container
: groupedContainers
){
182 groupedContainers
.clear();