001: /*
002: * Copyright (C) 2004 TiongHiang Lee
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * Email: thlee@onemindsoft.org
019: */
020:
021: package org.onemind.swingweb.client.gwt.widget;
022:
023: import com.google.gwt.user.client.DOM;
024: import com.google.gwt.user.client.Element;
025: import com.google.gwt.user.client.ui.TreeItem;
026: import com.google.gwt.user.client.ui.Widget;
027:
028: public class TreeNode implements ITreeNode {
029:
030: TreeNodeInfo _info = new TreeNodeInfo();
031:
032: private TreeItem _item;
033:
034: private String _id;
035:
036: private class TreeNodeItem extends TreeItem {
037:
038: private Element content;
039: private Element tdContent;
040:
041: public TreeNodeItem(Widget widget) {
042: super (widget);
043: Element el = getContentElement();
044: if (el != null) {
045: DOM.setStyleAttribute(el, "display", ""); //remove inline display from superclass
046: DOM.setAttribute(tdContent, "className", "treenode");
047: }
048: }
049:
050: public void setSelected(boolean selected) {
051: super .setSelected(selected);
052: if (selected) {
053: DOM.setAttribute(tdContent, "className",
054: "treenode-selected");
055: } else {
056: DOM.setAttribute(tdContent, "className", "treenode");
057: }
058: }
059:
060: public Element getContentElement() {
061: if (content == null) {
062: Element table = DOM.getChild(getElement(), 0);
063: Element tbody = DOM.getChild(table, 0);
064: Element tr = DOM.getChild(tbody, 0);
065: tdContent = DOM.getChild(tr, 1);
066: content = DOM.getChild(tdContent, 0);
067: }
068: return content;
069: }
070: }
071:
072: public TreeNode(String id, Widget widget) {
073: _id = id;
074: _item = new TreeNodeItem(widget);
075: DOM.setStyleAttribute(widget.getElement(), "backgroundColor",
076: "");
077: DOM.setAttribute(_item.getElement(), "swid", _id);
078: }
079:
080: /**
081: * {@inheritDoc}
082: */
083: public String getId() {
084: return _id;
085: }
086:
087: /**
088: * {@inheritDoc}
089: */
090: public TreeItem getItem() {
091: return _item;
092: }
093:
094: /**
095: * {@inheritDoc}
096: */
097: public void addNode(ITreeNode treeNode) {
098: _info.addTreeNode(treeNode);
099: _item.addItem(treeNode.getItem());
100: }
101:
102: /**
103: * {@inheritDoc}
104: */
105: public ITreeNode getNode(String id) {
106: return _info.getTreeNodeWithId(id);
107: }
108:
109: /**
110: * {@inheritDoc}
111: */
112: public void removeTreeNode(ITreeNode node) {
113: _info.removeTreeNode(node);
114: _item.removeItem(node.getItem());
115: }
116: }
|