[177039] Drag and Drop of elements and attributes
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveAction.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveAction.java
deleted file mode 100644
index be4764a..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveAction.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors:
- *     IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.xsd.ui.internal.actions;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.xsd.XSDAttributeDeclaration;
-import org.eclipse.xsd.XSDConcreteComponent;
-import org.eclipse.xsd.XSDModelGroup;
-import org.eclipse.xsd.XSDParticle;
-import org.eclipse.xsd.XSDParticleContent;
-import org.w3c.dom.Node;
-
-public class MoveAction extends Action
-{
-  protected List selectedNodes;
-  protected Node parentNode;
-  protected Node previousRefChild, nextRefChild;
-  boolean doInsertBefore;
-
-  List selectedComponentsList;
-  XSDModelGroup parentModelGroup;
-  XSDConcreteComponent previousRefComponent, nextRefComponent;
-
-  public MoveAction(XSDModelGroup parentComponent, List selectedComponents, XSDConcreteComponent previousRefChildComponent, XSDConcreteComponent nextRefChildComponent)
-  {
-    this.parentModelGroup = parentComponent;
-    this.selectedComponentsList = selectedComponents;
-    this.previousRefComponent = previousRefChildComponent;
-    this.nextRefComponent = nextRefChildComponent;
-
-    selectedNodes = new ArrayList(selectedComponents.size());
-    for (Iterator i = selectedComponents.iterator(); i.hasNext();)
-    {
-      XSDConcreteComponent concreteComponent = (XSDConcreteComponent) i.next();
-      selectedNodes.add(concreteComponent.getElement());
-    }
-    if (parentComponent == null) return;
-    parentNode = parentComponent.getElement();
-    nextRefChild = nextRefChildComponent != null ? nextRefChildComponent.getElement() : null;
-    previousRefChild = previousRefChildComponent != null ? previousRefChildComponent.getElement() : null;
-
-    doInsertBefore = (nextRefChild != null);
-    if (nextRefComponent != null)
-    {
-      if (nextRefComponent.getContainer().getContainer() == parentModelGroup)
-      {
-        doInsertBefore = true;
-      }
-    }
-    if (previousRefComponent != null)
-    {
-      if (previousRefComponent.getContainer().getContainer() == parentModelGroup)
-      {
-        doInsertBefore = false;
-      }
-    }
-  }
-
-  public boolean canMove()
-  {
-    boolean result = true;
-
-    if (nextRefComponent instanceof XSDAttributeDeclaration || previousRefComponent instanceof XSDAttributeDeclaration || parentModelGroup == null)
-      return false;
-
-    return result;
-  }
-
-  /*
-   * @see IAction#run()
-   */
-  public void run()
-  {
-    try
-    {
-      for (Iterator i = selectedComponentsList.iterator(); i.hasNext();)
-      {
-        XSDConcreteComponent concreteComponent = (XSDConcreteComponent) i.next();
-
-        if (doInsertBefore)
-        {
-          if (concreteComponent == nextRefComponent)
-            continue;
-        }
-        else
-        {
-          if (concreteComponent == previousRefComponent)
-            continue;
-        }
-
-        for (Iterator particles = parentModelGroup.getContents().iterator(); particles.hasNext();)
-        {
-          XSDParticle particle = (XSDParticle) particles.next();
-          XSDParticleContent particleContent = particle.getContent();
-          if (particleContent == concreteComponent)
-          {
-            parentModelGroup.getContents().remove(particle);
-            break;
-          }
-        }
-        int index = 0;
-        List particles = parentModelGroup.getContents();
-        for (Iterator iterator = particles.iterator(); iterator.hasNext();)
-        {
-          XSDParticle particle = (XSDParticle) iterator.next();
-          XSDParticleContent particleContent = particle.getContent();
-          if (doInsertBefore)
-          {
-            if (particleContent == nextRefComponent)
-            {
-              parentModelGroup.getContents().add(index, concreteComponent.getContainer());
-              break;
-            }
-          }
-          else
-          {
-            if (particleContent == previousRefComponent)
-            {
-              parentModelGroup.getContents().add(index + 1, concreteComponent.getContainer());
-              break;
-            }
-          }
-          index++;
-        }
-        if (particles.size() == 0)
-        {
-          parentModelGroup.getContents().add(concreteComponent.getContainer());
-        }
-
-      }
-    }
-    catch (Exception e)
-    {
-      e.printStackTrace();
-    }
-  }
-}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveAttributeAction.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveAttributeAction.java
deleted file mode 100644
index 896b84d..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveAttributeAction.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors:
- *     IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.xsd.ui.internal.actions;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.xsd.XSDAttributeDeclaration;
-import org.eclipse.xsd.XSDAttributeGroupContent;
-import org.eclipse.xsd.XSDAttributeGroupDefinition;
-import org.eclipse.xsd.XSDAttributeUse;
-import org.eclipse.xsd.XSDComplexTypeDefinition;
-import org.eclipse.xsd.XSDConcreteComponent;
-import org.eclipse.xsd.XSDElementDeclaration;
-import org.w3c.dom.Node;
-
-// TODO COMMON AND CLEAN UP THIS CODE
-public class MoveAttributeAction extends Action
-{
-
-  protected List selectedNodes;
-  protected Node parentNode;
-  protected Node previousRefChild, nextRefChild;
-  boolean doInsertBefore;
-
-  List selectedComponentsList;
-  XSDConcreteComponent parentComponent;
-  XSDConcreteComponent previousRefComponent, nextRefComponent;
-
-  public MoveAttributeAction(XSDConcreteComponent parentComponent, List selectedComponents, XSDConcreteComponent previousRefChildComponent, XSDConcreteComponent nextRefChildComponent)
-  {
-    this.parentComponent = parentComponent;
-    this.selectedComponentsList = selectedComponents;
-    this.previousRefComponent = previousRefChildComponent;
-    this.nextRefComponent = nextRefChildComponent;
-
-    selectedNodes = new ArrayList(selectedComponents.size());
-    for (Iterator i = selectedComponents.iterator(); i.hasNext();)
-    {
-      XSDConcreteComponent concreteComponent = (XSDConcreteComponent) i.next();
-      selectedNodes.add(concreteComponent.getElement());
-    }
-    parentNode = parentComponent.getElement();
-    nextRefChild = nextRefChildComponent != null ? nextRefChildComponent.getElement() : null;
-    previousRefChild = previousRefChildComponent != null ? previousRefChildComponent.getElement() : null;
-
-    doInsertBefore = (nextRefChild != null);
-
-    if (nextRefComponent != null)
-    {
-      if (nextRefComponent.getContainer().getContainer() == parentComponent)
-      {
-        doInsertBefore = true;
-      }
-    }
-    if (previousRefComponent != null)
-    {
-      if (previousRefComponent.getContainer().getContainer() == parentComponent)
-      {
-        doInsertBefore = false;
-      }
-    }
-
-  }
-
-  public boolean canMove()
-  {
-    boolean result = true;
-
-    if (nextRefComponent instanceof XSDElementDeclaration || previousRefComponent instanceof XSDElementDeclaration)
-      return false;
-
-    return result;
-  }
-
-  /*
-   * @see IAction#run()
-   */
-  public void run()
-  {
-    if (parentComponent instanceof XSDAttributeGroupDefinition)
-    {
-      moveUnderXSDAttributeGroupDefinition((XSDAttributeGroupDefinition) parentComponent);
-    }
-    else if (parentComponent instanceof XSDComplexTypeDefinition)
-    {
-      moveUnderXSDComplexTypeDefinition((XSDComplexTypeDefinition) parentComponent);
-    }
-  }
-
-  protected void moveUnderXSDAttributeGroupDefinition(XSDAttributeGroupDefinition parentModelGroup)
-  {
-    try
-    {
-      for (Iterator i = selectedComponentsList.iterator(); i.hasNext();)
-      {
-        XSDConcreteComponent concreteComponent = (XSDConcreteComponent) i.next();
-
-        if (doInsertBefore)
-        {
-          if (concreteComponent == nextRefComponent)
-            continue;
-        }
-        else
-        {
-          if (concreteComponent == previousRefComponent)
-            continue;
-        }
-
-        for (Iterator iterator = parentModelGroup.getContents().iterator(); iterator.hasNext();)
-        {
-          XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
-          if (attributeGroupContent instanceof XSDAttributeUse)
-          {
-            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
-            if (attribute == concreteComponent)
-            {
-              parentModelGroup.getContents().remove(attribute.getContainer());
-              break;
-            }
-          }
-        }
-        int index = 0;
-        List attributeGroupContents = parentModelGroup.getContents();
-        for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext();)
-        {
-          XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
-          if (attributeGroupContent instanceof XSDAttributeUse)
-          {
-            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
-            if (doInsertBefore)
-            {
-              if (attribute == nextRefComponent)
-              {
-                parentModelGroup.getContents().add(index, concreteComponent.getContainer());
-                break;
-              }
-            }
-            else
-            {
-              if (attribute == previousRefComponent)
-              {
-                parentModelGroup.getContents().add(index + 1, concreteComponent.getContainer());
-                break;
-              }
-            }
-          }
-          index++;
-        }
-        if (attributeGroupContents.size() == 0)
-        {
-          parentModelGroup.getContents().add(concreteComponent.getContainer());
-        }
-
-      }
-    }
-    catch (Exception e)
-    {
-      e.printStackTrace();
-    }
-  }
-
-  protected void moveUnderXSDComplexTypeDefinition(XSDComplexTypeDefinition complexType)
-  {
-    try
-    {
-      for (Iterator i = selectedComponentsList.iterator(); i.hasNext();)
-      {
-        XSDConcreteComponent concreteComponent = (XSDConcreteComponent) i.next();
-
-        if (doInsertBefore)
-        {
-          if (concreteComponent == nextRefComponent)
-            continue;
-        }
-        else
-        {
-          if (concreteComponent == previousRefComponent)
-            continue;
-        }
-
-        for (Iterator iterator = complexType.getAttributeContents().iterator(); iterator.hasNext();)
-        {
-          XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
-          if (attributeGroupContent instanceof XSDAttributeUse)
-          {
-            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
-            if (attribute == concreteComponent)
-            {
-              complexType.getAttributeContents().remove(attribute.getContainer());
-              break;
-            }
-          }
-        }
-        int index = 0;
-        List attributeGroupContents = complexType.getAttributeContents();
-        for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext();)
-        {
-          XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
-          if (attributeGroupContent instanceof XSDAttributeUse)
-          {
-            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
-            if (doInsertBefore)
-            {
-              if (attribute == nextRefComponent)
-              {
-                complexType.getAttributeContents().add(index, concreteComponent.getContainer());
-                break;
-              }
-            }
-            else
-            {
-              if (attribute == previousRefComponent)
-              {
-                complexType.getAttributeContents().add(index + 1, concreteComponent.getContainer());
-                break;
-              }
-            }
-          }
-          index++;
-        }
-        if (attributeGroupContents.size() == 0)
-        {
-          complexType.getAttributeContents().add(concreteComponent.getContainer());
-        }
-
-      }
-    }
-    catch (Exception e)
-    {
-      e.printStackTrace();
-    }
-
-  }
-}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveXSDAttributeAction.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveXSDAttributeAction.java
new file mode 100644
index 0000000..069a2f7
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveXSDAttributeAction.java
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.actions;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.xsd.XSDAttributeDeclaration;
+import org.eclipse.xsd.XSDAttributeGroupContent;
+import org.eclipse.xsd.XSDAttributeGroupDefinition;
+import org.eclipse.xsd.XSDAttributeUse;
+import org.eclipse.xsd.XSDComplexTypeDefinition;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.w3c.dom.Node;
+
+public class MoveXSDAttributeAction extends MoveXSDBaseAction
+{
+  private static int INSERT_BEFORE = 0;
+  private static int INSERT_AFTER = 1;
+  private static int INSERT_DIRECT = 2;
+  protected List selectedNodes;
+  protected Node parentNode;
+  protected Node previousRefChild, nextRefChild;
+  int insertType;
+
+  XSDConcreteComponent parentComponent;
+  XSDConcreteComponent selected, previousRefComponent, nextRefComponent;
+  boolean insertAtEnd = true;
+  
+  public MoveXSDAttributeAction(XSDConcreteComponent parentComponent, XSDConcreteComponent selected, XSDConcreteComponent previousRefChildComponent, XSDConcreteComponent nextRefChildComponent)
+  {
+    super();
+    this.parentComponent = parentComponent;
+    this.selected = selected;
+    this.previousRefComponent = previousRefChildComponent;
+    this.nextRefComponent = nextRefChildComponent;
+
+    if (parentComponent == null)
+      return;
+    parentNode = parentComponent.getElement();
+    nextRefChild = nextRefChildComponent != null ? nextRefChildComponent.getElement() : null;
+    previousRefChild = previousRefChildComponent != null ? previousRefChildComponent.getElement() : null;
+
+    if (nextRefComponent != null)
+    {
+      if (nextRefComponent.getContainer().getContainer() == parentComponent)
+      {
+        insertType = INSERT_BEFORE;
+      }
+    }
+    if (previousRefComponent != null)
+    {
+      if (previousRefComponent.getContainer().getContainer() == parentComponent)
+      {
+        insertType = INSERT_AFTER;
+      }
+    }
+    if (nextRefChildComponent == null && previousRefChildComponent == null)
+    {
+      insertType = INSERT_DIRECT;
+    }
+  }
+  
+  public MoveXSDAttributeAction(XSDConcreteComponent parentComponent, XSDConcreteComponent selected, XSDConcreteComponent previousRefChildComponent, XSDConcreteComponent nextRefChildComponent, boolean insertAtEnd)
+  {
+    this(parentComponent, selected, previousRefChildComponent, nextRefChildComponent);
+    this.insertAtEnd = insertAtEnd;
+  }
+  
+  public boolean canMove()
+  {
+    boolean result = true;
+   
+    if (nextRefComponent instanceof XSDElementDeclaration || previousRefComponent instanceof XSDElementDeclaration || parentComponent == null)
+      return false;
+
+    return result;
+  }
+
+  /*
+   * @see IAction#run()
+   */
+  public void run()
+  {
+    if (parentComponent instanceof XSDAttributeGroupDefinition)
+    {
+      moveUnderXSDAttributeGroupDefinition((XSDAttributeGroupDefinition) parentComponent);
+    }
+    else if (parentComponent instanceof XSDComplexTypeDefinition)
+    {
+      moveUnderXSDComplexTypeDefinition((XSDComplexTypeDefinition) parentComponent);
+    }
+  }
+
+  protected void moveUnderXSDAttributeGroupDefinition(XSDAttributeGroupDefinition parentGroup)
+  {
+    int originalIndex = 0;
+    for (Iterator iterator = parentGroup.getContents().iterator(); iterator.hasNext();)
+    {
+      XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
+      if (attributeGroupContent instanceof XSDAttributeUse)
+      {
+        XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
+        if (attribute == selected)
+        {
+          parentGroup.getContents().remove(attribute.getContainer());
+          break;
+        }
+      }
+      originalIndex++;
+    }
+    int index = 0;
+    boolean addedBack = false;
+    if (insertType == INSERT_DIRECT)
+    {
+      XSDConcreteComponent container = selected.getContainer();
+      if (container != null)
+      {
+        if (insertAtEnd)
+          ((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(container);
+        else
+          ((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(0, container);
+        addedBack = true;
+      }
+      return;
+    }
+
+    List attributeGroupContents = parentGroup.getContents();
+    for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext();)
+    {
+      XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
+      if (attributeGroupContent instanceof XSDAttributeUse)
+      {
+        XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
+        if (insertType == INSERT_BEFORE)
+        {
+          if (attribute == nextRefComponent)
+          {
+            parentGroup.getContents().add(index, selected.getContainer());
+            addedBack = true;
+            break;
+          }
+          if (selected == nextRefComponent && originalIndex == index)
+          {
+            parentGroup.getContents().add(index, selected.getContainer());
+            addedBack = true;
+            break;
+          }
+        }
+        else if (insertType == INSERT_AFTER)
+        {
+          if (attribute == previousRefComponent)
+          {
+            parentGroup.getContents().add(index + 1, selected.getContainer());
+            addedBack = true;
+            break;
+          }
+          if (selected == previousRefComponent && originalIndex == index)
+          {
+            parentGroup.getContents().add(index, selected.getContainer());
+            addedBack = true;
+            break;
+          }
+        }
+      }
+      index++;
+    }
+    if (attributeGroupContents.size() == 0)
+    {
+      parentGroup.getContents().add(selected.getContainer());
+      addedBack = true;
+    }
+
+    if (!addedBack)
+    {
+      parentGroup.getContents().add(originalIndex, selected.getContainer());
+    }
+  }
+
+  protected void moveUnderXSDComplexTypeDefinition(XSDComplexTypeDefinition complexType)
+  {
+    int originalIndex = 0;
+    for (Iterator iterator = complexType.getAttributeContents().iterator(); iterator.hasNext();)
+    {
+      XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
+      if (attributeGroupContent instanceof XSDAttributeUse)
+      {
+        XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
+        if (attribute == selected)
+        {
+          complexType.getAttributeContents().remove(attribute.getContainer());
+          break;
+        }
+      }
+      originalIndex++;
+    }
+    int index = 0;
+    boolean addedBack = false;
+    List attributeGroupContents = complexType.getAttributeContents();
+    for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext();)
+    {
+      XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
+      if (attributeGroupContent instanceof XSDAttributeUse)
+      {
+        XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
+        if (insertType == INSERT_AFTER)
+        {
+          if (attribute == previousRefComponent)
+          {
+            complexType.getAttributeContents().add(index + 1, selected.getContainer());
+            addedBack = true;
+            break;
+          }
+        }
+        else if (insertType == INSERT_BEFORE)
+        {
+          if (attribute == nextRefComponent)
+          {
+            complexType.getAttributeContents().add(index, selected.getContainer());
+            addedBack = true;
+            break;
+          }
+        }
+      }
+      index++;
+    }
+    if (attributeGroupContents.size() == 0)
+    {
+      complexType.getAttributeContents().add(selected.getContainer());
+      addedBack = true;
+    }
+
+    if (!addedBack)
+    {
+      complexType.getAttributeContents().add(originalIndex, selected.getContainer());
+    }
+  }
+
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveXSDBaseAction.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveXSDBaseAction.java
new file mode 100644
index 0000000..c6d9906
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveXSDBaseAction.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.actions;
+
+import org.eclipse.jface.action.Action;
+
+public class MoveXSDBaseAction extends Action
+{
+
+  public MoveXSDBaseAction()
+  {
+    super();
+  }
+
+  public boolean canMove()
+  {
+    return true;
+  }
+
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveXSDElementAction.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveXSDElementAction.java
new file mode 100644
index 0000000..7e73ff5
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/MoveXSDElementAction.java
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.actions;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.xsd.XSDAttributeDeclaration;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDModelGroup;
+import org.eclipse.xsd.XSDParticle;
+import org.eclipse.xsd.XSDParticleContent;
+import org.w3c.dom.Node;
+
+public class MoveXSDElementAction extends MoveXSDBaseAction
+{
+  private static int INSERT_BEFORE = 0;
+  private static int INSERT_AFTER = 1;
+  private static int INSERT_DIRECT = 2;
+  protected List selectedNodes;
+  protected Node parentNode;
+  protected Node previousRefChild, nextRefChild;
+  int insertType;
+
+  XSDModelGroup parentModelGroup;
+  XSDConcreteComponent selected, previousRefComponent, nextRefComponent;
+  boolean insertAtEnd = true;
+
+  public MoveXSDElementAction(XSDModelGroup parentComponent, XSDConcreteComponent selected, XSDConcreteComponent previousRefChildComponent, XSDConcreteComponent nextRefChildComponent)
+  {
+    super();
+    this.parentModelGroup = parentComponent;
+    this.selected = selected;
+    this.previousRefComponent = previousRefChildComponent;
+    this.nextRefComponent = nextRefChildComponent;
+
+    if (parentComponent == null)
+      return;
+    parentNode = parentComponent.getElement();
+    nextRefChild = nextRefChildComponent != null ? nextRefChildComponent.getElement() : null;
+    previousRefChild = previousRefChildComponent != null ? previousRefChildComponent.getElement() : null;
+
+    if (nextRefComponent != null)
+    {
+      if (nextRefComponent.getContainer().getContainer() == parentModelGroup)
+      {
+        insertType = INSERT_BEFORE;
+      }
+    }
+    if (previousRefComponent != null)
+    {
+      if (previousRefComponent.getContainer().getContainer() == parentModelGroup)
+      {
+        insertType = INSERT_AFTER;
+      }
+    }
+    if (nextRefChildComponent == null && previousRefChildComponent == null)
+    {
+      insertType = INSERT_DIRECT;
+    }
+  }
+
+  public MoveXSDElementAction(XSDModelGroup parentComponent, XSDConcreteComponent selected, XSDConcreteComponent previousRefChildComponent, XSDConcreteComponent nextRefChildComponent, boolean insertAtEnd)
+  {
+    this(parentComponent, selected, previousRefChildComponent, nextRefChildComponent);
+    this.insertAtEnd = insertAtEnd;
+  }
+  
+  public boolean canMove()
+  {
+    boolean result = true;
+   
+    if (nextRefComponent instanceof XSDAttributeDeclaration || previousRefComponent instanceof XSDAttributeDeclaration || parentModelGroup == null)
+      return false;
+
+    return result;
+  }
+
+  /*
+   * @see IAction#run()
+   */
+  public void run()
+  {
+    int originalIndex = 0;
+    for (Iterator particles = parentModelGroup.getContents().iterator(); particles.hasNext();)
+    {
+      XSDParticle particle = (XSDParticle) particles.next();
+      XSDParticleContent particleContent = particle.getContent();
+      if (particleContent == selected)
+      {
+        parentModelGroup.getContents().remove(particle);
+        break;
+      }
+      originalIndex++;
+    }
+    int index = 0;
+    boolean addedBack = false;
+    if (insertType == INSERT_DIRECT)
+    {
+      XSDConcreteComponent container = selected.getContainer();
+      if (container != null)
+      {
+        XSDConcreteComponent container2 = container.getContainer();
+        if (container2 instanceof XSDModelGroup)
+        {
+          ((XSDModelGroup) container2).getContents().remove(container);
+        }
+        if (insertAtEnd)
+          parentModelGroup.getContents().add(container);
+        else
+          parentModelGroup.getContents().add(0, container);
+        addedBack = true;
+      }
+      return;
+    }
+
+    List particles = parentModelGroup.getContents();
+    for (Iterator iterator = particles.iterator(); iterator.hasNext();)
+    {
+      XSDParticle particle = (XSDParticle) iterator.next();
+      XSDParticleContent particleContent = particle.getContent();
+      if (insertType == INSERT_BEFORE)
+      {
+        if (particleContent == nextRefComponent)
+        {
+          parentModelGroup.getContents().add(index, selected.getContainer());
+          addedBack = true;
+          break;
+        }
+        if (selected == nextRefComponent && originalIndex == index)
+        {
+          parentModelGroup.getContents().add(index, selected.getContainer());
+          addedBack = true;
+          break;
+        }
+      }
+      else if (insertType == INSERT_AFTER)
+      {
+        if (particleContent == previousRefComponent)
+        {
+          parentModelGroup.getContents().add(index + 1, selected.getContainer());
+          addedBack = true;
+          break;
+        }
+        if (selected == previousRefComponent && originalIndex == index)
+        {
+          parentModelGroup.getContents().add(index, selected.getContainer());
+          addedBack = true;
+          break;
+        }
+      }
+      index++;
+    }
+    if (particles.size() == 0)
+    {
+      parentModelGroup.getContents().add(selected.getContainer());
+      addedBack = true;
+    }
+
+    if (!addedBack)
+    {
+      parentModelGroup.getContents().add(originalIndex, selected.getContainer());
+    }
+  }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/BaseDragAndDropCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/BaseDragAndDropCommand.java
new file mode 100644
index 0000000..a0baa3e
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/BaseDragAndDropCommand.java
@@ -0,0 +1,416 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.commands;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.FreeformLayout;
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Polyline;
+import org.eclipse.draw2d.RoundedRectangle;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.editparts.ScalableRootEditPart;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.wst.xsd.ui.internal.actions.MoveXSDBaseAction;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
+import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseFieldEditPart;
+import org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.ConnectableEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.TargetConnectionSpacingFigureEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.figures.GenericGroupFigure;
+import org.eclipse.xsd.XSDConcreteComponent;
+
+public abstract class BaseDragAndDropCommand extends BaseCommand
+{
+  protected static int ABOVE_IS_CLOSER = 0;
+  protected static int BELOW_IS_CLOSER = 1;
+  
+  protected EditPartViewer viewer;    
+  protected ChangeBoundsRequest request;
+  protected boolean canExecute;
+  protected GraphicalEditPart target;
+  
+  protected GraphicalEditPart leftSiblingEditPart;
+  protected GraphicalEditPart rightSiblingEditPart;
+  protected Point location;
+
+  protected ConnectableEditPart parentEditPart;
+  protected XSDConcreteComponent previousRefComponent = null, nextRefComponent = null, xsdComponentToDrag;
+  protected XSDBaseFieldEditPart itemToDrag;
+  protected Rectangle originalLocation;
+  protected Polyline polyLine;
+  
+  protected MoveXSDBaseAction action;
+  protected List targetSpacesList = new ArrayList();
+  protected int closerSibling;
+  
+  public BaseDragAndDropCommand(EditPartViewer viewer, ChangeBoundsRequest request)
+  {
+    this.viewer = viewer;                    
+    this.request = request;
+  }
+  
+  protected abstract void setup();
+ 
+  public PointList getConnectionPoints(Rectangle draggedFigureBounds)
+  {
+    PointList pointList = null;
+    if (target != null && itemToDrag != null && parentEditPart != null)
+    {
+      pointList = getConnectionPoints(parentEditPart, itemToDrag, draggedFigureBounds);
+    }
+    return pointList != null ? pointList : new PointList();
+  }
+  
+  // This method supports the preview connection line function related to drag and drop
+  //     
+  public PointList getConnectionPoints(ConnectableEditPart parentEditPart, BaseFieldEditPart childRefEditPart, Rectangle draggedFigureBounds)
+  {           
+    PointList pointList = new PointList();                         
+    int[] data = new int[1];
+    Point a = getConnectionPoint(parentEditPart, childRefEditPart, data);
+    if (a != null)
+    {   
+      int draggedFigureBoundsY = draggedFigureBounds.y + draggedFigureBounds.height/2;
+
+      pointList.addPoint(a); 
+      
+      if (data[0] == 0) // insert between 2 items
+      {                                         
+        int x = a.x + 5;
+        pointList.addPoint(new Point(x, a.y));
+        pointList.addPoint(new Point(x, draggedFigureBoundsY));        
+        pointList.addPoint(new Point(draggedFigureBounds.x, draggedFigureBoundsY));
+      }
+      else // insert at first or last position
+      {
+        pointList.addPoint(new Point(a.x, draggedFigureBoundsY));   
+        pointList.addPoint(new Point(draggedFigureBounds.x, draggedFigureBoundsY));
+      }
+    }       
+    return pointList;
+  }
+
+  // This method supports the preview connection line function related to drag and drop
+  //     
+  protected Point getConnectionPoint(ConnectableEditPart parentEditPart, BaseFieldEditPart childRefEditPart, int[] data)
+  {                      
+    Point point = null;     
+    List childList = parentEditPart.getChildren();         
+    if (parentEditPart.getFigure() instanceof GenericGroupFigure && childList.size() > 0)
+    {
+      point = new Point();
+
+      Rectangle r = getConnectedEditPartConnectionBounds(parentEditPart);  
+      point.x = r.x + r.width;
+      point.y = r.y + r.height/2;
+    }    
+    return point;
+  }
+
+  protected Rectangle getConnectedEditPartConnectionBounds(ConnectableEditPart editPart)
+  {
+    return getZoomedBounds(((GenericGroupFigure)editPart.getFigure()).getIconFigure().getBounds());
+  }
+    
+  public void redo()
+  {
+  }
+
+  public void undo()
+  {
+  }
+
+  public void execute()
+  {
+    if (canExecute)
+    {
+      action.run();
+    }
+  }
+  
+  public boolean canExecute()
+  {
+    return canExecute;
+  }
+  
+  protected void commonSetup(List siblings, GraphicalEditPart movingEditPart)
+  {
+    closerSibling = ABOVE_IS_CLOSER;
+    int pointerYLocation = location.y;
+    int index;
+    
+    for (index = 0; index < siblings.size(); index++)
+    {
+      GraphicalEditPart sibling = (GraphicalEditPart) siblings.get(index);
+      if (sibling instanceof BaseFieldEditPart)
+      {
+        int siblingYLocation = getZoomedBounds(sibling.getFigure().getBounds()).getCenter().y;
+
+        if (siblingYLocation > pointerYLocation)
+        {
+          rightSiblingEditPart = sibling;
+          if (index > 0)
+          {
+            leftSiblingEditPart = (GraphicalEditPart) siblings.get(index - 1);
+          }
+
+          if (leftSiblingEditPart != null && Math.abs(getZoomedBounds(leftSiblingEditPart.getFigure().getBounds()).getCenter().y - pointerYLocation) > Math.abs(siblingYLocation - pointerYLocation))
+          {
+            closerSibling = BELOW_IS_CLOSER;
+          }
+          break;
+        }
+      }
+    }
+
+    boolean isHandled = handleFirstAndLastDropTargets(index, siblings);
+    if (!isHandled)
+      handleOtherTargets(index);
+
+    calculateLeftAndRightXSDComponents();
+    
+    xsdComponentToDrag = (XSDConcreteComponent) ((XSDBaseAdapter) itemToDrag.getModel()).getTarget();    
+  }
+  
+  protected void calculateLeftAndRightXSDComponents()
+  {
+    if (leftSiblingEditPart instanceof XSDBaseFieldEditPart)
+    {
+      Object leftModel = ((XSDBaseFieldEditPart) leftSiblingEditPart).getModel();
+      previousRefComponent = null;
+      if (leftModel instanceof XSDBaseAdapter)
+      {
+        XSDBaseAdapter leftAdapter = (XSDBaseAdapter) leftModel;
+        previousRefComponent = (XSDConcreteComponent) leftAdapter.getTarget();
+      }
+    }
+
+    if (rightSiblingEditPart instanceof XSDBaseFieldEditPart)
+    {
+      Object rightModel = ((XSDBaseFieldEditPart) rightSiblingEditPart).getModel();
+      nextRefComponent = null;
+      if (rightModel instanceof XSDBaseAdapter)
+      {
+        XSDBaseAdapter rightAdapter = (XSDBaseAdapter) rightModel;
+        nextRefComponent = (XSDConcreteComponent) rightAdapter.getTarget();
+      }
+    }
+  }
+  
+  protected boolean handleFirstAndLastDropTargets(int index, List siblings)
+  {
+    // Handle case where you drop to first position
+    if (index == 0 && siblings.size() > 0)
+    {
+      leftSiblingEditPart = null;
+      rightSiblingEditPart = (GraphicalEditPart) siblings.get(0);
+      closerSibling = BELOW_IS_CLOSER;
+    }
+    // Handle case where you drop to last position
+    else if (index > 0 && index == siblings.size())
+    {
+      leftSiblingEditPart = (GraphicalEditPart) siblings.get(index - 1);
+      rightSiblingEditPart = null;
+    }
+    return false;
+  }
+
+  protected void handleOtherTargets(int index)
+  {
+    int in = 0;
+    ConnectableEditPart previousModelEditPart = null;
+    for (Iterator i = targetSpacesList.iterator(); i.hasNext();)
+    {
+      Object o = i.next();
+      previousModelEditPart = parentEditPart;
+      TargetConnectionSpacingFigureEditPart sp = (TargetConnectionSpacingFigureEditPart) o;
+      if (sp.getParent() instanceof ConnectableEditPart)
+        parentEditPart = (ConnectableEditPart)sp.getParent();
+      else
+        parentEditPart = null;
+      in++;
+      if (in > index)
+      {
+        if (closerSibling == ABOVE_IS_CLOSER)
+        {
+          parentEditPart = previousModelEditPart;
+        }
+        break;
+      }
+    }    
+  }
+  
+  protected List calculateFieldEditParts()
+  {
+    List list = target.getParent().getChildren();
+    List listOfFields = new ArrayList();
+    for (Iterator i = list.iterator(); i.hasNext();)
+    {
+      Object o = i.next();
+      if (o instanceof BaseFieldEditPart)
+      {
+        listOfFields.add(o);
+      }
+    }
+    return listOfFields;
+  }
+  
+  protected PointList drawLines(Polyline polyLine)
+  {
+    PointList pointList = new PointList();
+
+    if (leftSiblingEditPart != null)
+    {
+      Rectangle leftRectangle = getZoomedBounds(leftSiblingEditPart.getFigure().getBounds());
+      int xCoord = leftRectangle.x;
+      int yCoord = leftRectangle.y;
+      int height = leftRectangle.height;
+      int width = leftRectangle.width;
+
+      // Draw left end line
+      addLineToPolyline(polyLine, xCoord, yCoord + height + 3, xCoord, yCoord + height - 3);
+      addLineToPolyline(polyLine, xCoord, yCoord + height - 3, xCoord, yCoord + height);
+
+      // Draw horizontal line
+      addLineToPolyline(polyLine, xCoord, yCoord + height, xCoord + width, yCoord + height);
+
+      // Draw right end line
+      addLineToPolyline(polyLine, xCoord + width, yCoord + height, xCoord + width, yCoord + height - 3);
+      addLineToPolyline(polyLine, xCoord + width, yCoord + height, xCoord + width, yCoord + height + 3);
+    }
+    else if (rightSiblingEditPart != null)
+    {
+      Rectangle rightRectangle = getZoomedBounds(rightSiblingEditPart.getFigure().getBounds());
+      int xCoord = rightRectangle.x;
+      int yCoord = rightRectangle.y;
+      int width = rightRectangle.width;
+
+      // Draw left end line
+      addLineToPolyline(polyLine, xCoord, yCoord + 3, xCoord, yCoord - 3);
+      addLineToPolyline(polyLine, xCoord, yCoord - 3, xCoord, yCoord);
+
+      // Draw horizontal line
+      addLineToPolyline(polyLine, xCoord, yCoord, xCoord + width, yCoord);
+
+      // Draw right end line
+      addLineToPolyline(polyLine, xCoord + width, yCoord, xCoord + width, yCoord - 3);
+      addLineToPolyline(polyLine, xCoord + width, yCoord, xCoord + width, yCoord + 3);
+    }
+
+    return pointList;
+  }
+
+  protected Polyline addLineToPolyline(Polyline polyline, int x1, int y1, int x2, int y2)
+  {
+    polyline.addPoint(new Point(x1, y1));
+    polyline.addPoint(new Point(x2, y2));
+
+    return polyline;
+  }
+  
+  public IFigure getFeedbackFigure()
+  {
+    Figure panel = new Figure();
+    panel.setLayoutManager(new FreeformLayout());
+    panel.setOpaque(false);
+
+    Polyline feedbackFigure = new Polyline();
+    feedbackFigure.setLineWidth(2);
+    drawLines(feedbackFigure);
+    originalLocation = new Rectangle(feedbackFigure.getBounds());
+    panel.add(feedbackFigure);
+
+    polyLine = new Polyline();
+    polyLine.setLineStyle(Graphics.LINE_DASHDOT);
+    polyLine.setLineWidth(1);
+    panel.add(polyLine);
+    
+    panel.setBounds(originalLocation);
+    
+    addConnectorToParent(panel);
+
+    if (parentEditPart != null && parentEditPart.getFigure() instanceof GenericGroupFigure)
+    {
+      GenericGroupFigure fig = (GenericGroupFigure)parentEditPart.getFigure();
+      Rectangle iconBounds = getZoomedBounds(fig.getIconFigure().getBounds());
+      RoundedRectangle roundedRectangle = new RoundedRectangle();
+      roundedRectangle.setFill(false);
+      roundedRectangle.setOpaque(true);
+//      roundedRectangle.setBounds(new Rectangle(iconBounds.x, iconBounds.y, iconBounds.width - 1, iconBounds.height - 1));
+      roundedRectangle.setBounds(iconBounds);
+      panel.add(roundedRectangle);
+    }
+    return panel;
+  }
+  
+  protected void addConnectorToParent(IFigure p)
+  {
+    Rectangle r = originalLocation.getCopy();
+    Rectangle pBounds = r.getCopy();
+    PointList pointList = getConnectionPoints(r);
+
+    if (pointList != null && pointList.size() > 0)
+    {
+      polyLine.setPoints(pointList);
+      Point firstPoint = pointList.getFirstPoint();
+      if (firstPoint != null)
+      {
+        pBounds = pBounds.getUnion(new Rectangle(firstPoint.x, firstPoint.y, 1, 1));
+      }
+    }
+
+    if (parentEditPart != null)
+    {
+      if (parentEditPart.getFigure() instanceof GenericGroupFigure)
+      {
+        GenericGroupFigure fig = (GenericGroupFigure)parentEditPart.getFigure();
+        Rectangle iconBounds = getZoomedBounds(fig.getIconFigure().getBounds());
+        pBounds = pBounds.getUnion(iconBounds);
+      }
+    }
+
+    p.setBounds(pBounds);
+    p.validate();
+  }
+  
+  public Point getZoomedPoint(Point p)
+  {
+    double factor = ((ScalableRootEditPart)viewer.getRootEditPart()).getZoomManager().getZoom();
+
+    int x = (int)Math.round(p.x * factor);
+    int y = (int)Math.round(p.y * factor);
+
+    return new Point(x, y);
+  }
+  
+  public Rectangle getZoomedBounds(Rectangle r)
+  {
+    double factor = ((ScalableRootEditPart)viewer.getRootEditPart()).getZoomManager().getZoom();
+
+    int x = (int)Math.round(r.x * factor);
+    int y = (int)Math.round(r.y * factor);
+    int width = (int)Math.round(r.width * factor);
+    int height = (int)Math.round(r.height * factor);
+
+    return new Rectangle(x, y, width, height);
+  }
+
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/DragAndDropCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/DragAndDropCommand.java
deleted file mode 100644
index 28f1f76..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/DragAndDropCommand.java
+++ /dev/null
@@ -1,505 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors:
- *     IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.xsd.ui.internal.commands;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.draw2d.FigureCanvas;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PointList;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
-import org.eclipse.wst.xsd.ui.internal.actions.MoveAction;
-import org.eclipse.wst.xsd.ui.internal.actions.MoveAttributeAction;
-import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
-import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAttributeAdapter;
-import org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter;
-import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseFieldEditPart;
-import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.CompartmentEditPart;
-import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.ComplexTypeEditPart;
-import org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand;
-import org.eclipse.wst.xsd.ui.internal.design.editparts.AttributeGroupDefinitionEditPart;
-import org.eclipse.wst.xsd.ui.internal.design.editparts.ConnectableEditPart;
-import org.eclipse.wst.xsd.ui.internal.design.editparts.ModelGroupDefinitionReferenceEditPart;
-import org.eclipse.wst.xsd.ui.internal.design.editparts.ModelGroupEditPart;
-import org.eclipse.wst.xsd.ui.internal.design.editparts.TargetConnectionSpacingFigureEditPart;
-import org.eclipse.wst.xsd.ui.internal.design.editparts.XSDAttributesForAnnotationEditPart;
-import org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart;
-import org.eclipse.wst.xsd.ui.internal.design.editparts.XSDGroupsForAnnotationEditPart;
-import org.eclipse.wst.xsd.ui.internal.design.figures.GenericGroupFigure;
-import org.eclipse.xsd.XSDAttributeGroupDefinition;
-import org.eclipse.xsd.XSDConcreteComponent;
-import org.eclipse.xsd.XSDModelGroup;
-
-// TODO : clean and common up code
-public class DragAndDropCommand extends BaseCommand
-{ 
-  protected EditPartViewer viewer;    
-  protected ChangeBoundsRequest request;
-  protected BaseFieldEditPart previousChildRefEditPart, nextChildRefEditPart;    
-  public ModelGroupEditPart parentEditPart;
-  protected AttributeGroupDefinitionEditPart parentAttributeGroupEditPart;
-  protected XSDConcreteComponent parentComponent;
-  public Point location;
-  protected MoveAction action;
-  protected MoveAttributeAction moveAttributeAction;
-  protected boolean canExecute, isElementToDrag;
-  EditPart target;
-  XSDBaseFieldEditPart selected;
-  List modelGroupsList = new ArrayList();
-  List targetSpacesList = new ArrayList();
-  List attributeGroupsList = new ArrayList();
-  XSDConcreteComponent previousRefComponent = null, nextRefComponent = null;
-  ComplexTypeEditPart complexTypeEditPart;
-
-  public DragAndDropCommand(EditPartViewer viewer, ChangeBoundsRequest request)
-  {
-    this.viewer = viewer;                    
-    this.request = request;
-    setup();
-  }
-  
-  protected void setup()
-  {
-    location = request.getLocation();
-    target = viewer.findObjectAt(location);
-    
-    if (viewer instanceof ScrollingGraphicalViewer)
-    {  
-      ScrollingGraphicalViewer sgv = (ScrollingGraphicalViewer)viewer;
-      Point p = ((FigureCanvas)sgv.getControl()).getViewport().getViewLocation();
-      location.y += p.y;
-      location.x += p.x;
-    }
-    List list = request.getEditParts();
-    canExecute = false;
-    // allow drag and drop of only one selected object
-    if (list.size() == 1 && target instanceof BaseFieldEditPart)
-    {
-      List editPartsList = request.getEditParts();
-      List concreteComponentList = new ArrayList(editPartsList.size());
-      for (Iterator i = editPartsList.iterator(); i.hasNext(); )
-      {                                                       
-        EditPart editPart = (EditPart)i.next();
-        concreteComponentList.add(((XSDBaseAdapter)editPart.getModel()).getTarget());
-      }
-
-      Object itemToDrag = list.get(0);
-      if (itemToDrag instanceof XSDBaseFieldEditPart)
-      {
-    	  selected = (XSDBaseFieldEditPart) itemToDrag;
-    	  if (selected.getModel() instanceof XSDElementDeclarationAdapter)
-    	  {
-    		  isElementToDrag = true;
-    	  }
-    	  else if (selected.getModel() instanceof XSDBaseAttributeAdapter)
-    	  {
-    		  isElementToDrag = false;
-    	  }
-    	  else
-    	  {
-    		  return;
-    	  }
-
-    	  if (!isElementToDrag)
-    	  {
-    		  XSDAttributeGroupDefinition attributeGroup = null;
-    		  attributeGroupsList.clear();
-    		  targetSpacesList.clear();
-          parentAttributeGroupEditPart = null;
-          calculateAttributeGroupList();
-          EditPart compartment = target.getParent();
-
-          parentEditPart = null;
-          if (compartment != null)
-          {
-            List l = compartment.getChildren();
-            Rectangle rectangle = new Rectangle(0, 0, 0, 0);
-            int index = 0;
-            BaseFieldEditPart childGraphNodeEditPart = null;
-            for (Iterator i = l.iterator(); i.hasNext(); )
-            {
-              EditPart child = (EditPart)i.next();
-              if (child instanceof BaseFieldEditPart)
-              {
-                previousChildRefEditPart = childGraphNodeEditPart;
-                childGraphNodeEditPart = (BaseFieldEditPart)child;
-                rectangle = childGraphNodeEditPart.getFigure().getBounds();
-              
-                if (location.y < (rectangle.getCenter().y))
-                {
-                  nextChildRefEditPart = childGraphNodeEditPart;
-                  TargetConnectionSpacingFigureEditPart tSpace = (TargetConnectionSpacingFigureEditPart)targetSpacesList.get(index);
-                  if (tSpace.getParent() instanceof AttributeGroupDefinitionEditPart)
-                  {
-                    parentAttributeGroupEditPart = (AttributeGroupDefinitionEditPart)tSpace.getParent();
-                    attributeGroup = parentAttributeGroupEditPart.getXSDAttributeGroupDefinition().getResolvedAttributeGroupDefinition();
-                    parentComponent = attributeGroup;
-                  }
-                  else if (tSpace.getParent() instanceof XSDAttributesForAnnotationEditPart)
-                  {
-                    parentComponent = (XSDConcreteComponent)((XSDBaseAdapter)complexTypeEditPart.getModel()).getTarget(); 
-                  }
-                  break;
-                }            
-              }
-              else
-              {
-              // This is the annotation edit part
-              }
-              index ++;
-            }  
-          }
-          calculatePreviousAndNextEditParts();
-          moveAttributeAction = new MoveAttributeAction(parentComponent, concreteComponentList, previousRefComponent, nextRefComponent);
-          canExecute = moveAttributeAction.canMove();
-    	  }
-    	  else if (isElementToDrag)
-    	  {
-    		  XSDModelGroup targetModelGroup = null;
-    		  modelGroupsList.clear();
-    		  targetSpacesList.clear();
-    		  calculateModelGroupList();
-
-          List modelGroups = new ArrayList(modelGroupsList.size());
-          for (Iterator i = modelGroupsList.iterator(); i.hasNext(); )
-          {
-            ModelGroupEditPart editPart = (ModelGroupEditPart)i.next();
-            modelGroups.add(editPart.getXSDModelGroup());
-          }
-        
-          EditPart compartment = target.getParent();
-          parentEditPart = null;
-          if (compartment != null)
-          {
-            List l = compartment.getChildren();
-            Rectangle rectangle = new Rectangle(0, 0, 0, 0);
-            int index = 0;
-            BaseFieldEditPart childGraphNodeEditPart = null;
-            for (Iterator i = l.iterator(); i.hasNext(); )
-            {
-              EditPart child = (EditPart)i.next();
-              if (child instanceof BaseFieldEditPart)
-              {
-                previousChildRefEditPart = childGraphNodeEditPart;
-                childGraphNodeEditPart = (BaseFieldEditPart)child;
-                rectangle = childGraphNodeEditPart.getFigure().getBounds();
-              
-                if (location.y < (rectangle.getCenter().y))
-                {
-                  nextChildRefEditPart = childGraphNodeEditPart;
-                  TargetConnectionSpacingFigureEditPart tSpace = (TargetConnectionSpacingFigureEditPart)targetSpacesList.get(index);
-                  parentEditPart = (ModelGroupEditPart)tSpace.getParent();
-                  targetModelGroup = parentEditPart.getXSDModelGroup();
-                  break;
-                }            
-              }
-              else
-              {
-           	  // This is the annotation edit part
-              }
-              index ++;
-            }  
-          }
-          calculatePreviousAndNextEditParts();
-          action = new MoveAction(targetModelGroup, concreteComponentList, previousRefComponent, nextRefComponent);
-          canExecute = action.canMove();
-        }
-      }            
-    }     
-  }
-  
-  protected void calculatePreviousAndNextEditParts()
-  {
-    if (nextChildRefEditPart != null)
-    {
-      if (nextChildRefEditPart.getModel() instanceof XSDBaseAdapter)
-      {
-        nextRefComponent = (XSDConcreteComponent)((XSDBaseAdapter)nextChildRefEditPart.getModel()).getTarget();
-      }
-    }
-    if (previousChildRefEditPart != null)
-    {
-      if (previousChildRefEditPart.getModel() instanceof XSDBaseAdapter)
-      {
-       previousRefComponent = (XSDConcreteComponent)((XSDBaseAdapter)previousChildRefEditPart.getModel()).getTarget();
-      }
-    }
-
-  }
-  
-  protected void calculateAttributeGroupList()
-  {
-    EditPart editPart = target;
-    while (editPart != null)
-    {                     
-      if (editPart instanceof ComplexTypeEditPart)
-      {
-        complexTypeEditPart = (ComplexTypeEditPart)editPart;
-        List list = editPart.getChildren();
-        for (Iterator i = list.iterator(); i.hasNext(); )
-        {
-          Object child = i.next();
-          if (child instanceof CompartmentEditPart)
-          {
-            List compartmentList = ((CompartmentEditPart)child).getChildren();
-            for (Iterator it = compartmentList.iterator(); it.hasNext(); )
-            {
-              Object obj = it.next();
-              if (obj instanceof XSDAttributesForAnnotationEditPart)
-              {
-                XSDAttributesForAnnotationEditPart groups = (XSDAttributesForAnnotationEditPart)obj;
-                List groupList = groups.getChildren();
-                for (Iterator iter = groupList.iterator(); iter.hasNext(); )
-                {
-                  Object groupChild = iter.next();
-                  if (groupChild instanceof TargetConnectionSpacingFigureEditPart)
-                  {
-                    targetSpacesList.add(groupChild);
-                  }
-                  else if (groupChild instanceof AttributeGroupDefinitionEditPart)
-                  {
-                    AttributeGroupDefinitionEditPart attributeGroupEditPart = (AttributeGroupDefinitionEditPart)groupChild;
-                    attributeGroupsList.add(attributeGroupEditPart);
-                    attributeGroupsList.addAll(getAttributeGroupEditParts(attributeGroupEditPart));
-                  }
-                }
-              }
-            }
-          }
-        }   
-      }
-      editPart = editPart.getParent();
-    }
-   
-  }
-             
-  protected void calculateModelGroupList()
-  {
-    EditPart editPart = target;
-    while (editPart != null)
-    {                     
-      if (editPart instanceof ModelGroupEditPart)
-      {
-        ModelGroupEditPart modelGroupEditPart = (ModelGroupEditPart)editPart;
-        modelGroupsList.addAll(getModelGroupEditParts(modelGroupEditPart));
-      }
-      else if (editPart instanceof ComplexTypeEditPart ||
-               editPart instanceof ModelGroupDefinitionReferenceEditPart)
-      {
-        List list = editPart.getChildren();
-        for (Iterator i = list.iterator(); i.hasNext(); )
-        {
-          Object child = i.next();
-          if (child instanceof CompartmentEditPart)
-          {
-            List compartmentList = ((CompartmentEditPart)child).getChildren();
-            for (Iterator it = compartmentList.iterator(); it.hasNext(); )
-            {
-              Object obj = it.next();
-              if (obj instanceof XSDGroupsForAnnotationEditPart)
-              {
-                XSDGroupsForAnnotationEditPart groups = (XSDGroupsForAnnotationEditPart)obj;
-                List groupList = groups.getChildren();
-                for (Iterator iter = groupList.iterator(); iter.hasNext(); )
-                {
-                  Object groupChild = iter.next();
-                  if (groupChild instanceof ModelGroupEditPart)
-                  {
-                    ModelGroupEditPart modelGroupEditPart = (ModelGroupEditPart)groupChild;
-                    modelGroupsList.add(modelGroupEditPart);
-                    modelGroupsList.addAll(getModelGroupEditParts(modelGroupEditPart));
-                  }
-                }
-              }
-            }
-          }
-        }   
-      }
-      editPart = editPart.getParent();
-    }
-  }
-  
-  protected List getAttributeGroupEditParts(AttributeGroupDefinitionEditPart attributeGroupEditPart)
-  {
-    List groupList = new ArrayList();
-    List list = attributeGroupEditPart.getChildren();
-    for (Iterator i = list.iterator(); i.hasNext(); )
-    {
-      Object object = i.next();
-      if (object instanceof TargetConnectionSpacingFigureEditPart)
-      {
-        targetSpacesList.add(object);
-      }
-      else if (object instanceof AttributeGroupDefinitionEditPart)
-      {
-        AttributeGroupDefinitionEditPart groupRef = (AttributeGroupDefinitionEditPart)object;
-        List groupRefChildren = groupRef.getChildren();
-        for (Iterator it = groupRefChildren.iterator(); it.hasNext(); )
-        {
-         Object o = it.next();
-         if (o instanceof TargetConnectionSpacingFigureEditPart)
-         {
-           targetSpacesList.add(o);
-         }
-         else if (o instanceof AttributeGroupDefinitionEditPart)
-         {
-           AttributeGroupDefinitionEditPart aGroup = (AttributeGroupDefinitionEditPart)o;
-           groupList.add(aGroup);
-           groupList.addAll(getAttributeGroupEditParts(aGroup));
-         }
-        }
-      }
-    }   
-    return groupList;   
-  }
-  
-  
-  protected List getModelGroupEditParts(ModelGroupEditPart modelGroupEditPart)
-  {
-	  List modelGroupList = new ArrayList();
-    List list = modelGroupEditPart.getChildren();
-    for (Iterator i = list.iterator(); i.hasNext(); )
-    {
-      Object object = i.next();
-      if (object instanceof TargetConnectionSpacingFigureEditPart)
-      {
-    	targetSpacesList.add(object);
-      }
-      else if (object instanceof ModelGroupDefinitionReferenceEditPart)
-      {
-    	  ModelGroupDefinitionReferenceEditPart groupRef = (ModelGroupDefinitionReferenceEditPart)object;
-    	  List groupRefChildren = groupRef.getChildren();
-    	  for (Iterator it = groupRefChildren.iterator(); it.hasNext(); )
-    	  {
-    		 Object o = it.next();
-    		 if (o instanceof ModelGroupEditPart)
-    		 {
-   		    	ModelGroupEditPart aGroup = (ModelGroupEditPart)o;
-   		        modelGroupList.add(aGroup);
-   		        modelGroupList.addAll(getModelGroupEditParts(aGroup));
-    		 }
-    	  }
-      }
-      else if (object instanceof ModelGroupEditPart)
-      {
-    	ModelGroupEditPart aGroup = (ModelGroupEditPart)object;
-        modelGroupList.add(aGroup);
-        modelGroupList.addAll(getModelGroupEditParts(aGroup));
-      }
-    }   
-    return modelGroupList;
-  }
-  
-
-  public void execute()
-  {
-    if (canExecute)
-    { 
-      if (isElementToDrag)
-        action.run();
-      else
-        moveAttributeAction.run();
-    }
-  }     
-  
-  public void redo()
-  {
-
-  }  
-  
-  public void undo()
-  {
-  }     
-  
-  public boolean canExecute()
-  { 
-    return canExecute;
-  } 
-
-  public PointList getConnectionPoints(Rectangle draggedFigureBounds)
-  {             
-    PointList pointList = null;
-    if (isElementToDrag)
-    {
-      if (parentEditPart != null && nextChildRefEditPart != null)
-      {                                
-        pointList = getConnectionPoints(parentEditPart, nextChildRefEditPart, draggedFigureBounds);      
-      }
-    }
-    else
-    {
-      if (parentAttributeGroupEditPart!= null && nextChildRefEditPart != null)
-      {
-        pointList = getConnectionPoints(parentAttributeGroupEditPart, nextChildRefEditPart, draggedFigureBounds);
-      }
-    }
-    return pointList != null ? pointList : new PointList();
-  }
-  
-  // This method supports the preview connection line function related to drag and drop
-  //     
-  public PointList getConnectionPoints(ConnectableEditPart parentEditPart, BaseFieldEditPart childRefEditPart, Rectangle draggedFigureBounds)
-  {           
-    PointList pointList = new PointList();                         
-    int[] data = new int[1];
-    Point a = getConnectionPoint(parentEditPart, childRefEditPart, data);
-    if (a != null)
-    {   
-      int draggedFigureBoundsY = draggedFigureBounds.y + draggedFigureBounds.height/2;
-
-      pointList.addPoint(a); 
-      
-      if (data[0] == 0) // insert between 2 items
-      {                                         
-        int x = a.x + (draggedFigureBounds.x - a.x)/2;
-        pointList.addPoint(new Point(x, a.y));
-        pointList.addPoint(new Point(x, draggedFigureBoundsY));        
-        pointList.addPoint(new Point(draggedFigureBounds.x, draggedFigureBoundsY));
-      }
-      else // insert at first or last position
-      {
-        pointList.addPoint(new Point(a.x, draggedFigureBoundsY));   
-        pointList.addPoint(new Point(draggedFigureBounds.x, draggedFigureBoundsY));
-      }
-    }       
-    return pointList;
-  }
-
-  // This method supports the preview connection line function related to drag and drop
-  //     
-  protected Point getConnectionPoint(ConnectableEditPart parentEditPart, BaseFieldEditPart childRefEditPart, int[] data)
-  {                      
-    Point point = null;     
-    List childList = parentEditPart.getChildren();         
-                                                                                                                                               
-    if (parentEditPart.getFigure() instanceof GenericGroupFigure && childList.size() > 0)
-    {   
-      point = new Point();
-
-      Rectangle r = getConnectedEditPartConnectionBounds(parentEditPart);  
-      point.x = r.x + r.width;
-      point.y = r.y + r.height/2;
-    }    
-    return point;
-  }
-
-  protected Rectangle getConnectedEditPartConnectionBounds(ConnectableEditPart editPart)
-  {
-	return ((GenericGroupFigure)editPart.getFigure()).getIconFigure().getBounds();
-  }
-
-}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/XSDAttributeDragAndDropCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/XSDAttributeDragAndDropCommand.java
new file mode 100644
index 0000000..bd4a191
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/XSDAttributeDragAndDropCommand.java
@@ -0,0 +1,210 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.commands;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.wst.xsd.ui.internal.actions.MoveXSDAttributeAction;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeDeclarationAdapter;
+import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseFieldEditPart;
+import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.CompartmentEditPart;
+import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.ComplexTypeEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.AttributeGroupDefinitionEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.TargetConnectionSpacingFigureEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.XSDAttributesForAnnotationEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.figures.GenericGroupFigure;
+import org.eclipse.xsd.XSDAttributeDeclaration;
+import org.eclipse.xsd.XSDConcreteComponent;
+
+public class XSDAttributeDragAndDropCommand extends BaseDragAndDropCommand
+{
+  public XSDAttributeDragAndDropCommand(EditPartViewer viewer, ChangeBoundsRequest request, GraphicalEditPart target, XSDBaseFieldEditPart itemToDrag, Point location)
+  {
+    super(viewer, request);
+    this.target = target;
+    this.itemToDrag = itemToDrag;
+    this.location = location;
+    setup();
+  }
+
+  protected void setup()
+  {
+    canExecute = false;
+
+    // Drop target is attribute group ref
+    if (target instanceof AttributeGroupDefinitionEditPart)
+    {
+      parentEditPart = (AttributeGroupDefinitionEditPart) target;
+      if (((GenericGroupFigure) parentEditPart.getFigure()).getIconFigure().getBounds().contains(location))
+      {
+        xsdComponentToDrag = (XSDConcreteComponent) ((XSDAttributeDeclarationAdapter) itemToDrag.getModel()).getTarget();
+        action = new MoveXSDAttributeAction(((AttributeGroupDefinitionEditPart) parentEditPart).getXSDAttributeGroupDefinition(), xsdComponentToDrag, null, null);
+        canExecute = action.canMove();
+      }
+    }
+    else if (target instanceof BaseFieldEditPart)
+    {
+      targetSpacesList = new ArrayList();
+      // Calculate the list of all sibling field edit parts;
+      List targetEditPartSiblings = calculateFieldEditParts();
+      calculateAttributeGroupList();
+
+      // Get 'left' and 'right' siblings
+      doDrop(targetEditPartSiblings, itemToDrag);
+    }
+  }
+
+  protected void doDrop(List siblings, GraphicalEditPart movingEditPart)
+  {
+    commonSetup(siblings, movingEditPart);
+
+    if (previousRefComponent instanceof XSDAttributeDeclaration && nextRefComponent instanceof XSDAttributeDeclaration)
+    {
+      XSDConcreteComponent parent = ((XSDAttributeDeclaration) previousRefComponent).getContainer().getContainer();
+      if (closerSibling == BELOW_IS_CLOSER)
+      {
+        parent = ((XSDAttributeDeclaration) nextRefComponent).getContainer().getContainer();
+      }
+      action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
+    }
+    else if (previousRefComponent == null && nextRefComponent instanceof XSDAttributeDeclaration)
+    {
+      XSDConcreteComponent parent = ((XSDAttributeDeclaration) nextRefComponent).getContainer().getContainer();
+      if (closerSibling == ABOVE_IS_CLOSER)
+      {
+        if (leftSiblingEditPart == null)
+        {
+          action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
+        }
+        else if (parentEditPart != null)
+        {
+          action = new MoveXSDAttributeAction(parentEditPart.getXSDConcreteComponent(), xsdComponentToDrag, previousRefComponent, nextRefComponent);
+        }
+      }
+      else
+      {
+        action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
+      }
+    }
+    else if (previousRefComponent instanceof XSDAttributeDeclaration && nextRefComponent == null)
+    {
+      XSDConcreteComponent parent = ((XSDAttributeDeclaration) previousRefComponent).getContainer().getContainer();
+      if (closerSibling == ABOVE_IS_CLOSER)
+      {
+        action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
+      }
+      else
+      {
+        if (rightSiblingEditPart == null)
+        {
+          action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
+        }
+        else
+        {
+          action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
+        }
+      }
+    }
+
+    if (action != null)
+      canExecute = action.canMove();
+  }
+
+  
+  // Attribute Group related helper method 
+  
+  protected void calculateAttributeGroupList()
+  {
+    EditPart editPart = target;
+    while (editPart != null)
+    {
+      if (editPart instanceof ComplexTypeEditPart)
+      {
+        List list = editPart.getChildren();
+        for (Iterator i = list.iterator(); i.hasNext();)
+        {
+          Object child = i.next();
+          if (child instanceof CompartmentEditPart)
+          {
+            List compartmentList = ((CompartmentEditPart) child).getChildren();
+            for (Iterator it = compartmentList.iterator(); it.hasNext();)
+            {
+              Object obj = it.next();
+              if (obj instanceof XSDAttributesForAnnotationEditPart)
+              {
+                XSDAttributesForAnnotationEditPart groups = (XSDAttributesForAnnotationEditPart) obj;
+                List groupList = groups.getChildren();
+                for (Iterator iter = groupList.iterator(); iter.hasNext();)
+                {
+                  Object groupChild = iter.next();
+                  if (groupChild instanceof TargetConnectionSpacingFigureEditPart)
+                  {
+                    targetSpacesList.add(groupChild);
+                  }
+                  else if (groupChild instanceof AttributeGroupDefinitionEditPart)
+                  {
+                    getAttributeGroupEditParts((AttributeGroupDefinitionEditPart) groupChild);
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+      editPart = editPart.getParent();
+    }
+
+  }
+
+  // Attribute Group related helper method
+  
+  protected List getAttributeGroupEditParts(AttributeGroupDefinitionEditPart attributeGroupEditPart)
+  {
+    List groupList = new ArrayList();
+    List list = attributeGroupEditPart.getChildren();
+    for (Iterator i = list.iterator(); i.hasNext();)
+    {
+      Object object = i.next();
+      if (object instanceof TargetConnectionSpacingFigureEditPart)
+      {
+        targetSpacesList.add(object);
+      }
+      else if (object instanceof AttributeGroupDefinitionEditPart)
+      {
+        AttributeGroupDefinitionEditPart groupRef = (AttributeGroupDefinitionEditPart) object;
+        List groupRefChildren = groupRef.getChildren();
+        for (Iterator it = groupRefChildren.iterator(); it.hasNext();)
+        {
+          Object o = it.next();
+          if (o instanceof TargetConnectionSpacingFigureEditPart)
+          {
+            targetSpacesList.add(o);
+          }
+          else if (o instanceof AttributeGroupDefinitionEditPart)
+          {
+            AttributeGroupDefinitionEditPart aGroup = (AttributeGroupDefinitionEditPart) o;
+            groupList.add(aGroup);
+            groupList.addAll(getAttributeGroupEditParts(aGroup));
+          }
+        }
+      }
+    }
+    return groupList;
+  }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/XSDElementDragAndDropCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/XSDElementDragAndDropCommand.java
new file mode 100644
index 0000000..3bb6b7c
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/commands/XSDElementDragAndDropCommand.java
@@ -0,0 +1,261 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.commands;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.wst.xsd.ui.internal.actions.MoveXSDElementAction;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter;
+import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseFieldEditPart;
+import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.CompartmentEditPart;
+import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.ComplexTypeEditPart;
+import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.StructureEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.ModelGroupDefinitionReferenceEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.ModelGroupEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.TargetConnectionSpacingFigureEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.XSDGroupsForAnnotationEditPart;
+import org.eclipse.wst.xsd.ui.internal.design.figures.GenericGroupFigure;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.eclipse.xsd.XSDModelGroup;
+
+
+public class XSDElementDragAndDropCommand extends BaseDragAndDropCommand
+{
+  protected ModelGroupEditPart topMostGroup;
+
+  public XSDElementDragAndDropCommand(EditPartViewer viewer, ChangeBoundsRequest request, GraphicalEditPart target, XSDBaseFieldEditPart itemToDrag, Point location)
+  {
+    super(viewer, request);
+    this.target = target;
+    this.itemToDrag = itemToDrag;
+    this.location = location;
+    setup();
+  }
+
+  protected void setup()
+  {
+    canExecute = false;
+
+    // Drop target is model group
+    if (target instanceof ModelGroupEditPart)
+    {
+      parentEditPart = (ModelGroupEditPart) target;
+      if (((GenericGroupFigure) parentEditPart.getFigure()).getIconFigure().getBounds().contains(location))
+      {
+        xsdComponentToDrag = (XSDConcreteComponent) ((XSDElementDeclarationAdapter) itemToDrag.getModel()).getTarget();
+        action = new MoveXSDElementAction(((ModelGroupEditPart) target).getXSDModelGroup(), xsdComponentToDrag, null, null);
+        canExecute = action.canMove();
+      }
+    }
+    else if (target instanceof BaseFieldEditPart)
+    {
+      targetSpacesList = new ArrayList();
+      // Calculate the list of all sibling field edit parts;
+      List targetEditPartSiblings = calculateFieldEditParts();
+      calculateModelGroupList();
+
+      doDrop(targetEditPartSiblings, itemToDrag);
+    }
+  }
+
+  protected void doDrop(List siblings, GraphicalEditPart movingEditPart)
+  {
+    commonSetup(siblings, movingEditPart);
+
+    // Can common this code up with XSDAttributeDragAndDropCommand... 
+    if (previousRefComponent instanceof XSDElementDeclaration && nextRefComponent instanceof XSDElementDeclaration)
+    {
+      XSDModelGroup modelGroup = (XSDModelGroup) ((XSDElementDeclaration) previousRefComponent).getContainer().getContainer();
+      if (parentEditPart != null)
+        modelGroup = ((ModelGroupEditPart) parentEditPart).getXSDModelGroup();
+      action = new MoveXSDElementAction(modelGroup, xsdComponentToDrag, previousRefComponent, nextRefComponent);
+    }
+    else if (previousRefComponent == null && nextRefComponent instanceof XSDElementDeclaration)
+    {
+      if (closerSibling == ABOVE_IS_CLOSER)
+      {
+        if (leftSiblingEditPart == null)
+        {
+          action = new MoveXSDElementAction(topMostGroup.getXSDModelGroup(), xsdComponentToDrag, null, null, false);
+        }
+        else if (parentEditPart != null)
+        {
+          action = new MoveXSDElementAction(((ModelGroupEditPart) parentEditPart).getXSDModelGroup(), xsdComponentToDrag, previousRefComponent, nextRefComponent);
+        }
+      }
+      else
+      {
+        XSDModelGroup modelGroup = (XSDModelGroup) ((XSDElementDeclaration) nextRefComponent).getContainer().getContainer();
+        action = new MoveXSDElementAction(modelGroup, xsdComponentToDrag, previousRefComponent, nextRefComponent);
+      }
+    }
+    else if (previousRefComponent instanceof XSDElementDeclaration && nextRefComponent == null)
+    {
+      XSDModelGroup modelGroup = (XSDModelGroup) ((XSDElementDeclaration) previousRefComponent).getContainer().getContainer();
+      if (parentEditPart != null)
+        modelGroup = ((ModelGroupEditPart) parentEditPart).getXSDModelGroup();
+      if (closerSibling == ABOVE_IS_CLOSER)
+      {
+        action = new MoveXSDElementAction(modelGroup, xsdComponentToDrag, previousRefComponent, nextRefComponent);
+      }
+      else
+      {
+        if (rightSiblingEditPart == null)
+        {
+          action = new MoveXSDElementAction(topMostGroup.getXSDModelGroup(), xsdComponentToDrag, null, null, true);
+        }
+        else
+        {
+          action = new MoveXSDElementAction(modelGroup, xsdComponentToDrag, previousRefComponent, nextRefComponent);
+        }
+      }
+    }
+
+    if (action != null)
+      canExecute = action.canMove();
+  }
+
+  /**
+   * overrides base
+   */
+  protected boolean handleFirstAndLastDropTargets(int index, List siblings)
+  {
+    // This boolean is to handle the Top and Bottom drop targets for which we want to drop
+    // to the top most model group
+    // TODO: I need to rearrange this code better
+    boolean isHandled = false;
+    int pointerYLocation = location.y;
+    // We need to find the parent editpart, which is the model group
+    // Handle case where you drop to first position
+    if (index == 0 && siblings.size() > 0)
+    {
+      leftSiblingEditPart = null;
+      rightSiblingEditPart = (GraphicalEditPart) siblings.get(0);
+      int siblingYLocation = getZoomedBounds(rightSiblingEditPart.getFigure().getBounds()).getCenter().y;
+      closerSibling = BELOW_IS_CLOSER;
+      if (Math.abs(pointerYLocation - siblingYLocation) > getZoomedBounds(rightSiblingEditPart.getFigure().getBounds()).height / 4)
+      {
+        isHandled = true;
+        parentEditPart = topMostGroup;
+        if (topMostGroup != null)
+          closerSibling = ABOVE_IS_CLOSER;
+      }
+    }
+    // Handle case where you drop to last position
+    if (index > 0 && index == siblings.size())
+    {
+      leftSiblingEditPart = (GraphicalEditPart) siblings.get(index - 1);
+      int siblingYLocation = getZoomedBounds(leftSiblingEditPart.getFigure().getBounds()).getCenter().y;
+      if (Math.abs(pointerYLocation - siblingYLocation) > getZoomedBounds(leftSiblingEditPart.getFigure().getBounds()).height / 4)
+      {
+        isHandled = true;
+        parentEditPart = topMostGroup;
+        if (topMostGroup != null)
+          closerSibling = BELOW_IS_CLOSER;
+      }
+    }
+    return isHandled;
+  }
+
+  // Methods specific to element as drag source
+  
+  // Model Group related helper method
+  protected void calculateModelGroupList()
+  {
+    EditPart editPart = target;
+    while (editPart != null)
+    {
+      if (editPart instanceof ModelGroupEditPart)
+      {
+        getModelGroupEditParts((ModelGroupEditPart) editPart);
+      }
+      else if (editPart instanceof ComplexTypeEditPart || editPart instanceof StructureEditPart)
+      {
+        boolean foundTop = false;
+        List list = editPart.getChildren();
+        for (Iterator i = list.iterator(); i.hasNext();)
+        {
+          Object child = i.next();
+          if (child instanceof CompartmentEditPart)
+          {
+            List compartmentList = ((CompartmentEditPart) child).getChildren();
+            for (Iterator it = compartmentList.iterator(); it.hasNext();)
+            {
+              Object obj = it.next();
+              if (obj instanceof XSDGroupsForAnnotationEditPart)
+              {
+                XSDGroupsForAnnotationEditPart groups = (XSDGroupsForAnnotationEditPart) obj;
+                List groupList = groups.getChildren();
+                for (Iterator iter = groupList.iterator(); iter.hasNext();)
+                {
+                  Object groupChild = iter.next();
+                  if (groupChild instanceof ModelGroupEditPart)
+                  {
+                    if (!foundTop)
+                    {
+                      foundTop = true;
+                      topMostGroup = (ModelGroupEditPart) groupChild;
+                    }
+                    getModelGroupEditParts((ModelGroupEditPart) groupChild);
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+      editPart = editPart.getParent();
+    }
+  }
+
+  // Model Group related helper method
+  
+  protected List getModelGroupEditParts(ModelGroupEditPart modelGroupEditPart)
+  {
+    List modelGroupList = new ArrayList();
+    List list = modelGroupEditPart.getChildren();
+    for (Iterator i = list.iterator(); i.hasNext();)
+    {
+      Object object = i.next();
+      if (object instanceof TargetConnectionSpacingFigureEditPart)
+      {
+        targetSpacesList.add(object);
+      }
+      else if (object instanceof ModelGroupDefinitionReferenceEditPart)
+      {
+        ModelGroupDefinitionReferenceEditPart groupRef = (ModelGroupDefinitionReferenceEditPart) object;
+        List groupRefChildren = groupRef.getChildren();
+        for (Iterator it = groupRefChildren.iterator(); it.hasNext();)
+        {
+          Object o = it.next();
+          if (o instanceof ModelGroupEditPart)
+          {
+            getModelGroupEditParts((ModelGroupEditPart) o);
+          }
+        }
+      }
+      else if (object instanceof ModelGroupEditPart)
+      {
+        getModelGroupEditParts((ModelGroupEditPart) object);
+      }
+    }
+    return modelGroupList;
+  }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editpolicies/DragAndDropEditPolicy.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editpolicies/DragAndDropEditPolicy.java
index e5bbbcc..142e3f6 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editpolicies/DragAndDropEditPolicy.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editpolicies/DragAndDropEditPolicy.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
+ * Copyright (c) 2001, 2007 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -10,10 +10,21 @@
  *******************************************************************************/
 package org.eclipse.wst.xsd.ui.internal.design.editpolicies;
 
+import java.util.List;
+
+import org.eclipse.draw2d.FigureCanvas;
+import org.eclipse.draw2d.geometry.Point;
 import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.GraphicalEditPart;
 import org.eclipse.gef.Request;
 import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.wst.xsd.ui.internal.commands.DragAndDropCommand;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAttributeAdapter;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter;
+import org.eclipse.wst.xsd.ui.internal.commands.BaseDragAndDropCommand;
+import org.eclipse.wst.xsd.ui.internal.commands.XSDAttributeDragAndDropCommand;
+import org.eclipse.wst.xsd.ui.internal.commands.XSDElementDragAndDropCommand;
+import org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart;
+
 
 public class DragAndDropEditPolicy extends org.eclipse.gef.editpolicies.GraphicalEditPolicy
 { 
@@ -34,12 +45,48 @@
   
   public org.eclipse.gef.commands.Command getCommand(Request request)
   {             
-    DragAndDropCommand command = null;                            
+    BaseDragAndDropCommand command = null;                            
     if (request instanceof ChangeBoundsRequest)
     {
-      command = new DragAndDropCommand(viewer, (ChangeBoundsRequest)request);
-      selectionHandlesEditPolicy.setDragAndDropCommand(command);
+      ChangeBoundsRequest changeBoundsRequest = (ChangeBoundsRequest)request;
+      Point location = changeBoundsRequest.getLocation();
+      
+      GraphicalEditPart target = (GraphicalEditPart)viewer.findObjectAt(location);
+      location = getPointerLocation(changeBoundsRequest.getLocation());
+      ((GraphicalEditPart)viewer.getRootEditPart()).getFigure().translateToRelative(location);
+
+      List list = changeBoundsRequest.getEditParts();
+      // allow drag and drop of only one selected object
+      if (list.size() == 1)
+      {
+        Object itemToDrag = list.get(0);
+        if (itemToDrag instanceof XSDBaseFieldEditPart)
+        {
+          XSDBaseFieldEditPart selected = (XSDBaseFieldEditPart) itemToDrag;
+          if (selected.getModel() instanceof XSDElementDeclarationAdapter)
+          {
+            command = new XSDElementDragAndDropCommand(viewer, (ChangeBoundsRequest)request, target, selected, location);
+            selectionHandlesEditPolicy.setDragAndDropCommand(command);
+          }
+          else if (selected.getModel() instanceof XSDBaseAttributeAdapter)
+          {
+            command = new XSDAttributeDragAndDropCommand(viewer, (ChangeBoundsRequest)request, target, selected, location);
+            selectionHandlesEditPolicy.setDragAndDropCommand(command);
+          }
+        }
+      }
     } 
     return command;             
-  }                                                     
+  }                         
+  
+  protected Point getPointerLocation(Point origPointerLocation)
+  {
+     Point compensatedLocation = origPointerLocation;
+     FigureCanvas figureCanvas = (FigureCanvas) viewer.getControl();
+     int yOffset = figureCanvas.getViewport().getVerticalRangeModel().getValue();
+     int xOffset = figureCanvas.getViewport().getHorizontalRangeModel().getValue();
+     compensatedLocation.y = compensatedLocation.y + yOffset;
+     compensatedLocation.x = compensatedLocation.x + xOffset;
+     return compensatedLocation;
+  }
 }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editpolicies/SelectionHandlesEditPolicyImpl.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editpolicies/SelectionHandlesEditPolicyImpl.java
index 655916c..d7f0b39 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editpolicies/SelectionHandlesEditPolicyImpl.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editpolicies/SelectionHandlesEditPolicyImpl.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
+ * Copyright (c) 2001, 2007 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -10,75 +10,34 @@
  *******************************************************************************/
 package org.eclipse.wst.xsd.ui.internal.design.editpolicies;
                                  
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.draw2d.ColorConstants;
-import org.eclipse.draw2d.Figure;
-import org.eclipse.draw2d.FigureUtilities;
-import org.eclipse.draw2d.FreeformLayout;
-import org.eclipse.draw2d.Graphics;
 import org.eclipse.draw2d.IFigure;
 import org.eclipse.draw2d.Polyline;
 import org.eclipse.draw2d.RectangleFigure;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PointList;
 import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
 import org.eclipse.gef.Request;
-import org.eclipse.gef.handles.MoveHandle;
-import org.eclipse.gef.handles.MoveHandleLocator;
 import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseEditPart;
 import org.eclipse.wst.xsd.ui.internal.adt.design.editpolicies.ADTSelectionFeedbackEditPolicy;
-import org.eclipse.wst.xsd.ui.internal.commands.DragAndDropCommand;
-
+import org.eclipse.wst.xsd.ui.internal.commands.BaseDragAndDropCommand;
 
 public class SelectionHandlesEditPolicyImpl	extends ADTSelectionFeedbackEditPolicy
 {
   protected IFigure feedback;
   protected Rectangle originalLocation;
-  protected DragAndDropCommand dragAndDropCommand;
+  protected BaseDragAndDropCommand dragAndDropCommand;
   protected Polyline polyLine;
   protected RectangleFigure ghostShape;
 
-  protected List createSelectionHandles()
-  {              
-    List list = new ArrayList();
-    EditPart editPart = getHost();
-     
-    if (editPart instanceof GraphicalEditPart)
-    {
-      GraphicalEditPart graphicalEditPart = (GraphicalEditPart)editPart;
-      IFigure figure = (graphicalEditPart instanceof BaseEditPart) ? 
-                          ((BaseEditPart)graphicalEditPart).getFigure() :
-                          graphicalEditPart.getFigure();
-   
-      Cursor cursorFigure = figure.getCursor();
-      MoveHandleLocator loc = new MoveHandleLocator(figure);    
-      MoveHandle moveHandle = new MoveHandle(graphicalEditPart, loc);     
-      moveHandle.setCursor(cursorFigure);
-      list.add(moveHandle);
-    }
-
-    return list;
-  }   
-  
-
   public boolean understandsRequest(Request request)
   {    
     boolean result = false;
 
-	  if (REQ_MOVE.equals(request.getType()))
+    if (REQ_MOVE.equals(request.getType()))
     {  
-		  result = false; // return false to disable move for now 
+      result = false; 
     }
     else
     {
-	    result = super.understandsRequest(request);
+      result = super.understandsRequest(request);
     }
     return result;
   }
@@ -89,109 +48,23 @@
     return null;  
   }   
 
-  public void setDragAndDropCommand(DragAndDropCommand dragAndDropCommand)
+  public void setDragAndDropCommand(BaseDragAndDropCommand dragAndDropCommand)
   {
     this.dragAndDropCommand = dragAndDropCommand;
   }
 
-  protected org.eclipse.gef.commands.Command getMoveCommand(ChangeBoundsRequest request) 
-  {
-	  ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_MOVE_CHILDREN);
-	  req.setEditParts(getHost());
-	
-	  req.setMoveDelta(request.getMoveDelta());
-	  req.setSizeDelta(request.getSizeDelta());
-	  req.setLocation(request.getLocation());
-
-	  return getHost().getParent().getCommand(req);
-  } 
-
   public void showSourceFeedback(Request request)
-  {  	
-	  if (REQ_MOVE.equals(request.getType()) ||
-		  REQ_ADD.equals(request.getType()))
-		  showChangeBoundsFeedback((ChangeBoundsRequest)request);
-  }
-
-  protected void showChangeBoundsFeedback(ChangeBoundsRequest request)
-  {
-  	IFigure p = getDragSourceFeedbackFigure();
-  	Rectangle r = originalLocation.getTranslated(request.getMoveDelta());
-  	Dimension resize = request.getSizeDelta();
-  	r.width += resize.width;
-  	r.height+= resize.height;
-  
-  	((GraphicalEditPart)getHost()).getFigure().translateToAbsolute(r);
-   
-  	p.translateToRelative(r);
-    Rectangle pBounds = r.getCopy();                            
-
-    if (dragAndDropCommand != null && dragAndDropCommand.canExecute())
-    {
-      int size = request.getEditParts().size();
-      if (size > 0 && request.getEditParts().get(size - 1) == getHost())
-      {         
-        PointList pointList = dragAndDropCommand.getConnectionPoints(r);
-        if (pointList != null && pointList.size() > 0)
-        {
-          polyLine.setPoints(pointList);
-          
-          Point firstPoint = pointList.getFirstPoint();
-          if (firstPoint != null)
-          {
-            pBounds = pBounds.getUnion(new Rectangle(firstPoint.x, firstPoint.y, 1, 1));
+  {   
+      eraseChangeBoundsFeedback(null);
+      if (dragAndDropCommand != null && dragAndDropCommand.canExecute()) {
+        if (REQ_MOVE.equals(request.getType()) || REQ_ADD.equals(request.getType())) {
+          if (dragAndDropCommand != null && dragAndDropCommand.getFeedbackFigure() != null) {
+            feedback = dragAndDropCommand.getFeedbackFigure();
+            addFeedback(feedback);
           }
         }
       }
-    }
-    p.setBounds(pBounds);
-    ghostShape.setBounds(r);
-  	p.validate();
-  }        
-
-
-
-
-  protected IFigure getDragSourceFeedbackFigure() 
-  {
-    EditPart editPart = getHost(); 
-    if (feedback == null && editPart instanceof BaseEditPart)
-    {                                       
-      BaseEditPart baseEditPart = (BaseEditPart)editPart;
-		  originalLocation = new Rectangle(baseEditPart.getFigure().getBounds());
-		  feedback = createDragSourceFeedbackFigure(baseEditPart.getFigure());
-	  }
-	  return feedback;
-  }  
-
-  protected IFigure createDragSourceFeedbackFigure(IFigure draggedFigure)
-  {
-		// Use a ghost rectangle for feedback  
-    Figure panel = new Figure();
-    panel.setLayoutManager(new FreeformLayout());
-
-		ghostShape = new RectangleFigure();
-		FigureUtilities.makeGhostShape(ghostShape);
-		ghostShape.setLineStyle(Graphics.LINE_DASHDOT);
-		ghostShape.setForegroundColor(ColorConstants.white);
-    ghostShape.setOpaque(false);
-    
-    Rectangle r = draggedFigure.getBounds();
-    panel.setOpaque(false);
-    panel.add(ghostShape);                 
-
-    polyLine = new Polyline();                         
-    //polyLine.setLineStyle(Graphics.LINE_DASHDOT);      
-    polyLine.setLineWidth(1);
-    panel.add(polyLine);
-
-    panel.setBounds(r);
-		ghostShape.setBounds(r);
-
-		addFeedback(panel);
-
-		return panel;
-	} 
+  }
 
   public void deactivate()
   {