Java Code Examples for com.google.gwt.user.client.History#addValueChangeHandler()

The following examples show how to use com.google.gwt.user.client.History#addValueChangeHandler() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: caja   File: Playground.java    License: Apache License 2.0 6 votes vote down vote up
public void onModuleLoad() {
  gui = new PlaygroundView(this);
  gui.setLoading(true);
  cajolingService.getBuildInfo(new AsyncCallback<String>() {
    public void onFailure(Throwable caught) {
      gui.setLoading(false);
      gui.addRuntimeMessage(caught.getMessage());
      gui.setVersion("Unknown");
    }

    public void onSuccess(String result) {
      gui.setLoading(false);
      gui.setVersion(result);
    }
  });
  History.addValueChangeHandler(this);
  History.fireCurrentHistoryState();
}
 
Example 2
Source Project: swellrt   File: HistoryChangeListener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Commonly we start to listen history changes when webclient starts calling this
 * method. If you are using wave client integrated with other different GWT application
 * and with a different History management, you can avoid to use this and just
 * call to the {@link WaveSelectionEvent} events (for example) or other uses.
 */
public static void init() {
  History.addValueChangeHandler(new ValueChangeHandler<String>() {
    @Override
    public void onValueChange(ValueChangeEvent<String> event) {
      String encodedToken = event.getValue();
      if (encodedToken == null || encodedToken.length() == 0) {
        return;
      }
      WaveRef waveRef;
      try {
        waveRef = GwtWaverefEncoder.decodeWaveRefFromPath(encodedToken);
      } catch (InvalidWaveRefException e) {
        LOG.info("History token contains invalid path: " + encodedToken);
        return;
      }
      LOG.info("Changing selected wave based on history event to " + waveRef.toString());
      ClientEvents.get().fireEvent(new WaveSelectionEvent(waveRef));
    }
  });
}
 
Example 3
@Override
public void registerAutoHider(final AutoHider autoHider) {
  autoHider.setRegistered(true);
  autoHiders.add(autoHider);

  if (eventPreviewRegistration == null) {
    eventPreviewRegistration = Event.addNativePreviewHandler(this);
  }

  if (onResizeRegistration == null) {
    onResizeRegistration = Window.addResizeHandler(this);
  }

  if (onHistoryRegistration == null) {
    onHistoryRegistration = History.addValueChangeHandler(this);
  }
}
 
Example 4
/**
 * Commonly we start to listen history changes when webclient starts calling this
 * method. If you are using wave client integrated with other different GWT application
 * and with a different History management, you can avoid to use this and just
 * call to the {@link WaveSelectionEvent} events (for example) or other uses.
 */
public static void init() {
  History.addValueChangeHandler(new ValueChangeHandler<String>() {
    @Override
    public void onValueChange(ValueChangeEvent<String> event) {
      String encodedToken = event.getValue();
      if (encodedToken == null || encodedToken.length() == 0) {
        return;
      }
      WaveRef waveRef;
      try {
        waveRef = GwtWaverefEncoder.decodeWaveRefFromPath(encodedToken);
      } catch (InvalidWaveRefException e) {
        LOG.info("History token contains invalid path: " + encodedToken);
        return;
      }
      LOG.info("Changing selected wave based on history event to " + waveRef.toString());
      ClientEvents.get().fireEvent(new WaveSelectionEvent(waveRef));
    }
  });
}
 
Example 5
@Override
public void registerAutoHider(final AutoHider autoHider) {
  autoHider.setRegistered(true);
  autoHiders.add(autoHider);

  if (eventPreviewRegistration == null) {
    eventPreviewRegistration = Event.addNativePreviewHandler(this);
  }

  if (onResizeRegistration == null) {
    onResizeRegistration = Window.addResizeHandler(this);
  }

  if (onHistoryRegistration == null) {
    onHistoryRegistration = History.addValueChangeHandler(this);
  }
}
 
Example 6
Source Project: core   File: Header.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Inject
public Header(final FeatureSet featureSet, final ToplevelTabs toplevelTabs, MessageCenter messageCenter,
              ProductConfig productConfig, BootstrapContext bootstrap, PlaceManager placeManager,
              Harvest harvest, Index index, PerspectiveStore perspectiveStore) {
    this.featureSet = featureSet;
    this.toplevelTabs = toplevelTabs;
    this.messageCenter = messageCenter;
    this.productConfig = productConfig;
    this.bootstrap = bootstrap;
    this.placeManager = placeManager;
    this.harvest = harvest;
    this.index = index;
    this.perspectiveStore = perspectiveStore;
    History.addValueChangeHandler(this);

    placeManager.getEventBus().addHandler(BreadcrumbEvent.TYPE, this);
}
 
