/** Handles change events from {@link History}. */ @Override public void onValueChange(final ValueChangeEvent<String> event) { if (locked) { defferedNavigation = new Command() { @Override public void execute() { onValueChange(event); } }; return; } if (!getLock()) { return; } String historyToken = event.getValue(); try { if (historyToken.trim().equals("")) { unlock(); revealDefaultPlace(); } else { historyToken = modifyNameToken(historyToken); placeHierarchy = tokenFormatter.toPlaceRequestHierarchy(historyToken); setPreviousRequestUrl(getCurrentPlaceRequest()); doRevealPlace(getCurrentPlaceRequest(), true); } } catch (TokenFormatException e) { unlock(); error(historyToken); NavigationEvent.fire(this, null); } }
@Override public String buildRelativeHistoryToken(int level) { List<PlaceRequest> placeHierarchyCopy = truncatePlaceHierarchy(level); if (placeHierarchyCopy.size() == 0) { return ""; } return tokenFormatter.toHistoryToken(placeHierarchyCopy); }
@Override public void updateHistory(PlaceRequest request, boolean updateBrowserUrl) { try { // Make sure the request match assert request.hasSameNameToken(getCurrentPlaceRequest()) : "Internal error, PlaceRequest passed to updateHistory doesn't match the tail of the place hierarchy."; placeHierarchy.set(placeHierarchy.size() - 1, request); if (updateBrowserUrl) { String historyToken = tokenFormatter.toHistoryToken(placeHierarchy); String browserHistoryToken = getBrowserHistoryToken(); if (browserHistoryToken == null || !browserHistoryToken.equals(historyToken)) { setBrowserHistoryToken(historyToken, false); } saveHistoryToken(historyToken); } } catch (TokenFormatException e) { // Do nothing. } }
@Override public void execute() { String initialToken = History.getToken(); if (!initialToken.isEmpty() && !isBlackListed(initialToken)) { List<PlaceRequest> hierarchy = formatter.toPlaceRequestHierarchy(initialToken); final PlaceRequest placeRequest = hierarchy.get(hierarchy.size() - 1); Scheduler.get() .scheduleDeferred( new Scheduler.ScheduledCommand() { @Override public void execute() { placeManager.revealPlace(placeRequest, true); } }); bootstrapContext.setInitialPlace(placeRequest.getNameToken()); } else { placeManager.revealDefaultPlace(); } }
@Override public String buildHistoryToken(PlaceRequest request) { return tokenFormatter.toPlaceToken(request); }
@Override public String buildRelativeHistoryToken(PlaceRequest request, int level) { List<PlaceRequest> placeHierarchyCopy = truncatePlaceHierarchy(level); placeHierarchyCopy.add(request); return tokenFormatter.toHistoryToken(placeHierarchyCopy); }