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
.swt
.widgets
.Event
;
23 import org
.eclipse
.swt
.widgets
.Listener
;
24 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
25 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
28 import eu
.etaxonomy
.taxeditor
.model
.Resources
;
35 public class GroupComposite
extends Composite
{
36 private static final Logger logger
= Logger
.getLogger(GroupComposite
.class);
38 protected AbstractTaxonEditor editor
;
39 protected Taxon taxon
;
41 private DropTarget target
;
42 private DropTargetListener dropListener
;
44 public GroupComposite(Composite parent
) {
45 super(parent
, SWT
.NONE
);
47 // Graphic layout of composite
48 this.setLayoutData(new TableWrapData(TableWrapData
.FILL_GRAB
));
49 this.setLayout(new TableWrapLayout());
50 Color groupBackgroundColor
= Resources
.
51 getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
);
52 this.setBackground(groupBackgroundColor
);
55 this.setDroppable(true);
57 logger
.trace("Created a new Group composite");
60 public GroupComposite(AbstractTaxonEditor editor
, Composite parent
){
63 this.taxon
= editor
.getTaxon();
66 public void setDroppable(boolean droppable
) {
68 Transfer
[] types
= new Transfer
[] {WidgetTransfer
.getInstance()};
69 int operations
= DND
.DROP_MOVE
| DND
.DROP_COPY
| DND
.DROP_DEFAULT
;
70 target
= new DropTarget(this, operations
);
71 target
.setTransfer(types
);
72 dropListener
= new DropTargetAdapter() {
74 public void dragEnter(DropTargetEvent event
) {
75 GroupComposite
.this.notifyListeners(SWT
.FocusIn
, null);
78 public void dragLeave(DropTargetEvent event
) {
79 GroupComposite
.this.notifyListeners(SWT
.FocusOut
, null);
82 public void drop(DropTargetEvent event
) {
84 if (event
.data
instanceof GroupedComposite
) {
86 final GroupedComposite composite
= (GroupedComposite
) event
.data
;
87 if (composite
.getDragSource() != null) {
89 // Make sure composite is not being dropped onto its current parent
90 if ( ! composite
.getParent().equals(GroupComposite
.this)) {
92 // Change parent at end of drag event
93 composite
.getDragSource().addListener(DND
.DragEnd
, new Listener() {
95 public void handleEvent(Event event
) {
96 composite
.setParent(GroupComposite
.this);
104 target
.addDropListener(dropListener
);
106 if (dropListener
!= null) {
107 target
.removeDropListener(dropListener
);
112 public void dispose() {
114 if (target
!= null) {
115 target
.removeDropListener(dropListener
);
125 public Taxon
getTaxon() {