From: Matti Tahvonen Date: Tue, 18 Sep 2007 08:26:56 +0000 (+0000) Subject: errors and description for button X-Git-Tag: 6.7.0.beta1~6011 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=27171f13ce37eda43c7266457c4669b46758e7cb;p=vaadin-framework.git errors and description for button svn changeset:2307/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IButton.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IButton.java index a6b747b5c2..2e091f11fa 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IButton.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IButton.java @@ -1,9 +1,14 @@ package com.itmill.toolkit.terminal.gwt.client.ui; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Element; +import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.ClickListener; +import com.google.gwt.user.client.ui.PopupPanel; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Button; import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; +import com.itmill.toolkit.terminal.gwt.client.ErrorMessage; import com.itmill.toolkit.terminal.gwt.client.Paintable; import com.itmill.toolkit.terminal.gwt.client.UIDL; @@ -15,6 +20,13 @@ public class IButton extends Button implements Paintable { ApplicationConnection client; + private Element errorIndicatorElement; + + private ErrorMessage errorMessage; + + private PopupPanel errorContainer; + + public IButton() { setStyleName(CLASSNAME); addClickListener(new ClickListener() { @@ -40,8 +52,70 @@ public class IButton extends Button implements Paintable { // Set text setText(uidl.getStringAttribute("caption")); + + if(uidl.hasAttribute("error")) { + UIDL errorUidl = uidl.getErrors(); + if(errorIndicatorElement == null) { + errorIndicatorElement = DOM.createDiv(); + DOM.setElementProperty(errorIndicatorElement, "className", "i-errorindicator"); + DOM.sinkEvents(errorIndicatorElement, Event.MOUSEEVENTS); + } + DOM.insertChild(getElement(), errorIndicatorElement, 0); + if(errorMessage == null) + errorMessage = new ErrorMessage(); + errorMessage.updateFromUIDL(errorUidl); + + } else if( errorIndicatorElement != null) { + DOM.setStyleAttribute(errorIndicatorElement, "display", "none"); + } + + if(uidl.hasAttribute("description")) { + setTitle(uidl.getStringAttribute("description")); + } + + } + + public void onBrowserEvent(Event event) { + Element target= DOM.eventGetTarget(event); + if(errorIndicatorElement != null && DOM.compare(target, errorIndicatorElement)) { + switch (DOM.eventGetType(event)) { + case Event.ONMOUSEOVER: + showErrorMessage(); + break; + case Event.ONMOUSEOUT: + hideErrorMessage(); + break; + case Event.ONCLICK: + ApplicationConnection.getConsole(). + log(DOM.getInnerHTML(errorMessage.getElement())); + return; + default: + break; + } + } + super.onBrowserEvent(event); + } - // TODO Handle description and errormessages + private void hideErrorMessage() { + if(errorContainer != null) { + errorContainer.hide(); + } } + private void showErrorMessage() { + if(errorMessage != null) { + if(errorContainer == null) { + errorContainer = new PopupPanel(); + errorContainer.setWidget(errorMessage); + } + errorContainer.setPopupPosition( + DOM.getAbsoluteLeft(errorIndicatorElement) + + 2*DOM.getElementPropertyInt(errorIndicatorElement, "offsetHeight"), + DOM.getAbsoluteTop(errorIndicatorElement) + + 2*DOM.getElementPropertyInt(errorIndicatorElement, "offsetHeight")); + errorContainer.show(); + } + } + + }