### Eclipse Workspace Patch 1.0
#P org.jboss.tools.vpe
Index: src/org/jboss/tools/vpe/editor/template/VpeDefineContainerTemplate.java
===================================================================
--- src/org/jboss/tools/vpe/editor/template/VpeDefineContainerTemplate.java	(revision 36864)
+++ src/org/jboss/tools/vpe/editor/template/VpeDefineContainerTemplate.java	(working copy)
@@ -42,49 +42,53 @@
 	initTemplateSections(templateElement, false, true, false, false, false);
     }
 
-    public VpeCreationData createTemplate(String includedFileName,
-	    VpePageContext pageContext, Node sourceNode,
-	    nsIDOMDocument visualDocument) {
-	VpeCreationData creationData = null;
-	if (includedFileName != null && includedFileName.trim().length() > 0) {
-	    IFile file = VpeCreatorUtil.getFile(includedFileName, pageContext);
-	    if (file != null) {
-		if (!pageContext.getVisualBuilder().isFileInIncludeStack(file)) {
-		    registerDefine(pageContext, sourceNode);
-		    Document document = pageContext.getVisualBuilder()
-			    .getIncludeDocuments().get(file);
-		    if (document == null) {
-			document = VpeCreatorUtil.getDocumentForRead(file);
-			if (document != null)
-			    pageContext.getVisualBuilder()
-				    .getIncludeDocuments().put(file, document);
-		    }
-		    // Document document =
-		    // VpeCreatorUtil.getDocumentForRead(file, pageContext);
-		    if (document != null) {
-			creationData = createInclude(document, visualDocument);
-			creationData.setData(new TemplateFileInfo(file));
-			pageContext.getVisualBuilder().pushIncludeStack(
-				new VpeIncludeInfo((Element) sourceNode, file,
-					document));
-			/*
-			 * we should add only real node, sourceNode can be a
-			 * proxy so
-			 */
-			if (sourceNode.getFirstChild() != null) {
-			    defineContainer.add(sourceNode.getFirstChild()
-				    .getParentNode());
+	public VpeCreationData createTemplate(String includedFileName,
+			VpePageContext pageContext, Node sourceNode,
+			nsIDOMDocument visualDocument) {
+		VpeCreationData creationData = null;
+		if (includedFileName != null && includedFileName.trim().length() > 0) {
+			IFile file = VpeCreatorUtil.getFile(includedFileName, pageContext);
+			if (file != null) {
+				if (!pageContext.getVisualBuilder().isFileInIncludeStack(file)) {
+//					registerDefine(pageContext, sourceNode);
+					Document document = pageContext.getVisualBuilder()
+							.getIncludeDocuments().get(file);
+					if (document == null) {
+						document = VpeCreatorUtil.getDocumentForRead(file);
+					}
+					// Document document = VpeCreatorUtil.getDocumentForRead(file, pageContext);
+					if (document != null) {
+						/*
+						 * Putting include document
+						 */
+						pageContext.getVisualBuilder()
+							.getIncludeDocuments().put(file, document);
+						creationData = createInclude(document, visualDocument);
+						creationData.setData(new TemplateFileInfo(file));
+						/*
+						 * Pushing include stack and right after that --
+						 * registering DOM Mapping with visual element:
+						 * which is <DIV VPE:INCLUDE-ELEMENT="yes">
+						 */
+						pageContext.getVisualBuilder().pushIncludeStack(
+								new VpeIncludeInfo((Element) sourceNode, file, document));
+						registerDefine(pageContext, sourceNode, creationData.getNode());
+						/*
+						 * we should add only real node, sourceNode can be a
+						 * proxy so
+						 */
+						if (sourceNode.getFirstChild() != null) {
+							defineContainer.add(sourceNode.getFirstChild().getParentNode());
+						}
+						return creationData;
+					}
+				}
 			}
-			return creationData;
-		    }
 		}
-	    }
-	}
 	/*
 	 * Create a stub when creationData is null.
 	 */
-	creationData = createStub(includedFileName, (Element) sourceNode,
-		visualDocument);
+	creationData = createStub(includedFileName, (Element) sourceNode,visualDocument);
 	creationData.setData(null);
 	return creationData;
     }
@@ -268,33 +272,39 @@
 	return true;
     }
 
-    private void registerDefine(VpePageContext pageContext, Node defineContainer) {
-	VpeTemplate template = null;
-	NodeList sourceChildren = defineContainer.getChildNodes();
-	int len = sourceChildren.getLength();
-	for (int i = 0; i < len; i++) {
-	    Node sourceChild = sourceChildren.item(i);
-	    if (sourceChild.getNodeType() == Node.ELEMENT_NODE
-		    && "define".equals(sourceChild.getLocalName())) { //$NON-NLS-1$
-		if (template == null) {
-		    VpeTemplateManager templateManager = pageContext
-			    .getVisualBuilder().getTemplateManager();
-		    template = templateManager.getTemplate(pageContext,
-			    (Element) sourceChild, null);
-		    if (template == null) {
-			break;
-		    }
+	private void registerDefine(VpePageContext pageContext, Node defineContainer, nsIDOMNode visualNode) {
+		VpeTemplate template = null;
+		NodeList sourceChildren = defineContainer.getChildNodes();
+		int len = sourceChildren.getLength();
+		for (int i = 0; i < len; i++) {
+			Node sourceChild = sourceChildren.item(i);
+			if (sourceChild.getNodeType() == Node.ELEMENT_NODE
+					&& "define".equals(sourceChild.getLocalName())) { //$NON-NLS-1$
+				if (template == null) {
+					VpeTemplateManager templateManager = pageContext
+							.getVisualBuilder().getTemplateManager();
+					template = templateManager.getTemplate(
+							pageContext, (Element) sourceChild, null);
+					if (template == null) {
+						break;
+					}
+				}
+//				System.out.println("-REGISTER DEFINE--> sourceChild = " + sourceChild);
+//				System.out.println(" visualNode=["
+//						+ visualNode.getNodeName() + ", "
+//						+ visualNode.getNodeValue() + "]");
+				pageContext.getVisualBuilder().registerNodes(
+						new VpeElementMapping(sourceChild, null, template, null, null, null)
+//						new VpeElementMapping((Element) sourceChild, 
+//								null, null, template, null, null)
+						);
+			}
 		}
-		pageContext.getVisualBuilder().registerNodes(
-			new VpeElementMapping((Element) sourceChild, null, template, null, null));
-	    }
 	}
-    }
 
     private VpeCreationData createInclude(Document sourceDocument,
 	    nsIDOMDocument visualDocument) {
-	nsIDOMElement visualNewElement = visualDocument
-		.createElement(HTML.TAG_DIV);
+	nsIDOMElement visualNewElement = visualDocument.createElement(HTML.TAG_DIV);
 	VpeVisualDomBuilder.markIncludeElement(visualNewElement);
 	VpeCreationData creationData = new VpeCreationData(visualNewElement);
 	VpeChildrenInfo childrenInfo = new VpeChildrenInfo(visualNewElement);
