return $wnd.itmill.pathInfo;
}-*/;
+ private native String getThemeUri()
+ /*-{
+ return $wnd.itmill.themeUri;
+ }-*/;
+
private void makeUidlRequest(String requestData) {
console.log("Making UIDL Request with params: " + requestData);
String uri = appUri + "/UIDL" + getPathInfo();
}
return contextMenu;
}
+
+ /**
+ * Translates custom protocols in UIRL URI's to be recognizable by browser.
+ * All uri's from UIDL should be routed via this method before giving them
+ * to browser due URI's in UIDL may contain custom protocols like theme://.
+ *
+ * @param toolkitUri
+ * toolkit URI from uidl
+ * @return translated URI ready for browser
+ */
+ public String translateToolkitUri(String toolkitUri) {
+ if (toolkitUri.startsWith("theme")) {
+ toolkitUri = getThemeUri() + toolkitUri.substring(7);
+ }
+ return toolkitUri;
+ }
}
private Element errorIndicatorElement;
+ private Element captionElement = DOM.createSpan();
+
private ErrorMessage errorMessage;
+ private Icon icon;
+
public IButton() {
setStyleName(CLASSNAME);
+
+ DOM.appendChild(getElement(), captionElement);
+
addClickListener(new ClickListener() {
public void onClick(Widget sender) {
if (id == null || client == null) {
// Set text
setText(uidl.getStringAttribute("caption"));
+ // handle error
if (uidl.hasAttribute("error")) {
UIDL errorUidl = uidl.getErrors();
if (errorIndicatorElement == null) {
DOM.setElementProperty(errorIndicatorElement, "className",
"i-errorindicator");
DOM.sinkEvents(errorIndicatorElement, Event.MOUSEEVENTS);
+ sinkEvents(Event.MOUSEEVENTS);
}
DOM.insertChild(getElement(), errorIndicatorElement, 0);
if (errorMessage == null) {
DOM.setStyleAttribute(errorIndicatorElement, "display", "none");
}
+ if (uidl.hasAttribute("icon")) {
+ if (icon == null) {
+ icon = new Icon(client);
+ DOM.insertChild(getElement(), icon.getElement(), 0);
+ }
+ icon.setUri(uidl.getStringAttribute("icon"));
+ }
+
+ // handle description
if (uidl.hasAttribute("description")) {
setTitle(uidl.getStringAttribute("description"));
}
}
+ public void setText(String text) {
+ DOM.setInnerText(captionElement, text);
+ }
+
public void onBrowserEvent(Event event) {
Element target = DOM.eventGetTarget(event);
if (errorIndicatorElement != null
--- /dev/null
+package com.itmill.toolkit.terminal.gwt.client.ui;
+
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.ui.UIObject;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
+
+public class Icon extends UIObject {
+ private ApplicationConnection client;
+ private String myUri;
+
+ public Icon(ApplicationConnection client) {
+ setElement(DOM.createImg());
+ DOM.setElementProperty(getElement(), "alt", "icon");
+ setStyleName("i-icon");
+ this.client = client;
+ }
+
+ public Icon(ApplicationConnection client, String uidlUri) {
+ this(client);
+ setUri(uidlUri);
+ }
+
+ public void setUri(String uidlUri) {
+ if (!uidlUri.equals(myUri)) {
+ DOM.setElementProperty(getElement(), "src", client
+ .translateToolkitUri(uidlUri));
+ myUri = uidlUri;
+ }
+ }
+}
String contextPath = request.getContextPath();
- page.write("', pathInfo: '" + pathInfo + "'\n};\n" + "</script>\n"
+ String themeUri = contextPath + "/" + THEME_DIRECTORY_PATH + themeName;
+
+ page.write("', pathInfo: '" + pathInfo + "', themeUri: '" + themeUri
+ + "'\n};\n" + "</script>\n"
+ "<script language='javascript' src='" + contextPath + "/"
+ WIDGETSET_DIRECTORY_PATH + widgetset + "/" + widgetset
+ ".nocache.js'></script>\n");
if (!themeName.equals("default")) {
page.write("<link REL=\"stylesheet\" TYPE=\"text/css\" HREF=\""
- + contextPath + "/" + THEME_DIRECTORY_PATH + themeName
- + "/styles.css\">\n");
+ + themeUri + "/styles.css\">\n");
}
page
.write("</head>\n<body class=\"i-generated-body\">\n"