]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed #677 disabling components inside a disabled container
authorArtur Signell <artur.signell@itmill.com>
Mon, 25 Aug 2008 08:42:23 +0000 (08:42 +0000)
committerArtur Signell <artur.signell@itmill.com>
Mon, 25 Aug 2008 08:42:23 +0000 (08:42 +0000)
svn changeset:5252/svn branch:trunk

WebContent/ITMILL/themes/default/common/common.css
WebContent/ITMILL/themes/default/styles.css
src/com/itmill/toolkit/tests/tickets/Ticket677.java
src/com/itmill/toolkit/ui/AbstractComponent.java
src/com/itmill/toolkit/ui/AbstractComponentContainer.java

index 8ca2f3ad3fc21553b3cac666dd64bb8eda7b63b7..bf5ccf7acef0d6d1bda5da06644563f4ddde158a 100644 (file)
 .i-disabled {
        opacity: 0.3;
        filter: Alpha(opacity=30);
-}
+}\r
+.i-disabled .i-disabled {\r
+       opacity: 1.0;\r
+}\r
 .i-required-field-indicator {
        padding-left:2px;
        color: red;
index 6db00414eb0f5f2bb6d432617395a72bcc9066c0..695fad84b7a23a47f93dc4c55c2e9ff7bf63aed8 100644 (file)
        opacity: 0.3;
        filter: Alpha(opacity=30);
 }
+.i-disabled .i-disabled {
+       opacity: 1.0;
+}
 .i-required-field-indicator {
        padding-left:2px;
        color: red;
index f72b42bf19076fb07d36c53362fe905113892707..07c66cfced74ae61688b6d0853a8581be8a5e402 100644 (file)
@@ -50,16 +50,28 @@ public class Ticket677 extends Application {
         innerLayout1.setSpacing(true);\r
         panel.addComponent(innerLayout1);\r
 \r
-        innerLayout1.addComponent(new TextField(\r
-                "TextField inside orderedLayout"));\r
-        innerLayout1.addComponent(new Button("Button inside orderedLayout"));\r
+        TextField tf = new TextField("TextField inside orderedLayout");\r
+        tf.setImmediate(true);\r
+        innerLayout1.addComponent(tf);\r
+        innerLayout1.addComponent(new Button("Button inside orderedLayout",\r
+                new ClickListener() {\r
+\r
+                    @Override\r
+                    public void buttonClick(ClickEvent event) {\r
+                        System.out.println("Clicked "\r
+                                + event.getButton().getCaption());\r
+                    }\r
+\r
+                }));\r
         innerLayout1.addComponent(new Label("Label inside orderedLayout"));\r
 \r
         panel.addComponent(new Label("Label 2"));\r
 \r
         GridLayout innerLayout2 = new GridLayout(3, 3);\r
         innerLayout2.setSpacing(true);\r
-        innerLayout2.addComponent(new TextField("TextField inside gridLayout"));\r
+        tf = new TextField("TextField inside gridLayout");\r
+        tf.setImmediate(true);\r
+        innerLayout2.addComponent(tf);\r
         innerLayout2.addComponent(new Button("Button inside gridLayout"));\r
         innerLayout2.addComponent(new Label("Label inside gridLayout"));\r
         panel.addComponent(innerLayout2);\r
index 634f58dbac512df5b0c2bbe0da2648f54f54fc87..0aa9d74fdf5840cb31e4a61a26804a17d36fd2d4 100644 (file)
@@ -58,10 +58,15 @@ public abstract class AbstractComponent implements Component, MethodEventSource
     private Resource icon;
 
     /**
-     * Is the component enable (its normal usage is allowed).
+     * Is the component enabled (its normal usage is allowed).
      */
     private boolean enabled = true;
 
+    /**
+     * Has the component been disabled by the container
+     */
+    private boolean disabledByContainer = false;
+
     /**
      * Is the component visible (it is rendered).
      */
@@ -306,7 +311,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
      * here, we use the default documentation from implemented interface.
      */
     public boolean isEnabled() {
-        return enabled && isVisible();
+        return enabled && !disabledByContainer && isVisible();
     }
 
     /*
@@ -320,6 +325,21 @@ public abstract class AbstractComponent implements Component, MethodEventSource
         }
     }
 
+    /**
+     * Enable or disable the component by the container. Normally used to
+     * disable the component when the container is disabled without altering the
+     * actual enabled state of the component.
+     * 
+     * @param disabledByContainer
+     *                Should the component be disabled
+     */
+    public void setDisabledByContainer(boolean disabledByContainer) {
+        if (disabledByContainer != this.disabledByContainer) {
+            this.disabledByContainer = disabledByContainer;
+            requestRepaint();
+        }
+    }
+
     /*
      * Tests if the component is in the immediate mode. Don't add a JavaDoc
      * comment here, we use the default documentation from implemented
index 93af36d248cd4b438b0de547d67f92d12b6bea67..bce552e3d99e1a845ed4fc95044762a2c76624eb 100644 (file)
@@ -205,4 +205,27 @@ public abstract class AbstractComponentContainer extends AbstractComponent
         }
     }
 
-}
+    public void setEnabled(boolean enabled) {
+        super.setEnabled(enabled);
+
+        updateComponentDisabledState(!enabled);
+    }
+
+    public void setDisabledByContainer(boolean disabledByContainer) {
+        super.setDisabledByContainer(disabledByContainer);
+
+        updateComponentDisabledState(disabledByContainer);
+    }
+
+    private void updateComponentDisabledState(boolean disabled) {
+        // Update the disabledByContainer state for all subcomponents
+        for (Iterator i = getComponentIterator(); i.hasNext();) {
+            Component c = (Component) i.next();
+            if (c instanceof AbstractComponent) {
+                ((AbstractComponent) c).setDisabledByContainer(disabled);
+            }
+        }
+
+    }
+
+}
\ No newline at end of file