From ac1118a249c34bba814de9b441350a33bc09e13f Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Tue, 11 Sep 2007 11:49:24 +0000 Subject: [PATCH] System errors, UIDL.XML fix, made console static, allow html in debug windows messages, clickin error icon prints error to console svn changeset:2276/svn branch:trunk --- .../gwt/client/ApplicationConnection.java | 8 +++-- .../toolkit/terminal/gwt/client/Caption.java | 12 ++++--- .../terminal/gwt/client/DebugConsole.java | 7 +++-- .../terminal/gwt/client/ErrorMessage.java | 3 ++ .../toolkit/terminal/gwt/client/UIDL.java | 13 +++++++- .../terminal/gwt/client/ui/IScrollTable.java | 31 ++++++++++--------- .../terminal/gwt/client/ui/ITextualDate.java | 2 +- .../toolkit/terminal/gwt/client/ui/ITree.java | 1 - 8 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java index 4c1b7d4e87..68d0c7faa8 100755 --- a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java @@ -38,7 +38,7 @@ public class ApplicationConnection implements EntryPoint, FocusListener { private RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, appUri + "/UIDL/?repaintAll=1&"); - public Console console; + private static Console console; private Vector pendingVariables = new Vector(); @@ -71,8 +71,12 @@ public class ApplicationConnection implements EntryPoint, FocusListener { RootPanel.get("itmtk-ajax-window").add(view); } + + public static Console getConsole() { + return console; + } - private native boolean isDebugMode() /*-{ + private native static boolean isDebugMode() /*-{ var uri = $wnd.location; var re = /debug[^\/]*$/; return re.test(uri); diff --git a/src/com/itmill/toolkit/terminal/gwt/client/Caption.java b/src/com/itmill/toolkit/terminal/gwt/client/Caption.java index d6268e445e..2a036ce9a5 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/Caption.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/Caption.java @@ -5,7 +5,6 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.PopupPanel; -import com.google.gwt.user.client.ui.SimplePanel; public class Caption extends HTML { @@ -36,7 +35,7 @@ public class Caption extends HTML { if(errorIndicatorElement == null) { errorIndicatorElement = DOM.createDiv(); - DOM.setAttribute(errorIndicatorElement, "className", "i-errorindicator"); + DOM.setElementProperty(errorIndicatorElement, "className", "i-errorindicator"); DOM.insertChild(getElement(), errorIndicatorElement, 0); } @@ -58,7 +57,7 @@ public class Caption extends HTML { if(uidl.hasAttribute("description")) { if(captionText != null) { - DOM.setAttribute(captionText, "title", uidl.getStringAttribute("description")); + DOM.setElementProperty(captionText, "title", uidl.getStringAttribute("description")); } else { setTitle(uidl.getStringAttribute("description")); } @@ -76,6 +75,9 @@ public class Caption extends HTML { case Event.ONMOUSEOUT: hideErrorMessage(); break; + case Event.ONCLICK: + ApplicationConnection.getConsole(). + log(DOM.getInnerHTML(errorMessage.getElement())); default: break; } @@ -96,9 +98,9 @@ public class Caption extends HTML { } errorContainer.setPopupPosition( DOM.getAbsoluteLeft(errorIndicatorElement) + - 2*DOM.getIntAttribute(errorIndicatorElement, "offsetHeight"), + 2*DOM.getElementPropertyInt(errorIndicatorElement, "offsetHeight"), DOM.getAbsoluteTop(errorIndicatorElement) + - 2*DOM.getIntAttribute(errorIndicatorElement, "offsetHeight")); + 2*DOM.getElementPropertyInt(errorIndicatorElement, "offsetHeight")); errorContainer.show(); } } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/DebugConsole.java b/src/com/itmill/toolkit/terminal/gwt/client/DebugConsole.java index 2652456f62..1908610cb2 100755 --- a/src/com/itmill/toolkit/terminal/gwt/client/DebugConsole.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/DebugConsole.java @@ -2,6 +2,7 @@ package com.itmill.toolkit.terminal.gwt.client; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Label; import com.itmill.toolkit.terminal.gwt.client.ui.IWindow; @@ -21,14 +22,14 @@ public final class DebugConsole extends IWindow implements Console { private void minimize() { // TODO stack to bottom (create window manager of some sort) setPixelSize(60, 60); - setPopupPosition(Window.getClientWidth() - 66, Window.getClientHeight() - 66); + setPopupPosition(Window.getClientWidth() - 80, Window.getClientHeight() - 80); } /* (non-Javadoc) * @see com.itmill.toolkit.terminal.gwt.client.Console#log(java.lang.String) */ public void log(String msg) { - panel.add(new Label(msg)); + panel.add(new HTML(msg)); System.out.println(msg); } @@ -36,7 +37,7 @@ public final class DebugConsole extends IWindow implements Console { * @see com.itmill.toolkit.terminal.gwt.client.Console#error(java.lang.String) */ public void error(String msg) { - panel.add((new Label(msg))); + panel.add((new HTML(msg))); System.out.println(msg); } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ErrorMessage.java b/src/com/itmill/toolkit/terminal/gwt/client/ErrorMessage.java index 697968217a..2426fe858b 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ErrorMessage.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ErrorMessage.java @@ -19,6 +19,9 @@ public class ErrorMessage extends FlowPanel { if (child instanceof String) { String errorMessage = (String) child; add(new HTML(errorMessage)); + } else if (child instanceof UIDL.XML) { + UIDL.XML xml = (UIDL.XML) child; + add(new HTML(xml.getXMLAsString())); } else { ErrorMessage childError = new ErrorMessage(); add(childError); diff --git a/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java b/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java index 18ef9306a9..d57c6048ac 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java @@ -398,7 +398,18 @@ public class UIDL { } public String getXMLAsString() { - return x.get("x").toString(); + StringBuffer sb = new StringBuffer(); + for(Iterator it = x.keySet().iterator(); it.hasNext();) { + String tag = (String) it.next(); + sb.append("<"); + sb.append(tag); + sb.append(">"); + sb.append(x.get(tag).isString().stringValue()); + sb.append(""); + } + return sb.toString(); } } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java index beb882f486..33c15f5f8e 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java @@ -566,7 +566,8 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll tHead.setHorizontalScrollPosition(scrollLeft); firstRowInViewPort = (int) Math.ceil( scrollTop / (double) tBody.getRowHeight() ); - client.console.log("At scrolltop: " + scrollTop + " At row " + firstRowInViewPort); + ApplicationConnection.getConsole() + .log("At scrolltop: " + scrollTop + " At row " + firstRowInViewPort); int postLimit = (int) (firstRowInViewPort + pageLength + pageLength*CACHE_REACT_RATE); if(postLimit > totalRows -1 ) @@ -585,7 +586,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll if(firstRowInViewPort - pageLength*CACHE_RATE > lastRendered || firstRowInViewPort + pageLength + pageLength*CACHE_RATE < firstRendered ) { // need a totally new set - client.console.log("Table: need a totally new set"); + ApplicationConnection.getConsole().log("Table: need a totally new set"); rowRequestHandler.setReqFirstRow((int) (firstRowInViewPort - pageLength*CACHE_RATE)); rowRequestHandler.setReqRows((int) (2*CACHE_RATE*pageLength + pageLength)); rowRequestHandler.deferRowFetch(); @@ -593,7 +594,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll } if(preLimit < firstRendered ) { // need some rows to the beginning of the rendered area - client.console.log("Table: need some rows to the beginning of the rendered area"); + ApplicationConnection.getConsole().log("Table: need some rows to the beginning of the rendered area"); rowRequestHandler.setReqFirstRow((int) (firstRowInViewPort - pageLength*CACHE_RATE)); rowRequestHandler.setReqRows(firstRendered - rowRequestHandler.getReqFirstRow()); rowRequestHandler.deferRowFetch(); @@ -602,7 +603,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll } if(postLimit > lastRendered) { // need some rows to the end of the rendered area - client.console.log("need some rows to the end of the rendered area"); + ApplicationConnection.getConsole().log("need some rows to the end of the rendered area"); rowRequestHandler.setReqFirstRow(lastRendered + 1); rowRequestHandler.setReqRows((int) ((firstRowInViewPort + pageLength + pageLength*CACHE_RATE) - lastRendered)); rowRequestHandler.deferRowFetch(); @@ -611,7 +612,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll } private void announceScrollPosition() { - client.console.log(""+firstRowInViewPort); + ApplicationConnection.getConsole().log(""+firstRowInViewPort); if(scrollPositionElement == null) { scrollPositionElement = DOM.createDiv(); DOM.setElementProperty(scrollPositionElement, "className", "i-table-scrollposition"); @@ -675,7 +676,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll } public void run() { - client.console.log("Getting " + reqRows + " rows from " + reqFirstRow); + ApplicationConnection.getConsole().log("Getting " + reqRows + " rows from " + reqFirstRow); client.updateVariable(paintableId, "firstvisible", firstRowInViewPort, false); client.updateVariable(paintableId, "reqfirstrow", reqFirstRow, false); client.updateVariable(paintableId, "reqrows", reqRows, true); @@ -833,23 +834,23 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll protected void handleCaptionEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONMOUSEDOWN: - client.console.log("HeaderCaption: mouse down"); + ApplicationConnection.getConsole().log("HeaderCaption: mouse down"); if(columnReordering) { dragging = true; moved = false; colIndex = getColIndexByKey(cid); DOM.setCapture(getElement()); this.headerX = tHead.getAbsoluteLeft(); - client.console.log("HeaderCaption: Caption set to capture mouse events"); + ApplicationConnection.getConsole().log("HeaderCaption: Caption set to capture mouse events"); DOM.eventPreventDefault(event); // prevent selecting text } break; case Event.ONMOUSEUP: - client.console.log("HeaderCaption: mouseUP"); + ApplicationConnection.getConsole().log("HeaderCaption: mouseUP"); if(columnReordering) { dragging = false; DOM.releaseCapture(getElement()); - client.console.log("HeaderCaption: Stopped column reordering"); + ApplicationConnection.getConsole().log("HeaderCaption: Stopped column reordering"); if(moved) { hideFloatingCopy(); tHead.removeSlotFocus(); @@ -884,7 +885,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll break; case Event.ONMOUSEMOVE: if (dragging) { - client.console.log("HeaderCaption: Dragging column, optimal index..."); + ApplicationConnection.getConsole().log("HeaderCaption: Dragging column, optimal index..."); if(!moved) { createFloatingCopy(); moved = true; @@ -912,7 +913,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll tHead.focusSlot(closestSlot); updateFloatingCopysPosition(x, -1); - client.console.log(""+closestSlot); + ApplicationConnection.getConsole().log(""+closestSlot); } break; default: @@ -1447,7 +1448,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll fixSpacers(); } else { // sorted or column reordering changed - client.console.log("Bad update" + firstIndex + "/"+ rows); + ApplicationConnection.getConsole().log("Bad update" + firstIndex + "/"+ rows); } } @@ -1700,7 +1701,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll switch (DOM.eventGetType(event)) { case Event.ONCLICK: if((CLASSNAME+"-cell-content").equals(s)) { - client.console.log("Row click"); + ApplicationConnection.getConsole().log("Row click"); if(selectMode > ITable.SELECT_MODE_NONE) { toggleSelection(); client.updateVariable(paintableId, "selected", selectedRowKeys.toArray(), immediate); @@ -1715,7 +1716,7 @@ public class IScrollTable extends Composite implements Paintable, ITable, Scroll } public void showContextMenu(Event event) { - client.console.log("Context menu"); + ApplicationConnection.getConsole().log("Context menu"); if(actionKeys != null) { int left = DOM.eventGetClientX(event); int top = DOM.eventGetClientY(event); diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java index 09b6dd5351..bd6c605603 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java @@ -111,7 +111,7 @@ public class ITextualDate extends IDateField implements Paintable, ChangeListene try { date = format.parse(text.getText()); } catch (Exception e) { - client.console.log(e.getMessage()); + ApplicationConnection.getConsole().log(e.getMessage()); text.addStyleName(ITextField.CLASSNAME+"-error"); Timer t = new Timer() { public void run() { diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java index aca8345453..2e682b05cf 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java @@ -245,7 +245,6 @@ public class ITree extends Tree implements Paintable { } public void showContextMenu(Event event) { - client.console.log("Context menu"); if(actionKeys != null) { int left = DOM.eventGetClientX(event); int top = DOM.eventGetClientY(event); -- 2.39.5