diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-11-23 11:46:14 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-11-23 11:46:14 +0200 |
commit | 9f97638b0f75b882b76eeb5d2b95f87bb5263a73 (patch) | |
tree | 4efd1ee49bb6d7322124e8c8bcf9c2ed7a51f042 | |
parent | b73ac55836d0d6a56af615572a3d7f29afc3fe5c (diff) | |
download | vaadin-framework-9f97638b0f75b882b76eeb5d2b95f87bb5263a73.tar.gz vaadin-framework-9f97638b0f75b882b76eeb5d2b95f87bb5263a73.zip |
Refactor BrowserPopupOpener API (#10241)
* Rename BrowserPopupOpener to BrowserWindowOpener
* Rename setPopupName -> setWindowName
* Rename BrowserPopupUIProvider -> BrowserWindowUIProvider
* Make BrowserWindowUIProvider a private static inner class
Change-Id: Id839b274762424bb50fe3590d7cd1187e92baa6c
-rw-r--r-- | client/src/com/vaadin/client/extensions/BrowserWindowOpenerConnector.java (renamed from client/src/com/vaadin/client/extensions/BrowserPopupOpenerConnector.java) | 16 | ||||
-rw-r--r-- | server/src/com/vaadin/server/BrowserPopupUIProvider.java | 50 | ||||
-rw-r--r-- | server/src/com/vaadin/server/BrowserWindowOpener.java (renamed from server/src/com/vaadin/server/BrowserPopupOpener.java) | 101 | ||||
-rw-r--r-- | shared/src/com/vaadin/shared/ui/BrowserWindowOpenerState.java (renamed from shared/src/com/vaadin/shared/ui/BrowserPopupExtensionState.java) | 3 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/extensions/BrowserPopupExtensionTest.java | 12 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/minitutorials/v7b6/OpeningUIInPopup.java | 4 |
6 files changed, 84 insertions, 102 deletions
diff --git a/client/src/com/vaadin/client/extensions/BrowserPopupOpenerConnector.java b/client/src/com/vaadin/client/extensions/BrowserWindowOpenerConnector.java index 2615444832..63915af1bd 100644 --- a/client/src/com/vaadin/client/extensions/BrowserPopupOpenerConnector.java +++ b/client/src/com/vaadin/client/extensions/BrowserWindowOpenerConnector.java @@ -22,18 +22,18 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; -import com.vaadin.server.BrowserPopupOpener; -import com.vaadin.shared.ui.BrowserPopupExtensionState; +import com.vaadin.server.BrowserWindowOpener; +import com.vaadin.shared.ui.BrowserWindowOpenerState; import com.vaadin.shared.ui.Connect; /** - * Client-side code for {@link BrowserPopupOpener} + * Client-side code for {@link BrowserWindowOpener} * * @author Vaadin Ltd * @since 7.0.0 */ -@Connect(BrowserPopupOpener.class) -public class BrowserPopupOpenerConnector extends AbstractExtensionConnector +@Connect(BrowserWindowOpener.class) +public class BrowserWindowOpenerConnector extends AbstractExtensionConnector implements ClickHandler { @Override @@ -44,13 +44,13 @@ public class BrowserPopupOpenerConnector extends AbstractExtensionConnector } @Override - public BrowserPopupExtensionState getState() { - return (BrowserPopupExtensionState) super.getState(); + public BrowserWindowOpenerState getState() { + return (BrowserWindowOpenerState) super.getState(); } @Override public void onClick(ClickEvent event) { - String url = getResourceUrl("popup"); + String url = getResourceUrl(BrowserWindowOpenerState.locationResource); if (url != null) { Window.open(url, getState().target, getState().features); } diff --git a/server/src/com/vaadin/server/BrowserPopupUIProvider.java b/server/src/com/vaadin/server/BrowserPopupUIProvider.java deleted file mode 100644 index 6259fb605d..0000000000 --- a/server/src/com/vaadin/server/BrowserPopupUIProvider.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2012 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.server; - -import com.vaadin.ui.UI; - -public class BrowserPopupUIProvider extends UIProvider { - - private final String path; - private final Class<? extends UI> uiClass; - - public BrowserPopupUIProvider(Class<? extends UI> uiClass, String path) { - this.path = ensureInitialSlash(path); - this.uiClass = uiClass; - } - - private static String ensureInitialSlash(String path) { - if (path == null) { - return null; - } else if (!path.startsWith("/")) { - return '/' + path; - } else { - return path; - } - } - - @Override - public Class<? extends UI> getUIClass(UIClassSelectionEvent event) { - String requestPathInfo = event.getRequest().getPathInfo(); - if (path.equals(requestPathInfo)) { - return uiClass; - } else { - return null; - } - } -} diff --git a/server/src/com/vaadin/server/BrowserPopupOpener.java b/server/src/com/vaadin/server/BrowserWindowOpener.java index c55fa65931..3ed039887c 100644 --- a/server/src/com/vaadin/server/BrowserPopupOpener.java +++ b/server/src/com/vaadin/server/BrowserWindowOpener.java @@ -17,7 +17,7 @@ package com.vaadin.server; import com.vaadin.shared.ApplicationConstants; -import com.vaadin.shared.ui.BrowserPopupExtensionState; +import com.vaadin.shared.ui.BrowserWindowOpenerState; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.UI; @@ -28,24 +28,55 @@ import com.vaadin.ui.UI; * @author Vaadin Ltd * @since 7.0.0 */ -public class BrowserPopupOpener extends AbstractExtension { +public class BrowserWindowOpener extends AbstractExtension { - private final BrowserPopupUIProvider uiProvider; + private static class BrowserWindowOpenerUIProvider extends UIProvider { + + private final String path; + private final Class<? extends UI> uiClass; + + public BrowserWindowOpenerUIProvider(Class<? extends UI> uiClass, String path) { + this.path = ensureInitialSlash(path); + this.uiClass = uiClass; + } + + private static String ensureInitialSlash(String path) { + if (path == null) { + return null; + } else if (!path.startsWith("/")) { + return '/' + path; + } else { + return path; + } + } + + @Override + public Class<? extends UI> getUIClass(UIClassSelectionEvent event) { + String requestPathInfo = event.getRequest().getPathInfo(); + if (path.equals(requestPathInfo)) { + return uiClass; + } else { + return null; + } + } + } + + private final BrowserWindowOpenerUIProvider uiProvider; /** - * Creates a popup opener that will open popups containing the provided UI + * Creates a window opener that will open windows containing the provided UI * class * * @param uiClass * the UI class that should be opened when the extended component * is clicked */ - public BrowserPopupOpener(Class<? extends UI> uiClass) { + public BrowserWindowOpener(Class<? extends UI> uiClass) { this(uiClass, generateUIClassUrl(uiClass)); } /** - * Creates a popup opener that will open popups containing the provided UI + * Creates a window opener that will open windows containing the provided UI * using the provided path * * @param uiClass @@ -54,36 +85,36 @@ public class BrowserPopupOpener extends AbstractExtension { * @param path * the path that the UI should be bound to */ - public BrowserPopupOpener(Class<? extends UI> uiClass, String path) { + public BrowserWindowOpener(Class<? extends UI> uiClass, String path) { // Create a Resource with a translated URL going to the VaadinService this(new ExternalResource(ApplicationConstants.APP_PROTOCOL_PREFIX - + path), new BrowserPopupUIProvider(uiClass, path)); + + path), new BrowserWindowOpenerUIProvider(uiClass, path)); } /** - * Creates a popup opener that will open popups to the provided URL + * Creates a window opener that will open windows to the provided URL * * @param url - * the URL to open in the popup + * the URL to open in the window */ - public BrowserPopupOpener(String url) { + public BrowserWindowOpener(String url) { this(new ExternalResource(url)); } /** - * Creates a popup opener that will open popups to the provided resource + * Creates a window opener that will open window to the provided resource * * @param resource - * the resource to open in the popup + * the resource to open in the window */ - public BrowserPopupOpener(Resource resource) { + public BrowserWindowOpener(Resource resource) { this(resource, null); } - private BrowserPopupOpener(Resource resource, - BrowserPopupUIProvider uiProvider) { + private BrowserWindowOpener(Resource resource, + BrowserWindowOpenerUIProvider uiProvider) { this.uiProvider = uiProvider; - setResource("popup", resource); + setResource(BrowserWindowOpenerState.locationResource, resource); } public void extend(AbstractComponent target) { @@ -91,38 +122,38 @@ public class BrowserPopupOpener extends AbstractExtension { } /** - * Sets the target window name that will be used when opening the popup. If - * a popup has already been opened with the same name, the contents of that - * window will be replaced instead of opening a new window. If the name is - * <code>null</code> or <code>"blank"</code>, the popup will always be - * opened in a new window. + * Sets the target window name that will be used. If a window has already + * been opened with the same name, the contents of that window will be + * replaced instead of opening a new window. If the name is + * <code>null</code> or <code>"_blank"</code>, a new window will always be + * opened. * - * @param popupName - * the target name for the popups + * @param windowName + * the target name for the window */ - public void setPopupName(String popupName) { - getState().target = popupName; + public void setWindowName(String windowName) { + getState().target = windowName; } /** - * Gets the popup target name. + * Gets the target window name. * - * @see #setPopupName(String) + * @see #setWindowName(String) * - * @return the popup target string + * @return the window target string */ - public String getPopupName() { + public String getWindowName() { return getState().target; } // Avoid breaking url to multiple lines // @formatter:off /** - * Sets the features for opening the popup. See e.g. + * Sets the features for opening the window. See e.g. * {@link https://developer.mozilla.org/en-US/docs/DOM/window.open#Position_and_size_features} * for a description of the commonly supported features. * - * @param features a string with popup features, or <code>null</code> to use the default features. + * @param features a string with window features, or <code>null</code> to use the default features. */ // @formatter:on public void setFeatures(String features) { @@ -130,7 +161,7 @@ public class BrowserPopupOpener extends AbstractExtension { } /** - * Gets the popup features. + * Gets the window features. * * @see #setFeatures(String) * @return @@ -140,8 +171,8 @@ public class BrowserPopupOpener extends AbstractExtension { } @Override - protected BrowserPopupExtensionState getState() { - return (BrowserPopupExtensionState) super.getState(); + protected BrowserWindowOpenerState getState() { + return (BrowserWindowOpenerState) super.getState(); } @Override diff --git a/shared/src/com/vaadin/shared/ui/BrowserPopupExtensionState.java b/shared/src/com/vaadin/shared/ui/BrowserWindowOpenerState.java index 199de54f8f..95e053b925 100644 --- a/shared/src/com/vaadin/shared/ui/BrowserPopupExtensionState.java +++ b/shared/src/com/vaadin/shared/ui/BrowserWindowOpenerState.java @@ -18,7 +18,8 @@ package com.vaadin.shared.ui; import com.vaadin.shared.AbstractComponentState; -public class BrowserPopupExtensionState extends AbstractComponentState { +public class BrowserWindowOpenerState extends AbstractComponentState { + public static final String locationResource = "url"; public String target = "_blank"; diff --git a/uitest/src/com/vaadin/tests/extensions/BrowserPopupExtensionTest.java b/uitest/src/com/vaadin/tests/extensions/BrowserPopupExtensionTest.java index d69ebfab56..196592d376 100644 --- a/uitest/src/com/vaadin/tests/extensions/BrowserPopupExtensionTest.java +++ b/uitest/src/com/vaadin/tests/extensions/BrowserPopupExtensionTest.java @@ -19,7 +19,7 @@ package com.vaadin.tests.extensions; import java.util.ArrayList; import java.util.List; -import com.vaadin.server.BrowserPopupOpener; +import com.vaadin.server.BrowserWindowOpener; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.components.popupview.ReopenPopupView; @@ -47,16 +47,16 @@ public class BrowserPopupExtensionTest extends AbstractTestUI { addComponents(components, "http://vaadin.com/download/nightly/"); Button uiClassButton = new Button("Open UI class"); - new BrowserPopupOpener(ReopenPopupView.class).extend(uiClassButton); + new BrowserWindowOpener(ReopenPopupView.class).extend(uiClassButton); addComponent(uiClassButton); Button uiWithPath = new Button("Open UI class with path"); - new BrowserPopupOpener(ReopenPopupView.class, "foobar") + new BrowserWindowOpener(ReopenPopupView.class, "foobar") .extend(uiWithPath); addComponent(uiWithPath); Button withPopupFeaturesButton = new Button("Open with features"); - BrowserPopupOpener featuresPopup = new BrowserPopupOpener( + BrowserWindowOpener featuresPopup = new BrowserWindowOpener( "http://vaadin.com/download/nightly/"); featuresPopup.setFeatures("width=400,height=400"); featuresPopup.extend(withPopupFeaturesButton); @@ -76,7 +76,7 @@ public class BrowserPopupExtensionTest extends AbstractTestUI { c.setHeight("100px"); hl.addComponent(c); - new BrowserPopupOpener(URL).extend(c); + new BrowserWindowOpener(URL).extend(c); if (c instanceof Button) { ((Button) c).addClickListener(new ClickListener() { @@ -95,7 +95,7 @@ public class BrowserPopupExtensionTest extends AbstractTestUI { @Override protected String getTestDescription() { - return "Test for " + BrowserPopupOpener.class.getSimpleName() + return "Test for " + BrowserWindowOpener.class.getSimpleName() + " features"; } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b6/OpeningUIInPopup.java b/uitest/src/com/vaadin/tests/minitutorials/v7b6/OpeningUIInPopup.java index 7fd8373bbd..43e2fdad7e 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7b6/OpeningUIInPopup.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7b6/OpeningUIInPopup.java @@ -16,7 +16,7 @@ package com.vaadin.tests.minitutorials.v7b6; -import com.vaadin.server.BrowserPopupOpener; +import com.vaadin.server.BrowserWindowOpener; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Button; import com.vaadin.ui.UI; @@ -27,7 +27,7 @@ public class OpeningUIInPopup extends UI { protected void init(VaadinRequest request) { Button popupButton = new Button("Open popup with MyPopupUI"); - BrowserPopupOpener popupOpener = new BrowserPopupOpener(MyPopupUI.class); + BrowserWindowOpener popupOpener = new BrowserWindowOpener(MyPopupUI.class); popupOpener.setFeatures("height=300,width=300"); popupOpener.extend(popupButton); |