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
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.dnd
.DND
;
15 import org
.eclipse
.swt
.dnd
.DropTarget
;
16 import org
.eclipse
.swt
.dnd
.DropTargetAdapter
;
17 import org
.eclipse
.swt
.dnd
.DropTargetEvent
;
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
.ui
.forms
.widgets
.TableWrapData
;
23 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
25 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
26 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
27 import eu
.etaxonomy
.taxeditor
.actions
.WidgetTransfer
;
34 public class GroupComposite
extends Composite
{
35 private static final Logger logger
= Logger
.getLogger(GroupComposite
.class);
37 private DropTarget target
;
38 private DropTargetListener dropListener
;
40 public GroupComposite(Composite parent
) {
41 super(parent
, SWT
.NONE
);
43 // Graphic layout of composite
44 this.setLayoutData(new TableWrapData(TableWrapData
.FILL_GRAB
));
45 this.setLayout(new TableWrapLayout());
46 Color groupBackgroundColor
= TaxEditorPlugin
.getDefault().
47 getColor(ITaxEditorConstants
.GROUP_GRAY_BKG_COLOR
);
48 this.setBackground(groupBackgroundColor
);
51 this.setDroppable(true);
55 public void setDroppable(boolean droppable
) {
57 Transfer
[] types
= new Transfer
[] {WidgetTransfer
.getInstance()};
58 int operations
= DND
.DROP_MOVE
| DND
.DROP_COPY
| DND
.DROP_DEFAULT
;
59 target
= new DropTarget(this, operations
);
60 target
.setTransfer(types
);
61 dropListener
= new DropTargetAdapter() {
63 public void dragEnter(DropTargetEvent event
) {
64 GroupComposite
.this.notifyListeners(SWT
.FocusIn
, null);
67 public void dragLeave(DropTargetEvent event
) {
68 GroupComposite
.this.notifyListeners(SWT
.FocusOut
, null);
71 public void drop(DropTargetEvent event
) {
73 if (event
.data
instanceof Composite
) {
74 Composite composite
= (Composite
) event
.data
;
75 if ( ! composite
.getParent().equals(GroupComposite
.this)) {
76 composite
.setParent(GroupComposite
.this);
81 target
.addDropListener(dropListener
);
83 if (dropListener
!= null) {
84 target
.removeDropListener(dropListener
);
89 public void dispose() {
91 target
.removeDropListener(dropListener
);
93 // for (Control control : getChildren()) {
94 // if (!control.isDisposed()) {