Example 7
private void setupHistory() {
	History.newItem(HISTORY_MAIN);

	// Add history listener
	History.addValueChangeHandler(new ValueChangeHandler<String>() {
		@Override
		public void onValueChange(ValueChangeEvent<String> event) {
			String token = event.getValue();
			if (!token.equals(HISTORY_MAIN)) {
				History.newItem(HISTORY_MAIN);
			}
		}
	});
}
 
Example 8
Source Project: cuba   File: HistoryGwtApi.java    License: Apache License 2.0 5 votes vote down vote up
protected void initHandler() {
    handlerRegistration = History.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String historyToken = event.getValue();
            if (isForward) {
                isForward = false;
                // here we assume that "forward" action was performed
                // and if current history token equals to TOP_HISTORY_TOKEN
                // then this is true, otherwise we ignore
                if (TOP_HISTORY_TOKEN.equals(historyToken)) {
                    handleHistoryStep();
                }
            } else {
                if (!TOP_HISTORY_TOKEN.equals(historyToken)) {
                    // if current history token equals to previous history token
                    // then we assume that "back" action was performed
                    if (previousHistoryToken.equals(historyToken)) {
                        isForward = true;
                    } else {
                        // otherwise we assume that some handmade token was processed
                        // and replace it with PREVIOUS_HISTORY_TOKEN
                        previousHistoryToken = historyToken;
                        History.newItem(PREVIOUS_HISTORY_TOKEN);
                    }
                }
                // we always must have TOP_HISTORY_TOKEN on top of history stack
                // if it is, then History will ignore the call of newItem method.
                History.newItem(TOP_HISTORY_TOKEN);
            }
        }
    });
    if (isFireHistoryState)
        History.fireCurrentHistoryState();
}
 
Example 9
Source Project: unitime   File: UniTimeBack.java    License: Apache License 2.0 5 votes vote down vote up
public UniTimeBack() {
	History.addValueChangeHandler(new ValueChangeHandler<String>() {
		@Override
		public void onValueChange(ValueChangeEvent<String> event) {
			if (event.getValue() == null || event.getValue().isEmpty() || "back".equals(event.getValue())) {
				open(GWT.getHostPageBaseURL() + "back.do?uri=" + iBackUrl);
			} else {
				String uri = token2uri(event.getValue().replace("%20", " "));
				if (uri != null)
					open(GWT.getHostPageBaseURL() + "back.do?uri=" + uri);
			}
		}
	});
}
 
Example 10
Source Project: blog   File: ToDoPresenter.java    License: MIT License 5 votes vote down vote up
/**
 * Set up the history changed handler, which provides routing.
 */
private void setupHistoryHandler() {
	History.addValueChangeHandler(new ValueChangeHandler<String>() {
		public void onValueChange(ValueChangeEvent<String> event) {
			String historyToken = event.getValue();
			routing = parseRoutingToken(historyToken);
			view.setRouting(routing);
			updateFilteredList();
		}
	});
}
 
Example 11
Source Project: shortyz   File: Game.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Inject
public Game(RootPanel rootPanel, PuzzleServiceProxy service,
    Resources resources, final PuzzleListView plv, Renderer renderer) {
    this.service = service;
    this.plv = plv;
    this.renderer = renderer;
    this.css = resources.css();

    History.newItem("list", false);
    History.addValueChangeHandler(new ValueChangeHandler<String>() {
            @Override
            public void onValueChange(ValueChangeEvent<String> event) {
                if (event.getValue().equals("list")) {
                    if (closingRegistration != null) {
                        closingRegistration.removeHandler();
                        closingRegistration = null;
                    }

                    if (autoSaveTimer != null) {
                        autoSaveTimer.cancel();
                        autoSaveTimer.run();
                        autoSaveTimer = null;
                    }

                    mainPanel.setWidget(plv);
                    keyboardIntercept.removeKeyboardListener(l);

                    getDisplayChangeListener().onDisplayChange();
                } else if (event.getValue().startsWith("play=")) {
                    Long id = Long.parseLong(event.getValue().split("=")[1]);
                    loadPuzzle(id);
                }
            }
        });
    verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    verticalPanel.setWidth("100%");
    StyleInjector.inject(resources.css().getText());
    keyboardIntercept.setWidth("1px");
    keyboardIntercept.setHeight("1px");
    keyboardIntercept.setStyleName(css.keyboardIntercept());
    rootPanel.add(keyboardIntercept);

    verticalPanel.add(status);
    verticalPanel.setCellHorizontalAlignment(status,
        HasHorizontalAlignment.ALIGN_CENTER);
    verticalPanel.add(mainPanel);
    verticalPanel.setCellHorizontalAlignment(mainPanel,
        HasHorizontalAlignment.ALIGN_CENTER);
    verticalPanel.add(below);
    display.add(verticalPanel);
    display.setWidth("97%");
    rootPanel.add(display);
}
 
Example 12
Source Project: mvp4g   File: DefaultHistoryProxy.java    License: Apache License 2.0 4 votes vote down vote up
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler) {
  return History.addValueChangeHandler(handler);
}