private ErrorMessage errorMessage;
- private PopupPanel errorContainer;
-
/* Caption must be attached to a Paintable */
private Caption() {
};
}
private void hideErrorMessage() {
- if (errorContainer != null) {
- errorContainer.hide();
+ if (errorMessage != null) {
+ errorMessage.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();
+ errorMessage.showAt(errorIndicatorElement);
}
}
import java.util.Iterator;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.PopupPanel;
public class ErrorMessage extends FlowPanel {
public static final String CLASSNAME = "i-error";
}
}
}
+
+ /**
+ * Shows this error message next to given element.
+ *
+ * @param indicatorElement
+ */
+ public void showAt(Element indicatorElement) {
+ PopupPanel errorContainer = (PopupPanel) this.getParent();
+ if (errorContainer == null) {
+ errorContainer = new PopupPanel();
+ errorContainer.setWidget(this);
+ }
+ errorContainer.setPopupPosition(DOM
+ .getAbsoluteLeft(indicatorElement)
+ + 2
+ * DOM.getElementPropertyInt(indicatorElement,
+ "offsetHeight"), DOM
+ .getAbsoluteTop(indicatorElement)
+ + 2
+ * DOM.getElementPropertyInt(indicatorElement,
+ "offsetHeight"));
+ errorContainer.show();
+
+ }
+
+ public void hide() {
+ PopupPanel errorContainer = (PopupPanel) this.getParent();
+ if(errorContainer != null)
+ errorContainer.hide();
+ }
}
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.Widget;
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;
ApplicationConnection client;
+ private Element errorIndicatorElement;
+
+ private ErrorMessage errorMessage;
+
public ICheckBox() {
setStyleName(CLASSNAME);
addClickListener(new ClickListener() {
}
});
+
}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ // Save details
+ this.client = client;
+ id = uidl.getId();
// Ensure correct implementation
if (client.updateComponent(this, uidl, false))
return;
+
+ if (uidl.hasAttribute("error")) {
+ UIDL errorUidl = uidl.getErrors();
+
+ if (errorIndicatorElement == null) {
+ errorIndicatorElement = DOM.createDiv();
+ DOM.sinkEvents(errorIndicatorElement, Event.MOUSEEVENTS);
+ DOM.setElementProperty(errorIndicatorElement, "className",
+ "i-errorindicator");
+ DOM.appendChild(getElement(), errorIndicatorElement);
+ }
+ 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"));
+ }
- // Save details
- this.client = client;
- id = uidl.getId();
// Set text
setText(uidl.getStringAttribute("caption"));
setChecked(uidl.getBooleanVariable("state"));
immediate = uidl.getBooleanAttribute("immediate");
}
+
+ public void onBrowserEvent(Event event) {
+ super.onBrowserEvent(event);
+ Element target = DOM.eventGetTarget(event);
+ if (errorIndicatorElement != null
+ && DOM.compare(target, errorIndicatorElement)) {
+ switch (DOM.eventGetType(event)) {
+ case Event.ONMOUSEOVER:
+ errorMessage.showAt(errorIndicatorElement);
+ break;
+ case Event.ONMOUSEOUT:
+ errorMessage.hide();
+ break;
+ case Event.ONCLICK:
+ ApplicationConnection.getConsole().log(
+ DOM.getInnerHTML(errorMessage.getElement()));
+ default:
+ break;
+ }
+ }
+ }
}