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
.swt
.widgets
.Menu
;
24 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
25 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
27 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 import eu
.etaxonomy
.taxeditor
.editor
.CdmDataTransfer
;
29 import eu
.etaxonomy
.taxeditor
.editor
.name
.dnd
.NameEditorDropTargetEffect
;
30 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.IDropTargetableE4
;
31 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
32 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.dnd
.NameEditorDropTargetListenerE4
;
33 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
34 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
42 public abstract class AbstractGroupE4
implements IDropTargetableE4
{
44 private Composite control
;
46 private final List
<AbstractGroupedContainerE4
> groupedContainers
= new ArrayList
<>();
48 protected TaxonNameEditorE4 editor
;
50 private DropTarget target
;
51 private DropTargetListener dropListener
;
53 public AbstractGroupE4(TaxonNameEditorE4 editor
){
57 protected void createContent(){
63 this.setDroppable(true);
65 editor
.getManagedForm().reflow(true);
68 protected void createControl() {
69 control
= editor
.getToolkit().createComposite(editor
.getControl());
71 control
.setLayoutData(new TableWrapData(TableWrapData
.FILL_GRAB
));
72 TableWrapLayout layout
= new TableWrapLayout();
75 layout
.rightMargin
= 0;
76 layout
.bottomMargin
= 1;
77 layout
.leftMargin
= 0;
79 layout
.verticalSpacing
= 0;
80 layout
.horizontalSpacing
= 0;
81 control
.setLayout(layout
);
83 control
.setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_GRAY
));
86 public void add(AbstractGroupedContainerE4 groupedContainer
){
87 groupedContainers
.add(groupedContainer
);
88 groupedContainer
.setGroup(this);
91 public void remove(AbstractGroupedContainerE4 groupedContainer
){
92 groupedContainer
.dispose();
93 groupedContainers
.remove(groupedContainer
);
95 if(!(this instanceof AcceptedGroupE4
) && groupedContainers
.isEmpty()){
96 getEditor().removeGroup(this);
100 public List
<AbstractGroupedContainerE4
> getGroupedContainers(){
101 return groupedContainers
;
105 public void setDroppable(boolean droppable
) {
107 Transfer
[] types
= new Transfer
[] {CdmDataTransfer
.getInstance()};
108 int operations
= DND
.DROP_MOVE
;
109 target
= new DropTarget(control
, operations
);
110 target
.setTransfer(types
);
111 dropListener
= new NameEditorDropTargetListenerE4(this);
112 target
.addDropListener(dropListener
);
114 target
.setDropTargetEffect(new NameEditorDropTargetEffect(control
));
117 if (dropListener
!= null) {
118 target
.removeDropListener(dropListener
);
124 public TaxonNameEditorE4
getEditor() {
129 public void dragEntered() {
130 Color color
= AbstractUtility
.getColor(Resources
.COLOR_DRAG_ENTER
);
132 for(AbstractGroupedContainerE4 container
: groupedContainers
){
133 container
.setBackground(color
);
138 public void dragLeft() {
139 for(AbstractGroupedContainerE4 container
: groupedContainers
){
140 container
.restoreColor();
146 public boolean postOperation(CdmBase objectAffectedByOperation
) {
147 editor
.changed(objectAffectedByOperation
);
152 public void redraw(){
157 protected abstract void createContainers();
160 public Composite
getControl() {
165 public boolean onComplete() {
169 public void dispose(){
170 if(getControl() != null){
171 for(AbstractGroupedContainerE4 container
: getGroupedContainers()){
174 getControl().setMenu(null);
175 getControl().dispose();
179 public void setMenu(Menu menu
) {
180 getControl().setMenu(menu
);
181 for(AbstractGroupedContainerE4 container
: getGroupedContainers()){
182 container
.setMenu(menu
);
187 protected void emptyGroup(){
188 for(AbstractGroupedContainerE4 container
: groupedContainers
){
191 groupedContainers
.clear();