[jbosstools-commits] JBoss Tools SVN: r7065 - trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Mar 21 12:47:32 EDT 2008


Author: dmaliarevich
Date: 2008-03-21 12:47:32 -0400 (Fri, 21 Mar 2008)
New Revision: 7065

Modified:
   trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabPanelTemplate.java
   trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabTemplate.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1697, toggling on tab with label facet fixed

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabPanelTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabPanelTemplate.java	2008-03-21 16:47:27 UTC (rev 7064)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabPanelTemplate.java	2008-03-21 16:47:32 UTC (rev 7065)
@@ -10,6 +10,7 @@
  ******************************************************************************/ 
 package org.jboss.tools.jsf.vpe.richfaces.template;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -23,6 +24,9 @@
 import org.jboss.tools.vpe.editor.template.VpeToggableTemplate;
 import org.mozilla.interfaces.nsIDOMDocument;
 import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMNodeList;
+import org.mozilla.xpcom.XPCOMException;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
@@ -64,6 +68,7 @@
 	private final String TAB = ":tab"; //$NON-NLS-1$
 	private final String NAME = "name"; //$NON-NLS-1$
 	
+	private List<nsIDOMElement> storedTabHeaders = new ArrayList<nsIDOMElement>();
 	private static Map toggleMap = new HashMap();
 
 	public VpeCreationData create(VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument) {
@@ -77,9 +82,7 @@
 		setDirAttr(table, sourceElement);
 		table.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, 
 				ComponentUtil.getAttribute(sourceElement,	HtmlComponentUtil.HTML_STYLECLASS_ATTR)
-				+ SPACE + CSS_PANEL
-				+ SPACE + CSS_CONTENT
-				+ SPACE + CSS_CONTENT_POSITION);
+				+ SPACE + CSS_PANEL);
 		table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, ZERO);
 		table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, ZERO);
 		table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, ZERO);
@@ -98,6 +101,8 @@
 		inerTable.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, ZERO);
 		inerTable.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, ZERO);
 		inerTable.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, ZERO);
+		inerTable.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, 
+				CSS_CONTENT + SPACE + CSS_CONTENT_POSITION);
 
 		// Encode header
 		nsIDOMElement inerTr = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR);
@@ -118,7 +123,7 @@
 			boolean active = (i == activeId);
 			
 			if(child.getNodeName().endsWith(TAB)) {
-				RichFacesTabTemplate.encodeHeader(creationData,
+				nsIDOMElement headerTd = RichFacesTabTemplate.encodeHeader(creationData,
 						(Element) child,
 						visualDocument, inerTr, active, 
 						ComponentUtil.getAttribute(sourceElement, 
@@ -142,6 +147,7 @@
 					headerSpacing = ONE;
 				}
 				spaceImg.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, "width: " + headerSpacing + "px"); //$NON-NLS-1$ //$NON-NLS-2$
+				storedTabHeaders.add(headerTd);
 			}
 		}
 
@@ -309,4 +315,68 @@
 		return true;
 	}
 	
+	/**
+	 * Is invoked after construction of all child nodes of the current visual node.
+	 * @param pageContext Contains the information on edited page.
+	 * @param sourceNode The current node of the source tree.
+	 * @param visualDocument The document of the visual tree.
+	 * @param data Object <code>VpeCreationData</code>, built by a method <code>create</code>
+	 */
+	public void validate(VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument, VpeCreationData data) {
+		
+		super.validate(pageContext, sourceNode, visualDocument, data);
+		if ((storedTabHeaders == null) || (storedTabHeaders.size() < 1)){
+			return;
+		}
+		
+		for (nsIDOMElement tab : storedTabHeaders) {
+			String value = tab.getAttribute(VpeVisualDomBuilder.VPE_USER_TOGGLE_ID);
+			applyAttributeValueOnChildren(VpeVisualDomBuilder.VPE_USER_TOGGLE_ID, value, getChildren(tab));
+			applyAttributeValueOnChildren(VpeVisualDomBuilder.VPE_USER_TOGGLE_LOOKUP_PARENT, "true", getChildren(tab));
+		}
+		
+	}
+	
+	/**
+	 * 	Sets the attribute to element children 
+	 * @param attrName attribute name
+	 * @param attrValue attribute value
+	 * @param children children
+	 */
+	private void applyAttributeValueOnChildren(String attrName, String attrValue, List<nsIDOMElement> children) {
+		if (children == null || attrName == null || attrValue == null) {
+			return;
+		}
+		for (nsIDOMElement child : children) {
+			child.setAttribute(attrName, attrValue);
+			applyAttributeValueOnChildren(attrName, attrValue, getChildren(child));
+		}
+	}
+	
+	/**
+	 * Gets element children
+	 * @param element the element
+	 * @return children
+	 */
+	private List<nsIDOMElement> getChildren(nsIDOMElement element) {
+		List<nsIDOMElement> result = new ArrayList<nsIDOMElement>();
+		if (element.hasChildNodes()) {
+			nsIDOMNodeList children = element.getChildNodes();
+			if (null != children) {
+				long len = children.getLength();
+				for (int i = 0; i < len; i++) {
+					nsIDOMNode item = children.item(i);
+					try {
+						nsIDOMElement elem = (nsIDOMElement) item
+								.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+						result.add(elem);
+					} catch (XPCOMException ex) {
+						// just ignore this exception
+					}
+				}
+			}
+		}
+		return result;
+	}
+	
 }
