Author: mareshkau
Date: 2008-07-30 14:27:32 -0400 (Wed, 30 Jul 2008)
New Revision: 9440
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlTextTemplate.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml
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/mapping/VpeElementMapping.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/IELService.java
Log:
JBIDE-2584
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-07-30
15:05:47 UTC (rev 9439)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-07-30
18:27:32 UTC (rev 9440)
@@ -390,9 +390,16 @@
}
return border;
}
-
+
+ /**
+ * Generates visual node
+ * @param sourceNode
+ * @param visualOldContainer
+ * @return
+ */
protected nsIDOMNode createNode(Node sourceNode,
nsIDOMNode visualOldContainer) {
+
boolean registerFlag = isCurrentMainDocument();
//reads and dispatch events
@@ -400,67 +407,41 @@
if(getPageContext().getSourceBuilder()==null ||includeDocuments==null) {
throw new VpeDisposeException();
-}
+ }
getPageContext().processDisplayEvents();
//check source node can be changed and link can be a null in this case
//we shouldn't process this node
- if(sourceNode==null) {
+ if(sourceNode==null||(
+ sourceNode.getNodeType()!=Node.TEXT_NODE
+ &&sourceNode.getNodeType()!=Node.ELEMENT_NODE
+ &&sourceNode.getNodeType()!=Node.COMMENT_NODE)) {
return null;
}
+
+// switch (sourceNode.getNodeType()) {
- switch (sourceNode.getNodeType()) {
- case Node.ELEMENT_NODE:
+// case Node.ELEMENT_NODE:
// Map<?, ?> xmlnsMap = createXmlns((Element) sourceNode);
Set<Node> ifDependencySet = new HashSet<Node>();
pageContext.setCurrentVisualNode(visualOldContainer);
VpeTemplate template = templateManager.getTemplate(pageContext,
- (Element) sourceNode, ifDependencySet);
+ sourceNode, ifDependencySet);
VpeCreationData creationData = null;
// FIX FOR JBIDE-1568, added by Max Areshkau
try {
-// if(getPageContext().isCreationDataExistInCash(sourceNode)) {
-
-// creationData =
getPageContext().getVpeCreationDataFromCash(sourceNode).createHashCopy();
-// } else {
-
-// VpeCreationData
-// Map<String, String> oldAttributes = new HashMap<String,
String>();
-// NamedNodeMap map = sourceNode.getAttributes();
-// for( int i = 0 ; i < map.getLength() ; i ++ ){
-// final Attr attr = (Attr) map.item(i);
-//
-// oldAttributes.put(attr.getName(),attr.getValue());
-//
System.err.println(MessageFormat.format("name={0},value={1}",
attr.getName(),attr.getValue()));
-//
-// }
- if (ElService.getInstance().isCloneableNode(getPageContext(),(Element)
sourceNode)) {
- final Element sourceNodeClone = (Element) ((Element)
sourceNode).cloneNode(true);
+ if (ElService.getInstance().isCloneableNode(getPageContext(),
sourceNode)) {
+ final Node sourceNodeClone = (sourceNode).cloneNode(true);
template.beforeTemplateCreated(getPageContext(), sourceNodeClone,
getVisualDocument());
creationData = template.create(getPageContext(), sourceNodeClone,
getVisualDocument());
} else {
creationData = template.create(getPageContext(), sourceNode,
getVisualDocument());
}
-
-
-//
-// map = sourceNode.getAttributes();
-// for( int i = 0 ; i < map.getLength() ; i ++ ){
-// final Attr attr = (Attr) map.item(i);
-//
-// attr.setValue(oldAttributes.get(attr.getName()));
-// }
-
-// if(creationData.getNode()!=null) {
-//
-// getPageContext().addCreationDataToCash(sourceNode,
creationData.createHashCopy());
-//
-// }
-// }
+
} catch (XPCOMException ex) {
VpePlugin.getPluginLog().logError(ex);
VpeTemplate defTemplate = templateManager.getDefTemplate();
@@ -468,46 +449,52 @@
getVisualDocument());
}
- pageContext.setCurrentVisualNode(null);
- nsIDOMElement visualNewElement = null;
+ getPageContext().setCurrentVisualNode(null);
- if(creationData.getNode()!=null) {
-
- visualNewElement = (nsIDOMElement) creationData
- .getNode().queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- }
-
- if ((visualNewElement != null) && template.hasImaginaryBorder()) {
+ nsIDOMNode visualNewNode =creationData.getNode();
- visualNewElement.setAttribute(HTML.ATTR_STYLE, visualNewElement
- .getAttribute(HTML.ATTR_STYLE)
- + VpeStyleUtil.SEMICOLON_STRING + DOTTED_BORDER);
-
- }
+// nsIDOMElement visualNewElement = null;
+ //TODO Max Areshkau process it's correctly
+// if(creationData.getNode()!=null) {
+//
+// visualNewElement = (nsIDOMElement) creationData
+// .getNode().queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+// }
+//
+// if ((visualNewElement != null) && template.hasImaginaryBorder()) {
+//
+// visualNewElement.setAttribute(HTML.ATTR_STYLE, visualNewElement
+// .getAttribute(HTML.ATTR_STYLE)
+// + VpeStyleUtil.SEMICOLON_STRING + DOTTED_BORDER);
+//
+// }
+//
+// if (visualNewElement != null)
+// correctVisualAttribute(visualNewElement);
- if (visualNewElement != null)
- correctVisualAttribute(visualNewElement);
-
nsIDOMElement border = null;
- setTooltip((Element) sourceNode, visualNewElement);
- if (YES_STRING.equals(VpePreference.SHOW_BORDER_FOR_ALL_TAGS
- .getValue())
- && visualNewElement != null) {
- boolean block = true;
- if (template.getTagDescription(null, null, null,
- visualNewElement, null).getDisplayType() ==
VpeTagDescription.DISPLAY_TYPE_INLINE) {
- block = false;
+ if(sourceNode instanceof Element && visualNewNode!= null) {
+
+ setTooltip((Element) sourceNode,
(nsIDOMElement)visualNewNode.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
}
- border = createBorder(sourceNode, visualNewElement, block);
- }
- if (!isCurrentMainDocument() && visualNewElement != null) {
- setReadOnlyElement(visualNewElement);
- }
+// if (YES_STRING.equals(VpePreference.SHOW_BORDER_FOR_ALL_TAGS
+// .getValue())
+// && visualNewElement != null) {
+// boolean block = true;
+// if (template.getTagDescription(null, null, null,
+// visualNewElement, null).getDisplayType() ==
VpeTagDescription.DISPLAY_TYPE_INLINE) {
+// block = false;
+// }
+// border = createBorder(sourceNode, visualNewElement, block);
+// }
+// if (!isCurrentMainDocument() && visualNewElement != null) {
+// setReadOnlyElement(visualNewElement);
+// }
if (registerFlag) {
VpeElementMapping elementMapping = new VpeElementMapping(
- (Element) sourceNode, visualNewElement, border,
+ sourceNode, visualNewNode, border,
template, ifDependencySet, creationData.getData(),
creationData.getElementData());
// elementMapping.setXmlnsMap(xmlnsMap);
@@ -517,35 +504,36 @@
List<?> childrenInfoList = creationData.getChildrenInfoList();
if (childrenInfoList == null) {
addChildren(template, sourceNode,
- visualNewElement != null ? visualNewElement
+ visualNewNode != null ? visualNewNode
: visualOldContainer);
} else {
addChildren(template, sourceNode, visualOldContainer,
childrenInfoList);
}
}
- pageContext.setCurrentVisualNode(visualOldContainer);
- template.validate(pageContext, (Element) sourceNode,
+ getPageContext().setCurrentVisualNode(visualOldContainer);
+ template.validate(getPageContext(), sourceNode,
visualDocument, creationData);
- pageContext.setCurrentVisualNode(null);
+ getPageContext().setCurrentVisualNode(null);
+
if (border != null)
- return border;
+ return border;
else
- return visualNewElement;
- case Node.TEXT_NODE:
- return createTextNode(sourceNode, registerFlag);
- case Node.COMMENT_NODE:
- if (!YES_STRING.equals(VpePreference.SHOW_COMMENTS.getValue())) {
- return null;
- }
- nsIDOMElement visualNewComment = createComment(sourceNode);
- if (registerFlag) {
- registerNodes(new VpeNodeMapping(sourceNode, visualNewComment));
- }
- return visualNewComment;
+ return visualNewNode;
+// case Node.TEXT_NODE:
+// return createTextNode(sourceNode, registerFlag);
+// case Node.COMMENT_NODE:
+// if (!YES_STRING.equals(VpePreference.SHOW_COMMENTS.getValue())) {
+// return null;
+// }
+// nsIDOMElement visualNewComment = createComment(sourceNode);
+// if (registerFlag) {
+// registerNodes(new VpeNodeMapping(sourceNode, visualNewComment));
+// }
+// return visualNewComment;
+// }
+// return null;
}
- return null;
- }
private void correctVisualAttribute(nsIDOMElement element) {
@@ -1509,9 +1497,9 @@
VpeNodeMapping node = domMapping.getNodeMapping(visualDragElement);
if (node instanceof VpeElementMapping) {
VpeElementMapping elementMapping = (VpeElementMapping) node;
- if (elementMapping != null) {
+ if (elementMapping != null && elementMapping.getSourceNode() instanceof
Element) {
return elementMapping.getTemplate().canInnerDrag(pageContext,
- (Element) elementMapping.getSourceNode(),
+ (Element)elementMapping.getSourceNode(),
visualDocument, visualDragElement,
elementMapping.getData());
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java 2008-07-30
15:05:47 UTC (rev 9439)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java 2008-07-30
18:27:32 UTC (rev 9440)
@@ -17,6 +17,7 @@
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
public class VpeElementMapping extends VpeNodeMapping {
private VpeTemplate template;
@@ -30,10 +31,10 @@
private VpeElementData elementData;
private nsIDOMElement border;
- public VpeElementMapping(Element sourceElement,
- nsIDOMElement visualElement, nsIDOMElement border,
+ public VpeElementMapping(Node sourceElement,
+ nsIDOMNode visualNode, nsIDOMElement border,
VpeTemplate template, Set ifDependencySet, Object data, VpeElementData elementData) {
- super(sourceElement, visualElement);
+ super(sourceElement, visualNode);
this.template = template;
if (ifDependencySet != null && ifDependencySet.size() > 0) {
this.ifDependencySet = ifDependencySet;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java 2008-07-30
15:05:47 UTC (rev 9439)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java 2008-07-30
18:27:32 UTC (rev 9440)
@@ -230,6 +230,10 @@
private VpeTemplateFileList templateFileList = new VpeTemplateFileList();
private Set<String> withoutWhitespaceContainerSet = new HashSet<String>();
private Set<String> withoutPseudoElementContainerSet = new
HashSet<String>();
+ //text template name
+ private static final String TEXT_TEMPLATE_NAME="#text"; //$NON-NLS-1$
+ //comment template name
+ private static final String COMMENT_TEMPLATE_NAME="#comment"; //$NON-NLS-1$
/**
* added by Max Areshkau, JBIDE-1494
@@ -300,31 +304,55 @@
return null;
}
+ /**
+ *
+ * @param pageContext
+ * @param sourceNode
+ * @return name of template
+ */
private String getTemplateName(VpePageContext pageContext, Node sourceNode) {
- String sourcePrefix = sourceNode.getPrefix();
-
- if (sourcePrefix == null
- || ((IDOMElement)sourceNode).isJSPTag()
- || "jsp".equals(sourcePrefix)) { //$NON-NLS-1$
- return sourceNode.getNodeName();
+
+ if(sourceNode==null) {
+ return null;
}
+ switch (sourceNode.getNodeType()){
- List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,pageContext);
-
- TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourcePrefix, taglibs);
+ case Node.TEXT_NODE:
+
+ return TEXT_TEMPLATE_NAME;
+
+ case Node.COMMENT_NODE:
+
+ return COMMENT_TEMPLATE_NAME;
+
+ case Node.ELEMENT_NODE:
+ String sourcePrefix = sourceNode.getPrefix();
- if(sourceNodeTaglib == null) {
+ if (sourcePrefix == null
+ || ((IDOMElement)sourceNode).isJSPTag()
+ || "jsp".equals(sourcePrefix)) { //$NON-NLS-1$
+ return sourceNode.getNodeName();
+ }
+
+ List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,pageContext);
+
+ TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourcePrefix, taglibs);
+
+ if(sourceNodeTaglib == null) {
+ return null;
+ }
+
+ String sourceNodeUri = sourceNodeTaglib.getUri();
+ String templateTaglibPrefix = getTemplateTaglibPrefix(sourceNodeUri);
+
+ if(templateTaglibPrefix != null) {
+ return templateTaglibPrefix + ":" + sourceNode.getLocalName();
//$NON-NLS-1$
+ }
return null;
+ default :
+ return null;
}
- String sourceNodeUri = sourceNodeTaglib.getUri();
- String templateTaglibPrefix = getTemplateTaglibPrefix(sourceNodeUri);
-
- if(templateTaglibPrefix != null) {
- return templateTaglibPrefix + ":" + sourceNode.getLocalName();
//$NON-NLS-1$
- }
-
- return null;
}
public String getTemplateTaglibPrefix(String sourceUri) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java 2008-07-30
15:05:47 UTC (rev 9439)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java 2008-07-30
18:27:32 UTC (rev 9440)
@@ -83,7 +83,7 @@
public String replaceEl(IFile resourceFile, String resourceString) {
// Assert.isNotNull(resourceString);
if ((resourceString == null) || (resourceFile == null)) {
- return "";
+ return ""; //$NON-NLS-1$
}
Assert.isNotNull(resourceFile);
String rst = resourceString;
@@ -124,7 +124,7 @@
*
* @return true, if is cloneable node
*/
- public boolean isCloneableNode(VpePageContext pageContext,Element sourceNode) {
+ public boolean isCloneableNode(VpePageContext pageContext,Node sourceNode) {
boolean rst = false;
final IFile file =
pageContext.getVisualBuilder().getCurrentIncludeInfo().getFile();
@@ -140,7 +140,7 @@
* @param sourceNode
* @return
*/
- public boolean isInResourcesBundle(VpePageContext pageContext, Element sourceNode) {
+ public boolean isInResourcesBundle(VpePageContext pageContext, Node sourceNode) {
boolean rst = findInResourcesBundle(pageContext, sourceNode);
if (!rst && (sourceNode.getChildNodes() != null) &&
(sourceNode.getChildNodes().getLength() > 0)) {
@@ -167,7 +167,7 @@
* @param sourceNode
* @return
*/
- private boolean findInResourcesBundle(VpePageContext pageContext, Element sourceNode)
{
+ private boolean findInResourcesBundle(VpePageContext pageContext, Node sourceNode) {
boolean rst = false;
BundleMap bundleMap = pageContext.getBundle();
@@ -209,8 +209,9 @@
* @param value
* @return
*/
+ //TODO E Sherbin It's shouldn't bee here
private boolean isContainsEl(final String value) {
- return (value.contains("#{") || value.contains("${"));
+ return (value.contains("#{") || value.contains("${"));
//$NON-NLS-1$//$NON-NLS-2$
}
@@ -222,7 +223,7 @@
*
* @return true, if is available for node
*/
- private boolean isAvailableForNode(Element sourceNode, IFile resourceFile) {
+ private boolean isAvailableForNode(Node sourceNode, IFile resourceFile) {
boolean rst = findForNode(sourceNode, resourceFile);
if (!rst && (sourceNode.getChildNodes() != null) &&
(sourceNode.getChildNodes().getLength() > 0)) {
@@ -247,7 +248,7 @@
* @param resourceFile
* @return
*/
- private boolean findForNode(Element sourceNode, IFile resourceFile) {
+ private boolean findForNode(Node sourceNode, IFile resourceFile) {
boolean rst = false;
final NamedNodeMap nodeMap = sourceNode.getAttributes();
final ResourceReference[] references =
ELReferenceList.getInstance().getAllResources(resourceFile);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/IELService.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/IELService.java 2008-07-30
15:05:47 UTC (rev 9439)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/IELService.java 2008-07-30
18:27:32 UTC (rev 9440)
@@ -16,6 +16,7 @@
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
/**
@@ -77,7 +78,7 @@
*
* @return true, if is cloneable node
*/
- public boolean isCloneableNode(VpePageContext pageContext, Element sourceNode);
+ public boolean isCloneableNode(VpePageContext pageContext, Node sourceNode);
/**
@@ -88,6 +89,6 @@
*
* @return true, if is in resources bundle
*/
- boolean isInResourcesBundle(VpePageContext pageContext, Element sourceNode);
+ boolean isInResourcesBundle(VpePageContext pageContext, Node sourceNode);
}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlTextTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlTextTemplate.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlTextTemplate.java 2008-07-30
18:27:32 UTC (rev 9440)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+* Copyright (c) 2007 Red Hat, Inc.
+* Distributed under license by Red Hat, Inc. All rights reserved.
+* This program is 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:
+* Red Hat, Inc. - initial API and implementation
+******************************************************************************/
+
+package org.jboss.tools.vpe.html.template;
+
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.jboss.tools.vpe.editor.util.TextUtil;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Node;
+
+/**
+ * @author mareshkau
+ * Template for text nodes
+ */
+public class HtmlTextTemplate extends VpeAbstractTemplate {
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.vpe.editor.template.VpeTemplate#create(org.jboss.tools.vpe.editor.context.VpePageContext,
org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMDocument)
+ */
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+ String sourceText = sourceNode.getNodeValue();
+
+ if (sourceText.trim().length() <= 0) {
+ return new VpeCreationData(visualDocument.createTextNode(sourceText));
+ }
+ String visualText = TextUtil.visualText(sourceText);
+
+ nsIDOMNode visualNewTextNode = visualDocument
+ .createTextNode(visualText);
+ //TODO Max Areshkau think may be we shouldn't use span
+ nsIDOMElement element = visualDocument.createElement(HTML.TAG_SPAN);
+ element.appendChild(visualNewTextNode);
+
+ return new VpeCreationData(element);
+ }
+
+}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml 2008-07-30
15:05:47 UTC (rev 9439)
+++ trunk/vpe/plugins/org.jboss.tools.vpe.html/templates/vpe-templates-html.xml 2008-07-30
18:27:32 UTC (rev 9440)
@@ -2136,7 +2136,13 @@
<vpe:comment />
</vpe:template>
</vpe:tag>
-
+
+ <vpe:tag name="#text" case-sensitive="no">
+ <vpe:template children="no" modify="yes"
+ class="org.jboss.tools.vpe.html.template.HtmlTextTemplate">
+ </vpe:template>
+ </vpe:tag>
+
<vpe:template children="yes" modify="yes">
<vpe:any value="{name()}" title="{tagstring()}" />
</vpe:template>