diff options
author | kchong | 2007-06-13 18:39:41 +0000 |
---|---|---|
committer | kchong | 2007-06-13 18:39:41 +0000 |
commit | fef3a5c8fbf1f810dd26874cc6841b6c7150c750 (patch) | |
tree | 6530a47d8f447b92748f9a981490736357433d36 /bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal | |
parent | 7123e00172aa2bf21a8d6c0e13d17d2b1ca17df4 (diff) | |
download | webtools.sourceediting-fef3a5c8fbf1f810dd26874cc6841b6c7150c750.tar.gz webtools.sourceediting-fef3a5c8fbf1f810dd26874cc6841b6c7150c750.tar.xz webtools.sourceediting-fef3a5c8fbf1f810dd26874cc6841b6c7150c750.zip |
[190326] Selection of newly added element is incorrect. PMC approved
Diffstat (limited to 'bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal')
-rw-r--r-- | bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/DesignViewGraphicalViewer.java | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/DesignViewGraphicalViewer.java b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/DesignViewGraphicalViewer.java index a2289e4301..5ab8babf76 100644 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/DesignViewGraphicalViewer.java +++ b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/DesignViewGraphicalViewer.java @@ -24,6 +24,7 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IEditorPart; import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.IHolderEditPart; import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.RootContentEditPart; +import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.StructureEditPart; import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement; import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IModelProxy; import org.eclipse.wst.xsd.ui.internal.adt.editor.CommonSelectionManager; @@ -214,8 +215,56 @@ public class DesignViewGraphicalViewer extends ScrollingGraphicalViewer implemen EditPart editPart = getEditPart((EditPart)i.next(), object); if (editPart != null) { - result = editPart; - break; + // First check to see if there is a selection + ISelection currentSelection = getSelection(); + + // If there is a selection then we will try to find the + // target edit part that is a child of the enclosing container. + // This is handy when you add an element to a structured edit part + // then you want to select the element immediately and put it in + // direct edit mode + if (currentSelection != null) + { + if (currentSelection instanceof StructuredSelection) + { + EditPart targetStructureEditPart = (EditPart)((StructuredSelection)currentSelection).getFirstElement(); + if (targetStructureEditPart != null) + { + while (targetStructureEditPart != null) + { + if (targetStructureEditPart instanceof StructureEditPart) + { + break; + } + targetStructureEditPart = targetStructureEditPart.getParent(); + } + } + EditPart potentialEditPartToSelect = editPart; + + while (potentialEditPartToSelect != null) + { + if (potentialEditPartToSelect instanceof StructureEditPart) + { + break; + } + potentialEditPartToSelect = potentialEditPartToSelect.getParent(); + } + + // If we found a potential edit part to select then return it + // OR, if there is no target found, then we should just return + // the edit part we found + if (potentialEditPartToSelect == targetStructureEditPart || potentialEditPartToSelect == null || targetStructureEditPart == null) + { + result = editPart; + break; + } + } + } + else // Otherwise just find the first one and return + { + result = editPart; + break; + } } } } |