public List<PerspectiveActivity> getPerspectiveActivities() { final Set<PerspectiveActivity> activities = activityManager.getActivities(PerspectiveActivity.class); List<PerspectiveActivity> sortedActivitiesForDisplay = new ArrayList<>(activities); Collections.sort(sortedActivitiesForDisplay, (o1, o2) -> o1.getDefaultPerspectiveLayout().getName().compareTo(o2.getDefaultPerspectiveLayout().getName())); return sortedActivitiesForDisplay; }
public ResourceType getResourceType(String activityId) { Activity activity = activityManager.getActivity(new DefaultPlaceRequest(activityId), false); if (activity != null) { if (activity instanceof PerspectiveActivity) { return PERSPECTIVE; } if (activity instanceof WorkbenchScreenActivity) { return SCREEN; } if (activity instanceof WorkbenchEditorActivity) { return EDITOR; } if (activity instanceof SplashScreenActivity) { return EDITOR; } if (activity instanceof PopupActivity) { return POPUP; } } return ResourceType.UNKNOWN; } }
@Test public void testProperSplashScreenShutdownOnPartClose() throws Exception { PlaceRequest oz = new DefaultPlaceRequest("oz"); WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(oz)).thenReturn(singleton((Activity) ozActivity)); final SplashScreenActivity lollipopGuildActivity = mock(SplashScreenActivity.class); when(lollipopGuildActivity.isType(ActivityResourceType.SPLASH.name())).thenReturn(true); when(activityManager.getSplashScreenInterceptor(oz)).thenReturn(lollipopGuildActivity); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); placeManager.goTo(oz, (PanelDefinition) null); placeManager.closePlace(oz); assertTrue(placeManager.getActiveSplashScreens().isEmpty()); verify(lollipopGuildActivity).closeIfOpen(); // splash screens are Application Scoped, but we still "destroy" them (activity manager will call their onShutdown) verify(activityManager).destroyActivity(lollipopGuildActivity); }
/** * Finds and opens the splash screen for the given place, if such a splash screen exists. The splash screen might * not actually display; each splash screen keeps track of its own preference setting for whether or not the user * wants to see it. * <p/> * Whether or not it chooses to display itself, the splash screen will be recorded in * {@link #availableSplashScreens} for lookup (for example, see {@link SplashScreenMenuPresenter}) and later disposal. * Internally, this method should be called every time any part or perspective is added to the workbench, and called * again when that part or perspective is removed. * @param place the place that has just been added to the workbench. Must not be null. */ private void addSplashScreenFor(final PlaceRequest place) { final SplashScreenActivity splashScreen = activityManager.getSplashScreenInterceptor(place); if (splashScreen != null) { availableSplashScreens.put(place.getIdentifier(), splashScreen); try { splashScreen.onOpen(); } catch (Exception ex) { availableSplashScreens.remove(place.getIdentifier()); lifecycleErrorHandler.handle(splashScreen, LifecyclePhase.OPEN, ex); activityManager.destroyActivity(splashScreen); return; } } newSplashScreenActiveEvent.fire(new NewSplashScreenActiveEvent()); }
@Test public void testPartLaunchWithSplashScreen() throws Exception { PlaceRequest oz = new DefaultPlaceRequest("oz"); WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(oz)).thenReturn(singleton((Activity) ozActivity)); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); final SplashScreenActivity lollipopGuildActivity = mock(SplashScreenActivity.class); when(activityManager.getSplashScreenInterceptor(oz)).thenReturn(lollipopGuildActivity); when(lollipopGuildActivity.isType(ActivityResourceType.SPLASH.name())).thenReturn(true); placeManager.goTo(oz, (PanelDefinition) null); assertTrue(placeManager.getActiveSplashScreens().contains(lollipopGuildActivity)); verify(lollipopGuildActivity, never()).onStartup(any(PlaceRequest.class)); InOrder inOrder = inOrder(lollipopGuildActivity, newSplashScreenActiveEvent); inOrder.verify(lollipopGuildActivity).onOpen(); inOrder.verify(newSplashScreenActiveEvent).fire(any(NewSplashScreenActiveEvent.class)); }
@Test public void testSwitchingPerspectives() throws Exception { PerspectiveActivity ozPerspectiveActivity = mock(PerspectiveActivity.class); PlaceRequest ozPerspectivePlace = new DefaultPlaceRequest("oz_perspective"); PerspectiveDefinition ozPerspectiveDef = new PerspectiveDefinitionImpl(); when(activityManager.getActivities(ozPerspectivePlace)) .thenReturn(singleton((Activity) ozPerspectiveActivity)); when(ozPerspectiveActivity.getDefaultPerspectiveLayout()).thenReturn(ozPerspectiveDef); when(ozPerspectiveActivity.getPlace()).thenReturn(ozPerspectivePlace); when(ozPerspectiveActivity.isType(ActivityResourceType.PERSPECTIVE.name())).thenReturn(true); when(kansasActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); // we'll pretend we started in kansas PerspectiveActivity kansasPerspectiveActivity = mock(PerspectiveActivity.class); when(perspectiveManager.getCurrentPerspective()).thenReturn(kansasPerspectiveActivity); placeManager.goTo(ozPerspectivePlace); // verify proper shutdown of kansasPerspective and its contents InOrder inOrder = inOrder(activityManager, kansasPerspectiveActivity, kansasActivity, workbenchLayout); // shut down the screens first inOrder.verify(kansasActivity).onClose(); inOrder.verify(activityManager).destroyActivity(kansasActivity); // then the perspective inOrder.verify(kansasPerspectiveActivity).onClose(); inOrder.verify(activityManager).destroyActivity(kansasPerspectiveActivity); inOrder.verify(workbenchLayout).onResize(); }
final Set<Activity> activities = activityManager.getActivities(resolvedPlaceRequest); resolvedPlaceRequest.getIdentifier()); if (activityManager.containsActivity(notFoundPopup)) { return new ResolvedRequest(null, notFoundPopup);
/** * Closes the splash screen associated with the given place request, if any. Internally, this method should be * invoked every time a part or perspective is removed from the workbench (cleaning up after the corresponding * earlier call to {@link #addSplashScreenFor(PlaceRequest)}. * @param place the place whose opening may have triggered a splash screen to launch. Must not be null. */ private void closeSplashScreen(final PlaceRequest place) { SplashScreenActivity splashScreenActivity = availableSplashScreens.remove(place.getIdentifier()); if (splashScreenActivity != null) { try { splashScreenActivity.closeIfOpen(); } catch (Exception ex) { lifecycleErrorHandler.handle(splashScreenActivity, LifecyclePhase.CLOSE, ex); } activityManager.destroyActivity(splashScreenActivity); newSplashScreenActiveEvent.fire(new NewSplashScreenActiveEvent()); } }
@Test public void testSwitchingPerspectives() throws Exception { PerspectiveActivity ozPerspectiveActivity = mock(PerspectiveActivity.class); PlaceRequest ozPerspectivePlace = new DefaultPlaceRequest("oz_perspective"); PerspectiveDefinition ozPerspectiveDef = new PerspectiveDefinitionImpl(); when(activityManager.getActivities(ozPerspectivePlace)) .thenReturn(singleton((Activity) ozPerspectiveActivity)); when(ozPerspectiveActivity.getDefaultPerspectiveLayout()).thenReturn(ozPerspectiveDef); when(ozPerspectiveActivity.getPlace()).thenReturn(ozPerspectivePlace); when(ozPerspectiveActivity.isType(ActivityResourceType.PERSPECTIVE.name())).thenReturn(true); when(kansasActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); // we'll pretend we started in kansas PerspectiveActivity kansasPerspectiveActivity = mock(PerspectiveActivity.class); when(perspectiveManager.getCurrentPerspective()).thenReturn(kansasPerspectiveActivity); placeManager.goTo(ozPerspectivePlace); // verify proper shutdown of kansasPerspective and its contents InOrder inOrder = inOrder(activityManager, kansasPerspectiveActivity, kansasActivity, workbenchLayout); // shut down the screens first inOrder.verify(kansasActivity).onClose(); inOrder.verify(activityManager).destroyActivity(kansasActivity); // then the perspective inOrder.verify(kansasPerspectiveActivity).onClose(); inOrder.verify(activityManager).destroyActivity(kansasPerspectiveActivity); inOrder.verify(workbenchLayout).onResize(); }
@Test public void testPartLaunchWithSplashScreen() throws Exception { PlaceRequest oz = new DefaultPlaceRequest("oz"); WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(oz)).thenReturn(singleton((Activity) ozActivity)); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); final SplashScreenActivity lollipopGuildActivity = mock(SplashScreenActivity.class); when(activityManager.getSplashScreenInterceptor(oz)).thenReturn(lollipopGuildActivity); when(lollipopGuildActivity.isType(ActivityResourceType.SPLASH.name())).thenReturn(true); placeManager.goTo(oz, (PanelDefinition) null); assertTrue(placeManager.getActiveSplashScreens().contains(lollipopGuildActivity)); verify(lollipopGuildActivity, never()).onStartup(any(PlaceRequest.class)); InOrder inOrder = inOrder(lollipopGuildActivity, newSplashScreenActiveEvent); inOrder.verify(lollipopGuildActivity).onOpen(); inOrder.verify(newSplashScreenActiveEvent).fire(any(NewSplashScreenActiveEvent.class)); }
activityManager.destroyActivity(activity); return;
protected void addPerspective(String perspectiveId, String optionLabel, boolean selected) { if (hasAccessToPerspective(perspectiveId) && !activityManager.getActivities(new DefaultPlaceRequest(perspectiveId)).isEmpty()) { view.addOption(optionLabel, perspectiveId, selected); } }
@Test public void testProperSplashScreenShutdownOnPartClose() throws Exception { PlaceRequest oz = new DefaultPlaceRequest("oz"); WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(oz)).thenReturn(singleton((Activity) ozActivity)); final SplashScreenActivity lollipopGuildActivity = mock(SplashScreenActivity.class); when(lollipopGuildActivity.isType(ActivityResourceType.SPLASH.name())).thenReturn(true); when(activityManager.getSplashScreenInterceptor(oz)).thenReturn(lollipopGuildActivity); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); placeManager.goTo(oz, (PanelDefinition) null); placeManager.closePlace(oz); assertTrue(placeManager.getActiveSplashScreens().isEmpty()); verify(lollipopGuildActivity).closeIfOpen(); // splash screens are Application Scoped, but we still "destroy" them (activity manager will call their onShutdown) verify(activityManager).destroyActivity(lollipopGuildActivity); }
PerspectiveDefinition ozPerspectiveDef = new PerspectiveDefinitionImpl(); when(activityManager.getActivities(ozPerspectivePlace)) .thenReturn(singleton((Activity) ozPerspectiveActivity)); when(ozPerspectiveActivity.getDefaultPerspectiveLayout()).thenReturn(ozPerspectiveDef); inOrder.verify(activityManager, never()).destroyActivity(kansasActivity); inOrder.verify(activityManager, never()).destroyActivity(kansasPerspectiveActivity); inOrder.verify(workbenchLayout, never()).onResize();
public ResourceType getResourceType(String activityId) { Activity activity = activityManager.getActivity(new DefaultPlaceRequest(activityId), false); if (activity != null) { if (activity instanceof PerspectiveActivity) { return PERSPECTIVE; } if (activity instanceof WorkbenchScreenActivity) { return SCREEN; } if (activity instanceof WorkbenchEditorActivity) { return EDITOR; } if (activity instanceof SplashScreenActivity) { return EDITOR; } if (activity instanceof PopupActivity) { return POPUP; } } return ResourceType.UNKNOWN; } }
SimpleWorkbenchPanelPresenter.class.getName()); when(perspectiveActivity.getDefaultPerspectiveLayout()).thenReturn(perspectiveDef); when(activityManager.getActivities(perspectivePlace)) .thenReturn(singleton((Activity) perspectiveActivity)); when(activityManager.getSplashScreenInterceptor(perspectivePlace)).thenReturn(splashScreenActivity); when(perspectiveActivity.isType(ActivityResourceType.PERSPECTIVE.name())).thenReturn(true); when(splashScreenActivity.isType(ActivityResourceType.SPLASH.name())).thenReturn(true);
private void switchToPerspective(final PlaceRequest place, final PerspectiveActivity newPerspectiveActivity, final ParameterizedCommand<PerspectiveDefinition> closeOldPerspectiveOpenPartsAndExecuteChainedCallback) { if (closeAllCurrentPanels()) { closeAllSplashScreens(); addSplashScreenFor(place); perspectiveManager.switchToPerspective(place, newPerspectiveActivity, closeOldPerspectiveOpenPartsAndExecuteChainedCallback); } else { // some panels didn't want to close, so not going to launch new perspective. clean up its activity. try { newPerspectiveActivity.onClose(); } catch (Exception ex) { lifecycleErrorHandler.handle(newPerspectiveActivity, LifecyclePhase.OPEN, ex); } existingWorkbenchActivities.remove(newPerspectiveActivity.getPlace()); activityManager.destroyActivity(newPerspectiveActivity); } }
private WorkbenchScreenActivity createWorkbenchScreenActivity(final PlaceRequest emeraldCityPlace) { WorkbenchScreenActivity emeraldCityActivity = mock(WorkbenchScreenActivity.class); when(emeraldCityActivity.onMayClose()).thenReturn(true); when(emeraldCityActivity.preferredWidth()).thenReturn(555); when(emeraldCityActivity.preferredHeight()).thenReturn(-1); when(emeraldCityActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); when(activityManager.getActivities(emeraldCityPlace)) .thenReturn(singleton((Activity) emeraldCityActivity)); return emeraldCityActivity; }
when(perspectiveActivity.getDefaultPerspectiveLayout()).thenReturn(perspectiveDef); when(perspectiveActivity.isType(ActivityResourceType.PERSPECTIVE.name())).thenReturn(true); when(activityManager.getActivities(perspectivePlace)) .thenReturn(singleton((Activity) perspectiveActivity)); when(activityManager.getSplashScreenInterceptor(perspectivePlace)).thenReturn(splashScreenActivity1); when(splashScreenActivity1.isType(ActivityResourceType.SPLASH.name())).thenReturn(true); when(activityManager.getSplashScreenInterceptor(kansas)).thenReturn(splashScreenActivity2); when(activityManager.getActivities(kansas)).thenReturn(singleton((Activity) kansasActivity)); when(splashScreenActivity2.isType(ActivityResourceType.SPLASH.name())).thenReturn(true); when(kansasActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); when(otherPerspectiveActivity.getDefaultPerspectiveLayout()).thenReturn(otherPerspectiveDef); when(otherPerspectiveActivity.isType(ActivityResourceType.PERSPECTIVE.name())).thenReturn(true); when(activityManager.getActivities(otherPerspectivePlace)) .thenReturn(singleton((Activity) otherPerspectiveActivity)); verify(activityManager).destroyActivity(splashScreenActivity1); verify(activityManager).destroyActivity(splashScreenActivity2);
PerspectiveDefinition ozPerspectiveDef = new PerspectiveDefinitionImpl(); when(activityManager.getActivities(ozPerspectivePlace)) .thenReturn(singleton((Activity) ozPerspectiveActivity)); when(ozPerspectiveActivity.getDefaultPerspectiveLayout()).thenReturn(ozPerspectiveDef); inOrder.verify(activityManager, never()).destroyActivity(kansasActivity); inOrder.verify(activityManager, never()).destroyActivity(kansasPerspectiveActivity); inOrder.verify(workbenchLayout, never()).onResize();