Thread: [Jsxe-cvs] SF.net SVN: jsxe: [1121] trunk/jsxe/src/net/sourceforge/jsxe/dom
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-08-08 05:55:28
|
Revision: 1121 Author: ian_lewis Date: 2006-08-07 22:55:21 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1121&view=rev Log Message: ----------- Fixed a bug with drag and drop and undo Modified Paths: -------------- trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-08-08 04:59:58 UTC (rev 1120) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-08-08 05:55:21 UTC (rev 1121) @@ -516,41 +516,54 @@ //node is already in the location specified return node; } - //add to this AdapterNode and the DOM. - if (node.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) { - //Add all children of the document fragment - for(int i=0; i<node.childCount(); i++) { - addAdapterNodeAt(node.child(i), location+i); - } - } else { - /* - if the node is already contained in this node - then we are effectively moving the node. - */ - if (m_children.contains(node)) { - if (location > m_children.indexOf(node)) { - location -= 1; + + XMLDocument doc = getOwnerDocument(); + try { + + doc.beginCompoundEdit(); + //add to this AdapterNode and the DOM. + if (node.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) { + //Add all children of the document fragment + for (int i=0; i<node.childCount(); i++) { + addAdapterNodeAt(node.child(i), location+i); } - m_children.remove(node); - } - if (location >= m_children.size()) { - m_domNode.appendChild(node.getNode()); - ensureChildrenSize(location); - m_children.add(node); } else { - m_domNode.insertBefore(node.getNode(), child(location).getNode()); - m_children.add(location, node); - } - - //Remove from previous parent - AdapterNode previousParent = node.getParentNode(); - if (previousParent != this) { - if (previousParent != null) { - previousParent.removeChild(node); + + + /* + if the node is already contained in this node + then we are effectively moving the node. + */ + if (m_children.contains(node)) { + if (location > m_children.indexOf(node)) { + location -= 1; + } + int index = index(node); + m_children.remove(node); + getOwnerDocument().addUndoableEdit(new RemoveNodeChange(this, node, index)); + } else { + //Remove from previous parent + AdapterNode previousParent = node.getParentNode(); + if (previousParent != this) { + if (previousParent != null) { + previousParent.removeChild(node); + } + } } + if (location >= m_children.size()) { + m_domNode.appendChild(node.getNode()); + ensureChildrenSize(location); + m_children.add(node); + } else { + m_domNode.insertBefore(node.getNode(), child(location).getNode()); + m_children.add(location, node); + } + + node.setParent(this); + fireNodeAdded(this, node, location); } - node.setParent(this); - fireNodeAdded(this, node); + } finally { + doc.endCompoundEdit(); } } else { throw new DOMException(DOMException.INDEX_SIZE_ERR, "The location to insert this node is invalid."); @@ -574,10 +587,11 @@ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "You cannot remove the root element node."); } if (child.getNodeType() != Node.DOCUMENT_TYPE_NODE) { + int index = index(child); m_domNode.removeChild(child.getNode()); m_children.remove(child); child.setParent(null); - fireNodeRemoved(this, child); + fireNodeRemoved(this, child, index); } else { throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot remove Document Type Nodes"); } @@ -911,7 +925,13 @@ */ void removeChild(AdapterNode node) { if (node != null) { + int index = index(node); m_children.remove(node); + if (index != -1) { + getOwnerDocument().addUndoableEdit(new RemoveNodeChange(this, node, index)); + } else { + Log.log(Log.DEBUG, this, "node not found"); + } } }//}}} @@ -960,7 +980,9 @@ //{{{ Private members //{{{ fireNodeAdded() - private void fireNodeAdded(AdapterNode source, AdapterNode child) { + private void fireNodeAdded(AdapterNode source, AdapterNode child, int index) { + getOwnerDocument().addUndoableEdit(new AddNodeChange(source, child, index)); + ListIterator iterator = m_listeners.listIterator(); while (iterator.hasNext()) { AdapterNodeListener listener = (AdapterNodeListener)iterator.next(); @@ -970,7 +992,9 @@ }//}}} //{{{ fireNodeRemoved() - private void fireNodeRemoved(AdapterNode source, AdapterNode child) { + private void fireNodeRemoved(AdapterNode source, AdapterNode child, int index) { + getOwnerDocument().addUndoableEdit(new RemoveNodeChange(source, child, index)); + ListIterator iterator = m_listeners.listIterator(); while (iterator.hasNext()) { AdapterNodeListener listener = (AdapterNodeListener)iterator.next(); Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java 2006-08-08 04:59:58 UTC (rev 1120) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java 2006-08-08 05:55:21 UTC (rev 1121) @@ -50,9 +50,9 @@ */ public class NodeNameChange extends AbstractUndoableEdit { - AdapterNode m_node; - String m_oldValue; - String m_newValue; + private AdapterNode m_node; + private String m_oldValue; + private String m_newValue; //{{{ NodeNameChange constructor public NodeNameChange(AdapterNode node, String oldValue, String newValue) { Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java 2006-08-08 04:59:58 UTC (rev 1120) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java 2006-08-08 05:55:21 UTC (rev 1121) @@ -50,9 +50,9 @@ */ public class NodePrefixChange extends AbstractUndoableEdit { - AdapterNode m_node; - String m_oldValue; - String m_newValue; + private AdapterNode m_node; + private String m_oldValue; + private String m_newValue; //{{{ NodePrefixChange constructor public NodePrefixChange(AdapterNode node, String oldValue, String newValue) { Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java 2006-08-08 04:59:58 UTC (rev 1120) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java 2006-08-08 05:55:21 UTC (rev 1121) @@ -50,9 +50,9 @@ */ public class NodeValueChange extends AbstractUndoableEdit { - AdapterNode m_node; - String m_oldValue; - String m_newValue; + private AdapterNode m_node; + private String m_oldValue; + private String m_newValue; //{{{ NodeValueChange constructor public NodeValueChange(AdapterNode node, String oldValue, String newValue) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ian...@us...> - 2006-08-09 21:53:17
|
Revision: 1129 Author: ian_lewis Date: 2006-08-09 14:53:09 -0700 (Wed, 09 Aug 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1129&view=rev Log Message: ----------- Added back undo for adding and removing nodes from the tree Modified Paths: -------------- trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java Added Paths: ----------- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AddNodeChange.java trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveNodeChange.java Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-08-09 21:51:10 UTC (rev 1128) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-08-09 21:53:09 UTC (rev 1129) @@ -541,7 +541,7 @@ } int index = index(node); m_children.remove(node); - // addUndoableEdit(new RemoveNodeChange(this, node, index)); + addUndoableEdit(new RemoveNodeChange(this, node, index)); } else { //Remove from previous parent AdapterNode previousParent = node.getParentNode(); @@ -942,9 +942,9 @@ if (node != null) { int index = index(node); m_children.remove(node); - // if (index != -1) { - // addUndoableEdit(new RemoveNodeChange(this, node, index)); - // } + if (index != -1) { + addUndoableEdit(new RemoveNodeChange(this, node, index)); + } } }//}}} @@ -994,7 +994,7 @@ //{{{ fireNodeAdded() private void fireNodeAdded(AdapterNode source, AdapterNode child, int index) { - // addUndoableEdit(new AddNodeChange(source, child, index)); + addUndoableEdit(new AddNodeChange(source, child, index)); ListIterator iterator = m_listeners.listIterator(); while (iterator.hasNext()) { @@ -1006,7 +1006,7 @@ //{{{ fireNodeRemoved() private void fireNodeRemoved(AdapterNode source, AdapterNode child, int index) { - // addUndoableEdit(new RemoveNodeChange(source, child, index)); + addUndoableEdit(new RemoveNodeChange(source, child, index)); ListIterator iterator = m_listeners.listIterator(); while (iterator.hasNext()) { Added: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AddNodeChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AddNodeChange.java (rev 0) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AddNodeChange.java 2006-08-09 21:53:09 UTC (rev 1129) @@ -0,0 +1,90 @@ +/* +AddNodeChange.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +Copyright (C) 2006 Ian Lewis (Ian...@me...) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + +package net.sourceforge.jsxe.dom.undo; + +//{{{ imports + +//{{{ jsXe classes +import net.sourceforge.jsxe.dom.AdapterNode; +import net.sourceforge.jsxe.util.Log; +//}}} + +//{{{ Swing classes +import javax.swing.undo.*; +//}}} + +//{{{ DOM classes +import org.w3c.dom.DOMException; +//}}} + +//}}} + +/** + * An undoable edit sigifying an addition of a child to an AdapterNode. + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id$ + * @see net.sourceforge.jsxe.dom.XMLDocument + * @see net.sourceforge.jsxe.dom.AdapterNode + */ +public class AddNodeChange extends AbstractUndoableEdit { + + private AdapterNode m_node; + private AdapterNode m_child; + private int m_index; + + //{{{ AddNodeChange constructor + public AddNodeChange(AdapterNode node, AdapterNode child, int index) { + m_node = node; + m_child = child; + m_index = index; + }//}}} + + //{{{ undo() + + public void undo() throws CannotUndoException { + super.undo(); + try { + Log.log(Log.DEBUG, this, "undo()"); + m_node.remove(m_child); + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); + throw new CannotUndoException(); + } + }//}}} + + //{{{ redo() + + public void redo() throws CannotRedoException { + super.redo(); + try { + Log.log(Log.DEBUG, this, "redo()"); + m_node.addAdapterNodeAt(m_child, m_index); + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); + throw new CannotRedoException(); + } + }//}}} + +} \ No newline at end of file Property changes on: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AddNodeChange.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveNodeChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveNodeChange.java (rev 0) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveNodeChange.java 2006-08-09 21:53:09 UTC (rev 1129) @@ -0,0 +1,90 @@ +/* +RemoveNodeChange.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +Copyright (C) 2006 Ian Lewis (Ian...@me...) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + +package net.sourceforge.jsxe.dom.undo; + +//{{{ imports + +//{{{ jsXe classes +import net.sourceforge.jsxe.dom.AdapterNode; +import net.sourceforge.jsxe.util.Log; +//}}} + +//{{{ Swing classes +import javax.swing.undo.*; +//}}} + +//{{{ DOM classes +import org.w3c.dom.DOMException; +//}}} + +//}}} + +/** + * An undoable edit sigifying a removal of a child from an AdapterNode. + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id$ + * @see net.sourceforge.jsxe.dom.XMLDocument + * @see net.sourceforge.jsxe.dom.AdapterNode + */ +public class RemoveNodeChange extends AbstractUndoableEdit { + + private AdapterNode m_node; + private AdapterNode m_child; + private int m_index; + + //{{{ RemoveNodeChange constructor + public RemoveNodeChange(AdapterNode node, AdapterNode child, int index) { + m_node = node; + m_child = child; + m_index = index; + }//}}} + + //{{{ undo() + + public void undo() throws CannotUndoException { + super.undo(); + try { + Log.log(Log.DEBUG, this, "undo()"); + m_node.addAdapterNodeAt(m_child, m_index); + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); + throw new CannotUndoException(); + } + }//}}} + + //{{{ redo() + + public void redo() throws CannotRedoException { + super.redo(); + try { + Log.log(Log.DEBUG, this, "redo()"); + m_node.remove(m_child); + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); + throw new CannotRedoException(); + } + }//}}} + +} \ No newline at end of file Property changes on: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveNodeChange.java ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |