Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 149772 Details for
Bug 247136
[outline] ArrayIndexOutOfBoundsException occurs when a node is moved to its parent by drag & drop
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Combined Patch of 247124 and 247136
clipboard.txt (text/plain), 5.00 KB, created by
David Carver
on 2009-10-16 11:50:30 EDT
(
hide
)
Description:
Combined Patch of 247124 and 247136
Filename:
MIME Type:
Creator:
David Carver
Created:
2009-10-16 11:50:30 EDT
Size:
5.00 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.wst.dtd.ui >Index: src/org/eclipse/wst/dtd/ui/internal/dnd/DTDDragAndDropManager.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/dnd/DTDDragAndDropManager.java,v >retrieving revision 1.3 >diff -u -r1.3 DTDDragAndDropManager.java >--- src/org/eclipse/wst/dtd/ui/internal/dnd/DTDDragAndDropManager.java 10 Apr 2007 20:05:22 -0000 1.3 >+++ src/org/eclipse/wst/dtd/ui/internal/dnd/DTDDragAndDropManager.java 16 Oct 2009 15:52:52 -0000 >@@ -14,7 +14,10 @@ > > package org.eclipse.wst.dtd.ui.internal.dnd; > >+import java.util.ArrayList; > import java.util.Collection; >+import java.util.Iterator; >+import java.util.List; > > import org.eclipse.wst.common.ui.internal.dnd.DragAndDropCommand; > import org.eclipse.wst.common.ui.internal.dnd.DragAndDropManager; >@@ -22,6 +25,7 @@ > import org.eclipse.wst.dtd.core.internal.CMNode; > import org.eclipse.wst.dtd.core.internal.DTDNode; > import org.eclipse.wst.dtd.core.internal.TopLevelNode; >+import org.w3c.dom.Node; > > public class DTDDragAndDropManager implements DragAndDropManager { > >@@ -29,6 +33,7 @@ > if (target instanceof DTDNode) { > DTDNode node = (DTDNode) target; > >+ source = mergeSource(source); > if (node instanceof TopLevelNode) { > return new DragTopLevelNodesCommand(target, location, operations, operation, source); > } >@@ -43,4 +48,55 @@ > return null; > } > >+ /** >+ * The source is merged only with the ancestor node. >+ */ >+ private Collection mergeSource(Collection collection) { >+ List result = new ArrayList(); >+ for(Iterator it = collection.iterator(); it.hasNext();) { >+ Node node = (Node) it.next(); >+ if(result.contains(node)) { >+ continue ; >+ } >+ >+ boolean isAdd = true; >+ for(int i = result.size() - 1; i >= 0; i--) { >+ Node addedNode = (Node)result.get(i); >+ if(isAncestor(node, addedNode)) { >+ if(isAdd) { >+ // Replace with the ancestor node >+ result.set(i, node); >+ isAdd = false; >+ } >+ else { >+ // Delete the child node >+ result.remove(i); >+ } >+ } >+ else if(!isAdd && isAncestor(addedNode, node)) { >+ // Do not add child nodes >+ isAdd = false; >+ break ; >+ } >+ } >+ if(isAdd) { >+ result.add(node); >+ } >+ } >+ return result; >+ } >+ >+ /** >+ * Returns with true if node1 is an ancestor of node2. >+ */ >+ private boolean isAncestor(Node node1, Node node2) { >+ boolean result = false; >+ for (Node parent = node2; parent != null; parent = parent.getParentNode()) { >+ if (parent == node1) { >+ result = true; >+ break; >+ } >+ } >+ return result; >+ } > } >Index: src/org/eclipse/wst/dtd/ui/internal/dnd/DragContentModelCommand.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/dnd/DragContentModelCommand.java,v >retrieving revision 1.4 >diff -u -r1.4 DragContentModelCommand.java >--- src/org/eclipse/wst/dtd/ui/internal/dnd/DragContentModelCommand.java 10 Apr 2007 20:05:22 -0000 1.4 >+++ src/org/eclipse/wst/dtd/ui/internal/dnd/DragContentModelCommand.java 16 Oct 2009 15:52:52 -0000 >@@ -26,6 +26,7 @@ > import org.eclipse.wst.dtd.core.internal.DTDNode; > import org.eclipse.wst.dtd.core.internal.Element; > import org.eclipse.wst.dtd.ui.internal.DTDUIMessages; >+import org.w3c.dom.Node; > > > public class DragContentModelCommand extends DefaultDragAndDropCommand { >@@ -45,6 +46,10 @@ > if (!(source instanceof CMNode)) { > return false; > } >+ // Can not drag parent to its children. >+ if(isAncestor((Node)source, (Node)target)) { >+ return false; >+ } > } > return true; > } >@@ -73,6 +78,7 @@ > return; > } > >+ boolean contentModelReplaced = false; > Iterator iter = sources.iterator(); > while (iter.hasNext()) { > DTDNode node = (DTDNode) iter.next(); >@@ -81,6 +87,9 @@ > if (element.getContentModel() == node) { > continue; > } >+ if(isAncestor(element.getContentModel(), node)) { >+ contentModelReplaced = true; >+ } > element.replaceContentModel(this, (CMNode) node); > } > else { >@@ -91,8 +100,14 @@ > group.insertIntoModel(this, (CMNode) referenceNode, (CMNode) node, isAfter()); > > } >- DTDNode nodeParent = (DTDNode) node.getParentNode(); >- nodeParent.delete(this, node); >+ if(!contentModelReplaced) { >+ DTDNode nodeParent = (DTDNode) node.getParentNode(); >+ nodeParent.delete(this, node); >+ } >+ else { >+ // replace only the first selected node >+ break; >+ } > } > } > dtdFile.getDTDModel().endRecording(this); >@@ -110,4 +125,18 @@ > > return super.getFeedback(); > } >+ >+ /** >+ * Returns with true if node1 is an ancestor of node2. >+ */ >+ private boolean isAncestor(Node node1, Node node2) { >+ boolean result = false; >+ for (Node parent = node2; parent != null; parent = parent.getParentNode()) { >+ if (parent == node1) { >+ result = true; >+ break; >+ } >+ } >+ return result; >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 247136
:
112401
| 149772 |
149773