Author: dmaliarevich
Date: 2008-04-24 10:43:50 -0400 (Thu, 24 Apr 2008)
New Revision: 7738
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/panelMenuGroup/style.css
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuGroupTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuItemTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/templates/vpe-templates-richfaces.xml
Log:
http://jira.jboss.com/jira/browse/JBIDE-2058, fixed
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/panelMenuGroup/style.css
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/panelMenuGroup/style.css 2008-04-24
14:09:04 UTC (rev 7737)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/panelMenuGroup/style.css 2008-04-24
14:43:50 UTC (rev 7738)
@@ -6,7 +6,7 @@
vertical-align: middle;
}
-.rich-pmenu-top-group-div, .rich-pmenu-group-div {
+.dr-pmenu-top-group-div, .dr-pmenu-group-div {
margin-bottom: 3px;
padding: 1px;
cursor: pointer;
@@ -16,7 +16,8 @@
height: 20px;
width: 100%;
}
-.rich-pmenu-top-group {
+
+.dr-pmenu-top-group, .dr-pmenu-group {
background-color: #D4CFC7;
font-family: Arial, Verdana, sans-serif;
font-size: 11px;
@@ -28,7 +29,6 @@
width: 100%;
}
-
.rich-pmenu-top-group-self-label, .rich-pmenu-group-self-label {
padding-left: 5px;
width: 100%;
@@ -38,5 +38,5 @@
}
.rich-pmenu-disabled-element {
- color: #B1ADA7;
+ /*color: #B1ADA7;*/
}
\ No newline at end of file
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuGroupTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuGroupTemplate.java 2008-04-24
14:09:04 UTC (rev 7737)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuGroupTemplate.java 2008-04-24
14:43:50 UTC (rev 7738)
@@ -11,16 +11,22 @@
package org.jboss.tools.jsf.vpe.richfaces.template;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
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.VpeSourceDomBuilder;
+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.VpeToggableTemplate;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMText;
@@ -30,8 +36,11 @@
import org.w3c.dom.Node;
import org.w3c.dom.Text;
-public class RichFacesPanelMenuGroupTemplate extends VpeAbstractTemplate {
+public class RichFacesPanelMenuGroupTemplate extends VpeAbstractTemplate implements
+VpeToggableTemplate {
+ public static final String VPE_EXPANDED_TOGGLE_IDS =
"vpe-expanded-toggle-ids"; //$NON-NLS-1$
+
public static final String GROUP_COUNT_SEPARATOR = "-"; //$NON-NLS-1$
public static final Map<String, String> DEFAULT_ICON_MAP = new HashMap<String,
String>();
@@ -41,6 +50,8 @@
private static final String DISABLED = "disabled"; //$NON-NLS-1$
private static final String DISABLED_CLASS = "disabledClass"; //$NON-NLS-1$
private static final String DISABLED_STYLE = "disabledStyle"; //$NON-NLS-1$
+ private static final String ICON_CLASS = "iconClass"; //$NON-NLS-1$
+ private static final String ICON_STYLE = "iconStyle"; //$NON-NLS-1$
private static final String ICON_EXPANDED = "iconExpanded"; //$NON-NLS-1$
private static final String ICON_COLLAPSED = "iconCollapsed"; //$NON-NLS-1$
private static final String ICON_DISABLED = "iconDisabled"; //$NON-NLS-1$
@@ -51,14 +62,16 @@
/*
* rich:panelMenuGroup css styles
*/
- private static final String CSS_TOP_GROUP_DIV = "rich-pmenu-top-group-div";
//$NON-NLS-1$
- private static final String CSS_TOP_GROUP = "rich-pmenu-top-group";
//$NON-NLS-1$
+ private static final String CSS_DR_TOP_GROUP_DIV = "dr-pmenu-top-group-div";
//$NON-NLS-1$
+ private static final String CSS_DR_TOP_GROUP = "dr-pmenu-top-group";
//$NON-NLS-1$
+ private static final String CSS_DR_GROUP = "dr-pmenu-group"; //$NON-NLS-1$
private static final String CSS_TOP_GROUP_ICON =
"rich-pmenu-top-group-self-icon"; //$NON-NLS-1$
private static final String CSS_TOP_GROUP_LABEL =
"rich-pmenu-top-group-self-label"; //$NON-NLS-1$
- private static final String CSS_GROUP_DIV = "rich-pmenu-group-div";
//$NON-NLS-1$
+ private static final String CSS_DR_GROUP_DIV = "dr-pmenu-group-div";
//$NON-NLS-1$
private static final String CSS_GROUP = "rich-pmenu-group"; //$NON-NLS-1$
private static final String CSS_GROUP_ICON = "rich-pmenu-group-self-icon";
//$NON-NLS-1$
private static final String CSS_GROUP_LABEL = "rich-pmenu-group-self-label";
//$NON-NLS-1$
+ private static final String CSS_HOVERED_ELEMENT =
"rich-pmenu-hovered-element"; //$NON-NLS-1$
private static final String CSS_DISABLED_ELEMENT =
"rich-pmenu-disabled-element"; //$NON-NLS-1$
private static final String NAME_COMPONENT = "panelMenuGroup"; //$NON-NLS-1$
@@ -67,13 +80,14 @@
private static final String PANEL_MENU_ITEM_END_TAG = ":panelMenuItem";
//$NON-NLS-1$
private static final String COMPONENT_ATTR_VPE_SUPPORT = "vpeSupport";
//$NON-NLS-1$
- private static final String COMPONENT_ATTR_VPE_USER_TOGGLE_ID =
"vpe-user-toggle-id"; //$NON-NLS-1$
private static final String PANEL_MENU_GROUP_ICON_SPACER_PATH =
"/panelMenuGroup/spacer.gif"; //$NON-NLS-1$
private static final String STYLE_PATH = "/panelMenuGroup/style.css";
//$NON-NLS-1$
- private static final String EMPTY_DIV_STYLE = "display: none;"; //$NON-NLS-1$
-
+
+ private static final String VSPACE = "vspace"; //$NON-NLS-1$
+ private static final String HSPACE = "hspace"; //$NON-NLS-1$
private static final String TRUE = "true"; //$NON-NLS-1$
private static final String RIGHT = "right"; //$NON-NLS-1$
+ private static final String LEFT = "right"; //$NON-NLS-1$
private static final String SPACE = " "; //$NON-NLS-1$
private static final String EMPTY = ""; //$NON-NLS-1$
@@ -85,40 +99,45 @@
/*
* rich:panelMenu attributes for groups
*/
- private static String pm_iconGroupPosition;
- private static String pm_iconGroupTopPosition;
- private static String pm_iconCollapsedGroup;
- private static String pm_iconCollapsedTopGroup;
- private static String pm_iconExpandedGroup;
- private static String pm_iconExpandedTopGroup;
- private static String pm_iconDisableGroup;
- private static String pm_iconTopDisableGroup;
+ private String pm_iconGroupPosition;
+ private String pm_iconGroupTopPosition;
+ private String pm_iconCollapsedGroup;
+ private String pm_iconCollapsedTopGroup;
+ private String pm_iconExpandedGroup;
+ private String pm_iconExpandedTopGroup;
+ private String pm_iconDisableGroup;
+ private String pm_iconTopDisableGroup;
+ private String pm_expandSingle;
/*
* rich:panelMenu style classes for groups
*/
- private static String pm_disabled;
- private static String pm_disabledGroupClass;
- private static String pm_disabledGroupStyle;
- private static String pm_topGroupClass;
- private static String pm_topGroupStyle;
- private static String pm_groupClass;
- private static String pm_groupStyle;
- private static String pm_style;
- private static String pm_styleClass;
+ private String pm_disabled;
+ private String pm_disabledGroupClass;
+ private String pm_disabledGroupStyle;
+ private String pm_topGroupClass;
+ private String pm_topGroupStyle;
+ private String pm_groupClass;
+ private String pm_groupStyle;
+ private String pm_style;
+ private String pm_styleClass;
/*
* pich:panelMenuGroup attributes
*/
- private static String pmg_disabledStyle;
- private static String pmg_disabledClass;
- private static String pmg_disabled;
- private static String pmg_iconExpanded;
- private static String pmg_iconCollapsed;
- private static String pmg_iconDisabled;
- private static String pmg_style;
- private static String pmg_styleClass;
-
+ private String pmg_disabledStyle;
+ private String pmg_disabledClass;
+ private String pmg_disabled;
+ private String pmg_iconClass;
+ private String pmg_iconStyle;
+ private String pmg_iconExpanded;
+ private String pmg_iconCollapsed;
+ private String pmg_iconDisabled;
+ private String pmg_style;
+ private String pmg_styleClass;
+
+ private List<String> expandedIds = new ArrayList<String>();
+
static {
DEFAULT_ICON_MAP.put("chevron", "/panelMenuGroup/chevron.gif");
//$NON-NLS-1$ //$NON-NLS-2$
DEFAULT_ICON_MAP.put("chevronUp", "/panelMenuGroup/chevronUp.gif");
//$NON-NLS-1$ //$NON-NLS-2$
@@ -131,118 +150,87 @@
DEFAULT_ICON_MAP.put("grid", "/panelMenuGroup/grid.gif");
//$NON-NLS-1$ //$NON-NLS-2$
}
+ @SuppressWarnings("unchecked")
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
- nsIDOMElement div = visualDocument
+
+ Element groupSourceElement = (Element) sourceNode;
+ nsIDOMElement creationDataDiv = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_DIV);
- div.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, EMPTY_DIV_STYLE);
- return new VpeCreationData(div);
- }
-
- public boolean isRecreateAtAttrChange(VpePageContext pageContext,
- Element sourceElement, nsIDOMDocument visualDocument,
- nsIDOMElement visualNode, Object data, String name, String value) {
- return true;
- }
-
- public static VpeCreationData encode(VpePageContext pageContext,
- VpeCreationData creationData, Element sourceParentElement,
- Element sourceElement, nsIDOMDocument visualDocument,
- nsIDOMElement parentVisualElement, List<String> activeIds,
- String childId) {
-
+ VpeCreationData creationData = new VpeCreationData(creationDataDiv);
+
+ expandedIds = (List<String>) sourceNode.getUserData(VPE_EXPANDED_TOGGLE_IDS);
+ String childId = (String)
sourceNode.getUserData(VpeVisualDomBuilder.VPE_USER_TOGGLE_ID);
+
/*
* Counts child groups in a parent group
*/
int childGroupCount = 1;
- boolean disabled = false;
- Element parent = getRichPanelParent(sourceElement);
- readPanelMenuGroupAttributes(sourceElement);
- readPanelMenuAttributes(sourceParentElement);
+ Element anySuitableParent = getGroupParent(groupSourceElement, false);
+ Element panelMenuParent = getGroupParent(groupSourceElement, true);
+ readPanelMenuGroupAttributes(groupSourceElement);
+ readPanelMenuAttributes(panelMenuParent);
+
ComponentUtil.setCSSLink(pageContext, STYLE_PATH, NAME_COMPONENT);
- boolean expanded = activeIds.contains(childId);
+ boolean expanded = false;
+ if (null != expandedIds) {
+ expanded = expandedIds.contains(childId);
+ }
nsIDOMElement div = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_DIV);
- parentVisualElement.appendChild(div);
+ creationDataDiv.appendChild(div);
div.setAttribute(COMPONENT_ATTR_VPE_SUPPORT, NAME_COMPONENT);
- div.setAttribute(COMPONENT_ATTR_VPE_USER_TOGGLE_ID, childId);
+ div.setAttribute(VpeVisualDomBuilder.VPE_USER_TOGGLE_ID, childId);
- if (TRUE.equalsIgnoreCase(pm_disabled)) {
- disabled = true;
- } else if (TRUE.equalsIgnoreCase(parent
- .getAttribute(DISABLED))) {
- disabled = true;
- } else if (TRUE.equalsIgnoreCase(pmg_disabled)) {
- disabled = true;
- }
+ buildTable(pageContext, anySuitableParent, groupSourceElement,
+ visualDocument, div, expanded, childId);
+
+ nsIDOMElement childSpan = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_SPAN);
+ VpeChildrenInfo childrenInfo = new VpeChildrenInfo(childSpan);
- buildTable(pageContext, sourceParentElement, parent, sourceElement,
- visualDocument, div, expanded, disabled, childId);
-
- List<Node> children = ComponentUtil.getChildren(sourceElement);
-
- if (!children.isEmpty()) {
- nsIDOMElement childSpan = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_SPAN);
- VpeChildrenInfo childrenInfo = new VpeChildrenInfo(childSpan);
+ List<Node> children = ComponentUtil.getChildren(groupSourceElement);
+ if (expanded) {
for (Node child : children) {
- if (!child.getNodeName().endsWith(PANEL_MENU_GROUP_END_TAG)
- && !child.getNodeName().endsWith(
- PANEL_MENU_ITEM_END_TAG)) {
- if (childrenInfo.getSourceChildren() == null
- || childrenInfo.getSourceChildren().size() == 0) {
- div.appendChild(childSpan);
- }
- childrenInfo.addSourceChild(child);
- } else {
- if (expanded && !disabled) {
- if (child.getNodeName().endsWith(
- PANEL_MENU_GROUP_END_TAG)) {
- RichFacesPanelMenuGroupTemplate.encode(pageContext,
- creationData, sourceParentElement,
- (Element) child, visualDocument, div, activeIds,
- childId + GROUP_COUNT_SEPARATOR + childGroupCount);
- childGroupCount++;
- } else {
- RichFacesPanelMenuItemTemplate
- .encode(pageContext, creationData,
- sourceParentElement,
- (Element) child, visualDocument,
- div, childId);
- }
- }
-
- if (childrenInfo.getSourceChildren() != null
- && childrenInfo.getSourceChildren().size() > 0) {
- creationData.addChildrenInfo(childrenInfo);
- childSpan = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_SPAN);
- childrenInfo = new VpeChildrenInfo(childSpan);
- }
+ boolean isGroup = child.getNodeName().endsWith(
+ PANEL_MENU_GROUP_END_TAG);
+ boolean isItem = child.getNodeName().endsWith(
+ PANEL_MENU_ITEM_END_TAG);
+ if (isGroup) {
+ String newLevelToggleId = childId + GROUP_COUNT_SEPARATOR
+ + childGroupCount;
+ childGroupCount++;
+ child.setUserData(VpeVisualDomBuilder.VPE_USER_TOGGLE_ID, newLevelToggleId, null);
+ child.setUserData(VPE_EXPANDED_TOGGLE_IDS, expandedIds, null);
}
- }
-
- if (childrenInfo.getSourceChildren() != null
- && childrenInfo.getSourceChildren().size() > 0) {
+ if (isItem) {
+ child.setUserData(RichFacesPanelMenuItemTemplate.VPE_PANEL_MENU_ITEM_ID, childId,
null);
+ }
+ childrenInfo = new VpeChildrenInfo(div);
+ childrenInfo.addSourceChild(child);
creationData.addChildrenInfo(childrenInfo);
}
}
+
+ if (childrenInfo.getSourceChildren() == null) {
+ creationData.addChildrenInfo(childrenInfo);
+ }
+
return creationData;
}
- private static final void buildTable(VpePageContext pageContext,
- Element sourceParentElement, Element parent, Element sourceElement,
- nsIDOMDocument visualDocument, nsIDOMElement div, boolean expanded,
- boolean disabled, String activeChildId) {
- String disabledStyle = EMPTY;
- String disableClass = EMPTY;
+ private void buildTable(VpePageContext pageContext,
+ Element anySuitableParent, Element groupSourceElement,
+ nsIDOMDocument visualDocument, nsIDOMElement div,
+ boolean expanded, String activeChildId) {
String tableStyle = MARGIN_TOP;
String tableClass = EMPTY;
- String col1ImgClass = EMPTY;
- String col2Class = EMPTY;
- String col3ImgClass = EMPTY;
+ String iconCellClass = EMPTY;
+ String iconCellStyle = EMPTY;
+ String labelCellClass = EMPTY;
+ String emptyCellClass = EMPTY;
String divClass = EMPTY;
nsIDOMElement table = visualDocument
@@ -258,9 +246,10 @@
table.appendChild(tableBodyRow);
/*
- * Add indentation for nested gruops
+ * Add indentation for nested groups
*/
String[] ids = activeChildId.split(GROUP_COUNT_SEPARATOR);
+ List<nsIDOMElement> indentTds = new ArrayList<nsIDOMElement>();
if (ids.length > 1) {
for (int i = 1; i <= ids.length - 1; i++) {
nsIDOMElement spacerTd = visualDocument
@@ -271,33 +260,34 @@
ComponentUtil.setImg(spacerImg, PANEL_MENU_GROUP_ICON_SPACER_PATH);
setDefaultImgAttributes(spacerImg);
tableBodyRow.appendChild(spacerTd);
+ indentTds.add(spacerTd);
}
}
nsIDOMElement column1 = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TD);
- column1.setAttribute(COMPONENT_ATTR_VPE_USER_TOGGLE_ID, activeChildId);
+ column1.setAttribute(VpeVisualDomBuilder.VPE_USER_TOGGLE_ID, activeChildId);
tableBodyRow.appendChild(column1);
- nsIDOMElement columnn1_img = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_IMG);
- column1.appendChild(columnn1_img);
- ComponentUtil.setImg(columnn1_img, PANEL_MENU_GROUP_ICON_SPACER_PATH);
-
nsIDOMElement column2 = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TD);
tableBodyRow.appendChild(column2);
column2.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, WIDTH_100_PERSENTS);
+ nsIDOMElement column3 = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TD);
+ column3.setAttribute(VpeVisualDomBuilder.VPE_USER_TOGGLE_ID, activeChildId);
+ tableBodyRow.appendChild(column3);
+
/*
- * Item label routine.
+ * Group Label Routine.
*/
Attr labelAttr = null;
String labelValue = EMPTY;
String bundleValue = EMPTY;
String resultValue = EMPTY;
- if (sourceElement.hasAttribute(LABEL)) {
- labelAttr = sourceElement.getAttributeNode(LABEL);
+ if (groupSourceElement.hasAttribute(LABEL)) {
+ labelAttr = groupSourceElement.getAttributeNode(LABEL);
}
if (null != labelAttr) {
labelValue = labelAttr.getNodeValue();
@@ -325,72 +315,132 @@
nsIDOMText text = visualDocument.createTextNode(resultValue);
column2.appendChild(text);
- column2.setAttribute(COMPONENT_ATTR_VPE_USER_TOGGLE_ID, activeChildId);
+ column2.setAttribute(VpeVisualDomBuilder.VPE_USER_TOGGLE_ID, activeChildId);
- nsIDOMElement column3 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- column3.setAttribute(COMPONENT_ATTR_VPE_USER_TOGGLE_ID, activeChildId);
- tableBodyRow.appendChild(column3);
+ boolean childOfPanelMenu = anySuitableParent.getNodeName().endsWith(
+ PANEL_MENU_END_TAG);
+
+ /*
+ * Group Icon Routine
+ */
+ nsIDOMElement iconCell = column1;
+ nsIDOMElement emptyCell = column3;
+ if (attrPresents(pm_iconGroupPosition)) {
+ if (RIGHT.equalsIgnoreCase(pm_iconGroupPosition)) {
+ /*
+ * Set icon image on the right
+ */
+ iconCell = column3;
+ emptyCell = column1;
+ }
+ }
+ if (childOfPanelMenu && attrPresents(pm_iconGroupTopPosition)) {
+ if (RIGHT.equalsIgnoreCase(pm_iconGroupTopPosition)) {
+ /*
+ * Set icon image on the right
+ */
+ iconCell = column3;
+ emptyCell = column1;
+ } else if (LEFT.equalsIgnoreCase(pm_iconGroupTopPosition)) {
+ iconCell = column1;
+ emptyCell = column3;
+ }
+ }
- nsIDOMElement column3_img = visualDocument
+ nsIDOMElement imgIcon = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_IMG);
- column3.appendChild(column3_img);
- ComponentUtil.setImg(column3_img, PANEL_MENU_GROUP_ICON_SPACER_PATH);
+
+ nsIDOMElement imgSpacer = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_IMG);
+ ComponentUtil.setImg(imgSpacer, PANEL_MENU_GROUP_ICON_SPACER_PATH);
+ setDefaultImgAttributes(imgSpacer);
+
+ iconCell.appendChild(imgIcon);
+ emptyCell.appendChild(imgSpacer);
- setIcon(pageContext, parent, sourceParentElement, sourceElement, columnn1_img,
- column3_img, expanded, disabled);
+ setIcon(pageContext, anySuitableParent, groupSourceElement,
+ imgIcon, expanded);
- boolean childOfPanelMenu = parent.getNodeName().endsWith(
- PANEL_MENU_END_TAG);
-
- tableClass += SPACE + CSS_GROUP;
+ /*
+ * Group Style Classes Routine
+ */
+ tableClass += SPACE + CSS_GROUP + SPACE + CSS_DR_GROUP;
+ if (TRUE.equalsIgnoreCase(pm_disabled)) {
+ if (childOfPanelMenu) {
+ tableClass = SPACE + CSS_DR_TOP_GROUP + SPACE + CSS_GROUP;
+ tableClass += SPACE + CSS_DISABLED_ELEMENT;
+ divClass += SPACE + CSS_DR_TOP_GROUP_DIV;
+ if (attrPresents(pm_disabledGroupClass)) {
+ tableClass += SPACE + pm_disabledGroupClass;
+ }
+ if (attrPresents(pm_topGroupStyle)) {
+ tableStyle += SPACE + pm_topGroupStyle;
+ }
+ }
+ }
- if (disabled) {
- if (attrPresents(pm_disabledGroupClass)) {
- disableClass += pm_disabledGroupClass;
+ if ((TRUE.equalsIgnoreCase(pmg_disabled))) {
+ tableClass += SPACE + CSS_GROUP + SPACE + CSS_DR_GROUP;
+
+ if (!(TRUE.equalsIgnoreCase(pm_disabled))) {
+ tableClass += SPACE + CSS_DISABLED_ELEMENT;
+ if (attrPresents(pm_disabledGroupClass)){
+ tableClass += SPACE + pm_disabledGroupClass;
+ }
}
+
if (attrPresents(pmg_disabledClass)) {
- disableClass += SPACE + pmg_disabledClass;
+ tableClass += SPACE + pmg_disabledClass;
}
- disableClass += SPACE + CSS_DISABLED_ELEMENT;
- tableClass += SPACE + disableClass;
-
if (attrPresents(pm_disabledGroupStyle)) {
- disabledStyle += pm_disabledGroupStyle;
+ tableStyle += SPACE + pm_disabledGroupStyle;
}
if (attrPresents(pmg_disabledStyle)) {
- disabledStyle += SPACE + pmg_disabledStyle;
+ tableStyle += SPACE + pmg_disabledStyle;
}
- tableStyle += SPACE + disabledStyle;
- } else {
-
+ }
+
+ if (!(TRUE.equalsIgnoreCase(pm_disabled))
+ && (!(TRUE.equalsIgnoreCase(pmg_disabled)))) {
+ tableClass = SPACE + CSS_DR_GROUP + SPACE + CSS_GROUP;
+ iconCellClass = SPACE + CSS_GROUP_ICON;
+ labelCellClass += SPACE + CSS_GROUP_LABEL;
+ emptyCellClass += SPACE + CSS_GROUP_ICON;
+ divClass += SPACE + CSS_DR_GROUP_DIV;
if (attrPresents(pm_groupClass)) {
tableClass += SPACE + pm_groupClass;
}
if (attrPresents(pm_groupStyle)) {
- tableStyle += pm_groupStyle;
+ tableStyle += SPACE + pm_groupStyle;
}
- col1ImgClass += SPACE + CSS_GROUP_ICON;
- col2Class += SPACE + CSS_GROUP_LABEL;
- col3ImgClass += SPACE + CSS_GROUP_ICON;
- divClass += SPACE + CSS_GROUP_DIV;
+ if (attrPresents(pmg_iconClass)) {
+ iconCellClass += SPACE + pmg_iconClass;
+ }
+ if (attrPresents(pmg_iconStyle)) {
+ iconCellStyle += SPACE + pmg_iconStyle;
+ }
if (childOfPanelMenu) {
+ tableClass = SPACE + CSS_DR_TOP_GROUP + SPACE + CSS_GROUP;
+ iconCellClass = SPACE + CSS_GROUP_ICON + SPACE + CSS_TOP_GROUP_ICON;
+ labelCellClass = SPACE + CSS_TOP_GROUP_LABEL;
+ emptyCellClass = SPACE + CSS_TOP_GROUP_ICON;
+ divClass += SPACE + CSS_DR_TOP_GROUP_DIV;
if (attrPresents(pm_topGroupClass)) {
tableClass += SPACE + pm_topGroupClass;
}
if (attrPresents(pm_topGroupStyle)) {
tableStyle += pm_topGroupStyle;
}
- tableClass += SPACE + CSS_TOP_GROUP + SPACE + CSS_GROUP;
- col1ImgClass += SPACE + CSS_TOP_GROUP_ICON;
- col2Class += SPACE + CSS_TOP_GROUP_LABEL;
- col3ImgClass += SPACE + CSS_TOP_GROUP_ICON;
- divClass += SPACE + CSS_TOP_GROUP_DIV;
+ if (attrPresents(pmg_iconClass)) {
+ iconCellClass += SPACE + pmg_iconClass;
+ }
+ if (attrPresents(pmg_iconStyle)) {
+ iconCellStyle += SPACE + pmg_iconStyle;
+ }
}
}
-
if (attrPresents(pm_styleClass)) {
tableClass += SPACE + pm_styleClass;
}
@@ -401,9 +451,15 @@
tableStyle += SPACE + pmg_style;
}
- columnn1_img.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, col1ImgClass);
- column2.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, col2Class);
- column3_img.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, col3ImgClass);
+ iconCell.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, iconCellClass);
+// iconCell.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, iconCellStyle);
+
+ for (nsIDOMElement indentTdCell : indentTds) {
+ indentTdCell.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, iconCellClass);
+ }
+
+ column2.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, labelCellClass);
+ emptyCell.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, emptyCellClass);
div.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, divClass);
table.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, tableClass);
table.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, tableStyle);
@@ -412,37 +468,47 @@
private static void setDefaultImgAttributes(nsIDOMElement element) {
element.setAttribute(HtmlComponentUtil.HTML_ATR_WIDTH,
DEFAULT_SIZE_VALUE);
- element.setAttribute("vspace", NO_SIZE_VALUE); //$NON-NLS-1$
- element.setAttribute("hspace", NO_SIZE_VALUE); //$NON-NLS-1$
+ element.setAttribute(VSPACE, NO_SIZE_VALUE);
+ element.setAttribute(HSPACE, NO_SIZE_VALUE);
element.setAttribute(HtmlComponentUtil.HTML_ATR_HEIGHT,
DEFAULT_SIZE_VALUE);
}
- private static final Element getRichPanelParent(Element sourceElement) {
+ /**
+ * Gets the panel menu group parent.
+ *
+ * @param sourceElement the source element
+ * @param findOnlyPanelMenuParent flag to find only panel menu parent
+ *
+ * @return the group parent
+ */
+ private static final Element getGroupParent(Element sourceElement,
+ boolean findOnlyPanelMenuParent) {
Element parent = (Element) sourceElement.getParentNode();
-
while (true) {
- if (parent.getNodeName().endsWith(PANEL_MENU_END_TAG)
- || parent.getNodeName().endsWith(PANEL_MENU_GROUP_END_TAG)) {
- break;
+ if (findOnlyPanelMenuParent) {
+ if (parent.getNodeName().endsWith(PANEL_MENU_END_TAG)) {
+ break;
+ }
} else {
- parent = (Element) parent.getParentNode();
+ if (parent.getNodeName().endsWith(PANEL_MENU_END_TAG)
+ || parent.getNodeName().endsWith(
+ PANEL_MENU_GROUP_END_TAG)) {
+ break;
+ }
}
+ parent = (Element) parent.getParentNode();
}
-
return parent;
}
- private static final void setIcon(VpePageContext pageContext, Node parent,
- Element sourceParentElement, Element sourceElement,
- nsIDOMElement img1, nsIDOMElement img2, boolean expanded,
- boolean disabled) {
- boolean needChangePosition = false;
+ private void setIcon(VpePageContext pageContext, Node anySuitableParent,
+ Element groupSourceElement, nsIDOMElement imgIcon, boolean expanded) {
String pathIconExpanded = pmg_iconExpanded;
String pathIconCollapsed = pmg_iconCollapsed;
String pathIconDisabled = pmg_iconDisabled;
- if (parent.getNodeName().endsWith(PANEL_MENU_END_TAG)) {
+ if (anySuitableParent.getNodeName().endsWith(PANEL_MENU_END_TAG)) {
if (pathIconExpanded == null) {
pathIconExpanded = pm_iconExpandedTopGroup;
}
@@ -452,62 +518,52 @@
if (pathIconDisabled == null) {
pathIconDisabled = pm_iconTopDisableGroup;
}
-
- if (RIGHT.equals(pm_iconGroupTopPosition)) {
- needChangePosition = true;
- }
- } else {
- if (pathIconExpanded == null) {
- pathIconExpanded = pm_iconExpandedGroup;
- }
- if (pathIconCollapsed == null) {
- pathIconCollapsed = pm_iconCollapsedGroup;
- }
- if (pathIconDisabled == null) {
- pathIconDisabled = pm_iconDisableGroup;
- }
-
- if (RIGHT.equals(pm_iconGroupPosition)) {
- needChangePosition = true;
- }
}
- if (needChangePosition) {
- nsIDOMElement temp = img2;
- img2 = img1;
- img1 = temp;
- }
-
- if (disabled) {
- if (pathIconDisabled != null
- && DEFAULT_ICON_MAP.containsKey(pathIconDisabled)) {
- pathIconDisabled = DEFAULT_ICON_MAP.get(pathIconDisabled);
- ComponentUtil.setImg(img1, pathIconDisabled);
+ if (TRUE.equalsIgnoreCase(pmg_disabled)) {
+ if (attrPresents(pathIconDisabled)) {
+ if (DEFAULT_ICON_MAP.containsKey(pathIconDisabled)) {
+ pathIconDisabled = DEFAULT_ICON_MAP.get(pathIconDisabled);
+ ComponentUtil.setImg(imgIcon, pathIconDisabled);
+ } else {
+ String imgFullPath = VpeStyleUtil.addFullPathToImgSrc(
+ pathIconDisabled, pageContext);
+ imgIcon.setAttribute(HtmlComponentUtil.HTML_ATR_SRC,
+ imgFullPath);
+ }
} else {
- ComponentUtil.setImgFromResources(pageContext, img1,
- pathIconDisabled, PANEL_MENU_GROUP_ICON_SPACER_PATH);
+ ComponentUtil.setImg(imgIcon, PANEL_MENU_GROUP_ICON_SPACER_PATH);
}
} else {
if (expanded) {
- if (pathIconExpanded != null
- && DEFAULT_ICON_MAP.containsKey(pathIconExpanded)) {
- pathIconExpanded = DEFAULT_ICON_MAP.get(pathIconExpanded);
- ComponentUtil.setImg(img1, pathIconExpanded);
+ if (attrPresents(pathIconExpanded)) {
+ if (DEFAULT_ICON_MAP.containsKey(pathIconExpanded)) {
+ pathIconExpanded = DEFAULT_ICON_MAP
+ .get(pathIconExpanded);
+ ComponentUtil.setImg(imgIcon, pathIconExpanded);
+ } else {
+ String imgFullPath = VpeStyleUtil.addFullPathToImgSrc(
+ pathIconExpanded, pageContext);
+ imgIcon.setAttribute(HtmlComponentUtil.HTML_ATR_SRC,
+ imgFullPath);
+ }
} else {
- ComponentUtil
- .setImgFromResources(pageContext, img1,
- pathIconExpanded,
- PANEL_MENU_GROUP_ICON_SPACER_PATH);
+ ComponentUtil.setImg(imgIcon, PANEL_MENU_GROUP_ICON_SPACER_PATH);
}
} else {
- if (pathIconCollapsed != null
- && DEFAULT_ICON_MAP.containsKey(pathIconCollapsed)) {
- pathIconCollapsed = DEFAULT_ICON_MAP.get(pathIconCollapsed);
- ComponentUtil.setImg(img1, pathIconCollapsed);
+ if (attrPresents(pathIconCollapsed)) {
+ if (DEFAULT_ICON_MAP.containsKey(pathIconCollapsed)) {
+ pathIconCollapsed = DEFAULT_ICON_MAP
+ .get(pathIconCollapsed);
+ ComponentUtil.setImg(imgIcon, pathIconCollapsed);
+ } else {
+ String imgFullPath = VpeStyleUtil.addFullPathToImgSrc(
+ pathIconCollapsed, pageContext);
+ imgIcon.setAttribute(HtmlComponentUtil.HTML_ATR_SRC,
+ imgFullPath);
+ }
} else {
- ComponentUtil.setImgFromResources(pageContext, img1,
- pathIconCollapsed,
- PANEL_MENU_GROUP_ICON_SPACER_PATH);
+ ComponentUtil.setImg(imgIcon, PANEL_MENU_GROUP_ICON_SPACER_PATH);
}
}
}
@@ -518,12 +574,12 @@
*
* @param sourceNode the source node
*/
- private static void readPanelMenuAttributes(Element sourceParentElement) {
+ private void readPanelMenuAttributes(Element sourceParentElement) {
if (null == sourceParentElement) {
return;
}
-
+
/*
* rich:panelMenu attributes for groups
*/
@@ -535,6 +591,7 @@
pm_iconExpandedTopGroup =
sourceParentElement.getAttribute(RichFacesPanelMenuTemplate.ICON_EXPANDED_TOP_GROUP);
pm_iconDisableGroup =
sourceParentElement.getAttribute(RichFacesPanelMenuTemplate.ICON_DISABLE_GROUP);
pm_iconTopDisableGroup =
sourceParentElement.getAttribute(RichFacesPanelMenuTemplate.ICON_TOP_DISABLE_GROUP);
+ pm_expandSingle =
sourceParentElement.getAttribute(RichFacesPanelMenuTemplate.EXPAND_SINGLE);
/*
* rich:panelMenu style classes for groups
@@ -555,7 +612,7 @@
*
* @param sourceNode the source node
*/
- private static void readPanelMenuGroupAttributes(Element sourceElement) {
+ private void readPanelMenuGroupAttributes(Element sourceElement) {
if (null == sourceElement) {
return;
@@ -567,6 +624,8 @@
pmg_disabledStyle = sourceElement.getAttribute(DISABLED_STYLE);
pmg_disabledClass = sourceElement.getAttribute(DISABLED_CLASS);
pmg_disabled = sourceElement.getAttribute(DISABLED);
+ pmg_iconClass = sourceElement.getAttribute(ICON_CLASS);
+ pmg_iconStyle = sourceElement.getAttribute(ICON_STYLE);
pmg_iconExpanded = sourceElement.getAttribute(ICON_EXPANDED);
pmg_iconCollapsed = sourceElement.getAttribute(ICON_COLLAPSED);
pmg_iconDisabled = sourceElement.getAttribute(ICON_DISABLED);
@@ -585,4 +644,125 @@
private static boolean attrPresents(String attr) {
return ((null != attr) && (!EMPTY.equalsIgnoreCase(attr)));
}
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.vpe.editor.template.VpeToggableTemplate#toggle(org.jboss.tools.vpe.editor.VpeVisualDomBuilder,
org.w3c.dom.Node, java.lang.String)
+ */
+ @SuppressWarnings("unchecked")
+ public void toggle(VpeVisualDomBuilder builder, Node sourceNode,
+ String toggleId) {
+ if ((null != sourceNode) && (sourceNode instanceof Element)) {
+ Element sourceElement = (Element) sourceNode;
+ pmg_disabled = sourceElement.getAttribute(DISABLED);
+ Element panelMenu = getGroupParent(sourceElement, true);
+ if (null != panelMenu) {
+ pm_disabled = panelMenu.getAttribute(DISABLED);
+ pm_expandSingle = panelMenu.getAttribute(RichFacesPanelMenuTemplate.EXPAND_SINGLE);
+ }
+ }
+
+ /*
+ * Do nothing when panel menu or panel group are disabled.
+ */
+// if ((TRUE.equalsIgnoreCase(pm_disabled))
+// || (TRUE.equalsIgnoreCase(pmg_disabled))) {
+// return;
+// }
+
+ expandedIds = (List<String>) sourceNode.getUserData(VPE_EXPANDED_TOGGLE_IDS);
+ if (null == expandedIds) {
+ expandedIds = new ArrayList<String>();
+ }
+ /*
+ * Expand only one group.
+ */
+ if ((null != pm_expandSingle) && (TRUE.equalsIgnoreCase(pm_expandSingle))) {
+ if (expandedIds.contains(toggleId)) {
+ /*
+ * Close group and its children
+ */
+ expandedIds.remove(toggleId);
+ for (Iterator<String> iterator = expandedIds.iterator(); iterator.hasNext();)
{
+ String id = iterator.next();
+ if (id.startsWith(toggleId)) {
+ iterator.remove();
+ }
+ }
+ } else {
+ /*
+ * Expand new group, close others
+ */
+ String[] toggleIds =
toggleId.split(RichFacesPanelMenuGroupTemplate.GROUP_COUNT_SEPARATOR);
+ if ((null != toggleIds) && (toggleIds.length > 0)) {
+ for (Iterator<String> iterator = expandedIds.iterator(); iterator.hasNext();)
{
+ String id = iterator.next();
+ String[] ids = id.split(RichFacesPanelMenuGroupTemplate.GROUP_COUNT_SEPARATOR);
+ if ((null != ids) && (ids.length > 0)) {
+ if (ids.length >= toggleIds.length) {
+ /*
+ * Remove all ids that are deeper than selected
+ * and that are on the same level.
+ */
+ iterator.remove();
+ } else {
+ /*
+ * Remove all ids that are not in the selected branch.
+ */
+ for (int i = 0; i < ids.length; i++) {
+ if (!ids[i].equalsIgnoreCase(toggleIds[i])) {
+ iterator.remove();
+ }
+ }
+ }
+ }
+ }
+ }
+ expandedIds.add(toggleId);
+ }
+ } else {
+ /*
+ * Expand any number of groups.
+ */
+ if (expandedIds.contains(toggleId)) {
+ expandedIds.remove(toggleId);
+ for (Iterator<String> iterator = expandedIds.iterator(); iterator.hasNext();)
{
+ String id = iterator.next();
+ if (id.startsWith(toggleId)) {
+ iterator.remove();
+ }
+ }
+ } else {
+ expandedIds.add(toggleId);
+ }
+ }
+ sourceNode.setUserData(VPE_EXPANDED_TOGGLE_IDS, expandedIds, null);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.vpe.editor.template.VpeToggableTemplate#stopToggling(org.w3c.dom.Node)
+ */
+ public void stopToggling(Node sourceNode) {
+ if (null != expandedIds) {
+ expandedIds.clear();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#isRecreateAtAttrChange(org.jboss.tools.vpe.editor.context.VpePageContext,
org.w3c.dom.Element, org.mozilla.interfaces.nsIDOMDocument,
org.mozilla.interfaces.nsIDOMElement, java.lang.Object, java.lang.String,
java.lang.String)
+ */
+ public boolean isRecreateAtAttrChange(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualNode, Object data, String name, String value) {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#setSourceAttributeSelection(org.jboss.tools.vpe.editor.context.VpePageContext,
org.w3c.dom.Element, int, int, java.lang.Object)
+ */
+ @Override
+ public void setSourceAttributeSelection(VpePageContext pageContext,
+ Element sourceElement, int offset, int length, Object data) {
+ VpeSourceDomBuilder sourceBuilder = pageContext.getSourceBuilder();
+ sourceBuilder.setSelection(sourceElement, 0, 0);
+ }
}
\ No newline at end of file
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuItemTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuItemTemplate.java 2008-04-24
14:09:04 UTC (rev 7737)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuItemTemplate.java 2008-04-24
14:43:50 UTC (rev 7738)
@@ -15,6 +15,7 @@
import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
+import org.jboss.tools.vpe.editor.VpeSourceDomBuilder;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
@@ -30,6 +31,8 @@
public class RichFacesPanelMenuItemTemplate extends VpeAbstractTemplate {
+ public static final String VPE_PANEL_MENU_ITEM_ID = "vpe-panel-menu-item-id";
//$NON-NLS-1$
+
/*
* rich:panelMenuItem attributes
*/
@@ -54,6 +57,7 @@
public static final String CSS_ITEM_ICON = "rich-pmenu-item-icon";
//$NON-NLS-1$
public static final String CSS_ITEM_LABEL = "rich-pmenu-item-label";
//$NON-NLS-1$
public static final String CSS_ITEM_SELECTED = "rich-pmenu-item-selected";
//$NON-NLS-1$
+ public static final String CSS_HOVERED_ELEMENT = "rich-pmenu-hovered-element";
//$NON-NLS-1$
public static final String CSS_DISABLED_ELEMENT =
"rich-pmenu-disabled-element"; //$NON-NLS-1$
/*
@@ -79,7 +83,6 @@
private static final String COMPONENT_NAME = "panelMenuItem"; //$NON-NLS-1$
private static final String PANEL_MENU_END_TAG = ":panelMenu"; //$NON-NLS-1$
private static final String PANEL_MENU_GROUP_END_TAG = ":panelMenuGroup";
//$NON-NLS-1$
- private static final String EMPTY_DIV_STYLE = "display: none; ";
//$NON-NLS-1$
private static final String MARGIN_TOP = "margin-top: 3px; "; //$NON-NLS-1$
private static final String WIDTH_100_PERCENTS = "width: 100%; ";
//$NON-NLS-1$
@@ -119,43 +122,35 @@
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
- nsIDOMElement div = visualDocument
+ nsIDOMElement creationDataDiv = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_DIV);
- div.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, EMPTY_DIV_STYLE);
-
- return new VpeCreationData(div);
- }
-
- public static VpeCreationData encode(VpePageContext pageContext,
- VpeCreationData creationData, Element sourceParentElement,
- Element sourceElement, nsIDOMDocument visualDocument,
- nsIDOMElement parentVisualElement, String childId) {
-
+ VpeCreationData creationData = new VpeCreationData(creationDataDiv);
+ Element itemSourceElement = (Element) sourceNode;
+ String childId = (String) sourceNode.getUserData(VPE_PANEL_MENU_ITEM_ID);
+
ComponentUtil.setCSSLink(pageContext, STYLE_PATH, COMPONENT_NAME);
- readPanelMenuAttributes(sourceParentElement);
- readPanelMenuItemAttributes(sourceElement);
+ Element anySuitableParent = getItemParent(itemSourceElement, false);
+ Element panelMenuParent = getItemParent(itemSourceElement, true);
- nsIDOMElement parentDiv =
visualDocument.createElement(HtmlComponentUtil.HTML_TAG_DIV);
- parentDiv.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, DR_TOP_DIV);
- parentDiv.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, "0");
//$NON-NLS-1$
- parentDiv.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, MARGIN_TOP);
- parentVisualElement.appendChild(parentDiv);
- nsIDOMElement div = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_DIV);
- parentDiv.appendChild(div);
+ readPanelMenuAttributes(panelMenuParent);
+ readPanelMenuItemAttributes(itemSourceElement);
+ creationDataDiv.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, DR_TOP_DIV);
+ creationDataDiv.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, "0");
//$NON-NLS-1$
+ creationDataDiv.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, MARGIN_TOP);
- boolean childOfPanelMenu = sourceElement.getParentNode().getNodeName().endsWith(
+ boolean childOfPanelMenu = anySuitableParent.getNodeName().endsWith(
PANEL_MENU_END_TAG);
- boolean childOfPanelMenuGroup = sourceElement.getParentNode().getNodeName().endsWith(
+ boolean childOfPanelMenuGroup = anySuitableParent.getNodeName().endsWith(
PANEL_MENU_GROUP_END_TAG);
if (childOfPanelMenu || childOfPanelMenuGroup) {
- div.setAttribute("vpeSupport", COMPONENT_NAME); //$NON-NLS-1$
+ creationDataDiv.setAttribute("vpeSupport", COMPONENT_NAME); //$NON-NLS-1$
+
nsIDOMElement table = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TABLE);
- div.appendChild(table);
+ creationDataDiv.appendChild(table);
table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR,
NO_SIZE_VALUE);
@@ -212,8 +207,8 @@
String labelValue = EMPTY;
String bundleValue = EMPTY;
String resultValue = EMPTY;
- if (sourceElement.hasAttribute(LABEL)) {
- labelAttr = sourceElement.getAttributeNode(LABEL);
+ if (itemSourceElement.hasAttribute(LABEL)) {
+ labelAttr = itemSourceElement.getAttributeNode(LABEL);
}
if (null != labelAttr) {
labelValue = labelAttr.getNodeValue();
@@ -246,10 +241,10 @@
.createElement(HtmlComponentUtil.HTML_TAG_TD);
tr.appendChild(tdRight);
- nsIDOMElement imgPoints = visualDocument
+ nsIDOMElement imgIcon = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_IMG);
- setDefaultImgAttributes(imgPoints);
- setIcon(childOfPanelMenu, pageContext, imgPoints);
+ setDefaultImgAttributes(imgIcon);
+ setIcon(childOfPanelMenu, pageContext, imgIcon);
nsIDOMElement imgSpacer1 = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_IMG);
@@ -258,10 +253,10 @@
tdNowrapLeft.appendChild(imgSpacer1);
- nsIDOMElement imgSpacer2 = visualDocument
+ nsIDOMElement imgSpacer = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_IMG);
- setDefaultImgAttributes(imgSpacer2);
- ComponentUtil.setImg(imgSpacer2, IMG_SPACER_SRC);
+ setDefaultImgAttributes(imgSpacer);
+ ComponentUtil.setImg(imgSpacer, IMG_SPACER_SRC);
nsIDOMElement iconCell = tdNowrapLeft;
nsIDOMElement emptyCell = tdRight;
@@ -286,23 +281,32 @@
emptyCell = tdRight;
}
}
- iconCell.appendChild(imgPoints);
- emptyCell.appendChild(imgSpacer2);
+ iconCell.appendChild(imgIcon);
+ emptyCell.appendChild(imgSpacer);
- setItemClassAndStyle(childOfPanelMenu, table, tr, iconCell, tdLabel, emptyCell);
+ setItemClassAndStyle(childOfPanelMenu, table, tr, iconCell, imgIcon, tdLabel,
emptyCell);
- List<Node> children = ComponentUtil.getChildren(sourceElement);
-
+ List<Node> children = ComponentUtil.getChildren(itemSourceElement);
+
+ nsIDOMElement childSpan = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_SPAN);
+ VpeChildrenInfo childrenInfo = new VpeChildrenInfo(childSpan);
+
if (!children.isEmpty()) {
- VpeChildrenInfo childInfo = new VpeChildrenInfo(tdLabel);
- creationData.addChildrenInfo(childInfo);
+ childrenInfo = new VpeChildrenInfo(tdLabel);
+ creationData.addChildrenInfo(childrenInfo);
for (Node child : children) {
if (!(child.getNodeName().endsWith(PANEL_MENU_GROUP_END_TAG) || child
.getNodeName().endsWith(PANEL_MENU_END_TAG))) {
- childInfo.addSourceChild(child);
+ childrenInfo.addSourceChild(child);
}
}
}
+
+ if (childrenInfo.getSourceChildren() == null) {
+ creationData.addChildrenInfo(childrenInfo);
+ }
+
}
return creationData;
}
@@ -366,17 +370,15 @@
* The second array element contains default icon path.
*/
String[] imgPath = {EMPTY, EMPTY};
- boolean disabled = (TRUE.equalsIgnoreCase(pmi_disabled))
- || (TRUE.equalsIgnoreCase(pm_disabled));
if (childOfPanelMenu) {
- if (disabled) {
+ if (TRUE.equalsIgnoreCase(pmi_disabled)) {
imgPath = getSpecifiedIcon(pm_iconTopDisabledItem, pmi_iconDisabled);
} else {
imgPath = getSpecifiedIcon(pm_iconTopItem, pmi_icon);
}
} else {
- if (disabled) {
+ if (TRUE.equalsIgnoreCase(pmi_disabled)) {
imgPath = getSpecifiedIcon(pm_iconDisabledItem, pmi_iconDisabled);
} else {
imgPath = getSpecifiedIcon(pm_iconItem, pmi_icon);
@@ -415,15 +417,19 @@
nsIDOMElement table,
nsIDOMElement tr,
nsIDOMElement iconCell,
+ nsIDOMElement imgIcon,
nsIDOMElement labelCell,
nsIDOMElement emptyCell) {
String tableStyle = MARGIN_TOP;
- String iconStyle = EMPTY;
+ String iconCellStyle = EMPTY;
+ String labelCellStyle = WIDTH_100_PERCENTS;
+ String emptyCellStyle = EMPTY;
String tableClass = EMPTY;
String trClass = EMPTY;
String iconCellClass = EMPTY;
+ String imgIconClass = EMPTY;
String labelCellClass = EMPTY;
String emptyCellClass = EMPTY;
@@ -434,12 +440,26 @@
tableStyle += SPACE + pmi_style;
}
- tableClass = CSS_ITEM;
+ tableClass += SPACE + CSS_ITEM;
- if ((TRUE.equalsIgnoreCase(pmi_disabled))
- || (TRUE.equalsIgnoreCase(pm_disabled))) {
- tableClass += SPACE + CSS_DISABLED_ELEMENT;
- if (attrPresents(pm_disabledItemClass)) {
+ if (TRUE.equalsIgnoreCase(pm_disabled)) {
+ if (childOfPanelMenu) {
+ tableClass += SPACE + CSS_TOP_ITEM;
+ iconCellClass += SPACE + CSS_TOP_ITEM_ICON;
+ labelCellClass += SPACE + CSS_TOP_ITEM_LABEL;
+ if (attrPresents(pm_disabledItemClass)) {
+ tableClass += SPACE + pm_disabledItemClass;
+ }
+ if (attrPresents(pm_topItemStyle)) {
+ tableStyle += SPACE + pm_topItemStyle;
+ }
+ }
+ }
+
+ if (TRUE.equalsIgnoreCase(pmi_disabled)) {
+// tableClass += SPACE + CSS_DISABLED_ELEMENT;
+ if ((attrPresents(pm_disabledItemClass))
+ && !(TRUE.equalsIgnoreCase(pm_disabled))) {
tableClass += SPACE + pm_disabledItemClass;
}
if (attrPresents(pm_disabledItemStyle)) {
@@ -451,27 +471,25 @@
if (attrPresents(pmi_disabledStyle)) {
tableStyle += SPACE + pmi_disabledStyle;
}
-
- } else {
- iconCellClass = DR_NOWARP_CLASS + SPACE + CSS_ITEM_ICON;
+ }
+
+ if (!(TRUE.equalsIgnoreCase(pm_disabled))
+ && (!(TRUE.equalsIgnoreCase(pmi_disabled)))) {
+// iconCellClass = DR_NOWARP_CLASS + SPACE + CSS_ITEM_ICON;
+ iconCellClass = DR_NOWARP_CLASS;
+ imgIconClass = CSS_ITEM_ICON;
labelCellClass = CSS_ITEM_LABEL;
emptyCellClass = DR_NOWARP_CLASS;
if (attrPresents(pmi_iconClass)) {
- iconCellClass += SPACE + pmi_iconClass;
+ imgIconClass += SPACE + pmi_iconClass;
}
if (attrPresents(pmi_iconStyle)) {
- iconStyle += SPACE + pmi_iconStyle;
+ iconCellStyle += SPACE + pmi_iconStyle;
}
- if (attrPresents(pm_itemClass)) {
- tableClass += SPACE + pm_itemClass;
- }
- if (attrPresents(pm_itemStyle)) {
- tableStyle += SPACE + pm_itemStyle;
- }
if (childOfPanelMenu) {
tableClass += SPACE + CSS_TOP_ITEM;
- iconCellClass += SPACE + CSS_TOP_ITEM_ICON;
+ imgIconClass += SPACE + CSS_TOP_ITEM_ICON;
labelCellClass += SPACE + CSS_TOP_ITEM_LABEL;
if (attrPresents(pm_topItemClass)) {
tableClass += SPACE + pm_topItemClass;
@@ -479,21 +497,58 @@
if (attrPresents(pm_topItemStyle)) {
tableStyle += SPACE + pm_topItemStyle;
}
+ } else {
+ if (attrPresents(pm_itemClass)) {
+ tableClass += SPACE + pm_itemClass;
+ }
+ if (attrPresents(pm_itemStyle)) {
+ tableStyle += SPACE + pm_itemStyle;
+ }
}
}
table.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, tableStyle);
- iconCell.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, iconStyle);
- labelCell.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, WIDTH_100_PERCENTS);
+ iconCell.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, iconCellStyle);
+ labelCell.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, labelCellStyle);
+ emptyCell.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, emptyCellStyle);
table.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, tableClass);
tr.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, trClass);
iconCell.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, iconCellClass);
+ imgIcon.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, imgIconClass);
labelCell.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, labelCellClass);
emptyCell.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, emptyCellClass);
}
/**
+ * Gets the panel menu item parent.
+ *
+ * @param sourceItemElement the source item element
+ * @param findOnlyPanelMenuParent flag to find only panel menu parent
+ *
+ * @return the item parent
+ */
+ private static final Element getItemParent(Element sourceItemElement,
+ boolean findOnlyPanelMenuParent) {
+ Element parent = (Element) sourceItemElement.getParentNode();
+ while (true) {
+ if (findOnlyPanelMenuParent) {
+ if (parent.getNodeName().endsWith(PANEL_MENU_END_TAG)) {
+ break;
+ }
+ } else {
+ if (parent.getNodeName().endsWith(PANEL_MENU_END_TAG)
+ || parent.getNodeName().endsWith(
+ PANEL_MENU_GROUP_END_TAG)) {
+ break;
+ }
+ }
+ parent = (Element) parent.getParentNode();
+ }
+ return parent;
+ }
+
+ /**
* Read attributes from the source element.
*
* @param sourceNode the source node
@@ -563,4 +618,14 @@
private static boolean attrPresents(String attr) {
return ((null != attr) && (!EMPTY.equalsIgnoreCase(attr)));
}
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#setSourceAttributeSelection(org.jboss.tools.vpe.editor.context.VpePageContext,
org.w3c.dom.Element, int, int, java.lang.Object)
+ */
+ @Override
+ public void setSourceAttributeSelection(VpePageContext pageContext,
+ Element sourceElement, int offset, int length, Object data) {
+ VpeSourceDomBuilder sourceBuilder = pageContext.getSourceBuilder();
+ sourceBuilder.setSelection(sourceElement, 0, 0);
+ }
}
\ No newline at end of file
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuTemplate.java 2008-04-24
14:09:04 UTC (rev 7737)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesPanelMenuTemplate.java 2008-04-24
14:43:50 UTC (rev 7738)
@@ -11,10 +11,7 @@
package org.jboss.tools.jsf.vpe.richfaces.template;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
@@ -23,11 +20,9 @@
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.VpeToggableTemplate;
import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
-import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -36,8 +31,7 @@
* @author ezheleznyakov(a)exadel.com
*
*/
-public class RichFacesPanelMenuTemplate extends VpeAbstractTemplate implements
- VpeToggableTemplate {
+public class RichFacesPanelMenuTemplate extends VpeAbstractTemplate {
/*
* rich:panelMenu attributes
@@ -101,25 +95,17 @@
private static final String PANEL_MENU_GROUP_END = ":panelMenuGroup";
//$NON-NLS-1$
private static final String PANEL_MENU_ITEM_END = ":panelMenuItem";
//$NON-NLS-1$
- private static final String TRUE = "true"; //$NON-NLS-1$
private static final String MARGIN_TOP = "margin-top: 3px; "; //$NON-NLS-1$
private static final String TOP_MENU_ITEM_ID = ""; //$NON-NLS-1$
- private List<String> activeIds = new ArrayList<String>();
-
- private String expandSingle;
- // private static final String DISABLED_STYLE_FOR_TABLE = "color:#B1ADA7";
-
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
Element sourceElement = (Element) sourceNode;
-
String width = sourceElement.getAttribute(WIDTH);
String style = sourceElement.getAttribute(STYLE);
String styleClass = sourceElement.getAttribute(STYLE_CLASS);
- expandSingle = sourceElement.getAttribute(EXPAND_SINGLE);
if (width != null) {
style += "" + "; width:" + width; //$NON-NLS-1$ //$NON-NLS-2$
@@ -139,128 +125,29 @@
List<Node> children = ComponentUtil.getChildren(sourceElement);
int i = 1;
-
+ List<String> expandedIds = new ArrayList<String>();
for (Node child : children) {
if (child.getNodeName().endsWith(PANEL_MENU_GROUP_END)) {
- RichFacesPanelMenuGroupTemplate.encode(pageContext,
- vpeCreationData, sourceElement, (Element) child,
- visualDocument, div, getActiveIds(), String.valueOf(i));
+ child.setUserData(VpeVisualDomBuilder.VPE_USER_TOGGLE_ID, String.valueOf(i), null);
+ child.setUserData(RichFacesPanelMenuGroupTemplate.VPE_EXPANDED_TOGGLE_IDS,
expandedIds, null);
i++;
- } else if (child.getNodeName().endsWith(PANEL_MENU_ITEM_END)) {
- RichFacesPanelMenuItemTemplate.encode(pageContext,
- vpeCreationData, sourceElement, (Element) child,
- visualDocument, div, TOP_MENU_ITEM_ID);
- } else {
- nsIDOMElement childDiv = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_DIV);
- VpeChildrenInfo childrenInfo = new VpeChildrenInfo(childDiv);
- div.appendChild(childDiv);
- childrenInfo.addSourceChild(child);
- vpeCreationData.addChildrenInfo(childrenInfo);
}
+ if (child.getNodeName().endsWith(PANEL_MENU_ITEM_END)) {
+ child.setUserData(RichFacesPanelMenuItemTemplate.VPE_PANEL_MENU_ITEM_ID,
TOP_MENU_ITEM_ID, null);
+ }
+
+ VpeChildrenInfo childrenInfo = new VpeChildrenInfo(div);
+ childrenInfo.addSourceChild(child);
+ vpeCreationData.addChildrenInfo(childrenInfo);
}
-
return vpeCreationData;
}
- /**
- * Gets the active ids.
- *
- * @return the active ids
- */
- private List<String> getActiveIds() {
- return activeIds;
- }
-
- /**
- *
- * @param children
- * @return
- */
- private int getChildrenCount(List<Node> children) {
- int count = 0;
- for (Node child : children) {
- if (child.getNodeName().endsWith(PANEL_MENU_GROUP_END)) {
- count++;
- }
- }
- return count;
- }
-
- public void toggle(VpeVisualDomBuilder builder, Node sourceNode,
- String toggleId) {
-
- /*
- * Expand only one group.
- */
- if ((null != expandSingle) && (TRUE.equalsIgnoreCase(expandSingle))) {
- if (activeIds.contains(toggleId)) {
- /*
- * Close group and its children
- */
- activeIds.remove(toggleId);
- for (Iterator<String> iterator = activeIds.iterator(); iterator.hasNext();) {
- String id = iterator.next();
- if (id.startsWith(toggleId)) {
- iterator.remove();
- }
- }
- } else {
- /*
- * Expand new group, close others
- */
- String[] toggleIds =
toggleId.split(RichFacesPanelMenuGroupTemplate.GROUP_COUNT_SEPARATOR);
- if ((null != toggleIds) && (toggleIds.length > 0)) {
- for (Iterator<String> iterator = activeIds.iterator(); iterator.hasNext();) {
- String id = iterator.next();
- String[] ids = id.split(RichFacesPanelMenuGroupTemplate.GROUP_COUNT_SEPARATOR);
- if ((null != ids) && (ids.length > 0)) {
- if (ids.length >= toggleIds.length) {
- /*
- * Remove all ids that are deeper than selected
- * and that are on the same level.
- */
- iterator.remove();
- } else {
- /*
- * Remove all ids that are not in the selected branch.
- */
- for (int i = 0; i < ids.length; i++) {
- if (!ids[i].equalsIgnoreCase(toggleIds[i])) {
- iterator.remove();
- }
- }
- }
- }
- }
- }
- activeIds.add(toggleId);
- }
- } else {
- /*
- * Expand any number of groups.
- */
- if (activeIds.contains(toggleId)) {
- activeIds.remove(toggleId);
- for (Iterator<String> iterator = activeIds.iterator(); iterator.hasNext();) {
- String id = iterator.next();
- if (id.startsWith(toggleId)) {
- iterator.remove();
- }
- }
- } else {
- activeIds.add(toggleId);
- }
- }
- }
-
- public void stopToggling(Node sourceNode) {
- activeIds.clear();
- }
-
public boolean isRecreateAtAttrChange(VpePageContext pageContext,
Element sourceElement, nsIDOMDocument visualDocument,
nsIDOMElement visualNode, Object data, String name, String value) {
return true;
}
+
+
}
\ No newline at end of file
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-04-24
14:09:04 UTC (rev 7737)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/templates/vpe-templates-richfaces.xml 2008-04-24
14:43:50 UTC (rev 7738)
@@ -574,6 +574,8 @@
<vpe:template children="yes" modify="yes"
class="org.jboss.tools.jsf.vpe.richfaces.template.RichFacesPanelMenuItemTemplate">
<vpe:drag start-enable="yes"/>
<vpe:drop container="yes"/>
+ <vpe:textFormatting use-default-formats="yes">
+ </vpe:textFormatting>
</vpe:template>
</vpe:tag>
@@ -581,6 +583,8 @@
<vpe:template children="yes" modify="yes"
class="org.jboss.tools.jsf.vpe.richfaces.template.RichFacesPanelMenuGroupTemplate">
<vpe:drag start-enable="yes"/>
<vpe:drop container="yes"/>
+ <vpe:textFormatting use-default-formats="yes">
+ </vpe:textFormatting>
</vpe:template>
</vpe:tag>
@@ -588,6 +592,7 @@
<vpe:template children="yes" modify="yes"
class="org.jboss.tools.jsf.vpe.richfaces.template.RichFacesPanelMenuTemplate">
<vpe:resize>
<vpe:width width-attr="width" />
+ <vpe:height height-attr="style.height" />
</vpe:resize>
<vpe:drag start-enable="yes"/>
<vpe:drop container="yes"/>