Author: mareshkau
Date: 2008-02-28 09:21:12 -0500 (Thu, 28 Feb 2008)
New Revision: 6640
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeChildrenInfo.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreationData.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/XmlUtil.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-675, cashing of templates results was added to
visual editor.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-02-28
13:57:40 UTC (rev 6639)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-02-28
14:21:12 UTC (rev 6640)
@@ -446,6 +446,8 @@
break;
case INodeNotifier.ADD:
+ //we should remove all parent nodes from vpe cash
+ visualBuilder.removeNode((Node)newValue);
break;
case INodeNotifier.REMOVE:
@@ -473,11 +475,6 @@
}
break;
}
- //TODO Max Areshkau JBIDE-1457
-// if (visualBuilder.rebuildFlag) {
-//// pageContext.fireTaglibsChanged();
-// }
-
switcher.stopActiveEditor();
}
@@ -1186,27 +1183,12 @@
visualRefresh();
}
- // VpeTaglibListener implementation
-// public void taglibPrefixChanged(String[] prefixs) {
-// if (VpeDebug.printSourceMutationEvent) {
-// String s = ""; //$NON-NLS-1$
-// for (int i = 0; i < prefixs.length; i++) {
-// if (i > 0) {
-// s += ", "; //$NON-NLS-1$
-// }
-// s += prefixs[i];
-// }
-// }
-// queryVisualRefresh = true;
-//// visualRefreshImpl();
-// }
-
+
public void visualRefresh() {
if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
}
visualRefreshImpl();
-// pageContext.fireTaglibsChanged();
switcher.stopActiveEditor();
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-02-28
13:57:40 UTC (rev 6639)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-02-28
14:21:12 UTC (rev 6640)
@@ -234,6 +234,7 @@
private boolean addNode(Node sourceNode, nsIDOMNode visualNextNode,
nsIDOMNode visualContainer) {
+
nsIDOMNode visualNewNode = createNode(sourceNode, visualContainer);
// Fix for JBIDE-1097
try {
@@ -384,18 +385,35 @@
VpeCreationData creationData = null;
// FIX FOR JBIDE-1568, added by Max Areshkau
try {
- creationData = template.create(getPageContext(), sourceNode,
- getVisualDocument());
+ if(getPageContext().isCreationDataExistInCash(sourceNode)) {
+
+ creationData =
getPageContext().getVpeCreationDataFromCash(sourceNode).createHashCopy();
+ } else {
+ creationData = template.create(getPageContext(), sourceNode,
+ getVisualDocument());
+ if(creationData.getNode()!=null) {
+
+ getPageContext().addCreationDataToCash(sourceNode,
creationData.createHashCopy());
+
+ }
+ }
} catch (XPCOMException ex) {
VpePlugin.getPluginLog().logError(ex);
VpeTemplate defTemplate = templateManager.getDefTemplate();
creationData = defTemplate.create(getPageContext(), sourceNode,
getVisualDocument());
}
+
pageContext.setCurrentVisualNode(null);
- nsIDOMElement visualNewElement = (nsIDOMElement) creationData
- .getNode();
+ nsIDOMElement visualNewElement = null;
+ if(creationData.getNode()!=null) {
+
+ visualNewElement = (nsIDOMElement) creationData
+ .getNode().queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ }
+
+
if (visualNewElement != null)
correctVisualAttribute(visualNewElement);
@@ -842,6 +860,8 @@
}
public void removeNode(Node sourceNode) {
+ //remove from cash should be called first
+ getPageContext().removeNodeFromVpeCash(sourceNode);
domMapping.remove(sourceNode);
getSourceNodes().remove(sourceNode);
if (sourceNode instanceof INodeNotifier) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java 2008-02-28
13:57:40 UTC (rev 6639)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java 2008-02-28
14:21:12 UTC (rev 6640)
@@ -10,9 +10,11 @@
******************************************************************************/
package org.jboss.tools.vpe.editor.context;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
@@ -43,6 +45,8 @@
import org.jboss.tools.vpe.editor.css.ResourceReference;
import org.jboss.tools.vpe.editor.css.TaglibReferenceList;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
import org.jboss.tools.vpe.editor.util.FileUtil;
import org.jboss.tools.vpe.editor.util.XmlUtil;
@@ -62,8 +66,11 @@
private VpeVisualDomBuilder visualBuilder;
private VpeEditorPart editPart;
WtpKbConnector connector;
- private nsIDOMNode currentVisualNode;
+ private nsIDOMNode currentVisualNode;
+ //Added by Max Areshkau to increase perfomance of VPE JBIDE-675
+ private Map<Node,VpeCreationData> vpeCash;
+
public VpePageContext(VpeTemplateManager templateManager, BundleMap bundle,
VpeEditorPart editPart) {
this.bundle = bundle;
this.editPart = editPart;
@@ -107,6 +114,8 @@
public void clearAll() {
bundleDependencySet.clear();
bundle.clearAll();
+ //clean a cash nodes
+ clearVpeCash();
}
public void dispose() {
@@ -267,53 +276,7 @@
return null;
}
-// public List<TaglibData> getTagLibs() {
-// List<TaglibData> clone = new ArrayList<TaglibData>();
-// Iterator iter = taglibs.iterator();
-// while (iter.hasNext()) {
-// TaglibData taglib = (TaglibData)iter.next();
-// if (!taglib.inList(clone)) {
-// clone.add(taglib);
-// }
-// }
-// return clone;
-// }
-// private boolean buildTaglibsDifferences(List newTaglibs, List delTaglibs) {
-// Iterator lastIter = lastTaglibs.iterator();
-// while (lastIter.hasNext()) {
-// TaglibData oldTaglib = (TaglibData)lastIter.next();
-// Iterator newIter = newTaglibs.iterator();
-// while (newIter.hasNext()) {
-// if (oldTaglib.isEquals((TaglibData)newIter.next())) {
-// newIter.remove();
-// oldTaglib = null;
-// break;
-// }
-// }
-// if (oldTaglib != null) {
-// delTaglibs.add(oldTaglib);
-// }
-// }
-// return newTaglibs.size() > 0 || delTaglibs.size() > 0;
-// }
-
-// public void fireTaglibsChanged() {
-// List newTaglibs = getTagLibs();
-// List delTaglibs = new ArrayList();
-// if (buildTaglibsDifferences(newTaglibs, delTaglibs)) {
-// if (VpeDebug.PRINT_SOURCE_MUTATION_EVENT) {
-// System.out.println(">>> TaglibsChanged");
-// }
-// for (int i = 0; i < taglibListeners.length; i++) {
-// taglibListeners[i].taglibPrefixChanged(null);
-// fireTaglibChanged(taglibListeners[i], newTaglibs, delTaglibs);
-// }
-// lastTaglibs = getTagLibs();
-// }
-// taglibChanged = false;
-// }
-
private void fireTaglibChanged(VpeTaglibListener taglibListener, List newTaglibs, List
delTaglibs) {
Iterator iter = delTaglibs.iterator();
while (iter.hasNext()) {
@@ -327,13 +290,6 @@
}
}
-// public boolean isTaglibChanged() {
-// if (!taglibChanged) return false;
-// List newTaglibs = getTagLibs();
-// List delTaglibs = new ArrayList();
-// return buildTaglibsDifferences(newTaglibs, delTaglibs);
-// }
-
public WtpKbConnector getConnector() {
return connector;
}
@@ -372,41 +328,77 @@
this.currentVisualNode = currentVisualNode;
}
-// boolean registerTaglibs(WtpKbConnector wtpKbConnector, VpeTaglibManager taglibManager,
IDocument document) {
-// if(wtpKbConnector == null) return false;
-// TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(document);
-// if(taglibManager != null) {
-// List list = taglibManager.getTagLibs();
-// if(list != null) {
-// Iterator it = list.iterator();
-// while(it.hasNext()) {
-// TaglibData data = (TaglibData)it.next();
-// IEditorInput ei = editPart.getEditorInput();
-// TLDRegisterHelper.registerTld(data, (JspWtpKbConnector)wtpKbConnector, document,
ei);
-// }
-// return true;
-// }
-// }
-// if(manager != null) {
-// List list = manager.getTaglibTrackers();
-// for (int i = 0; i < list.size(); i++) {
-// TaglibTracker tracker = (TaglibTracker)list.get(i);
-// if(tracker == null) continue;
-// String version = TLDVersionHelper.getTldVersion(tracker);
-// KbTldResource resource = new KbTldResource(tracker.getURI(), "",
tracker.getPrefix(), version);
-// wtpKbConnector.registerResource(resource);
-// }
-// return true;
-// }
-// return false;
-// }
-
-// public nsIDOMNode getCurrentVisualNode() {
-// return currentVisualNode;
-// }
-//
-// public void setCurrentVisualNode(nsIDOMNode currentVisualNode) {
-// this.currentVisualNode = currentVisualNode;
-// }
+ /**
+ * Removes information about source node from vpe cash
+ * @param sourceNode
+ */
+ public void removeNodeFromVpeCash(Node sourceNode) {
+
+ getVpeCash().remove(sourceNode);
+ Node parentNode = sourceNode.getParentNode();
+ //we should on change remove also parent nodes because information for
+ //this nodes doen't actual when we change child
+ while(parentNode!=null) {
+ getVpeCash().remove(parentNode);
+ parentNode=parentNode.getParentNode();
+ }
+ }
+ /**
+ * Clears all information in cash
+ */
+ public void clearVpeCash() {
+
+ getVpeCash().clear();
+ }
+ /**
+ * Checs is creation data exist in cash
+ * @param sourceNode
+ * @return true - if date exist
+ * false -otherwise
+ */
+ public boolean isCreationDataExistInCash(Node sourceNode){
+
+// Iterator<Node> keys = getVpeCash().keySet().iterator();
+//
+// //Map.get() doesn't work correctly for this situation
+//// while(keys.hasNext()){
+//// Node key= keys.next();
+//// if(sourceNode.isEqu alNode(key)) {
+//// return true;
+//// }
+//// }
+//// return false;
+ return getVpeCash().containsKey(sourceNode);
+ }
+ /**
+ * Inserts creation data into cash
+ * @param sourceNode
+ * @param creationData
+ */
+ public void addCreationDataToCash(Node sourceNode,VpeCreationData creationData) {
+ //TODO Max Areshkau JBIDE-675 Adds data to cash, think about cloning creationData
+ getVpeCash().put(sourceNode, creationData);
+ }
+ /**
+ * Looks creates data in cash
+ * @param sourceNode
+ * @return returns creation data
+ */
+ public VpeCreationData getVpeCreationDataFromCash(Node sourceNode) {
+
+ return getVpeCash().get(sourceNode);
+ }
+ /**
+ * Return vpe Cash
+ * @return the vpeCash
+ */
+ private Map<Node, VpeCreationData> getVpeCash() {
+
+ if(vpeCash ==null) {
+
+ vpeCash = new HashMap<Node, VpeCreationData>();
+ }
+ return vpeCash;
+ }
}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeChildrenInfo.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeChildrenInfo.java 2008-02-28
13:57:40 UTC (rev 6639)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeChildrenInfo.java 2008-02-28
14:21:12 UTC (rev 6640)
@@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.jboss.tools.vpe.editor.util.XmlUtil;
import org.mozilla.interfaces.nsIDOMElement;
import org.w3c.dom.Node;
@@ -59,4 +60,16 @@
}
return sourceChildren;
}
+ /**
+ * Creates a copy of element for vpe cash.
+ * We should clone nsI* elements and copy all others
+ * added by Max Aresahkau
+ */
+ public VpeChildrenInfo createCashCopy(){
+
+ VpeChildrenInfo childrenInfo = new
VpeChildrenInfo(visualParent!=null?(nsIDOMElement)(XmlUtil.createClone(this.visualParent)).
+ queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID):null);
+ childrenInfo.sourceChildren=this.sourceChildren;
+ return childrenInfo;
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreationData.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreationData.java 2008-02-28
13:57:40 UTC (rev 6639)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreationData.java 2008-02-28
14:21:12 UTC (rev 6640)
@@ -13,6 +13,9 @@
import java.util.ArrayList;
import java.util.List;
+import org.jboss.tools.common.model.util.XMLUtil;
+import org.jboss.tools.vpe.editor.util.VpeDebugUtil;
+import org.jboss.tools.vpe.editor.util.XmlUtil;
import org.mozilla.interfaces.nsIDOMNode;
import org.w3c.dom.Node;
@@ -30,7 +33,7 @@
return node;
}
- public void addChildrenInfo(VpeChildrenInfo info) {
+ public void addChildrenInfo(VpeChildrenInfo info) {
if (childrenInfoList == null) {
childrenInfoList = new ArrayList<VpeChildrenInfo>();
}
@@ -59,4 +62,34 @@
public Object getData() {
return data;
}
+
+ /**
+ * Added method for creation copy which will
+ * placed in cash to improve perfomance of VPE
+ * Added by Max Areshkau JBIDE-675.
+ * Here copyed only nsI****
+ * @return
+ */
+ public VpeCreationData createHashCopy() {
+ nsIDOMNode node=null;
+ if(this.node!=null) {
+ node = XmlUtil.createClone(this.node);
+ } else {
+ VpeDebugUtil.debugInfo("Node is Null");
+ }
+ if(node.getNodeType()!=nsIDOMNode.ELEMENT_NODE) {
+ VpeDebugUtil.debugInfo("It's Not Element");
+ }
+
+ VpeCreationData data = new VpeCreationData(node);
+ if(this.childrenInfoList!=null) {
+ data.childrenInfoList= new ArrayList<VpeChildrenInfo>();
+ for (VpeChildrenInfo childrenInfo : this.childrenInfoList) {
+ data.childrenInfoList.add(childrenInfo.createCashCopy());
+ }
+ }
+ data.illegalChildren =this.illegalChildren;
+ data.data = this.data;
+ return data;
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java 2008-02-28
13:57:40 UTC (rev 6639)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java 2008-02-28
14:21:12 UTC (rev 6640)
@@ -160,7 +160,8 @@
}
@Override
public void validate(VpePageContext pageContext, Node sourceNode, nsIDOMDocument
visualDocument, VpeCreationData creationdata) {
- validateVisualElement(pageContext, (Element)sourceNode, visualDocument, null,
(nsIDOMElement)creationdata.getNode(),
(Map<VpeTemplate,ModifyInfo>)creationdata.getData());
+ validateVisualElement(pageContext, (Element)sourceNode, visualDocument, null,
creationdata.getNode()==null?null:
+ (nsIDOMElement)(creationdata.getNode().queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID)),
(Map<VpeTemplate,ModifyInfo>)creationdata.getData());
}
@Override
public void setAttribute(VpePageContext pageContext, Element sourceElement,
nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data, String name, String
value) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/XmlUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/XmlUtil.java 2008-02-28
13:57:40 UTC (rev 6639)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/XmlUtil.java 2008-02-28
14:21:12 UTC (rev 6640)
@@ -21,7 +21,10 @@
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
import org.jboss.tools.jst.web.tld.TaglibData;
+import org.jboss.tools.vpe.VpeDebug;
import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.xulrunner.browser.util.DOMTreeDumper;
+import org.mozilla.interfaces.nsIDOMNode;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -109,7 +112,8 @@
public static List<TaglibData> getTaglibsForNode(Node source,IDocument document)
{
List<TaglibData> taglibData = new ArrayList<TaglibData>();
-
+ //TODO Max Areshkau Looks like exist possability to check is it jsp document
+ //node.getOwnerDocument return null for jsp apply it for CA
TLDCMDocumentManager tldcmDocumentManager=
TaglibController.getTLDCMDocumentManager(document);
if(tldcmDocumentManager!=null) {
List<TaglibTracker> taglibs_JSP = tldcmDocumentManager.getTaglibTrackers();
@@ -183,5 +187,16 @@
}
}
return null;
- }
+ }
+ /**
+ * Creates clone node
+ * @param cloneNode
+ * @return
+ */
+ public static final nsIDOMNode createClone(nsIDOMNode nodeToClone){
+ nsIDOMNode result = nodeToClone.cloneNode(true);
+ return result;
+ }
+
+
}