@Test public void placeManagerRevealRelativePlaceWithZeroLevelShouldGoToDefaultPlace() { // Given doAnswer( invocation -> { Object[] args = invocation.getArguments(); deferredCommandManager.addCommand( () -> placeManager.updateHistory( new PlaceRequest.Builder().nameToken("defaultPlace").build(), true)); ((PlaceRequestInternalEvent) args[0]).setHandled(); return null; }) .when(eventBus) .fireEventFromSource(isA(PlaceRequestInternalEvent.class), eq(placeManager)); // When placeManager.revealRelativePlace(0); deferredCommandManager.pump(); // Then PlaceRequest placeRequest = placeManager.getCurrentPlaceRequest(); assertEquals("defaultPlace", placeRequest.getNameToken()); assertEquals(0, placeRequest.getParameterNames().size()); verify(gwtWindowMethods).setBrowserHistoryToken(any(String.class), eq(false)); }
@Test public void placeManagerUserCallUpdateHistoryWhenRevealingPlace() { // Given doAnswer( invocation -> { Object[] args = invocation.getArguments(); deferredCommandManager.addCommand( () -> placeManager.updateHistory( new PlaceRequest.Builder() .nameToken("dummyNameToken") .with("dummyParam", "dummyValue") .build(), true)); ((PlaceRequestInternalEvent) args[0]).setHandled(); return null; }) .when(eventBus) .fireEventFromSource(isA(PlaceRequestInternalEvent.class), eq(placeManager)); // When placeManager.revealPlace(new PlaceRequest.Builder().nameToken("dummyNameToken").build()); deferredCommandManager.pump(); // Then PlaceRequest placeRequest = placeManager.getCurrentPlaceRequest(); assertEquals("dummyNameToken", placeRequest.getNameToken()); assertEquals(1, placeRequest.getParameterNames().size()); assertEquals("dummyValue", placeRequest.getParameter("dummyParam", null)); verify(gwtWindowMethods).setBrowserHistoryToken(any(String.class), eq(false)); }
@Override public void manualReveal(Presenter<?, ?> presenter) { // Reveal only if there are no pending navigation requests if (!placeManager.hasPendingNavigation()) { if (!presenter.isVisible()) { // This will trigger a reset in due time presenter.forceReveal(); } else { // We have to do the reset ourselves ResetPresentersEvent.fire(this); } } placeManager.unlock(); }
// Save the current state of the Workbench private void saveState() { onClose(); final PerspectiveDefinition perspective = panelManager.getPerspective(); if (perspective == null) { // On startup the Workbench has not been set to contain a perspective loadState(); } else if (perspective.isTransient()) { // Transient Perspectives are not saved placeManager.closeAllPlaces(); loadState(); } else { // Save first, then close all places before loading persisted state wbServices .call( new RemoteCallback<Void>() { @Override public void callback(Void response) { placeManager.closeAllPlaces(); loadState(); } }) .save(perspective); } }
private void addChildren(final PanelDefinition panel) { Set<PartDefinition> parts = panel.getParts(); for (PartDefinition part : parts) { final PlaceRequest place = clonePlaceAndMergeParameters(part.getPlace()); part.setPlace(place); placeManager.goTo(part, panel); } buildPerspective(panel); }
/** * Tracks open/closed lifecycle. Subclasses should always call <tt>super.onOpen()</tt> in methods * that override this one. */ @Override public void onOpen() { if (this.place == null) { throw new IllegalStateException("Activity " + this + " has not been started"); } if (open) { throw new IllegalStateException("Activity " + this + " already open"); } open = true; placeManager.executeOnOpenCallback(this.place); }
// Initialise Workbench state to that of the provided perspective private void initialisePerspective(final PerspectiveDefinition perspective) { panelManager.setPerspective(perspective); Set<PartDefinition> parts = panelManager.getRoot().getParts(); for (PartDefinition part : parts) { final PlaceRequest place = clonePlaceAndMergeParameters(part.getPlace()); part.setPlace(place); placeManager.goTo(part, panelManager.getRoot()); } buildPerspective(panelManager.getRoot()); onOpen(); }
@Override public void manualRevealFailed() { placeManager.unlock(); }