\ No newline at end of file

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabTemplate.java	2008-03-21 16:47:27 UTC (rev 7064)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesTabTemplate.java	2008-03-21 16:47:32 UTC (rev 7065)
@@ -126,25 +126,25 @@
 	 * Encode Header of tab
 	 * @param sourceElement
 	 * @param visualDocument
-	 * @param parentDiv
+	 * @param parentTr
 	 * @param active
 	 * @param activeTabClass
 	 * @param inactiveTabClass
 	 * @param disabledTabClass
 	 */
-	public static void encodeHeader(VpeCreationData creationData,
+	public static nsIDOMElement encodeHeader(VpeCreationData creationData,
 			Element sourceElement, 
 			nsIDOMDocument visualDocument,
-			nsIDOMElement parentDiv,
+			nsIDOMElement parentTr,
 			boolean active,
 			String activeTabClass,
 			String inactiveTabClass,
 			String disabledTabClass, 
 			String toggleId) {
 	    
-		nsIDOMElement td = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
-		parentDiv.appendChild(td);
-		td.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, "height: 100%; vertical-align: bottom;");
+		nsIDOMElement headerTd = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
+		parentTr.appendChild(headerTd);
+		headerTd.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, "height: 100%; vertical-align: bottom;");
 		String styleClass = "dr-tbpnl-tbcell-dsbl rich-tabhdr-cell-dsbl";
 		if(!"true".equalsIgnoreCase(sourceElement.getAttribute(DISABLED))) {
 			if(active) {
@@ -155,11 +155,11 @@
 					+ SPACE + RichFacesTabPanelTemplate.CSS_CELL_INACTIVE;
 			}
 		}
-		td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, styleClass);
-		td.setAttribute(VPE_USER_TOGGLE_ID, toggleId);
+		headerTd.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, styleClass);
+		headerTd.setAttribute(VPE_USER_TOGGLE_ID, toggleId);
 
 		nsIDOMElement table = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE);
-		td.appendChild(table);
+		headerTd.appendChild(table);
 		table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, ZERO);
 		table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, ZERO);
 		table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, ZERO);
@@ -170,16 +170,16 @@
 		table.appendChild(mainTr);
 		encodeSpacer(mainTr, visualDocument);
 
-		td = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
-		mainTr.appendChild(td);
-		td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, "dr-tbpnl-tbtopbrdr"
+		headerTd = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
+		mainTr.appendChild(headerTd);
+		headerTd.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, "dr-tbpnl-tbtopbrdr"
 				+ SPACE + RichFacesTabPanelTemplate.CSS_SIDE_CELL);
-		td.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, "width: "
+		headerTd.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, "width: "
 				+ ComponentUtil.getAttribute(sourceElement, LABEL_WIDTH) + ";");
-		td.setAttribute(VPE_USER_TOGGLE_ID, toggleId);
+		headerTd.setAttribute(VPE_USER_TOGGLE_ID, toggleId);
 
 		table = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE);
-		td.appendChild(table);
+		headerTd.appendChild(table);
 		table.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, "height: 100%; width: 100%;");
 		table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, ZERO);
 		table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, ZERO);
@@ -188,8 +188,8 @@
 
 		nsIDOMElement tr = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR);
 		table.appendChild(tr);
-		td = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
-		tr.appendChild(td);
+		headerTd = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
+		tr.appendChild(headerTd);
 
 		styleClass = "dr-tbpnl-tb dr-tbpnl-tb-dsbl"
 			+ SPACE + CSS_HEADER
@@ -215,24 +215,25 @@
 			}
 		}
 
-		td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, styleClass);
+		headerTd.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, styleClass);
 		String style = "background-image: url(file:///" + bgImgPath.replace('\\', '/') + ");";
-		td.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, style);
-		td.setAttribute(VPE_USER_TOGGLE_ID, toggleId);
+		headerTd.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, style);
+		headerTd.setAttribute(VPE_USER_TOGGLE_ID, toggleId);
 		Node labelFacet = ComponentUtil.getFacet(sourceElement, LABEL, true);
 		String labelAttr = sourceElement.getAttribute(LABEL);
 		if (null != labelFacet) {
-			VpeChildrenInfo child = new VpeChildrenInfo(td);
+			VpeChildrenInfo child = new VpeChildrenInfo(headerTd);
 			child.addSourceChild(labelFacet);
 			creationData.addChildrenInfo(child);
 		} else if (null != labelAttr) {
-			td.appendChild(visualDocument.createTextNode(labelAttr));
+			headerTd.appendChild(visualDocument.createTextNode(labelAttr));
 		} else {
 			char space = 160;
 			labelAttr = EMPTY + space;
-			td.appendChild(visualDocument.createTextNode(labelAttr));
+			headerTd.appendChild(visualDocument.createTextNode(labelAttr));
 		}
 		encodeSpacer(mainTr, visualDocument);
+		return headerTd;
 	}
 
 	/*




More information about the jbosstools-commits mailing list