]> source.dussan.org Git - vaadin-framework.git/commitdiff
Implement HasEnabled in VPopupView. (#14797)
authorSauli Tähkäpää <sauli@vaadin.com>
Thu, 2 Oct 2014 19:19:05 +0000 (22:19 +0300)
committerVaadin Code Review <review@vaadin.com>
Tue, 7 Oct 2014 13:10:03 +0000 (13:10 +0000)
Change-Id: I7384fb6312a921330d8b57193e53c235213dcf00

client/src/com/vaadin/client/ui/VPopupView.java
uitest/src/com/vaadin/tests/components/popupview/DisabledPopupView.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/popupview/DisabledPopupViewTest.java [new file with mode: 0644]

index 1a59501d383a8d7adc42b43e26a0a374898d4287..7d9811044678716e5cc99f5a91d960ef1e6cf3b2 100644 (file)
@@ -33,13 +33,7 @@ import com.google.gwt.event.logical.shared.CloseHandler;
 import com.google.gwt.event.shared.HandlerRegistration;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Event;
-import com.google.gwt.user.client.ui.Focusable;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.HasWidgets;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.PopupPanel;
-import com.google.gwt.user.client.ui.RootPanel;
-import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.*;
 import com.vaadin.client.ApplicationConnection;
 import com.vaadin.client.ComponentConnector;
 import com.vaadin.client.DeferredWorker;
@@ -51,7 +45,7 @@ import com.vaadin.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner;
 import com.vaadin.client.ui.popupview.VisibilityChangeEvent;
 import com.vaadin.client.ui.popupview.VisibilityChangeHandler;
 
-public class VPopupView extends HTML implements Iterable<Widget>,
+public class VPopupView extends HTML implements HasEnabled, Iterable<Widget>,
         DeferredWorker {
 
     public static final String CLASSNAME = "v-popupview";
@@ -78,6 +72,7 @@ public class VPopupView extends HTML implements Iterable<Widget>,
     private final Label loading = new Label();
 
     private boolean popupShowInProgress;
+    private boolean enabled = true;
 
     /**
      * loading constructor
@@ -97,10 +92,12 @@ public class VPopupView extends HTML implements Iterable<Widget>,
         addClickHandler(new ClickHandler() {
             @Override
             public void onClick(ClickEvent event) {
-                preparePopup(popup);
-                showPopup(popup);
-                center();
-                fireEvent(new VisibilityChangeEvent(true));
+                if(isEnabled()) {
+                    preparePopup(popup);
+                    showPopup(popup);
+                    center();
+                    fireEvent(new VisibilityChangeEvent(true));
+                }
             }
         });
 
@@ -196,6 +193,25 @@ public class VPopupView extends HTML implements Iterable<Widget>,
         }
     }-*/;
 
+    /**
+     * Returns true if the popup is enabled, false if not.
+     */
+    @Override
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+    /**
+     * Sets whether this popup is enabled.
+     *
+     * @param enabled <code>true</code> to enable the popup, <code>false</code>
+     *          to disable it
+     */
+    @Override
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+
     /**
      * This class is only public to enable overriding showPopup, and is
      * currently not intended to be extended or otherwise used directly. Its API
diff --git a/uitest/src/com/vaadin/tests/components/popupview/DisabledPopupView.java b/uitest/src/com/vaadin/tests/components/popupview/DisabledPopupView.java
new file mode 100644 (file)
index 0000000..ecce178
--- /dev/null
@@ -0,0 +1,23 @@
+package com.vaadin.tests.components.popupview;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.PopupView;
+
+public class DisabledPopupView extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        PopupView popupView = new PopupView("Disabled Popup", new Button("Hi!"));
+
+        popupView.setEnabled(false);
+
+        addComponent(popupView);
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 14797;
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/components/popupview/DisabledPopupViewTest.java b/uitest/src/com/vaadin/tests/components/popupview/DisabledPopupViewTest.java
new file mode 100644 (file)
index 0000000..be9345d
--- /dev/null
@@ -0,0 +1,20 @@
+package com.vaadin.tests.components.popupview;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.PopupViewElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+
+public class DisabledPopupViewTest extends MultiBrowserTest {
+
+    @Test
+    public void disabledPopupDoesNotOpen() {
+        openTestURL();
+
+        $(PopupViewElement.class).first().click();
+
+        assertFalse($(ButtonElement.class).exists());
+    }
+}
\ No newline at end of file