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.ui;
022:
023: import java.util.List;
024: import org.onemind.swingweb.client.core.AbstractClient;
025: import org.onemind.swingweb.client.dom.DomNode;
026: import org.onemind.swingweb.client.gwt.GwtClient;
027: import org.onemind.swingweb.client.gwt.widget.*;
028: import com.google.gwt.user.client.DOM;
029: import com.google.gwt.user.client.ui.*;
030:
031: public class TableUIHandler extends ContainerUIHandler implements
032: TableDataListener, DoubleClickListener {
033:
034: public TableUIHandler(AbstractClient client) {
035: super (client);
036: }
037:
038: /**
039: * {@inheritDoc}
040: */
041: protected void registerListeners(Object com) {
042: ((Table) com).addTableDataListener(this );
043: }
044:
045: /**
046: * {@inheritDoc}
047: */
048: protected Object createComponentInstance(Object parent,
049: DomNode element) {
050: Table t = new Table();
051: t.addDoubleClickListener(this );
052: return t;
053: }
054:
055: /**
056: * {@inheritDoc}
057: */
058: protected void handleChildren(AbstractClient rootHandler,
059: IContainer c, DomNode element) {
060: Table t = (Table) c;
061: String id = element.getAttribute("id");
062: long now = System.currentTimeMillis();
063: int rows = getInt(element, "rows");
064: int cols = getInt(element, "cols");
065: t.resize(rows, cols);
066: List headerList = getChildrenByTag(element, "header");
067: if (headerList.size() > 0) {
068: DomNode headersNode = (DomNode) headerList.get(0);
069: List headers = getChildrenByTag(headersNode, "col");
070: for (int i = 0; i < headers.size(); i++) {
071: DomNode colNode = (DomNode) headers.get(i);
072: DomNode valueNode = getFirstChildElement(colNode);
073: Widget value = (Widget) getClient().handle(this ,
074: valueNode);
075: DOM.setStyleAttribute(value.getElement(), "width",
076: "100%");
077: DOM.setStyleAttribute(value.getElement(), "height",
078: "100%");
079: t.setHeaderWidget(i, value);
080: getClient().setEventInterceptor(value, t);
081: }
082: }
083: List rowList = getChildrenByTag(element, "row");
084: for (int row = 0; row < rowList.size(); row++) {
085: DomNode rowNode = (DomNode) rowList.get(row);
086: List colList = getChildrenByTag(rowNode, "col");
087: for (int col = 0; col < colList.size(); col++) {
088: DomNode colNode = (DomNode) colList.get(col);
089: DomNode valueNode = getFirstChildElement(colNode);
090: String pregenId = id + "_" + row + "_" + col;
091: Widget value = (Widget) getClient().handle(this ,
092: valueNode, pregenId);
093: DOM.setStyleAttribute(value.getElement(),
094: "borderWidth", "0px");
095: DOM.setStyleAttribute(value.getElement(), "width",
096: "100%");
097: DOM.setStyleAttribute(value.getElement(), "height",
098: "100%");
099: t.setCellWidget(row, col, value);
100: getClient().setEventInterceptor(value, t);
101: }
102: }
103: ((GwtClient) getClient()).log(AbstractClient.LOG_VERBOSE,
104: "Time used: " + (System.currentTimeMillis() - now)
105: + "ms");
106: }
107:
108: public void onDataChanged(Object sender, Object data) {
109: handleEvent(sender, data);
110: }
111:
112: public void postEvent(Object source, Object data) {
113: postEvent(source, data, false);
114: }
115:
116: public void onDoubleClick(Widget sender) {
117: System.out.println("Double clicked on " + sender);
118: }
119: }
|