Author: svasilyev
Date: 2007-07-06 11:03:51 -0400 (Fri, 06 Jul 2007)
New Revision: 2346
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/toolBar/separatorLine.gif
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/HtmlComponentUtil.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesToolBarGroupTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesToolBarTemplate.java
Log:
http://jira.jboss.org/jira/browse/EXIN-231
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/toolBar/separatorLine.gif
===================================================================
(Binary files differ)
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/HtmlComponentUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/HtmlComponentUtil.java 2007-07-06
15:03:39 UTC (rev 2345)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/HtmlComponentUtil.java 2007-07-06
15:03:51 UTC (rev 2346)
@@ -75,6 +75,9 @@
/** HTML_ALIGN_LEFT_VALUE * */
public static final String HTML_ALIGN_LEFT_VALUE = "left";
+ /** HTML_ALIGN_CENTER_VALUE * */
+ public static final String HTML_ALIGN_CENTER_VALUE = "center";
+
/** HTML_ATR_WIDTH */
public static final String HTML_ATR_WIDTH = "width";
@@ -120,4 +123,9 @@
/** HTML_WIDTH_ATTR * */
public static final String HTML_WIDTH_ATTR = "width";
+ /** HTML_ATTR_VALIGN */
+ public static final String HTML_ATTR_VALIGN = "valign";
+
+ /** HTML_ATTR_VALIGN_MIDDLE_VALUE */
+ public static final String HTML_ATTR_VALIGN_MIDDLE_VALUE = "middle";
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesToolBarGroupTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesToolBarGroupTemplate.java 2007-07-06
15:03:39 UTC (rev 2345)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesToolBarGroupTemplate.java 2007-07-06
15:03:51 UTC (rev 2346)
@@ -12,12 +12,13 @@
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.jsf.vpe.richfaces.template.RichFacesToolBarTemplate.SourceToolBarColumnElements;
+import org.jboss.tools.vpe.VpePlugin;
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,359 +31,209 @@
import org.w3c.dom.NodeList;
public class RichFacesToolBarGroupTemplate extends VpeAbstractTemplate {
-
+ public static final String TAG_NAME = "toolBarGroup";
+
+ public static final String ATTR_ITEMSEPARATOR_NAME = "itemSeparator";
+
+ public static final String ATTR_LOCATION_NAME = "location";
+
+ public static final String ATTR_LOCATION_RIGHT_VALUE = "right";
+
@Override
public boolean isRecreateAtAttrChange(VpePageContext pageContext, Element sourceElement,
Document visualDocument, Node visualNode, Object data, String name, String value) {
return true;
}
- public VpeCreationData create(VpePageContext pageContext, Node sourceNode, Document
visualDocument) {
- Map visualNodeMap = pageContext.getDomMapping().getVisualMap();
+ private class SourceToolBarGroupItem {
+ private Node toolBarGroupItem;
+ private String itemSeparator;
- RichFacesToolBarTemplate.SourceToolBarElements sourceElements = new
RichFacesToolBarTemplate.SourceToolBarElements(sourceNode);
- RichFacesToolBarTemplate.VisualToolBarElements visualElements = new
RichFacesToolBarTemplate.VisualToolBarElements();
+ public SourceToolBarGroupItem(Node toolBarGroupItem) {
+ this.toolBarGroupItem = toolBarGroupItem;
+ this.itemSeparator = null;
+ }
- Element sourceElement = (Element)sourceNode;
-
- Element visualRow = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_SPAN);
- visualRow.setAttribute("style", "border: 0px; margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;");
+ public SourceToolBarGroupItem(String itemSeparator) {
+ this.toolBarGroupItem = null;
+ this.itemSeparator = itemSeparator;
+ }
- VpeCreationData creatorInfo = new VpeCreationData(visualRow);
-
- Element cell = null;
-
- if (true || sourceElements.hasBodySection()) {
-
- // Columns at left
- for (int i = 0; i < sourceElements.getColumnAtLeftCount(); i++) {
- SourceToolBarColumnElements column = sourceElements.getColumnAtLeft(i);
-
- if (column.hasBody()) {
- Node columnBody = column.getColumn();
- cell = visualDocument.createElement("td");
- ComponentUtil.correctAttribute(sourceElement, cell,
- RichFacesToolBarTemplate.CONTENTCLASS_ATTR_NAME,
- HtmlComponentUtil.HTML_CLASS_ATTR, "dr-toolbar-int rich-toolbar-item",
"dr-toolbar-int rich-toolbar-item");
- ComponentUtil.correctAttribute(sourceElement, cell,
- RichFacesToolBarTemplate.CONTENTSTYLE_ATTR_NAME,
- HtmlComponentUtil.HTML_STYLE_ATTR, null, null);
-
- visualRow.appendChild(cell);
-
- VpeChildrenInfo info = new VpeChildrenInfo(cell);
- creatorInfo.addChildrenInfo(info);
-
- info.addSourceChild(column.getColumn());
- MozillaSupports.release(cell);
- } else if (column.isSeparator()){
- String itemSeparator = column.getSeparatorType();
- String separatorImageUrl = RichFacesToolBarTemplate.getSeparatorImageUrlString
(itemSeparator);
-
- if (separatorImageUrl != null) {
- // Insert separator here
- cell = visualDocument.createElement("td");
- cell.setAttribute("align", "center");
- ComponentUtil.correctAttribute(sourceElement, cell,
- RichFacesToolBarTemplate.SEPARATORCLASS_ATTR_NAME,
- HtmlComponentUtil.HTML_CLASS_ATTR, null, null);
- Element separatorImage = visualDocument.createElement("img");
- ComponentUtil.setImg(separatorImage, separatorImageUrl);
- cell.appendChild(separatorImage);
- visualRow.appendChild(cell);
- MozillaSupports.release(separatorImage);
- MozillaSupports.release(cell);
- }
- }
- }
-
- // Columns at right
- for (int i = 0; i < sourceElements.getColumnAtRightCount(); i++) {
- SourceToolBarColumnElements column = sourceElements.getColumnAtRight(i);
- if (column.hasBody()) {
- Node columnBody = column.getColumn();
- cell = visualDocument.createElement("td");
- ComponentUtil.correctAttribute(sourceElement, cell,
- RichFacesToolBarTemplate.CONTENTCLASS_ATTR_NAME,
- HtmlComponentUtil.HTML_CLASS_ATTR, "dr-toolbar-int rich-toolbar-item",
"dr-toolbar-int rich-toolbar-item");
- ComponentUtil.correctAttribute(sourceElement, cell,
- RichFacesToolBarTemplate.CONTENTSTYLE_ATTR_NAME,
- HtmlComponentUtil.HTML_STYLE_ATTR, null, null);
- visualRow.appendChild(cell);
-
- VpeChildrenInfo info = new VpeChildrenInfo(cell);
- creatorInfo.addChildrenInfo(info);
-
- info.addSourceChild(column.getColumn());
- MozillaSupports.release(cell);
- } else if (column.isSeparator()){
- String itemSeparator = column.getSeparatorType();
- String separatorImageUrl = RichFacesToolBarTemplate.getSeparatorImageUrlString
(itemSeparator);
-
- if (separatorImageUrl != null) {
- // Insert separator here
- cell = visualDocument.createElement("td");
- cell.setAttribute("align", "center");
- ComponentUtil.correctAttribute(sourceElement, cell,
- RichFacesToolBarTemplate.SEPARATORCLASS_ATTR_NAME,
- HtmlComponentUtil.HTML_CLASS_ATTR, null, null);
- Element separatorImage = visualDocument.createElement("img");
- ComponentUtil.setImg(separatorImage, separatorImageUrl);
- cell.appendChild(separatorImage);
- visualRow.appendChild(cell);
- MozillaSupports.release(separatorImage);
- MozillaSupports.release(cell);
- }
- }
- }
-
- // Empty column
- cell = visualDocument.createElement("td");
- cell.setAttribute("width", "100%");
- visualRow.appendChild(cell);
- MozillaSupports.release(cell);
+ public Node getToolBarGroupItem() {
+ return toolBarGroupItem;
}
- Object[] elements = new Object[2];
- elements[0] = visualElements;
- elements[1] = sourceElements;
- visualNodeMap.put(this, elements);
-
- return creatorInfo;
- }
-
- private VisualToolBarGroupElements getVisualToolBarElements(Map visualNodeMap) {
- if (visualNodeMap != null) {
- Object o = visualNodeMap.get(this);
- try {
- if (o != null && o instanceof Object[] && ((Object[])o)[0] instanceof
VisualToolBarGroupElements) {
- return (VisualToolBarGroupElements)((Object[])o)[0];
- }
- } catch (Exception e) {
- }
+ public String getItemSeparator() {
+ return itemSeparator;
}
- return null;
- }
- private void setRowDisplayStyle(Element row, boolean visible) {
- if (row != null) {
- row.setAttribute("style", "display:" + (visible ? "" :
"none"));
+ public boolean isItem() {
+ return toolBarGroupItem != null;
}
}
-
- class SourceToolBarGroupElements {
- private List columns;
- Map attributes;
+
+ private class SourceToolBarGroupItems {
+ private boolean isToolBarGroupLocationRight;
+ private String itemSeparator;
+ boolean isItemSeparatorExists;
+ private List<SourceToolBarGroupItem> toolBarGroupItems = new
ArrayList<SourceToolBarGroupItem>();
- public SourceToolBarGroupElements(Node sourceNode) {
+ public SourceToolBarGroupItems(Node sourceNode, boolean isToolBarGroupLocationRight,
+ String itemSeparator) {
+ this.isToolBarGroupLocationRight = isToolBarGroupLocationRight;
+ this.itemSeparator = itemSeparator;
+ this.isItemSeparatorExists = !(itemSeparator == null
+ || (itemSeparator != null && itemSeparator.length() == 0)
+ || RichFacesToolBarTemplate.ITEM_SEPARATOR_NONE.equals(itemSeparator));
+
init(sourceNode);
- initAttributes(sourceNode);
}
- void initAttributes(Node sourceNode) {
- NamedNodeMap attrs = sourceNode.getAttributes();
- attributes = new HashMap<String, String>();
- for (int i = 0; attrs != null && i < attrs.getLength(); i++) {
- Node attribute = attrs.item(i);
- attributes.put(attribute.getNodeName(), attribute.getNodeValue());
- }
- }
-
- void init (Node sourceNode) {
- NodeList children = sourceNode.getChildNodes();
-
- int cnt = children != null ? children.getLength() : 0;
- if (cnt > 0) {
- for (int i = 0; i < cnt; i++) {
- Node child = children.item(i);
- if (child.getNodeType() == Node.ELEMENT_NODE) {
- Element childElement = (Element)child;
-
- if (childElement.getNodeName().endsWith(":toolBarGroup")) {
- initToolBarGroup(childElement);
- } else {
- if (columns == null) columns = new ArrayList();
- columns.add(new SourceToolBarGroupColumnElements(child));
- columns.add(new SourceToolBarGroupColumnElements(null));
- }
- } else if (child.getNodeType() == Node.TEXT_NODE) {
- String text = child.getNodeValue();
- text = (text == null ? null : text.trim());
- if (text != null && text.length() > 0) {
- if (columns == null) columns = new ArrayList();
- columns.add(new SourceToolBarGroupColumnElements(child));
- columns.add(new SourceToolBarGroupColumnElements(null));
- }
+ private void init(Node sourceNode) {
+ NodeList childrenList = sourceNode.getChildNodes();
+ int childrenCount = childrenList.getLength();
+ boolean isFirstItem = true;
+ for (int i=0; i<childrenCount; i++) {
+ Node child = childrenList.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE
+ || isVisibleText(child)) {
+ if (isItemSeparatorExists && isToolBarGroupLocationRight
+ && !isFirstItem) {
+ toolBarGroupItems.add(new SourceToolBarGroupItem(itemSeparator));
}
- }
- }
- }
-
- void initToolBarGroup(Element sourceElement) {
- if (sourceElement == null) return;
- NodeList children = sourceElement.getChildNodes();
-
- int cnt = children != null ? children.getLength() : 0;
- if (cnt > 0) {
- for (int i = 0; i < cnt; i++) {
- Node child = children.item(i);
- if (child.getNodeType() == Node.ELEMENT_NODE) {
- Element childElement = (Element)child;
-
- if (childElement.getNodeName().endsWith(":toolBarGroup")) {
- initToolBarGroup(childElement);
- } else {
- if (columns == null) columns = new ArrayList();
- columns.add(new SourceToolBarGroupColumnElements(child));
- }
- } else if (child.getNodeType() == Node.TEXT_NODE) {
- String text = child.getNodeValue();
- text = (text == null ? null : text.trim());
- if (text != null && text.length() > 0) {
- if (columns == null) columns = new ArrayList();
- columns.add(new SourceToolBarGroupColumnElements(child));
- }
+
+ toolBarGroupItems.add(new SourceToolBarGroupItem(child));
+
+ if (isItemSeparatorExists && !isToolBarGroupLocationRight
+ && !isLastItem(childrenList, i)) {
+ toolBarGroupItems.add(new SourceToolBarGroupItem(itemSeparator));
}
+
+ isFirstItem = false;
}
}
}
- public SourceToolBarGroupColumnElements getColumn(int index) {
- if (columns != null && index < getColumnCount()) return
(SourceToolBarGroupColumnElements)columns.get(index);
- return null;
+ private boolean isVisibleText(Node textNode) {
+ return textNode.getNodeType() == Node.TEXT_NODE
+ && textNode.getNodeValue() != null
+ && textNode.getNodeValue().trim().length() > 0;
}
-
- public int getColumnCount() {
- if (columns != null) return columns.size();
- return 0;
- }
-
- public boolean hasColspan() {
- return (getColumnCount()) >= 2;
- }
-
- public boolean hasBodySection() {
- for (int i = 0; i < getColumnCount(); i++) {
- SourceToolBarGroupColumnElements column = getColumn(i);
- if (column.hasBody()) return true;
+
+ private boolean isLastItem(NodeList list, int index) {
+ int listLength = list.getLength();
+
+ for (int i=index+1; i < listLength; i++ ) {
+ Node item = list.item(i);
+ if (item.getNodeType() == Node.ELEMENT_NODE
+ || isVisibleText(item)) {
+ return false;
+ }
}
- return false;
+
+ return true;
}
-
- Map getAttributes() {
- return attributes;
- }
- String getAttributeValue(String name) {
- return (String)attributes.get(name);
+ public Iterator<SourceToolBarGroupItem> iterator() {
+ return toolBarGroupItems.iterator();
}
}
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ Document visualDocument) {
+ Element visualNode = null;
+ VpeCreationData creationData = null;
+
+ Element sourceElement = (Element)sourceNode;
+ String itemSeparator = sourceElement.getAttribute(ATTR_ITEMSEPARATOR_NAME);
+
+ if (!sourceNode.getParentNode().getNodeName().endsWith(":" +
RichFacesToolBarTemplate.TAG_NAME)) {
+ visualNode = RichFacesToolBarTemplate.createExceptionNode(visualDocument, "Parent
should be toolBar");
+
+ creationData = new VpeCreationData(visualNode);
+ } else if (!RichFacesToolBarTemplate.isValidItemSeparatorName(itemSeparator)) {
+ visualNode = RichFacesToolBarTemplate.createExceptionNode(visualDocument,
+ "Unknown type of separator \"" + itemSeparator +
"\"");
+
+ creationData = new VpeCreationData(visualNode);
+ } else {
+
+ SourceToolBarGroupItems sourceToolBarGroupItems = new
SourceToolBarGroupItems(sourceNode,
+ ATTR_LOCATION_RIGHT_VALUE.equals(sourceElement.getAttribute(ATTR_LOCATION_NAME)),
+ itemSeparator);
+
+
+ visualNode = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE);
+ visualNode.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR, "border: 0px none;
margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px;");
+ Element body = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TBODY);
+ Element row = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR);
+ row.setAttribute(HtmlComponentUtil.HTML_ATTR_VALIGN,
HtmlComponentUtil.HTML_ATTR_VALIGN_MIDDLE_VALUE);
+
+ creationData = new VpeCreationData(visualNode);
+
+ Iterator<SourceToolBarGroupItem> iterator = sourceToolBarGroupItems.iterator();
+ while(iterator.hasNext()) {
+ SourceToolBarGroupItem toolBarGroupItem = iterator.next();
+
+ Element cell = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
+ if (toolBarGroupItem.isItem()) {
+ ComponentUtil.correctAttribute(sourceElement, cell,
+ RichFacesToolBarTemplate.CONTENTCLASS_ATTR_NAME,
+ HtmlComponentUtil.HTML_CLASS_ATTR, "dr-toolbar-int rich-toolbar-item",
"dr-toolbar-int rich-toolbar-item");
+ ComponentUtil.correctAttribute(sourceElement, cell,
+ RichFacesToolBarTemplate.CONTENTSTYLE_ATTR_NAME,
+ HtmlComponentUtil.HTML_STYLE_ATTR, null, null);
- public static class SourceToolBarGroupColumnElements {
- private Node column;
- private List body;
-
- public SourceToolBarGroupColumnElements(Node columnNode) {
- init(columnNode);
- }
-
- private void init(Node columnNode) {
- column = columnNode;
- if (columnNode != null) {
- body = new ArrayList();
- body.add(columnNode);
+ VpeChildrenInfo childrenInfo = new VpeChildrenInfo(cell);
+ creationData.addChildrenInfo(childrenInfo);
+ childrenInfo.addSourceChild(toolBarGroupItem.getToolBarGroupItem());
+ } else {
+ cell.setAttribute(HtmlComponentUtil.HTML_ALIGN_ATTR,
HtmlComponentUtil.HTML_ALIGN_CENTER_VALUE);
+ ComponentUtil.correctAttribute(sourceElement, cell,
+ RichFacesToolBarTemplate.SEPARATORCLASS_ATTR_NAME,
+ HtmlComponentUtil.HTML_CLASS_ATTR, null, null);
+ String separatorImageUrl = RichFacesToolBarTemplate
+ .getSeparatorImageUrlString(toolBarGroupItem.getItemSeparator());
+ Element separatorImage =
visualDocument.createElement(HtmlComponentUtil.HTML_TAG_IMG);
+ ComponentUtil.setImg(separatorImage, separatorImageUrl);
+ cell.appendChild(separatorImage);
+ MozillaSupports.release(separatorImage);
+ }
+
+ row.appendChild(cell);
+ MozillaSupports.release(cell);
}
+
+ body.appendChild(row);
+ MozillaSupports.release(row);
+ visualNode.appendChild(body);
+ MozillaSupports.release(body);
}
+
+ return creationData;
+ }
+
- public boolean hasBody() {
- return body != null && body.size() > 0;
- }
-
- public List getBody() {
- return body;
- }
-
- public void setBody(List body) {
- this.body = body;
- }
-
- public void setColumn(Node column) {
- this.column = column;
- }
-
- public int getBodyElementsCount() {
- if (body != null) return body.size();
- return 0;
- }
-
- public Node getBodyElement(int index) {
- if (body != null) return (Node)body.get(index);
+ @Override
+ public Node getNodeForUptate(VpePageContext pageContext, Node sourceNode,
+ Node visualNode, Object data) {
+ String prefix = sourceNode.getPrefix();
+ if (prefix == null) {
return null;
}
- public Node getColumn() {
- return column;
- }
- }
-
- public static class VisualToolBarGroupElements {
- private Element body;
- private Element bodyRow;
- private List columns;
-
- public VisualToolBarGroupElements() {
- }
- public VisualToolBarGroupElements(Element body) {
- this.body = body;
- }
+ String parentNodeName = prefix + ":" + RichFacesToolBarTemplate.TAG_NAME;
- private VisualToolBarGroupColumnElements getColumn(int index) {
- if (columns != null && index < getColumnCount()) return
(VisualToolBarGroupColumnElements)columns.get(index);
- return null;
+ Node parent = sourceNode.getParentNode();
+ while (parent != null) {
+ if (parentNodeName.equals(parent.getNodeName())) {
+ break;
+ }
+
+ parent = parent.getParentNode();
}
-
- private int getColumnCount() {
- if (columns != null) return columns.size();
- return 0;
- }
-
- private List getColumns() {
- if (columns == null) columns = new ArrayList();
- return columns;
- }
-
- public Element getBody() {
- return body;
- }
-
- public void setBody(Element body) {
- this.body = body;
- }
-
- public Element getBodyRow() {
- return bodyRow;
- }
-
- public void setBodyRow(Element bodyRow) {
- this.bodyRow = bodyRow;
- }
+
+ return parent;
}
-
- public static class VisualToolBarGroupColumnElements {
- private Element bodyCell;
-
- private boolean isEmpty() {
- return bodyCell == null;
- }
-
- public Element getBodyCell() {
- return bodyCell;
- }
-
- public void setBodyCell(Element bodyCell) {
- this.bodyCell = bodyCell;
- }
- }
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesToolBarTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesToolBarTemplate.java 2007-07-06
15:03:39 UTC (rev 2345)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesToolBarTemplate.java 2007-07-06
15:03:51 UTC (rev 2346)
@@ -12,6 +12,8 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -27,11 +29,11 @@
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
-import com.sun.org.apache.bcel.internal.generic.CPInstruction;
-
public class RichFacesToolBarTemplate extends VpeAbstractTemplate {
-
+ public static final String TAG_NAME = "toolBar";
+
public static final String ITEM_SEPARATOR_NONE = "none";
public static final String ITEM_SEPARATOR_LINE = "line";
public static final String ITEM_SEPARATOR_GRID = "grid";
@@ -43,7 +45,8 @@
public static final String ITEM_SEPARATOR_DISC_URL =
"toolBar/separatorDisc.gif";
public static final String ITEM_SEPARATOR_SQUARE_URL =
"toolBar/separatorSquare.gif";
-
+ public static final String EXCEPTION_ATTR_STYLE_VALUE = "color: red;
font-weight:bold;";
+
static final String CONTENTCLASS_ATTR_NAME = "contentClass";
static final String CONTENTSTYLE_ATTR_NAME = "contentStyle";
static final String STYLECLASS_ATTR_NAME = "styleClass";
@@ -58,150 +61,292 @@
return true;
}
- public VpeCreationData create(VpePageContext pageContext, Node sourceNode, Document
visualDocument) {
- SourceToolBarElements sourceElements = new SourceToolBarElements(sourceNode);
- VisualToolBarElements visualElements = new VisualToolBarElements();
-
- Element sourceElement = (Element)sourceNode;
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ Document visualDocument) {
+ VpeCreationData creationData = null;
+ Element visualNode = null;
- ComponentUtil.setCSSLink(pageContext, "toolBar/toolBar.css",
"richFacesToolBar");
-
- Element visualTable = visualDocument.createElement("table");
-
- ComponentUtil.correctAttribute(sourceElement, visualTable,
- WIDTH_ATTR_NAME,
- HtmlComponentUtil.HTML_WIDTH_ATTR, null, "100%");
- ComponentUtil.correctAttribute(sourceElement, visualTable,
- HEIGHT_ATTR_NAME,
- HtmlComponentUtil.HTML_HEIGHT_ATTR, null, null);
- ComponentUtil.correctAttribute(sourceElement, visualTable,
- STYLECLASS_ATTR_NAME,
- HtmlComponentUtil.HTML_CLASS_ATTR, "dr-toolbar-ext rich-toolbar",
"dr-toolbar-ext rich-toolbar");
-
- String style = ComponentUtil.getHeaderBackgoundImgStyle() + ";";
- ComponentUtil.correctAttribute(sourceElement, visualTable,
- STYLE_ATTR_NAME,
- HtmlComponentUtil.HTML_STYLE_ATTR, style, style);
-
-
- VpeCreationData creatorInfo = new VpeCreationData(visualTable);
-
- String separatorClass = sourceElement.getAttribute("separatorClass");
-
- Element section = null, row = null, cell = null;
-
- if (true || sourceElements.hasBodySection()) {
- section = visualDocument.createElement("tbody");
- row = visualDocument.createElement("tr");
- row.setAttribute("valign", "middle");
+ Element sourceElement = (Element) sourceNode;
+ String itemSeparator = sourceElement.getAttribute(ITEMSEPARATOR_ATTR_NAME);
+ if (!isValidItemSeparatorName(itemSeparator)) {
+ visualNode = createExceptionNode(visualDocument,
+ "Unknown type of separator \"" + itemSeparator +
"\"");
- // Columns at left
- for (int i = 0; i < sourceElements.getColumnAtLeftCount(); i++) {
- SourceToolBarColumnElements column = sourceElements.getColumnAtLeft(i);
-
- if (column.hasBody()) {
- Node columnBody = column.getColumn();
- cell = visualDocument.createElement("td");
+ creationData = new VpeCreationData(visualNode);
+ } else {
+ SourceToolBarItems sourceToolBarItems = new SourceToolBarItems(sourceNode,
itemSeparator);
+ String itemSeparatorImageUrl =
getSeparatorImageUrlString(sourceToolBarItems.getItemSeparator());
+
+ ComponentUtil.setCSSLink(pageContext, "toolBar/toolBar.css",
"richFacesToolBar");
+
+ visualNode = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TABLE);
+
+ ComponentUtil.correctAttribute(sourceElement, visualNode,
+ WIDTH_ATTR_NAME,
+ HtmlComponentUtil.HTML_WIDTH_ATTR, null, "100%");
+ ComponentUtil.correctAttribute(sourceElement, visualNode,
+ HEIGHT_ATTR_NAME,
+ HtmlComponentUtil.HTML_HEIGHT_ATTR, null, null);
+ ComponentUtil.correctAttribute(sourceElement, visualNode,
+ STYLECLASS_ATTR_NAME,
+ HtmlComponentUtil.HTML_CLASS_ATTR, "dr-toolbar-ext rich-toolbar",
"dr-toolbar-ext rich-toolbar");
+
+ String style = ComponentUtil.getHeaderBackgoundImgStyle() + ";";
+ ComponentUtil.correctAttribute(sourceElement, visualNode,
+ STYLE_ATTR_NAME,
+ HtmlComponentUtil.HTML_STYLE_ATTR, style, style);
+
+ creationData = new VpeCreationData(visualNode);
+
+ Element body = null, row = null, cell = null;
+
+ body = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TBODY);
+ row = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TR);
+ row.setAttribute(HtmlComponentUtil.HTML_ATTR_VALIGN,
HtmlComponentUtil.HTML_ATTR_VALIGN_MIDDLE_VALUE);
+
+ SourceToolBarItem toolBarItem;
+ Iterator<SourceToolBarItem> iterator =
sourceToolBarItems.getLeftItemsIterator();
+ while (iterator.hasNext()) {
+ toolBarItem = iterator.next();
+ cell = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
+ if (toolBarItem.isItem()) {
ComponentUtil.correctAttribute(sourceElement, cell,
CONTENTCLASS_ATTR_NAME,
HtmlComponentUtil.HTML_CLASS_ATTR, "dr-toolbar-int rich-toolbar-item",
"dr-toolbar-int rich-toolbar-item");
ComponentUtil.correctAttribute(sourceElement, cell,
CONTENTSTYLE_ATTR_NAME,
- HtmlComponentUtil.HTML_STYLE_ATTR, null, null);
-
- row.appendChild(cell);
-
- VpeChildrenInfo info = new VpeChildrenInfo(cell);
- creatorInfo.addChildrenInfo(info);
+ HtmlComponentUtil.HTML_STYLE_ATTR,
+ toolBarItem.isToolBarGroupItem() ? "padding: 0px 0px 0px 0px;" : null,
+ toolBarItem.isToolBarGroupItem() ? "padding: 0px 0px 0px 0px;" : null);
- info.addSourceChild(column.getColumn());
- MozillaSupports.release(cell);
- } else if (column.isSeparator()){
- String itemSeparator = column.getSeparatorType();
- String separatorImageUrl = getSeparatorImageUrlString (itemSeparator);
-
- if (separatorImageUrl != null) {
- // Insert separator here
- cell = visualDocument.createElement("td");
- cell.setAttribute("align", "center");
+ VpeChildrenInfo childrenInfo = new VpeChildrenInfo(cell);
+ creationData.addChildrenInfo(childrenInfo);
+ childrenInfo.addSourceChild(toolBarItem.getToolBarItem());
+ } else {
+ if (itemSeparatorImageUrl != null) {
+ cell = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
+ cell.setAttribute(HtmlComponentUtil.HTML_ALIGN_ATTR,
HtmlComponentUtil.HTML_ALIGN_CENTER_VALUE);
ComponentUtil.correctAttribute(sourceElement, cell,
SEPARATORCLASS_ATTR_NAME,
HtmlComponentUtil.HTML_CLASS_ATTR, null, null);
- Element separatorImage = visualDocument.createElement("img");
- ComponentUtil.setImg(separatorImage, separatorImageUrl);
+ Element separatorImage =
visualDocument.createElement(HtmlComponentUtil.HTML_TAG_IMG);
+ ComponentUtil.setImg(separatorImage, itemSeparatorImageUrl);
cell.appendChild(separatorImage);
- row.appendChild(cell);
MozillaSupports.release(separatorImage);
- MozillaSupports.release(cell);
}
}
+
+ row.appendChild(cell);
+ MozillaSupports.release(cell);
}
-
+
// Empty column
- cell = visualDocument.createElement("td");
- cell.setAttribute("width", "100%");
+ cell = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
+ cell.setAttribute(HtmlComponentUtil.HTML_WIDTH_ATTR, "100%");
row.appendChild(cell);
MozillaSupports.release(cell);
-
- // Columns at right
- for (int i = 0; i < sourceElements.getColumnAtRightCount(); i++) {
- SourceToolBarColumnElements column = sourceElements.getColumnAtRight(i);
- if (column.hasBody()) {
- Node columnBody = column.getColumn();
- cell = visualDocument.createElement("td");
+
+ iterator = sourceToolBarItems.getRightItemsIterator();
+ while (iterator.hasNext()) {
+ toolBarItem = iterator.next();
+ cell = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
+ if (toolBarItem.isItem()) {
ComponentUtil.correctAttribute(sourceElement, cell,
CONTENTCLASS_ATTR_NAME,
HtmlComponentUtil.HTML_CLASS_ATTR, "dr-toolbar-int rich-toolbar-item",
"dr-toolbar-int rich-toolbar-item");
ComponentUtil.correctAttribute(sourceElement, cell,
CONTENTSTYLE_ATTR_NAME,
- HtmlComponentUtil.HTML_STYLE_ATTR, null, null);
- row.appendChild(cell);
-
- VpeChildrenInfo info = new VpeChildrenInfo(cell);
- creatorInfo.addChildrenInfo(info);
+ HtmlComponentUtil.HTML_STYLE_ATTR,
+ toolBarItem.isToolBarGroupItem() ? "padding: 0px;" : null,
+ toolBarItem.isToolBarGroupItem() ? "padding: 0px;" : null);
- info.addSourceChild(column.getColumn());
- MozillaSupports.release(cell);
- } else if (column.isSeparator()){
- String itemSeparator = column.getSeparatorType();
- String separatorImageUrl = getSeparatorImageUrlString (itemSeparator);
-
- if (separatorImageUrl != null) {
- // Insert separator here
- cell = visualDocument.createElement("td");
- cell.setAttribute("align", "center");
+ VpeChildrenInfo childrenInfo = new VpeChildrenInfo(cell);
+ creationData.addChildrenInfo(childrenInfo);
+ childrenInfo.addSourceChild(toolBarItem.getToolBarItem());
+ } else {
+ if (itemSeparatorImageUrl != null) {
+ cell = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_TD);
+ cell.setAttribute(HtmlComponentUtil.HTML_ALIGN_ATTR,
HtmlComponentUtil.HTML_ALIGN_CENTER_VALUE);
ComponentUtil.correctAttribute(sourceElement, cell,
SEPARATORCLASS_ATTR_NAME,
HtmlComponentUtil.HTML_CLASS_ATTR, null, null);
- Element separatorImage = visualDocument.createElement("img");
- ComponentUtil.setImg(separatorImage, separatorImageUrl);
+ Element separatorImage =
visualDocument.createElement(HtmlComponentUtil.HTML_TAG_IMG);
+ ComponentUtil.setImg(separatorImage, itemSeparatorImageUrl);
cell.appendChild(separatorImage);
- row.appendChild(cell);
MozillaSupports.release(separatorImage);
- MozillaSupports.release(cell);
}
}
+
+ row.appendChild(cell);
+ MozillaSupports.release(cell);
}
-
- section.appendChild(row);
+ body.appendChild(row);
MozillaSupports.release(row);
- visualTable.appendChild(section);
- MozillaSupports.release(section);
- visualElements.setBodyRow(row);
- visualElements.setBody(section);
+ visualNode.appendChild(body);
+ MozillaSupports.release(body);
}
-
- Map visualNodeMap = pageContext.getDomMapping().getVisualMap();
- Object[] elements = new Object[2];
- elements[0] = visualElements;
- elements[1] = sourceElements;
- visualNodeMap.put(this, elements);
+ return creationData;
+ }
- return creatorInfo;
+ static Element createExceptionNode(Document visualDocument, String message) {
+ Element visualNode;
+ visualNode = visualDocument.createElement(HtmlComponentUtil.HTML_TAG_SPAN);
+ visualNode.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
EXCEPTION_ATTR_STYLE_VALUE);
+ Text text = visualDocument.createTextNode(message);
+ visualNode.appendChild(text);
+ MozillaSupports.release(text);
+
+ return visualNode;
}
+
+
+// public VpeCreationData create(VpePageContext pageContext, Node sourceNode, Document
visualDocument) {
+// SourceToolBarElements sourceElements = new SourceToolBarElements(sourceNode);
+// VisualToolBarElements visualElements = new VisualToolBarElements();
+//
+// Element sourceElement = (Element)sourceNode;
+//
+// ComponentUtil.setCSSLink(pageContext, "toolBar/toolBar.css",
"richFacesToolBar");
+//
+// Element visualTable = visualDocument.createElement("table");
+//
+// ComponentUtil.correctAttribute(sourceElement, visualTable,
+// WIDTH_ATTR_NAME,
+// HtmlComponentUtil.HTML_WIDTH_ATTR, null, "100%");
+// ComponentUtil.correctAttribute(sourceElement, visualTable,
+// HEIGHT_ATTR_NAME,
+// HtmlComponentUtil.HTML_HEIGHT_ATTR, null, null);
+// ComponentUtil.correctAttribute(sourceElement, visualTable,
+// STYLECLASS_ATTR_NAME,
+// HtmlComponentUtil.HTML_CLASS_ATTR, "dr-toolbar-ext rich-toolbar",
"dr-toolbar-ext rich-toolbar");
+//
+// String style = ComponentUtil.getHeaderBackgoundImgStyle() + ";";
+// ComponentUtil.correctAttribute(sourceElement, visualTable,
+// STYLE_ATTR_NAME,
+// HtmlComponentUtil.HTML_STYLE_ATTR, style, style);
+//
+//
+// VpeCreationData creatorInfo = new VpeCreationData(visualTable);
+//
+// String separatorClass = sourceElement.getAttribute("separatorClass");
+//
+// Element section = null, row = null, cell = null;
+//
+// if (true || sourceElements.hasBodySection()) {
+// section = visualDocument.createElement("tbody");
+// row = visualDocument.createElement("tr");
+// row.setAttribute("valign", "middle");
+//
+// // Columns at left
+// for (int i = 0; i < sourceElements.getColumnAtLeftCount(); i++) {
+// SourceToolBarColumnElements column = sourceElements.getColumnAtLeft(i);
+//
+// if (column.hasBody()) {
+// Node columnBody = column.getColumn();
+// cell = visualDocument.createElement("td");
+// ComponentUtil.correctAttribute(sourceElement, cell,
+// CONTENTCLASS_ATTR_NAME,
+// HtmlComponentUtil.HTML_CLASS_ATTR, "dr-toolbar-int rich-toolbar-item",
"dr-toolbar-int rich-toolbar-item");
+// ComponentUtil.correctAttribute(sourceElement, cell,
+// CONTENTSTYLE_ATTR_NAME,
+// HtmlComponentUtil.HTML_STYLE_ATTR, null, null);
+//
+// row.appendChild(cell);
+//
+// VpeChildrenInfo info = new VpeChildrenInfo(cell);
+// creatorInfo.addChildrenInfo(info);
+//
+// info.addSourceChild(column.getColumn());
+// MozillaSupports.release(cell);
+// } else if (column.isSeparator()){
+// String itemSeparator = column.getSeparatorType();
+// String separatorImageUrl = getSeparatorImageUrlString (itemSeparator);
+//
+// if (separatorImageUrl != null) {
+// // Insert separator here
+// cell = visualDocument.createElement("td");
+// cell.setAttribute("align", "center");
+// ComponentUtil.correctAttribute(sourceElement, cell,
+// SEPARATORCLASS_ATTR_NAME,
+// HtmlComponentUtil.HTML_CLASS_ATTR, null, null);
+// Element separatorImage = visualDocument.createElement("img");
+// ComponentUtil.setImg(separatorImage, separatorImageUrl);
+// cell.appendChild(separatorImage);
+// row.appendChild(cell);
+// MozillaSupports.release(separatorImage);
+// MozillaSupports.release(cell);
+// }
+// }
+// }
+//
+// // Empty column
+// cell = visualDocument.createElement("td");
+// cell.setAttribute("width", "100%");
+// row.appendChild(cell);
+// MozillaSupports.release(cell);
+//
+// // Columns at right
+// for (int i = 0; i < sourceElements.getColumnAtRightCount(); i++) {
+// SourceToolBarColumnElements column = sourceElements.getColumnAtRight(i);
+// if (column.hasBody()) {
+// Node columnBody = column.getColumn();
+// cell = visualDocument.createElement("td");
+// ComponentUtil.correctAttribute(sourceElement, cell,
+// CONTENTCLASS_ATTR_NAME,
+// HtmlComponentUtil.HTML_CLASS_ATTR, "dr-toolbar-int rich-toolbar-item",
"dr-toolbar-int rich-toolbar-item");
+// ComponentUtil.correctAttribute(sourceElement, cell,
+// CONTENTSTYLE_ATTR_NAME,
+// HtmlComponentUtil.HTML_STYLE_ATTR, null, null);
+// row.appendChild(cell);
+//
+// VpeChildrenInfo info = new VpeChildrenInfo(cell);
+// creatorInfo.addChildrenInfo(info);
+//
+// info.addSourceChild(column.getColumn());
+// MozillaSupports.release(cell);
+// } else if (column.isSeparator()){
+// String itemSeparator = column.getSeparatorType();
+// String separatorImageUrl = getSeparatorImageUrlString (itemSeparator);
+//
+// if (separatorImageUrl != null) {
+// // Insert separator here
+// cell = visualDocument.createElement("td");
+// cell.setAttribute("align", "center");
+// ComponentUtil.correctAttribute(sourceElement, cell,
+// SEPARATORCLASS_ATTR_NAME,
+// HtmlComponentUtil.HTML_CLASS_ATTR, null, null);
+// Element separatorImage = visualDocument.createElement("img");
+// ComponentUtil.setImg(separatorImage, separatorImageUrl);
+// cell.appendChild(separatorImage);
+// row.appendChild(cell);
+// MozillaSupports.release(separatorImage);
+// MozillaSupports.release(cell);
+// }
+// }
+// }
+//
+//
+// section.appendChild(row);
+// MozillaSupports.release(row);
+// visualTable.appendChild(section);
+// MozillaSupports.release(section);
+// visualElements.setBodyRow(row);
+// visualElements.setBody(section);
+// }
+//
+// Map visualNodeMap = pageContext.getDomMapping().getVisualMap();
+//
+// Object[] elements = new Object[2];
+// elements[0] = visualElements;
+// elements[1] = sourceElements;
+// visualNodeMap.put(this, elements);
+//
+// return creatorInfo;
+// }
+
public static String getSeparatorImageUrlString (String itemSeparator) {
String separatorImageUrl = null;
if (ITEM_SEPARATOR_DISC.equals(itemSeparator)) {
@@ -215,323 +360,139 @@
}
return separatorImageUrl;
}
- private VisualToolBarElements getVisualToolBarElements(Map visualNodeMap) {
- if (visualNodeMap != null) {
- Object o = visualNodeMap.get(this);
- try {
- if (o != null && o instanceof Object[] && ((Object[])o)[0] instanceof
VisualToolBarElements) {
- return (VisualToolBarElements)((Object[])o)[0];
- }
- } catch (Exception e) {
- }
- }
- return null;
- }
- private void setRowDisplayStyle(Element row, boolean visible) {
- if (row != null) {
- row.setAttribute("style", "display:" + (visible ? "" :
"none"));
- }
+ static boolean isValidItemSeparatorName(String itemSeparator) {
+ return itemSeparator == null
+ || (itemSeparator != null && itemSeparator.length() == 0)
+ || ITEM_SEPARATOR_DISC.equals(itemSeparator)
+ || ITEM_SEPARATOR_LINE.equals(itemSeparator)
+ || ITEM_SEPARATOR_GRID.equals(itemSeparator)
+ || ITEM_SEPARATOR_SQUARE.equals(itemSeparator)
+ || ITEM_SEPARATOR_NONE.equals(itemSeparator);
}
-
- private SourceToolBarElements getSourceToolBarElements(Map visualNodeMap) {
- if (visualNodeMap != null) {
- Object o = visualNodeMap.get(this);
- try {
- if (o != null && o instanceof Object[] && ((Object[])o)[1] instanceof
VisualToolBarElements) {
- return (SourceToolBarElements)o;
+
+ private class SourceToolBarItem {
+ private Node toolBarItem;
+ private String itemSeparator;
+ private boolean isToolBarItemLocationRight;
+ private boolean isToolBarGroupItem;
+
+ public SourceToolBarItem(Node toolBarItem) {
+ this.toolBarItem = toolBarItem;
+ this.itemSeparator = null;
+ this.isToolBarItemLocationRight = false;
+
+ if (toolBarItem.getNodeType() == Node.ELEMENT_NODE) {
+ Element element = (Element) toolBarItem;
+ this.isToolBarGroupItem = element.getNodeName().endsWith(":" +
RichFacesToolBarGroupTemplate.TAG_NAME);
+ if (isToolBarGroupItem()) {
+ isToolBarItemLocationRight = RichFacesToolBarGroupTemplate
+ .ATTR_LOCATION_RIGHT_VALUE
+ .equals(element.getAttribute(RichFacesToolBarGroupTemplate.ATTR_LOCATION_NAME));
}
- } catch (Exception e) {
}
}
- return null;
- }
-
- public static final String TOOLBARGROUP_LOCATE_ATTRIBUTE = "location";
- public static final String TOOLBARGROUP_LOCATE_AT_RIGHT_ATTRIBUTE_VALUE =
"right";
- public static final String TOOLBARGROUP_LOCATE_AT_LEFT_ATTRIBUTE_VALUE =
"left";
-
- public static class SourceToolBarElements {
- private List columnsAtLeft;
- private List columnsAtRight;
- Map attributes;
-
- public SourceToolBarElements(Node sourceNode) {
- init(sourceNode);
- initAttributes(sourceNode);
+
+ public SourceToolBarItem(String itemSeparator) {
+ this.toolBarItem = null;
+ this.itemSeparator = itemSeparator;
}
- void initAttributes(Node sourceNode) {
- NamedNodeMap attrs = sourceNode.getAttributes();
- attributes = new HashMap<String, String>();
- for (int i = 0; attrs != null && i < attrs.getLength(); i++) {
- Node attribute = attrs.item(i);
- attributes.put(attribute.getNodeName(), attribute.getNodeValue());
- }
+ public Node getToolBarItem() {
+ return toolBarItem;
}
-
- void init (Node sourceNode) {
-
- String separator = ((Element)sourceNode).getAttribute("itemSeparator");
- NodeList children = sourceNode.getChildNodes();
+ public String getItemSeparator() {
+ return itemSeparator;
+ }
- int cnt = children != null ? children.getLength() : 0;
- if (cnt > 0) {
- for (int i = 0; i < cnt; i++) {
- Node child = children.item(i);
- if (child.getNodeType() == Node.ELEMENT_NODE) {
- Element childElement = (Element)child;
-
- if (childElement.getNodeName().endsWith(":toolBarGroup")) {
- boolean locateAtRight =
TOOLBARGROUP_LOCATE_AT_RIGHT_ATTRIBUTE_VALUE.equals(childElement.getAttribute(TOOLBARGROUP_LOCATE_ATTRIBUTE));
- String itemSeparator = childElement.getAttribute(ITEMSEPARATOR_ATTR_NAME);
- if (itemSeparator == null || itemSeparator.trim().length() == 0) {
- itemSeparator = ITEM_SEPARATOR_NONE;
- }
- if (locateAtRight) {
- if (columnsAtRight == null) columnsAtRight = new ArrayList();
- if (i != 0 && !(ITEM_SEPARATOR_NONE.equals(separator)))
columnsAtRight.add(new SourceToolBarColumnElements(separator));
- }
- initToolBarGroup(childElement, locateAtRight);
- if (!locateAtRight) {
- if (columnsAtLeft == null) columnsAtLeft = new ArrayList();
- if (!isLastChild(children, i) &&
!(ITEM_SEPARATOR_NONE.equals(separator))) columnsAtLeft.add(new
SourceToolBarColumnElements(separator));
- }
+ public boolean isItem() {
+ return toolBarItem != null;
+ }
+
+ public boolean isToolBarItemLocationRight() {
+ return isToolBarItemLocationRight;
+ }
- } else {
- if (columnsAtLeft == null) columnsAtLeft = new ArrayList();
- columnsAtLeft.add(new SourceToolBarColumnElements(child));
- if (!isLastChild(children, i) && !(ITEM_SEPARATOR_NONE.equals(separator)))
columnsAtLeft.add(new SourceToolBarColumnElements(separator));
- }
- } else if (child.getNodeType() == Node.TEXT_NODE) {
- String text = child.getNodeValue();
- text = (text == null ? null : text.trim());
- if (text != null && text.length() > 0) {
- if (columnsAtLeft == null) columnsAtLeft = new ArrayList();
- columnsAtLeft.add(new SourceToolBarColumnElements(child));
- if (!isLastChild(children, i) && !(ITEM_SEPARATOR_NONE.equals(separator)))
columnsAtLeft.add(new SourceToolBarColumnElements(separator));
- }
- }
- }
- }
+ public boolean isToolBarGroupItem() {
+ return isToolBarGroupItem;
}
+ }
+
+ private class SourceToolBarItems {
+ private List<SourceToolBarItem> leftToolBarItems;
+ private List<SourceToolBarItem> rightToolBarItems;
+ private String itemSeparator;
+ private boolean itemSeparatorExists;
- private boolean isLastChild(NodeList children, int index) {
- int cnt = children != null ? children.getLength() : 0;
- if (cnt > index + 1) {
- for (int i = index + 1; i < cnt; i++) {
- if (children.item(i).getNodeType() == Node.ELEMENT_NODE) return false;
- else if (children.item(i).getNodeType() == Node.TEXT_NODE) {
- String text = children.item(i).getNodeValue();
- text = (text == null ? null : text.trim());
- if (text != null && text.length() > 0) {
- return false;
- }
- }
- }
- }
- return true;
+ public SourceToolBarItems(Node sourceNode, String itemSeparator) {
+ this.leftToolBarItems = new LinkedList<SourceToolBarItem>();
+ this.rightToolBarItems = new LinkedList<SourceToolBarItem>();
+ this.itemSeparator = itemSeparator;
+ this.itemSeparatorExists = itemSeparator != null &&
!ITEMSEPARATOR_ATTR_NAME.equals(itemSeparator);
+
+ init(sourceNode);
}
- void initToolBarGroup(Element sourceElement, boolean locateAtRight) {
- if (sourceElement == null) return;
- String itemSeparator = sourceElement.getAttribute(ITEMSEPARATOR_ATTR_NAME);
- if (itemSeparator == null || itemSeparator.trim().length() == 0) {
- itemSeparator = ITEM_SEPARATOR_NONE;
- }
- NodeList children = sourceElement.getChildNodes();
-
- int cnt = children != null ? children.getLength() : 0;
- if (cnt > 0) {
- for (int i = 0; i < cnt; i++) {
- Node child = children.item(i);
- if (child.getNodeType() == Node.ELEMENT_NODE) {
- Element childElement = (Element)child;
-
- if (childElement.getNodeName().endsWith(":toolBarGroup")) {
- if (locateAtRight) {
- if (columnsAtRight == null) columnsAtRight = new ArrayList();
- if (i != 0 && !(ITEM_SEPARATOR_NONE.equals(itemSeparator)))
columnsAtRight.add(new SourceToolBarColumnElements(itemSeparator));
- }
- initToolBarGroup(childElement, locateAtRight);
- if (!locateAtRight) {
- if (columnsAtLeft == null) columnsAtLeft = new ArrayList();
- if (!isLastChild(children, i) &&
!(ITEM_SEPARATOR_NONE.equals(itemSeparator))) columnsAtLeft.add(new
SourceToolBarColumnElements(itemSeparator));
- }
- } else {
- if (locateAtRight) {
- if (columnsAtRight == null) columnsAtRight = new ArrayList();
- if (i != 0 && !(ITEM_SEPARATOR_NONE.equals(itemSeparator)))
columnsAtLeft.add(new SourceToolBarColumnElements(itemSeparator));
- columnsAtRight.add(new SourceToolBarColumnElements(child));
- } else {
- if (columnsAtLeft == null) columnsAtLeft = new ArrayList();
- columnsAtLeft.add(new SourceToolBarColumnElements(child));
- if (!isLastChild(children, i) &&
!(ITEM_SEPARATOR_NONE.equals(itemSeparator))) columnsAtLeft.add(new
SourceToolBarColumnElements(itemSeparator));
- }
+ private void init(Node sourceNode) {
+ NodeList childrenList = sourceNode.getChildNodes();
+ int childrenCount = childrenList.getLength();
+ for (int i=0; i < childrenCount; i++) {
+ Node child = childrenList.item(i);
+ if (isVisibleNode(child)) {
+ SourceToolBarItem toolBarItem = new SourceToolBarItem(child);
+ if (toolBarItem.isToolBarItemLocationRight()) {
+ if (isItemSeparatorExists()) {
+ rightToolBarItems.add(new SourceToolBarItem(itemSeparator));
}
- } else if (child.getNodeType() == Node.TEXT_NODE) {
- String text = child.getNodeValue();
- text = (text == null ? null : text.trim());
- if (text != null && text.length() > 0) {
- if (locateAtRight) {
- if (columnsAtRight == null) columnsAtRight = new ArrayList();
- if (i != 0 && !(ITEM_SEPARATOR_NONE.equals(itemSeparator)))
columnsAtLeft.add(new SourceToolBarColumnElements(itemSeparator));
- columnsAtRight.add(new SourceToolBarColumnElements(child));
- } else {
- if (columnsAtLeft == null) columnsAtLeft = new ArrayList();
- columnsAtLeft.add(new SourceToolBarColumnElements(child));
- if (!isLastChild(children, i) &&
!(ITEM_SEPARATOR_NONE.equals(itemSeparator))) columnsAtLeft.add(new
SourceToolBarColumnElements(itemSeparator));
- }
+ rightToolBarItems.add(toolBarItem);
+ } else {
+ leftToolBarItems.add(toolBarItem);
+ if (isItemSeparatorExists()) {
+ leftToolBarItems.add(new SourceToolBarItem(itemSeparator));
}
}
}
}
- }
-
- public SourceToolBarColumnElements getColumnAtLeft(int index) {
- if (columnsAtLeft != null && index < getColumnAtLeftCount()) return
(SourceToolBarColumnElements)columnsAtLeft.get(index);
- return null;
- }
-
- public SourceToolBarColumnElements getColumnAtRight(int index) {
- if (columnsAtRight != null && index < getColumnAtRightCount()) return
(SourceToolBarColumnElements)columnsAtRight.get(index);
- return null;
- }
-
- public int getColumnAtLeftCount() {
- if (columnsAtLeft != null) return columnsAtLeft.size();
- return 0;
- }
-
- public int getColumnAtRightCount() {
- if (columnsAtRight != null) return columnsAtRight.size();
- return 0;
- }
-
- public boolean hasColspan() {
- return (getColumnAtLeftCount() + getColumnAtRightCount()) >= 2;
- }
-
- public boolean hasBodySection() {
- for (int i = 0; i < getColumnAtLeftCount(); i++) {
- SourceToolBarColumnElements column = getColumnAtLeft(i);
- if (column.hasBody()) return true;
+
+ if (!isLeftItemsExists()) {
+ rightToolBarItems.remove(0);
}
- for (int i = 0; i < getColumnAtRightCount(); i++) {
- SourceToolBarColumnElements column = getColumnAtRight(i);
- if (column.hasBody()) return true;
+
+ if (!isRightItemsExists()) {
+ leftToolBarItems.remove(leftToolBarItems.size()-1);
}
- return false;
}
-
- Map getAttributes() {
- return attributes;
- }
- String getAttributeValue(String name) {
- return (String)attributes.get(name);
+ public boolean isLeftItemsExists() {
+ return !leftToolBarItems.isEmpty();
}
- }
-
-
-
- public static class SourceToolBarColumnElements {
- private Node column;
- private String separatorType;
-
- public SourceToolBarColumnElements(Node columnNode) {
- init(columnNode);
- separatorType = null;
+ public boolean isRightItemsExists() {
+ return !rightToolBarItems.isEmpty();
}
-
- public SourceToolBarColumnElements(String separatorType) {
- column = null;
- this.separatorType = separatorType;
- }
-
- private void init(Node columnNode) {
- column = columnNode;
- }
-
- public boolean hasBody() {
- return column != null;
- }
-
- public void setColumn(Node column) {
- this.column = column;
- }
-
- public Node getColumn() {
- return column;
- }
- public boolean isSeparator() {
- return (column == null);
+ public Iterator<SourceToolBarItem> getLeftItemsIterator() {
+ return leftToolBarItems.iterator();
}
-
- public String getSeparatorType() {
- return separatorType;
- }
- }
- public static class VisualToolBarElements {
- private Element body;
- private Element bodyRow;
- private List columns;
-
- public VisualToolBarElements() {
+ public Iterator<SourceToolBarItem> getRightItemsIterator() {
+ return rightToolBarItems.iterator();
}
- public VisualToolBarElements(Element body) {
- this.body = body;
- }
- private VisualToolBarColumnElements getColumn(int index) {
- if (columns != null && index < getColumnCount()) return
(VisualToolBarColumnElements)columns.get(index);
- return null;
+ private boolean isVisibleNode(Node node) {
+ return node.getNodeType() == Node.ELEMENT_NODE
+ || (node.getNodeType() == Node.TEXT_NODE
+ && node.getNodeValue() != null
+ && node.getNodeValue().trim().length() > 0);
}
- private int getColumnCount() {
- if (columns != null) return columns.size();
- return 0;
+ public boolean isItemSeparatorExists() {
+ return itemSeparatorExists;
}
- private List getColumns() {
- if (columns == null) columns = new ArrayList();
- return columns;
+ public String getItemSeparator() {
+ return itemSeparator;
}
-
- public Element getBody() {
- return body;
- }
-
- public void setBody(Element body) {
- this.body = body;
- }
-
- public Element getBodyRow() {
- return bodyRow;
- }
-
- public void setBodyRow(Element bodyRow) {
- this.bodyRow = bodyRow;
- }
}
-
- public static class VisualToolBarColumnElements {
- private Element bodyCell;
-
- private boolean isEmpty() {
- return bodyCell == null;
- }
-
- public Element getBodyCell() {
- return bodyCell;
- }
-
- public void setBodyCell(Element bodyCell) {
- this.bodyCell = bodyCell;
- }
- }
}
\ No newline at end of file