]> source.dussan.org Git - vaadin-framework.git/commitdiff
support for multiple style names
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 14 Aug 2007 11:18:44 +0000 (11:18 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 14 Aug 2007 11:18:44 +0000 (11:18 +0000)
svn changeset:2004/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java
src/com/itmill/toolkit/terminal/gwt/server/JsonPaintTarget.java
src/com/itmill/toolkit/ui/AbstractComponent.java
src/com/itmill/toolkit/ui/Component.java
src/com/itmill/toolkit/ui/CustomComponent.java
src/com/itmill/toolkit/ui/CustomLayout.java

index 535605532a05ce042739dcc21659db3679c8c0dd..e9db2b64fd5831c4fdd005bf9ea5fee78c3c7490 100755 (executable)
@@ -387,6 +387,10 @@ public class ApplicationConnection implements EntryPoint, FocusListener {
                component.setVisible(visible);
                if (!visible)
                        return true;
+               
+               // add additional styles as css classes
+               if(uidl.hasAttribute("style"))
+                       component.addStyleName(uidl.getStringAttribute("style"));
 
                return false;
        }
index e1a3e6e14819b0ffac3fec35c3a91f7926bb14a5..05d10eb9975d0c304146ec25e6bfb8ad58edf22b 100644 (file)
@@ -32,7 +32,7 @@ public class ICustomLayout extends ComplexPanel implements Paintable, Layout {
        private HashMap widgetToCaptionWrapper = new HashMap();
 
        /** Currently rendered style */
-       String currentStyle;
+       String currentTemplate;
 
        /** Unexecuted scripts loaded from the template */
        private String scripts = "";
@@ -115,16 +115,16 @@ public class ICustomLayout extends ComplexPanel implements Paintable, Layout {
        private void updateHTML(UIDL uidl, ApplicationConnection client) {
 
                // Update only if style has changed
-               String newStyle = uidl.getStringAttribute("style");
-               if (currentStyle != null && currentStyle.equals(newStyle))
+               String newTemplate = uidl.getStringAttribute("template");
+               if (currentTemplate != null && currentTemplate.equals(newTemplate))
                        return;
 
                // Get the HTML-template from client
-               String template = client.getResource("layout/" + newStyle + ".html");
+               String template = client.getResource("layout/" + newTemplate + ".html");
                if (template == null) {
-                       template = "Layout file layout/" + newStyle + ".html is missing.";
+                       template = "Layout file layout/" + newTemplate + ".html is missing.";
                } else {
-                       currentStyle = newStyle;
+                       currentTemplate = newTemplate;
                }
 
                // Connect body of the template to DOM
index 17fb67a6205515d831313cddce99974d0d0dfcf9..a755ca9c651e8fa566d9970ddd22113b8133fd45 100644 (file)
@@ -469,7 +469,7 @@ public class JsonPaintTarget implements PaintTarget {
 
                tag.addAttribute("\"" + name + "\": \"" + escapeJSON(value) + "\"");
 
-               if (customLayoutArgumentsOpen && "style".equals(name))
+               if (customLayoutArgumentsOpen && "template".equals(name))
                        getPreCachedResources().add("layout/" + value + ".html");
                
                if(name.equals("locale"))
index 6c2a04f170450a24643f9472483d3a7225a6fb65..9015169e437cc5f6ae9dd360956ee71583c7ccf3 100644 (file)
@@ -33,7 +33,9 @@ import com.itmill.toolkit.event.EventRouter;
 import com.itmill.toolkit.event.MethodEventSource;
 import com.itmill.toolkit.terminal.*;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Locale;
 import java.util.Map;
@@ -55,11 +57,11 @@ import java.lang.reflect.Method;
 public abstract class AbstractComponent implements Component, MethodEventSource {
 
        /* Private members ************************************************* */
-
+       
        /**
-        * Look-and-feel style of the component.
+        * Style names.
         */
-       private String style;
+       private ArrayList styles;
 
        /**
         * Caption text.
@@ -159,7 +161,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource
         * default documentation from implemented interface.
         */
        public String getStyle() {
-               return this.style;
+               String s = "";
+               if(styles != null) {
+                       for(Iterator it = styles.iterator();it.hasNext();)
+                               s += " " + (String) it.next();
+               }
+               return s;
        }
 
        /*
@@ -167,10 +174,27 @@ public abstract class AbstractComponent implements Component, MethodEventSource
         * default documentation from implemented interface.
         */
        public void setStyle(String style) {
-               this.style = style;
+               if(this.styles == null) {
+                       styles = new ArrayList();
+               }
+               styles.clear();
+               styles.add(style);
                requestRepaint();
        }
-
+       
+       public void addStyleName(String style) {
+               if(this.styles == null) {
+                       styles = new ArrayList();
+               }
+               if(! styles.contains(style))
+                       this.styles.add(style);
+               requestRepaint();
+       }
+       
+       public void removeStyleName(String style) {
+               styles.remove(style);
+       }
+       
        /*
         * Get's the component's caption. Don't add a JavaDoc comment here, we use
         * the default documentation from implemented interface.
@@ -516,7 +540,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
        public final void paint(PaintTarget target) throws PaintException {
 
                if (!target.startTag(this, this.getTag())) {
-                       if (getStyle() != null && getStyle().length() > 0)
+                       if (styles != null && styles.size() > 0)
                                target.addAttribute("style", getStyle());
                        if (isReadOnly())
                                target.addAttribute("readonly", true);
index dc686f5f05fbc4bef9dfde8312ed0ac5f714ff7e..234b8d983659b18878e5b44a1ca6363ee52cb968 100644 (file)
@@ -51,21 +51,41 @@ import java.util.Locale;
 public interface Component extends Paintable, VariableOwner {
 
        /**
-        * Gets the look-and-feel style of the component.
-        * 
+        * Gets style for component. Multiple styles are joined with spaces.
+        *
         * @return the component's styleValue of property style.
         */
        public String getStyle();
 
        /**
-        * Sets the look-and-feel style of the component. This method will trigger a
+        * Sets and replaces all previous style names of the component. This method will trigger a
         * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
         * 
         * @param style
         *            the new style of the component.
         */
        public void setStyle(String style);
-
+       
+       /**
+        * Adds style name to component. Handeling additional style names is terminal spesicif,
+        * but in web browser enviroment they will most likely become CSS classes as given on server side.
+        *
+        * This method will trigger a
+        * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
+        * 
+        * @param style
+        *                      the new style to be added to the component
+        */
+       public void addStyleName(String style);
+       
+       /**
+        * Removes given style name from component.
+        * 
+        * @param style
+        *                      the style to be removed
+        */
+       public void removeStyleName(String style);
+       
        /**
         * <p>
         * Tests if the component is enabled or not. All the variable change events
index 3aebcfeb6bd12b84ea031aded73bedee27323243..abf546641f4ab31c766f5a95b80afbe4967e30f1 100644 (file)
@@ -519,4 +519,21 @@ public class CustomComponent implements Component {
                this.componentType = componentType;
        }
 
+       /**
+        * Custom component does not implement custom styles by default.
+        * 
+        * @see com.itmill.toolkit.ui.Component#getStyle()
+        */
+       public void addStyleName(String style) {
+       }
+
+       /**
+        * Custom component does not implement custom styles by default.
+        * 
+        * @see com.itmill.toolkit.ui.Component#getStyle()
+        */
+       public void removeStyleName(String style) {
+               
+       }
+
 }
index 06ec7f4f1083b0eccaa84ca45fb8d81243ab1705..c0b598d42e4833bc75dd11b522ebb4fac918b27f 100644 (file)
@@ -67,12 +67,14 @@ public class CustomLayout extends AbstractComponentContainer implements Layout {
         * Custom layout slots containing the components.
         */
        private HashMap slots = new HashMap();
+       
+       private String templateName;
 
        /**
-        * Constructor for custom layout with given style.
+        * Constructor for custom layout with given template name.
         */
-       public CustomLayout(String style) {
-               setStyle(style);
+       public CustomLayout(String template) {
+               templateName = template;
        }
 
        /**
@@ -172,6 +174,7 @@ public class CustomLayout extends AbstractComponentContainer implements Layout {
         */
        public void paintContent(PaintTarget target) throws PaintException {
 
+               target.addAttribute("template", templateName);
                // Adds all items in all the locations
                for (Iterator i = slots.keySet().iterator(); i.hasNext();) {