import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.server.Page;
-import com.vaadin.server.Page.FragmentChangedEvent;
-import com.vaadin.server.Page.FragmentChangedListener;
+import com.vaadin.server.Page.UriFragmentChangedEvent;
+import com.vaadin.server.Page.UriFragmentChangedListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.CssLayout;
* and static to enable testing.
*/
public static class UriFragmentManager implements NavigationStateManager,
- FragmentChangedListener {
+ UriFragmentChangedListener {
private final Page page;
private Navigator navigator;
*/
public UriFragmentManager(Page page) {
this.page = page;
- page.addFragmentChangedListener(this);
+ page.addUriFragmentChangedListener(this);
}
@Override
}
@Override
- public void fragmentChanged(FragmentChangedEvent event) {
+ public void uriFragmentChanged(UriFragmentChangedEvent event) {
navigator.navigateTo(getState());
}
* @return The URI fragment.
*/
protected String getFragment() {
- return page.getFragment();
+ return page.getUriFragment();
}
/**
* The new URI fragment.
*/
protected void setFragment(String fragment) {
- page.setFragment(fragment, false);
+ page.setUriFragment(fragment, false);
}
}
public static final BorderStyle BORDER_DEFAULT = BorderStyle.DEFAULT;
/**
- * Listener that listens changes in URI fragment.
+ * Listener that listens to changes in URI fragment.
*/
- public interface FragmentChangedListener extends Serializable {
- public void fragmentChanged(FragmentChangedEvent event);
+ public interface UriFragmentChangedListener extends Serializable {
+ public void uriFragmentChanged(UriFragmentChangedEvent event);
}
- private static final Method FRAGMENT_CHANGED_METHOD = ReflectTools
- .findMethod(Page.FragmentChangedListener.class, "fragmentChanged",
- FragmentChangedEvent.class);
+ private static final Method URI_FRAGMENT_CHANGED_METHOD = ReflectTools
+ .findMethod(Page.UriFragmentChangedListener.class,
+ "uriFragmentChanged", UriFragmentChangedEvent.class);
/**
* Resources to be opened automatically on next repaint. The list is
/**
* Event fired when uri fragment changes.
*/
- public static class FragmentChangedEvent extends EventObject {
+ public static class UriFragmentChangedEvent extends EventObject {
/**
* The new uri fragment
*/
- private final String fragment;
+ private final String uriFragment;
/**
* Creates a new instance of UriFragmentReader change event.
* @param source
* the Source of the event.
*/
- public FragmentChangedEvent(Page source, String fragment) {
+ public UriFragmentChangedEvent(Page source, String uriFragment) {
super(source);
- this.fragment = fragment;
+ this.uriFragment = uriFragment;
}
/**
*
* @return the new fragment
*/
- public String getFragment() {
- return fragment;
+ public String getUriFragment() {
+ return uriFragment;
}
}
}
}
- public void addFragmentChangedListener(Page.FragmentChangedListener listener) {
- addListener(FragmentChangedEvent.class, listener,
- FRAGMENT_CHANGED_METHOD);
+ public void addUriFragmentChangedListener(
+ Page.UriFragmentChangedListener listener) {
+ addListener(UriFragmentChangedEvent.class, listener,
+ URI_FRAGMENT_CHANGED_METHOD);
}
/**
* @deprecated Since 7.0, replaced by
- * {@link #addFragmentChangedListener(FragmentChangedListener)}
+ * {@link #addUriFragmentChangedListener(UriFragmentChangedListener)}
**/
@Deprecated
- public void addListener(Page.FragmentChangedListener listener) {
- addFragmentChangedListener(listener);
+ public void addListener(Page.UriFragmentChangedListener listener) {
+ addUriFragmentChangedListener(listener);
}
- public void removeFragmentChangedListener(
- Page.FragmentChangedListener listener) {
- removeListener(FragmentChangedEvent.class, listener,
- FRAGMENT_CHANGED_METHOD);
+ public void removeUriFragmentChangedListener(
+ Page.UriFragmentChangedListener listener) {
+ removeListener(UriFragmentChangedEvent.class, listener,
+ URI_FRAGMENT_CHANGED_METHOD);
}
/**
* @deprecated Since 7.0, replaced by
- * {@link #removeFragmentChangedListener(FragmentChangedListener)}
+ * {@link #removeUriFragmentChangedListener(UriFragmentChangedListener)}
**/
@Deprecated
- public void removeListener(Page.FragmentChangedListener listener) {
- removeFragmentChangedListener(listener);
+ public void removeListener(Page.UriFragmentChangedListener listener) {
+ removeUriFragmentChangedListener(listener);
}
/**
* Sets the fragment part in the current location URI. Optionally fires a
- * {@link FragmentChangedEvent}.
+ * {@link UriFragmentChangedEvent}.
* <p>
* The fragment is the optional last component of a URI, prefixed with a
* hash sign ("#").
* trailing "#" in the URI.) This is consistent with the semantics of
* {@link java.net.URI}.
*
- * @param newFragment
+ * @param newUriFragment
* The new fragment.
* @param fireEvent
* true to fire event
*
- * @see #getFragment()
+ * @see #getUriFragment()
* @see #setLocation(URI)
- * @see FragmentChangedEvent
- * @see Page.FragmentChangedListener
+ * @see UriFragmentChangedEvent
+ * @see Page.UriFragmentChangedListener
*
*/
- public void setFragment(String newFragment, boolean fireEvents) {
- String oldFragment = location.getFragment();
- if (newFragment == oldFragment
- || (newFragment != null && newFragment.equals(oldFragment))) {
+ public void setUriFragment(String newUriFragment, boolean fireEvents) {
+ String oldUriFragment = location.getFragment();
+ if (newUriFragment == oldUriFragment
+ || (newUriFragment != null && newUriFragment
+ .equals(oldUriFragment))) {
return;
}
try {
location = new URI(location.getScheme(),
- location.getSchemeSpecificPart(), newFragment);
+ location.getSchemeSpecificPart(), newUriFragment);
} catch (URISyntaxException e) {
// This should not actually happen as the fragment syntax is not
// constrained
throw new RuntimeException(e);
}
if (fireEvents) {
- fireEvent(new FragmentChangedEvent(this, newFragment));
+ fireEvent(new UriFragmentChangedEvent(this, newUriFragment));
}
uI.markAsDirty();
}
}
/**
- * Sets URI fragment. This method fires a {@link FragmentChangedEvent}
+ * Sets URI fragment. This method fires a {@link UriFragmentChangedEvent}
*
- * @param newFragment
+ * @param newUriFragment
* id of the new fragment
- * @see FragmentChangedEvent
- * @see Page.FragmentChangedListener
+ * @see UriFragmentChangedEvent
+ * @see Page.UriFragmentChangedListener
*/
- public void setFragment(String newFragment) {
- setFragment(newFragment, true);
+ public void setUriFragment(String newUriFragment) {
+ setUriFragment(newUriFragment, true);
}
/**
* there is an empty fragment.
* <p>
* To listen to changes in fragment, hook a
- * {@link Page.FragmentChangedListener}.
+ * {@link Page.UriFragmentChangedListener}.
*
* @return the current fragment in browser location URI.
*
* @see #getLocation()
- * @see #setFragment(String)
- * @see #addFragmentChangedListener(FragmentChangedListener)
+ * @see #setUriFragment(String)
+ * @see #addUriFragmentChangedListener(UriFragmentChangedListener)
*/
- public String getFragment() {
+ public String getUriFragment() {
return location.getFragment();
}
*/
public void updateLocation(String location) {
try {
- String oldFragment = this.location.getFragment();
+ String oldUriFragment = this.location.getFragment();
this.location = new URI(location);
- String newFragment = this.location.getFragment();
- if (newFragment == null ? oldFragment != null : !newFragment
- .equals(oldFragment)) {
- fireEvent(new FragmentChangedEvent(this, newFragment));
+ String newUriFragment = this.location.getFragment();
+ if (newUriFragment == null ? oldUriFragment != null
+ : !newUriFragment.equals(oldUriFragment)) {
+ fireEvent(new UriFragmentChangedEvent(this, newUriFragment));
}
} catch (URISyntaxException e) {
throw new RuntimeException(e);
import com.vaadin.navigator.Navigator;
import com.vaadin.navigator.Navigator.UriFragmentManager;
import com.vaadin.server.Page;
-import com.vaadin.server.Page.FragmentChangedEvent;
+import com.vaadin.server.Page.UriFragmentChangedEvent;
public class UriFragmentManagerTest extends TestCase {
- public void testGetSetFragment() {
+ public void testGetSetUriFragment() {
Page page = EasyMock.createMock(Page.class);
UriFragmentManager manager = new UriFragmentManager(page);
// prepare mock
- EasyMock.expect(page.getFragment()).andReturn("");
- page.setFragment("!test", false);
- EasyMock.expect(page.getFragment()).andReturn("!test");
+ EasyMock.expect(page.getUriFragment()).andReturn("");
+ page.setUriFragment("!test", false);
+ EasyMock.expect(page.getUriFragment()).andReturn("!test");
EasyMock.replay(page);
// test manager using the mock
UriFragmentManager manager = new UriFragmentManager(page);
manager.setNavigator(navigator);
- EasyMock.expect(page.getFragment()).andReturn("!test");
+ EasyMock.expect(page.getUriFragment()).andReturn("!test");
navigator.navigateTo("test");
control.replay();
- FragmentChangedEvent event = new FragmentChangedEvent(page, "oldtest");
- manager.fragmentChanged(event);
+ UriFragmentChangedEvent event = new UriFragmentChangedEvent(page, "oldtest");
+ manager.uriFragmentChanged(event);
}
}
import com.vaadin.server.ExternalResource;
import com.vaadin.server.LegacyApplication;
import com.vaadin.server.Page;
-import com.vaadin.server.Page.FragmentChangedEvent;
+import com.vaadin.server.Page.UriFragmentChangedEvent;
import com.vaadin.ui.Component;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.HorizontalSplitPanel;
VerticalLayout lo = new VerticalLayout();
lo.addComponent(menu);
- mainWindow.getPage().addListener(new Page.FragmentChangedListener() {
+ mainWindow.getPage().addListener(new Page.UriFragmentChangedListener() {
@Override
- public void fragmentChanged(FragmentChangedEvent source) {
- String fragment = source.getFragment();
+ public void uriFragmentChanged(UriFragmentChangedEvent source) {
+ String fragment = source.getUriFragment();
if (fragment != null && !"".equals(fragment)) {
// try to find a proper test class
package com.vaadin.tests.application;
import com.vaadin.annotations.PreserveOnRefresh;
-import com.vaadin.server.Page.FragmentChangedEvent;
-import com.vaadin.server.Page.FragmentChangedListener;
+import com.vaadin.server.Page.UriFragmentChangedEvent;
+import com.vaadin.server.Page.UriFragmentChangedListener;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.tests.util.Log;
addComponent(new Label("UI id: " + getUIId()));
addComponent(log);
- log.log("Initial fragment: " + getPage().getFragment());
- getPage().addFragmentChangedListener(new FragmentChangedListener() {
+ log.log("Initial fragment: " + getPage().getUriFragment());
+ getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() {
@Override
- public void fragmentChanged(FragmentChangedEvent event) {
- log.log("Fragment changed to " + event.getFragment());
+ public void uriFragmentChanged(UriFragmentChangedEvent event) {
+ log.log("Fragment changed to " + event.getUriFragment());
}
});
}
package com.vaadin.tests.components.ui;
-import com.vaadin.server.Page.FragmentChangedEvent;
-import com.vaadin.server.Page.FragmentChangedListener;
+import com.vaadin.server.Page.UriFragmentChangedEvent;
+import com.vaadin.server.Page.UriFragmentChangedListener;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.tests.util.Log;
@Override
protected void setup(VaadinRequest request) {
- getPage().addFragmentChangedListener(new FragmentChangedListener() {
+ getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() {
- public void fragmentChanged(FragmentChangedEvent source) {
- String newFragment = source.getFragment();
+ public void uriFragmentChanged(UriFragmentChangedEvent source) {
+ String newFragment = source.getUriFragment();
log.log("Fragment changed from " + lastKnownFragment + " to "
+ newFragment);
lastKnownFragment = newFragment;
}
protected void setFragment(String fragment) {
- getPage().setFragment(fragment);
+ getPage().setUriFragment(fragment);
}
@Override
package com.vaadin.tests.components.ui;
import com.vaadin.server.Page;
-import com.vaadin.server.Page.FragmentChangedEvent;
+import com.vaadin.server.Page.UriFragmentChangedEvent;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button;
protected void setup(VaadinRequest request) {
addComponent(fragmentLabel);
updateLabel();
- getPage().addListener(new Page.FragmentChangedListener() {
+ getPage().addListener(new Page.UriFragmentChangedListener() {
@Override
- public void fragmentChanged(FragmentChangedEvent event) {
+ public void uriFragmentChanged(UriFragmentChangedEvent event) {
updateLabel();
}
});
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
- getPage().setFragment("test");
+ getPage().setUriFragment("test");
}
}));
}
private void updateLabel() {
- String fragment = getPage().getFragment();
+ String fragment = getPage().getUriFragment();
if (fragment == null) {
fragmentLabel.setValue("No URI fragment set");
} else {
package com.vaadin.tests.minitutorials.v7a1;
-import com.vaadin.server.Page.FragmentChangedEvent;
-import com.vaadin.server.Page.FragmentChangedListener;
+import com.vaadin.server.Page.UriFragmentChangedEvent;
+import com.vaadin.server.Page.UriFragmentChangedListener;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
@Override
protected void init(VaadinRequest request) {
Label label = new Label("Hello, your fragment is "
- + getPage().getFragment());
+ + getPage().getUriFragment());
getContent().addComponent(label);
// React to fragment changes
- getPage().addListener(new FragmentChangedListener() {
+ getPage().addListener(new UriFragmentChangedListener() {
@Override
- public void fragmentChanged(FragmentChangedEvent source) {
- handleFragment(source.getFragment());
+ public void uriFragmentChanged(UriFragmentChangedEvent source) {
+ handleFragment(source.getUriFragment());
}
});
// Handle the fragment received in the initial request
- handleFragment(getPage().getFragment());
+ handleFragment(getPage().getUriFragment());
addComponent(new Button("Show and set fragment",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
- handleFragment(getPage().getFragment());
- getPage().setFragment("customFragment");
+ handleFragment(getPage().getUriFragment());
+ getPage().setUriFragment("customFragment");
}
}));
}
import com.vaadin.server.Page;
import com.vaadin.server.Page.BrowserWindowResizeEvent;
import com.vaadin.server.Page.BrowserWindowResizeListener;
-import com.vaadin.server.Page.FragmentChangedEvent;
-import com.vaadin.server.Page.FragmentChangedListener;
+import com.vaadin.server.Page.UriFragmentChangedEvent;
+import com.vaadin.server.Page.UriFragmentChangedListener;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Notification;
}
});
- page.setFragment(page.getFragment() + "foo");
- page.addFragmentChangedListener(new FragmentChangedListener() {
+ page.setUriFragment(page.getUriFragment() + "foo");
+ page.addUriFragmentChangedListener(new UriFragmentChangedListener() {
@Override
- public void fragmentChanged(FragmentChangedEvent event) {
- Notification.show("Fragment=" + event.getFragment());
+ public void uriFragmentChanged(UriFragmentChangedEvent event) {
+ Notification.show("Fragment=" + event.getUriFragment());
}
});
}
import com.vaadin.server.LegacyApplication;
import com.vaadin.server.Page;
-import com.vaadin.server.Page.FragmentChangedEvent;
+import com.vaadin.server.Page.UriFragmentChangedEvent;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Component;
"Test app for URI fragment management/reading", mainLayout);
setMainWindow(mainWin);
- mainWin.getPage().addListener(new Page.FragmentChangedListener() {
+ mainWin.getPage().addListener(new Page.UriFragmentChangedListener() {
@Override
- public void fragmentChanged(FragmentChangedEvent event) {
+ public void uriFragmentChanged(UriFragmentChangedEvent event) {
getMainWindow().showNotification(
- "Fragment now: " + event.getFragment());
+ "Fragment now: " + event.getUriFragment());
// try to change to view mapped by fragment string
- setView(event.getFragment());
+ setView(event.getUriFragment());
}
});
public void buttonClick(ClickEvent event) {
String viewName = tf.getValue().toString();
// fragmentChangedListener will change the view if possible
- event.getButton().getUI().getPage().setFragment(viewName);
+ event.getButton().getUI().getPage().setUriFragment(viewName);
}
});