Author: dmaliarevich
Date: 2008-08-28 10:57:25 -0400 (Thu, 28 Aug 2008)
New Revision: 9941
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/menuGroup/
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/menuGroup/spacer.gif
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/menuItem/
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/menuItem/spacer.gif
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMenuGroupTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMenuItemTemplate.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDropDownMenuTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/templates/vpe-templates-richfaces.xml
Log:
https://jira.jboss.org/jira/browse/JBIDE-2497,
templates for menuGroup and menuItem were added, dropDownMenu template was updated.
Added: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/menuGroup/spacer.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/menuGroup/spacer.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/menuItem/spacer.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/menuItem/spacer.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDropDownMenuTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDropDownMenuTemplate.java 2008-08-28
12:28:20 UTC (rev 9940)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesDropDownMenuTemplate.java 2008-08-28
14:57:25 UTC (rev 9941)
@@ -1,284 +1,317 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and 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:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ * Copyright (c) 2007-2008 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.jsf.vpe.richfaces.template;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
+import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.template.VpeMouseOverTemplate;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;
+import org.mozilla.interfaces.nsIDOMText;
import org.mozilla.xpcom.XPCOMException;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
public class RichFacesDropDownMenuTemplate extends VpeAbstractTemplate {
- private static final String STYLECLASS_ATTR_NAME = "styleClass";
- private static final String STYLE_ATTR_NAME = "style";
- private static final String ITEMCLASS_ATTR_NAME = "itemClass";
- private static final String ITEMSTYLE_ATTR_NAME = "itemStyle";
- private static final String LABEL_FACET_NAME = "label";
+ /*
+ * rich:dropDownMenu constants
+ */
+ private static final String LABEL_FACET_NAME = "label"; //$NON-NLS-1$
+ private static final String EMPTY = ""; //$NON-NLS-1$
+ private static final String SPACE = " "; //$NON-NLS-1$
+
+ /*
+ * rich:dropDownMenu css styles names
+ */
+ private static final String CSS_RICH_DDMENU_LABEL = "rich-ddmenu-label";
//$NON-NLS-1$
+ private static final String CSS_RICH_DDMENU_LABEL_UNSELECT =
"rich-ddmenu-label-unselect"; //$NON-NLS-1$
+ private static final String CSS_RICH_DDMENU_LABEL_SELECT =
"rich-ddmenu-label-select"; //$NON-NLS-1$
+ private static final String CSS_RICH_DDMENU_LABEL_DISABLED =
"rich-ddmenu-label-disabled"; //$NON-NLS-1$
+ private static final String CSS_RICH_LABEL_TEXT_DECOR =
"rich-label-text-decor"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_LIST_BORDER =
"rich-menu-list-border"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_LIST_BG = "rich-menu-list-bg";
//$NON-NLS-1$
+ private static final String CSS_RICH_DDEMENU_LIST_DIV_STYLE = "position: relative;
z-index: 100;"; //$NON-NLS-1$
+ private static final String CSS_RICH_DDEMENU_BORDER_DIV_STYLE = "position:
relative; z-index: 2;"; //$NON-NLS-1$
+ /*
+ * rich:dropDownMenu attributes names
+ */
+ private static final String DIRECTION = "direction"; //$NON-NLS-1$
+ private static final String HORIZONTAL_OFFCET = "horizontalOffset";
//$NON-NLS-1$
+ private static final String JOINT_POINT = "jontPoint"; //$NON-NLS-1$
+ private static final String POPUP_WIDTH = "popupWidth"; //$NON-NLS-1$
+ private static final String VERTICAL_OFFSET = "verticalOffset"; //$NON-NLS-1$
+
+ /*
+ * rich:menuGroup css styles and classes attributes names
+ */
+ private static final String DISABLED_ITEM_CLASS = "disabledItemClass";
//$NON-NLS-1$
+ private static final String DISABLED_ITEM_STYLE = "disabledItemStyle";
//$NON-NLS-1$
+ private static final String DISABLED_LABEL_CLASS = "disabledLabelClass";
//$NON-NLS-1$
+ private static final String ITEM_CLASS = "itemClass"; //$NON-NLS-1$
+ private static final String ITEM_STYLE = "itemStyle"; //$NON-NLS-1$
+ private static final String SELECED_LABEL_CLASS = "selectedLabelClass";
//$NON-NLS-1$
+ private static final String SELECT_ITEM_CLASS = "selectItemClass";
//$NON-NLS-1$
+
+ /*
+ * rich:dropDownMenu attributes
+ */
+ private String ddm_direction;
+ private String ddm_disabled;
+ private String ddm_horizontalOffset;
+ private String ddm_jointPoint;
+ private String ddm_popupWidth;
+ private String ddm_verticalOffset;
+ /*
+ * rich:dropDownMenu css styles and classes attributes
+ */
+ private String ddm_disabledItemClass;
+ private String ddm_disabledItemStyle;
+ private String ddm_disabledLabelClass;
+ private String ddm_itemClass;
+ private String ddm_itemStyle;
+ private String ddm_selectedLabelClass;
+ private String ddm_selectItemClass;
+ private String ddm_style;
+ private String ddm_styleClass;
+
+ private nsIDOMElement storedVisualMenu = null;
+ private int ddmId = 1;
+
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
- VpeCreationData creatorInfo = null;
-
+ VpeCreationData creationData = null;
Element sourceElement = (Element)sourceNode;
- nsIDOMElement visualMenu =
visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
-
- ComponentUtil.setCSSLink(pageContext, "dropDownMenu/dropDownMenu.css",
"richFacesDropDownMenu");
-
- correctAttribute(sourceElement, visualMenu,
- STYLECLASS_ATTR_NAME,
- HtmlComponentUtil.HTML_CLASS_ATTR,
- "dr-menu-label dr-menu-label-unselect rich-ddmenu-label
rich-ddmenu-label-unselect",
- "dr-menu-label dr-menu-label-unselect rich-ddmenu-label
rich-ddmenu-label-unselect");
- correctAttribute(sourceElement, visualMenu,
- STYLE_ATTR_NAME,
- HtmlComponentUtil.HTML_STYLE_ATTR, null, null);
-
- nsIDOMElement visualMenuLabel =
visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
- visualMenuLabel.setAttribute("class", "dr-label-text-decor
rich-label-text-decor");
- correctAttribute(sourceElement, visualMenuLabel,
- ITEMCLASS_ATTR_NAME,
- HtmlComponentUtil.HTML_CLASS_ATTR,
- "dr-label-text-decor rich-label-text-decor",
- "dr-label-text-decor rich-label-text-decor");
- correctAttribute(sourceElement, visualMenuLabel,
- ITEMSTYLE_ATTR_NAME,
- HtmlComponentUtil.HTML_STYLE_ATTR, null, null);
-
-
- visualMenu.appendChild(visualMenuLabel);
- creatorInfo = new VpeCreationData(visualMenu);
- VpeChildrenInfo childrenInfo = new VpeChildrenInfo(visualMenuLabel);
- Element facetElement = getLabelFacet(sourceElement);
+ readDropDownMenuAttributes(sourceElement);
+
+ /*
+ * DropDownMenu component structure.
+ * In order of nesting.
+ */
+ nsIDOMElement ddmLabelDiv;
+ nsIDOMElement ddmTextSpan;
+ nsIDOMText ddmLabelText;
+ nsIDOMElement ddmListDiv;
+ nsIDOMElement ddmListBorderDiv;
+ nsIDOMElement ddmListBgDiv;
+
+ /*
+ * Creating visual elements
+ */
+ ddmLabelDiv = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ ddmTextSpan = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_SPAN);
+ ddmLabelText = visualDocument.createTextNode(""); //$NON-NLS-1$
+ ddmListDiv = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ ddmListBorderDiv = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ ddmListBgDiv = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ creationData = new VpeCreationData(ddmLabelDiv);
+ storedVisualMenu = ddmLabelDiv;
+
+ /*
+ * Nesting elements
+ */
+ ddmLabelDiv.appendChild(ddmTextSpan);
+ ddmTextSpan.appendChild(ddmLabelText);
+ ddmLabelDiv.appendChild(ddmListDiv);
+ ddmListDiv.appendChild(ddmListBorderDiv);
+ ddmListBorderDiv.appendChild(ddmListBgDiv);
+
+ /*
+ * Setting css classes
+ */
+ String labelDivClass = EMPTY;
+ String listBorderDivClass = EMPTY;
- if (facetElement != null) {
- childrenInfo.addSourceChild(facetElement);
- } else {
- Attr ddmLabelFromAttribute = sourceElement.getAttributeNode("value");
- String valueForLabel = ddmLabelFromAttribute != null &&
ddmLabelFromAttribute.getValue() != null
- ? ddmLabelFromAttribute.getValue()
- : "";
- nsIDOMNode textLabel = visualDocument.createTextNode(valueForLabel);
- visualMenuLabel.appendChild(textLabel);
- }
-
- creatorInfo.addChildrenInfo(childrenInfo);
- visualMenu.appendChild(visualMenuLabel);
+ labelDivClass += SPACE + CSS_RICH_DDMENU_LABEL + SPACE +
CSS_RICH_DDMENU_LABEL_UNSELECT;
+ listBorderDivClass += SPACE + CSS_RICH_MENU_LIST_BORDER;
- return creatorInfo;
- }
-
-
-
- private Element getLabelFacet(Element sourceElement) {
- if (sourceElement == null) {
- return null;
+ if (attrPresents(ddm_styleClass)) {
+ labelDivClass += SPACE + ddm_styleClass;
+ listBorderDivClass += SPACE + ddm_styleClass;
}
- NodeList children = sourceElement.getChildNodes();
- if (children != null) {
- int size = children.getLength();
- if (size > 0) {
- for (int i=0; i<size; i++) {
- Node child = children.item(i);
- if (child.getNodeType() == Node.ELEMENT_NODE
- && child.getNodeName().endsWith(":facet")) {
- Element facetElement = (Element)child;
- if (LABEL_FACET_NAME.equals(facetElement.getAttribute("name"))) {
- return facetElement;
- }
- }
- }
- }
+ ddmLabelDiv.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, labelDivClass);
+ ddmTextSpan.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
CSS_RICH_LABEL_TEXT_DECOR);
+ ddmListBorderDiv.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, listBorderDivClass);
+ ddmListBgDiv.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_RICH_MENU_LIST_BG);
+
+ /*
+ * Setting css styles
+ */
+ String cssLabelDivStyle = EMPTY;
+ String cssListBorderDivStyle = EMPTY;
+
+ cssLabelDivStyle += SPACE + CSS_RICH_DDEMENU_LIST_DIV_STYLE;
+ cssListBorderDivStyle += SPACE + CSS_RICH_DDEMENU_BORDER_DIV_STYLE;
+
+ ddmListDiv.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, cssLabelDivStyle);
+ ddmListBorderDiv.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
cssListBorderDivStyle);
+
+ /*
+ * Encoding label value
+ */
+ Element labelFacet = ComponentUtil.getFacet(sourceElement, LABEL_FACET_NAME);
+ if (null != labelFacet) {
+ VpeChildrenInfo childrenInfo = new VpeChildrenInfo(ddmTextSpan);
+ childrenInfo.addSourceChild(labelFacet);
+ creationData.addChildrenInfo(childrenInfo);
+ } else {
+ Attr valueAttr = sourceElement.getAttributeNode(HtmlComponentUtil.HTML_VALUE_ATTR);
+ String labelValue = valueAttr != null && valueAttr.getValue() != null
+ ? valueAttr.getValue()
+ : EMPTY;
+ ddmLabelText.setNodeValue(labelValue);
}
+
- return null;
- }
-
- private String getElementTextContent(Element element) {
- String content = null;
- NodeList children = element.getChildNodes();
- for (int i = 0; children != null && i < children.getLength(); i++) {
- String text = null;
- if (children.item(i).getNodeType() == Node.TEXT_NODE) {
- text = children.item(i).getNodeValue();
- } else if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
- text = getElementTextContent((Element)children.item(i));
+ /*
+ * Adding child nodes
+ */
+ List<Node> children = ComponentUtil.getChildren(sourceElement);
+ int groupCount = 1;
+ for (Node child : children) {
+ if (child.getNodeType() == Node.ELEMENT_NODE
+ && child.getNodeName().endsWith(":menuGroup")) { //$NON-NLS-1$
+ child.setUserData(RichFacesMenuGroupTemplate.MENU_GROUP_ID,
+ String.valueOf(groupCount), null);
+ groupCount++;
}
- if (text != null && text.trim().length() > 0) {
- if (content == null) {
- content = text;
- } else {
- content += " " + text;
- }
- }
+ nsIDOMElement childDiv = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ ddmListBorderDiv.appendChild(childDiv);
+ VpeChildrenInfo childDivInfo = new VpeChildrenInfo(childDiv);
+ childDivInfo.addSourceChild(child);
+ creationData.addChildrenInfo(childDivInfo);
}
-
- return content;
+
+ return creationData;
}
-
- @Override
- public void removeAttribute(VpePageContext pageContext, Element sourceElement,
nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data, String name) {
- processAttributeChanges(pageContext, sourceElement, visualDocument, visualNode, data,
name);
- }
- @Override
- public void setAttribute(VpePageContext pageContext, Element sourceElement,
nsIDOMDocument visualDocument, nsIDOMNode visualNode, Object data, String name, String
value) {
- processAttributeChanges(pageContext, sourceElement, visualDocument, visualNode, data,
name);
- }
+ @Override
+ public void validate(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument, VpeCreationData data) {
+ super.validate(pageContext, sourceNode, visualDocument, data);
+ List<nsIDOMElement> children = getChildren(storedVisualMenu);
+
+ storedVisualMenu.setAttribute(VpeVisualDomBuilder.VPE_USER_MOUSE_OVER_ID,
String.valueOf(ddmId));
+// applyAttributeValueOnChildren(VpeVisualDomBuilder.VPE_USER_MOUSE_OVER_ID,
String.valueOf(ddmId), children);
+// applyAttributeValueOnChildren(
+// VpeVisualDomBuilder.VPE_USER_MOUSE_OVER_LOOKUP_PARENT,
+// "true", children); //$NON-NLS-1$
+ }
- /**
- * Correct list style accordinly parameters
- *
- * @param pageContext
- * @param sourceElement
- * @param visualDocument
- * @param visualNode
- * @param data
- * @param name
- */
-
- private void processAttributeChanges(VpePageContext pageContext,
- Element sourceElement, nsIDOMDocument visualDocument, nsIDOMNode visualNode,
- Object data, String name) {
- nsIDOMElement el = (nsIDOMElement)
visualNode.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
-
- if (STYLECLASS_ATTR_NAME.equals(name)) {
- if (el.getNodeName()
- .equalsIgnoreCase(HtmlComponentUtil.HTML_TAG_DIV)) {
- correctAttribute(sourceElement, el,
- STYLECLASS_ATTR_NAME,
- HtmlComponentUtil.HTML_CLASS_ATTR,
- "dr-menu-label dr-menu-label-unselect rich-ddmenu-label
rich-ddmenu-label-unselect",
- "dr-menu-label dr-menu-label-unselect rich-ddmenu-label
rich-ddmenu-label-unselect");
+ /**
+ * 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;
}
- } else if (STYLE_ATTR_NAME.equals(name)) {
- if (el.getNodeName()
- .equalsIgnoreCase(HtmlComponentUtil.HTML_TAG_DIV)) {
- correctAttribute(sourceElement, el,
- STYLE_ATTR_NAME,
- HtmlComponentUtil.HTML_STYLE_ATTR, null, null);
+ for (nsIDOMElement child : children) {
+ child.setAttribute(attrName, attrValue);
+ applyAttributeValueOnChildren(attrName, attrValue, getChildren(child));
}
- } else if (ITEMCLASS_ATTR_NAME.equals(name)) {
- nsIDOMNodeList nodeList = el.getChildNodes();
- nsIDOMNode temp = null;
- for (int i = 0; i < nodeList.getLength(); i++) {
- temp = nodeList.item(i);
- if ((temp instanceof Element)
- && (temp.getNodeName()
- .equalsIgnoreCase(HtmlComponentUtil.HTML_TAG_DIV))) {
- correctAttribute(sourceElement, (nsIDOMElement)
temp.queryInterface(nsIDOMNode.NS_IDOMNODE_IID),
- ITEMCLASS_ATTR_NAME,
- HtmlComponentUtil.HTML_CLASS_ATTR,
- "dr-label-text-decor rich-label-text-decor",
- "dr-label-text-decor rich-label-text-decor");
+ }
+
+ /**
+ * 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
+ }
+ }
}
}
- } else if (ITEMSTYLE_ATTR_NAME.equals(name)) {
- nsIDOMNodeList nodeList = el.getChildNodes();
- nsIDOMNode temp = null;
- for (int i = 0; i < nodeList.getLength(); i++) {
- temp = nodeList.item(i);
- if ((temp instanceof Element)
- && (temp.getNodeName()
- .equalsIgnoreCase(HtmlComponentUtil.HTML_TAG_DIV))) {
- correctAttribute(sourceElement, (nsIDOMElement)
temp.queryInterface(nsIDOMNode.NS_IDOMNODE_IID),
- ITEMSTYLE_ATTR_NAME,
- HtmlComponentUtil.HTML_STYLE_ATTR, null, null);
- }
- }
+ return result;
}
- }
- /**
- * Move attributes from sourceNode to html
- *
- * @param sourceNode
- * @param visualElement
- * @param attrName
- * @param htmlAttrName
- * @param prefValue
- * @param defValue
- */
- private void correctAttribute(Element sourceNode, nsIDOMElement visualElement,
- String attrName, String htmlAttrName, String prefValue, String defValue) {
- String attrValue = ((Element) sourceNode).getAttribute(attrName);
- if (prefValue != null && prefValue.trim().length() > 0 && attrValue
!= null) {
- attrValue = prefValue.trim() + " " + attrValue;
+ /**
+ * Read attributes from the source element.
+ *
+ * @param sourceNode the source node
+ */
+ private void readDropDownMenuAttributes(Element sourceElement) {
+ if (null == sourceElement) {
+ return;
+ }
+
+ ddm_direction = sourceElement.getAttribute(DIRECTION);
+ ddm_disabled = sourceElement.getAttribute(HtmlComponentUtil.HTML_ATTR_DISABLED);
+ ddm_horizontalOffset = sourceElement.getAttribute(HORIZONTAL_OFFCET);
+ ddm_jointPoint = sourceElement.getAttribute(JOINT_POINT);
+ ddm_popupWidth = sourceElement.getAttribute(POPUP_WIDTH);
+ ddm_verticalOffset = sourceElement.getAttribute(VERTICAL_OFFSET);
+
+ ddm_disabledItemClass = sourceElement.getAttribute(DISABLED_ITEM_CLASS);
+ ddm_disabledItemStyle = sourceElement.getAttribute(DISABLED_ITEM_STYLE);
+ ddm_disabledLabelClass = sourceElement.getAttribute(DISABLED_LABEL_CLASS);
+ ddm_itemClass = sourceElement.getAttribute(ITEM_CLASS);
+ ddm_itemStyle = sourceElement.getAttribute(ITEM_STYLE);
+ ddm_selectedLabelClass = sourceElement.getAttribute(SELECED_LABEL_CLASS);
+ ddm_selectItemClass = sourceElement.getAttribute(SELECT_ITEM_CLASS);
+ ddm_style = sourceElement.getAttribute(HtmlComponentUtil.HTML_STYLE_ATTR);
+ ddm_styleClass = sourceElement.getAttribute(HtmlComponentUtil.HTML_STYLECLASS_ATTR);
}
- if (attrValue != null) {
- visualElement.setAttribute(htmlAttrName, attrValue);
- } else if (defValue != null) {
- visualElement.setAttribute(htmlAttrName, defValue);
- } else
- visualElement.removeAttribute(attrName);
- }
- /**
- * 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>
- */
-
- @Override
- public void validate(VpePageContext pageContext, Node sourceNode,
- nsIDOMDocument visualDocument, VpeCreationData data) {
- super.validate(pageContext, sourceNode, visualDocument, data);
- correctLabelStyles(data.getNode());
- }
-
/**
- * Correct font for label
+ * Checks is attribute have some value.
*
- * @param node
+ * @param attr the attribute
+ *
+ * @return true, if successful
*/
- private void correctLabelStyles(nsIDOMNode node) {
+ private static boolean attrPresents(String attr) {
+ return ((null != attr) && (!EMPTY.equalsIgnoreCase(attr)));
+ }
+
+ public void onMouseOver(VpeVisualDomBuilder visualDomBuilder, Node sourceNode, String
mouseOverId) {
+ // TODO Auto-generated method stub
+// visualDomBuilder.updateNode(sourceNode);
+ }
- try {
- nsIDOMElement element = (nsIDOMElement) node
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- if (node.getNodeName().equalsIgnoreCase(
- HtmlComponentUtil.HTML_TAG_SPAN)) {
- String styleClass = element.getAttribute(HtmlComponentUtil.HTML_CLASS_ATTR);
- styleClass = (styleClass==null?"":styleClass) + " dr-label-text-decor
dr-menu-label";
- element.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, styleClass);
- }
- nsIDOMNodeList list = node.getChildNodes();
- for (int i = 0; i < list.getLength(); i++) {
- correctLabelStyles(list.item(i));
- }
- } catch (XPCOMException e) {
- return;
+ public void stopMouseOver(Node sourceNode) {
+ // TODO Auto-generated method stub
+
}
- }
+
+
}
\ No newline at end of file
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMenuGroupTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMenuGroupTemplate.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMenuGroupTemplate.java 2008-08-28
14:57:25 UTC (rev 9941)
@@ -0,0 +1,286 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.vpe.richfaces.template;
+
+import java.util.List;
+
+import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
+import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
+import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
+import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.template.VpeMouseOverTemplate;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMText;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class RichFacesMenuGroupTemplate extends VpeAbstractTemplate {
+
+ /*
+ * rich:menuGroup constants
+ */
+ public static final String MENU_GROUP_ID = "MENU-GROUP-ID"; //$NON-NLS-1$
+ private static final String ICON_FACET_NAME = "icon"; //$NON-NLS-1$
+ private static final String ICON_DISABLED_FACET_NAME = "iconDisabled";
//$NON-NLS-1$
+ private static final String SPACER_IMG_PATH = "menuGroup/spacer.gif";
//$NON-NLS-1$
+ private static final String EMPTY = ""; //$NON-NLS-1$
+ private static final String SPACE = " "; //$NON-NLS-1$
+
+ /*
+ * rich:menuGroup css styles names
+ */
+ private static final String CSS_RICH_MENU_GROUP = "rich-menu-group";
//$NON-NLS-1$
+ private static final String CSS_RICH_MENU_GROUP_LABEL =
"rich-menu-group-label"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_GROUP_FOLDER =
"rich-menu-group-folder"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_GROUP_HOVER =
"rich-menu-group-over"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_LABEL = "rich-menu-item-label";
//$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_ICON = "rich-menu-item-icon";
//$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_FOLDER =
"rich-menu-item-folder"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_LABEL_DISABLED =
"rich-menu-item-label-disabled"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_ICON_DISABLED =
"rich-menu-item-icon-disabled"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_FOLDER_DISABLED =
"rich-menu-item-folder-disabled"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_ICON_ENABLED =
"rich-menu-item-icon-enabled"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_ICON_SELECTED =
"rich-menu-item-icon-seleceted"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_LIST_BORDER =
"rich-menu-list-border"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_LIST_BG = "rich-menu-list-bg";
//$NON-NLS-1$
+ private static final String CSS_RICH_LIST_FOLDER_DIV_STYLE = "position: relative;
z-index: 100;"; //$NON-NLS-1$
+ private static final String CSS_RICH_LIST_BORDER_DIV_STYLE = "position: relative;
z-index: 2;"; //$NON-NLS-1$
+
+ /*
+ * rich:menuGroup attributes names
+ */
+ private static final String DIRECTION = "direction"; //$NON-NLS-1$
+ private static final String ICON = "icon"; //$NON-NLS-1$
+ private static final String ICON_DISABLED = "iconDisabled"; //$NON-NLS-1$
+ private static final String ICON_FOLDER = "iconFolder"; //$NON-NLS-1$
+ private static final String ICON_FOLDER_DISABLED = "iconFolderDisabled";
//$NON-NLS-1$
+
+ /*
+ * rich:menuGroup css styles and classes attributes names
+ */
+ private static final String ICON_CLASS = "iconClass"; //$NON-NLS-1$
+ private static final String ICON_STYLE = "iconStyle"; //$NON-NLS-1$
+ private static final String LABEL_CLASS = "labelClass"; //$NON-NLS-1$
+ private static final String SELECT_CLASS = "selectClass"; //$NON-NLS-1$
+ private static final String SELECT_STYLE = "selectStyle"; //$NON-NLS-1$
+
+ /*
+ * rich:menuGroup attributes
+ */
+ private String mg_direction;
+ private String mg_disabled;
+ private String mg_icon;
+ private String mg_iconDisabled;
+ private String mg_iconFolder;
+ private String mg_iconFolderDisabled;
+ private String mg_value;
+
+ /*
+ * rich:menuGroup css styles and classes attributes
+ */
+ private String mg_iconClass;
+ private String mg_iconStyle;
+ private String mg_labelClass;
+ private String mg_selectClass;
+ private String mg_selectStyle;
+ private String mg_style;
+ private String mg_styleClass;
+
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+ VpeCreationData creationData = null;
+ Element sourceElement = (Element)sourceNode;
+
+ /*
+ * MenuGroup component structure.
+ * In order of nesting.
+ */
+ nsIDOMElement grTopDiv;
+ nsIDOMElement grImgSpan;
+ nsIDOMElement grImg;
+ nsIDOMElement grLabelSpan;
+ nsIDOMText grLabelText;
+ nsIDOMElement grFolderDiv;
+ nsIDOMElement grListBorderDiv;
+ nsIDOMElement grListBgDiv;
+
+ /*
+ * Creating visual elements
+ */
+ grTopDiv = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ grImgSpan = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_SPAN);
+ grImg = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_IMG);
+ grLabelSpan = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_SPAN);
+ grLabelText = visualDocument.createTextNode(EMPTY);
+ grFolderDiv = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ grListBorderDiv = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ grListBgDiv = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ creationData = new VpeCreationData(grTopDiv);
+
+ /*
+ * Nesting elements
+ */
+ grTopDiv.appendChild(grImgSpan);
+ grTopDiv.appendChild(grLabelSpan);
+ grLabelSpan.appendChild(grLabelText);
+ grTopDiv.appendChild(grFolderDiv);
+ grFolderDiv.appendChild(grListBorderDiv);
+ grListBorderDiv.appendChild(grListBgDiv);
+
+ /*
+ * Setting css classes
+ */
+
+ String topDivClass = EMPTY;
+ String imgSpanClass = EMPTY;
+ String labelSpanClass = EMPTY;
+ String folderDivClass = EMPTY;
+
+ topDivClass += SPACE + CSS_RICH_MENU_GROUP;
+ imgSpanClass += SPACE + CSS_RICH_MENU_ITEM_ICON_ENABLED;
+ labelSpanClass += SPACE + CSS_RICH_MENU_ITEM_LABEL + SPACE +
CSS_RICH_MENU_GROUP_LABEL;
+ folderDivClass += SPACE + CSS_RICH_MENU_ITEM_FOLDER + SPACE +
CSS_RICH_MENU_GROUP_FOLDER;
+
+ if (attrPresents(mg_styleClass)) {
+ topDivClass += SPACE + mg_styleClass;
+ }
+ if (attrPresents(mg_iconClass)) {
+ imgSpanClass += SPACE + mg_iconClass;
+ folderDivClass += SPACE + mg_iconClass;
+ }
+ if (attrPresents(mg_labelClass)) {
+ labelSpanClass += SPACE + mg_labelClass;
+ }
+
+ grTopDiv.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, topDivClass);
+ grImgSpan.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, imgSpanClass);
+ grLabelSpan.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, labelSpanClass);
+ grFolderDiv.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, folderDivClass);
+ grListBorderDiv.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
CSS_RICH_MENU_LIST_BORDER);
+ grListBgDiv.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_RICH_MENU_LIST_BG);
+
+ /*
+ * Setting css styles
+ */
+ grFolderDiv.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
CSS_RICH_LIST_FOLDER_DIV_STYLE);
+ grListBorderDiv.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
CSS_RICH_LIST_BORDER_DIV_STYLE);
+
+ /*
+ * Encode label value
+ */
+ Attr valueAttr = sourceElement.getAttributeNode(HtmlComponentUtil.HTML_VALUE_ATTR);
+ String labelValue = valueAttr != null
+ && valueAttr.getValue() != null ? valueAttr.getValue() : EMPTY;
+ grLabelText.setNodeValue(labelValue);
+
+ /*
+ * Encode icon facets
+ */
+ Element iconFacet = ComponentUtil.getFacet(sourceElement, ICON_FACET_NAME);
+ Element iconDisabledFacet = ComponentUtil.getFacet(sourceElement,
ICON_DISABLED_FACET_NAME);
+ if (null != iconFacet) {
+ VpeChildrenInfo childInfo = new VpeChildrenInfo(grImgSpan);
+ childInfo.addSourceChild(iconFacet);
+ creationData.addChildrenInfo(childInfo);
+ } else {
+ String iconPath = sourceElement.getAttribute(ICON);
+ if (attrPresents(iconPath)) {
+ /*
+ * Add path to specified image
+ */
+ String imgFullPath = VpeStyleUtil.addFullPathToImgSrc(iconPath, pageContext, true);
+ grImg.setAttribute(HtmlComponentUtil.HTML_ATR_SRC, imgFullPath);
+ } else {
+ /*
+ * Create spacer image
+ */
+ ComponentUtil.setImg(grImg, SPACER_IMG_PATH);
+ grImgSpan.appendChild(grImg);
+ }
+ }
+
+ String menuGroupId = (String) sourceNode.getUserData(MENU_GROUP_ID);
+ /*
+ * Adding child nodes
+ */
+ List<Node> children = ComponentUtil.getChildren(sourceElement);
+ for (Node child : children) {
+ nsIDOMElement childDiv = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ grTopDiv.appendChild(childDiv);
+ VpeChildrenInfo childDivInfo = new VpeChildrenInfo(childDiv);
+ childDivInfo.addSourceChild(child);
+ creationData.addChildrenInfo(childDivInfo);
+ }
+
+ return creationData;
+ }
+
+ /**
+ * Read attributes from the source element.
+ *
+ * @param sourceNode the source node
+ */
+ private void readMenuGroupAttributes(Element sourceElement) {
+ if (null == sourceElement) {
+ return;
+ }
+ mg_direction = sourceElement.getAttribute(DIRECTION);
+ mg_disabled = sourceElement.getAttribute(HtmlComponentUtil.HTML_ATTR_DISABLED);
+ mg_icon = sourceElement.getAttribute(ICON);
+ mg_iconDisabled = sourceElement.getAttribute(ICON_DISABLED);
+ mg_iconFolder = sourceElement.getAttribute(ICON_FOLDER);
+ mg_iconFolderDisabled = sourceElement.getAttribute(ICON_FOLDER_DISABLED);
+ mg_value = sourceElement.getAttribute(HtmlComponentUtil.HTML_VALUE_ATTR);
+
+ mg_iconClass = sourceElement.getAttribute(ICON_CLASS);
+ mg_iconStyle = sourceElement.getAttribute(ICON_STYLE);
+ mg_labelClass = sourceElement.getAttribute(LABEL_CLASS);
+ mg_selectClass = sourceElement.getAttribute(SELECT_CLASS);
+ mg_selectStyle = sourceElement.getAttribute(SELECT_STYLE);
+ mg_style = sourceElement.getAttribute(HtmlComponentUtil.HTML_STYLE_ATTR);
+ mg_styleClass = sourceElement.getAttribute(HtmlComponentUtil.HTML_STYLECLASS_ATTR);
+ }
+ /**
+ * Checks is attribute have some value.
+ *
+ * @param attr the attribute
+ *
+ * @return true, if successful
+ */
+ private static boolean attrPresents(String attr) {
+ return ((null != attr) && (!EMPTY.equalsIgnoreCase(attr)));
+ }
+
+ @Override
+ public boolean isRecreateAtAttrChange(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualNode, Object data, String name, String value) {
+ return true;
+ }
+
+ public void onMouseOver(VpeVisualDomBuilder visualDomBuilder, Node sourceNode, String
mouseOverId) {
+ // TODO Auto-generated method stub
+// visualDomBuilder.updateNode(sourceNode);
+ }
+
+ public void stopMouseOver(Node sourceNode) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMenuGroupTemplate.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMenuItemTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMenuItemTemplate.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMenuItemTemplate.java 2008-08-28
14:57:25 UTC (rev 9941)
@@ -0,0 +1,252 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.vpe.richfaces.template;
+
+import java.util.List;
+
+import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
+import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
+import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
+import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
+import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.template.VpeMouseOverTemplate;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMText;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+public class RichFacesMenuItemTemplate extends VpeAbstractTemplate {
+
+ /*
+ * rich:menuItem constants
+ */
+ private static final String ICON_FACET_NAME = "icon"; //$NON-NLS-1$
+ private static final String ICON_DISABLED_FACET_NAME = "iconDisabled";
//$NON-NLS-1$
+ private static final String SPACER_IMG_PATH = "menuItem/spacer.gif";
//$NON-NLS-1$
+ private static final String EMPTY = ""; //$NON-NLS-1$
+ private static final String SPACE = " "; //$NON-NLS-1$
+
+ /*
+ * rich:menuItem css styles names
+ */
+ private static final String CSS_RICH_MENU_ITEM = "rich-menu-item";
//$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_LABEL = "rich-menu-item-label";
//$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_ICON = "rich-menu-item-item";
//$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_DISABLED =
"rich-menu-item-disabled"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_ENABLED =
"rich-menu-item-enabled"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_HOVER = "rich-menu-item-hover";
//$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_LABEL_DISBLED =
"rich-menu-item-label-disabled"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_ICON_DISABLED =
"rich-menu-item-icon-disabled"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_LABEL_ENABLED =
"rich-menu-item-label-enabled"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_ICON_ENABLED =
"rich-menu-item-icon-enabled"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_LABEL_SELECTED =
"rich-menu-item-label-selected"; //$NON-NLS-1$
+ private static final String CSS_RICH_MENU_ITEM_ICON_SELECTED =
"rich-menu-item-icon-selected"; //$NON-NLS-1$
+
+ /*
+ * rich:menuItem attributes names
+ */
+ private static final String ICON = "icon"; //$NON-NLS-1$
+
+ /*
+ * rich:menuItem css styles and classes attributes names
+ */
+ private static final String ICON_CLASS = "iconClass"; //$NON-NLS-1$
+ private static final String ICON_DISABLED = "iconDisabled"; //$NON-NLS-1$
+ private static final String ICON_STYLE = "iconStyle"; //$NON-NLS-1$
+ private static final String LABEL_CLASS = "labelClass"; //$NON-NLS-1$
+ private static final String SELECT_STYLE = "selectStyle"; //$NON-NLS-1$
+ private static final String SELECT_CLASS = "selectClass"; //$NON-NLS-1$
+
+ /*
+ * rich:menuItem attributes
+ */
+ private String mi_disabled;
+ private String mi_icon;
+ private String mi_value;
+
+ /*
+ * rich:menuItem css styles and classes attributes
+ */
+ private String mi_iconClass;
+ private String mi_iconDisabled;
+ private String mi_iconStyle;
+ private String mi_labelClass;
+ private String mi_selectClass;
+ private String mi_selectStyle;
+ private String mi_style;
+ private String mi_styleClass;
+
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+ VpeCreationData creationData = null;
+ Element sourceElement = (Element)sourceNode;
+
+ readMenuItemAttributes(sourceElement);
+
+ /*
+ * MenuItem component structure.
+ * In order of nesting.
+ */
+ nsIDOMElement itemTopDiv;
+ nsIDOMElement itemIconImgSpan;
+ nsIDOMElement itemIconImg;
+ nsIDOMElement itemLabelSpan;
+ nsIDOMText itemLabelText;
+
+ /*
+ * Creating visual elements
+ */
+ itemTopDiv = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ itemIconImgSpan = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_SPAN);
+ itemIconImg = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_IMG);
+ itemLabelSpan = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_SPAN);
+ itemLabelText = visualDocument.createTextNode(""); //$NON-NLS-1$
+ creationData = new VpeCreationData(itemTopDiv);
+
+ /*
+ * Nesting elements
+ */
+ itemTopDiv.appendChild(itemIconImgSpan);
+ itemTopDiv.appendChild(itemLabelSpan);
+ itemLabelSpan.appendChild(itemLabelText);
+
+ /*
+ * Setting css classes
+ */
+ String topDivClass = EMPTY;
+ String iconImgSpanClass = EMPTY;
+ String labelSpanClass = EMPTY;
+
+ topDivClass += SPACE + CSS_RICH_MENU_ITEM;
+ iconImgSpanClass += SPACE + CSS_RICH_MENU_ITEM_ICON;
+ labelSpanClass += SPACE + CSS_RICH_MENU_ITEM_LABEL;
+
+ if (attrPresents(mi_styleClass)) {
+ topDivClass += SPACE + mi_styleClass;
+ }
+ if (attrPresents(mi_iconClass)) {
+ iconImgSpanClass += SPACE + mi_iconClass;
+ }
+ if (attrPresents(mi_labelClass)) {
+ labelSpanClass += SPACE + mi_labelClass;
+ }
+
+ itemTopDiv.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, topDivClass);
+ itemIconImgSpan.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, iconImgSpanClass);
+ itemLabelSpan.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, labelSpanClass);
+
+ /*
+ * Encode label and icon value
+ */
+ Attr valueAttr = sourceElement.getAttributeNode(HtmlComponentUtil.HTML_VALUE_ATTR);
+ String labelValue = valueAttr != null
+ && valueAttr.getValue() != null ? valueAttr.getValue() : "";
//$NON-NLS-1$
+ itemLabelText.setNodeValue(labelValue);
+
+ /*
+ * Encode icon facets
+ */
+ Element iconFacet = ComponentUtil.getFacet(sourceElement, ICON_FACET_NAME);
+ Element iconDisabledFacet = ComponentUtil.getFacet(sourceElement,
ICON_DISABLED_FACET_NAME);
+ if (null != iconFacet) {
+ VpeChildrenInfo childInfo = new VpeChildrenInfo(itemIconImgSpan);
+ childInfo.addSourceChild(iconFacet);
+ creationData.addChildrenInfo(childInfo);
+ } else {
+ String iconPath = sourceElement.getAttribute(ICON);
+ if (attrPresents(iconPath)) {
+ /*
+ * Add path to specified image
+ */
+ String imgFullPath = VpeStyleUtil.addFullPathToImgSrc(iconPath, pageContext, true);
+ itemIconImg.setAttribute(HtmlComponentUtil.HTML_ATR_SRC, imgFullPath);
+ } else {
+ /*
+ * Create spacer image
+ */
+ ComponentUtil.setImg(itemIconImg, SPACER_IMG_PATH);
+ }
+ /*
+ * Add image to span
+ */
+ itemIconImgSpan.appendChild(itemIconImg);
+ }
+
+ /*
+ * Adding child nodes
+ */
+ List<Node> children = ComponentUtil.getChildren(sourceElement);
+ for (Node child : children) {
+ VpeChildrenInfo childInfo = new VpeChildrenInfo(itemLabelSpan);
+ childInfo.addSourceChild(child);
+ creationData.addChildrenInfo(childInfo);
+ }
+
+ return creationData;
+ }
+
+
+ /**
+ * Read attributes from the source element.
+ *
+ * @param sourceNode the source node
+ */
+ private void readMenuItemAttributes(Element sourceElement) {
+ if (null == sourceElement) {
+ return;
+ }
+ mi_disabled = sourceElement.getAttribute(HtmlComponentUtil.HTML_ATTR_DISABLED);
+ mi_icon = sourceElement.getAttribute(ICON);
+ mi_value = sourceElement.getAttribute(HtmlComponentUtil.HTML_VALUE_ATTR);
+
+ mi_iconClass = sourceElement.getAttribute(ICON_CLASS);
+ mi_iconDisabled = sourceElement.getAttribute(ICON_DISABLED);
+ mi_iconStyle = sourceElement.getAttribute(ICON_STYLE);
+ mi_labelClass = sourceElement.getAttribute(LABEL_CLASS);
+ mi_selectClass = sourceElement.getAttribute(SELECT_CLASS);
+ mi_selectStyle = sourceElement.getAttribute(SELECT_STYLE);
+ mi_style = sourceElement.getAttribute(HtmlComponentUtil.HTML_STYLE_ATTR);
+ mi_styleClass = sourceElement.getAttribute(HtmlComponentUtil.HTML_STYLECLASS_ATTR);
+ }
+
+ /**
+ * Checks is attribute have some value.
+ *
+ * @param attr the attribute
+ *
+ * @return true, if successful
+ */
+ private static boolean attrPresents(String attr) {
+ return ((null != attr) && (!EMPTY.equalsIgnoreCase(attr)));
+ }
+
+ @Override
+ public boolean isRecreateAtAttrChange(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualNode, Object data, String name, String value) {
+ return true;
+ }
+
+ public void onMouseOver(VpeVisualDomBuilder visualDomBuilder, Node sourceNode, String
mouseOverId) {
+ // TODO Auto-generated method stub
+// visualDomBuilder.updateNode(sourceNode);
+ }
+
+ public void stopMouseOver(Node sourceNode) {
+ // TODO Auto-generated method stub
+
+ }
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesMenuItemTemplate.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/templates/vpe-templates-richfaces.xml
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/templates/vpe-templates-richfaces.xml 2008-08-28
12:28:20 UTC (rev 9940)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/templates/vpe-templates-richfaces.xml 2008-08-28
14:57:25 UTC (rev 9941)
@@ -524,12 +524,30 @@
</vpe:tag>
<vpe:tag name="rich:menuItem" case-sensitive="yes" >
- <vpe:template children="no" modify="no">
+ <vpe:template
class="org.jboss.tools.jsf.vpe.richfaces.template.RichFacesMenuItemTemplate"
+ children="yes" modify="no">
+ <vpe:resize>
+ <vpe:width width-attr="style.width" />
+ <vpe:height height-attr="style.height" />
+ </vpe:resize>
+ <vpe:dnd>
+ <vpe:drag start-enable="yes"/>
+ <vpe:drop container="no"/>
+ </vpe:dnd>
</vpe:template>
</vpe:tag>
<vpe:tag name="rich:menuGroup" case-sensitive="yes" >
- <vpe:template children="no" modify="no">
+ <vpe:template
class="org.jboss.tools.jsf.vpe.richfaces.template.RichFacesMenuGroupTemplate"
+ children="yes" modify="no">
+ <vpe:resize>
+ <vpe:width width-attr="style.width" />
+ <vpe:height height-attr="style.height" />
+ </vpe:resize>
+ <vpe:dnd>
+ <vpe:drag start-enable="yes"/>
+ <vpe:drop container="no"/>
+ </vpe:dnd>
</vpe:template>
</vpe:tag>