]> source.dussan.org Git - vaadin-framework.git/commitdiff
Theme resource support + icons for Button
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 16 Nov 2007 11:00:16 +0000 (11:00 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 16 Nov 2007 11:00:16 +0000 (11:00 +0000)
svn changeset:2843/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IButton.java
src/com/itmill/toolkit/terminal/gwt/client/ui/Icon.java [new file with mode: 0644]
src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java

index d5bc4dd7fddf2d2c695cda63faab1b8887da1ba4..7f5dc47d253e2d672a8b4d3d94b125b9c00da1eb 100755 (executable)
@@ -91,6 +91,11 @@ public class ApplicationConnection {
      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();
@@ -489,4 +494,20 @@ public class ApplicationConnection {
         }
         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;
+    }
 }
index e8198bbd68d36703601f411868075d262c1db78e..ce230247e6735f71a39652cf649db29f4d3f0c23 100644 (file)
@@ -21,10 +21,17 @@ public class IButton extends Button implements Paintable {
 
     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) {
@@ -55,6 +62,7 @@ public class IButton extends Button implements Paintable {
         // Set text
         setText(uidl.getStringAttribute("caption"));
 
+        // handle error
         if (uidl.hasAttribute("error")) {
             UIDL errorUidl = uidl.getErrors();
             if (errorIndicatorElement == null) {
@@ -62,6 +70,7 @@ public class IButton extends Button implements Paintable {
                 DOM.setElementProperty(errorIndicatorElement, "className",
                         "i-errorindicator");
                 DOM.sinkEvents(errorIndicatorElement, Event.MOUSEEVENTS);
+                sinkEvents(Event.MOUSEEVENTS);
             }
             DOM.insertChild(getElement(), errorIndicatorElement, 0);
             if (errorMessage == null) {
@@ -73,12 +82,25 @@ public class IButton extends Button implements Paintable {
             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
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/Icon.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/Icon.java
new file mode 100644 (file)
index 0000000..c960057
--- /dev/null
@@ -0,0 +1,30 @@
+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;
+        }
+    }
+}
index 9bf6dbf470b1c603787c2f3decdca317d15507ae..dbe34baf57a4d3644a8bbd03ae9af98c722f4d7c 100644 (file)
@@ -520,14 +520,16 @@ public class ApplicationServlet extends HttpServlet {
 
         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"