/* (non-Javadoc) * @see PerspectiveMenu#run(IPerspectiveDescriptor) */ protected void run(IPerspectiveDescriptor desc) { // IPreferenceStore store = PrefUtil.getInternalPreferenceStore(); // int mode = store.getInt(IPreferenceConstants.OPEN_PERSP_MODE); int mode = IPreferenceConstants.OPM_ACTIVE_PAGE; IWorkbenchPage page = getWindow().getActivePage(); IPerspectiveDescriptor persp = null; if (page != null) { persp = page.getPerspective(); } // Only open a new window if user preference is set and the window // has an active perspective. if (IPreferenceConstants.OPM_NEW_WINDOW == mode && persp != null) { try { IWorkbench workbench = getWindow().getWorkbench(); IAdaptable input = ((Workbench) workbench).getDefaultPageInput(); workbench.openWorkbenchWindow(desc.getId(), input); } catch (WorkbenchException e) { handleWorkbenchException(e); } } else { if (page != null) { page.setPerspective(desc); } else { try { IWorkbench workbench = getWindow().getWorkbench(); IAdaptable input = ((Workbench) workbench).getDefaultPageInput(); getWindow().openPage(desc.getId(), input); } catch (WorkbenchException e) { handleWorkbenchException(e); } } } }
@Override public void widgetSelected(SelectionEvent e) { IPerspectiveRegistry perspectiveRegistry = PlatformUI.getWorkbench().getPerspectiveRegistry(); IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); activePage.setPerspective( perspectiveRegistry.findPerspectiveWithId(LiteratureReviewPhasesPerspective.ID)); LiteratureReviewPhasesView literatureReviewStudiesView = (LiteratureReviewPhasesView) ReviewerViewRegister.getView(LiteratureReviewPhasesView.ID); }
private static void replaceCurrentPerspective(IPerspectiveDescriptor persp) { // Get the active page. IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { // Set the perspective. page.setPerspective(persp); } } }
boolean openPerspective( final String perspId, final IAdaptable input, final IWorkbench workbench, final IPreferenceStore store, final ILog logger) { try { // Verify the requested perspective ID IPerspectiveRegistry reg = workbench.getPerspectiveRegistry(); IPerspectiveDescriptor perspective = reg.findPerspectiveWithId(perspId); if (perspective == null) { logger.log(statusFactory.error("Unable to open perspective: " + perspId)); return false; } // Get "Open Behavior" preference. String pref = store.getString(IWorkbenchPreferenceConstants.OPEN_NEW_PERSPECTIVE); // Implement open behavior. if (pref.equals(IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_WINDOW)) { workbench.openWorkbenchWindow(perspId, input); } else if (pref.equals(IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE)) { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); IWorkbenchPage activePage = window.getActivePage(); if (activePage != null) { activePage.setPerspective(perspective); } else { window.openPage(perspId, input); } } Shell shell = workbench.getActiveWorkbenchWindow().getShell(); shell.setMinimized(false); shell.forceActive(); logger.log(statusFactory.info("Opened perspective: " + perspId)); return true; } catch (WorkbenchException e) { logger.log(statusFactory.error("Error opening perspective: " + e.getMessage(), e)); return false; } }
@Test public void testFilter() throws CoreException { IPerspectiveDescriptor persDescription = PlatformUI.getWorkbench() .getPerspectiveRegistry() .findPerspectiveWithId(JavaUI.ID_PERSPECTIVE); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); page.setPerspective(persDescription); IViewPart arquilliaView = page.showView(ArquillianView.ID); try { assertTrue(arquilliaView instanceof CommonNavigator); PackageExplorerPart packageView = (PackageExplorerPart) page.showView(JavaUI.ID_PACKAGES); IProject project = getProject(TEST_PROJECT_NAME); packageView.selectAndReveal(project); CommonNavigator navigator = (CommonNavigator) arquilliaView; CommonViewer viewer = navigator.getCommonViewer(); TreeItem[] items = viewer.getTree().getItems(); assertTrue(items.length == 1); ViewerFilter[] filters = viewer.getFilters(); assertTrue(filters.length > 0); WorkingSetFilter activeFilter = null; List<ViewerFilter> newFilters = new ArrayList<ViewerFilter>(); int i = 0; for (ViewerFilter filter : filters) { if (!(filter instanceof ActiveProjectFilter)) { newFilters.add(filter); } } newFilters.add(new WorkingSetFilter()); viewer.setFilters(newFilters.toArray(new ViewerFilter[0])); items = viewer.getTree().getItems(); assertTrue("Invalid filter", items.length == 2); } finally { if (arquilliaView != null) { page.hideView(arquilliaView); } } }
public void notifyChanged(Notification notification) { super.notifyChanged(notification); /* * We create partOpened / partClosed events based on both MPartWidget * events. * * The initial MPartVisible events are sent early and don't have the * actual implementation included. The MPartWidget events are sent as a * final step of "part is created" and therefore we use it to create * partOpened events. When the part is closed the widget is set to null. */ if (MApplicationPackage.Literals.UI_ELEMENT__WIDGET.equals(notification.getFeature())) { if (notification.getEventType() != Notification.SET) return; if (notification.getOldValue() == notification.getNewValue()) return; // avoid extra notifications Object part = notification.getNotifier(); if (part instanceof MPart) { IWorkbenchPartReference ref = toPartRef((MPart) part); if (ref != null) { boolean isVisible = ((MPart) part).isVisible(); if (isVisible) { if (notification.getNewValue() == null) { /* * not sure if this is the right place to fix bug * 283922 but if there is no widget and * isVisible==true, we must be shutting down, and we * should not send partOpened notifications. */ return; } SaveablesList modelManager = (SaveablesList) ref.getPart(true).getSite().getService(ISaveablesLifecycleListener.class); modelManager.postOpen(ref.getPart(true)); partList.firePartOpened(ref); } } } return; } // Interpret E4 activation events: if (!MApplicationPackage.Literals.ELEMENT_CONTAINER__ACTIVE_CHILD.equals( notification.getFeature())) return; // at this time we only interpreting SET events if (notification.getEventType() != Notification.SET || notification.getEventType() != Notification.CREATE) return; // make sure something actually changed Object oldPart = notification.getOldValue(); Object newPart = notification.getNewValue(); // create 3.x visibility events if ((newPart != oldPart) && (oldPart instanceof MPart) && (newPart instanceof MPart)) changeVisibility((MPart) oldPart, (MPart) newPart); // create 3.x activation events final Object object = e4Context.get(IServiceConstants.ACTIVE_PART); if ((newPart != oldPart) && newPart instanceof MPerspective) { // let legacy Workbench know about perspective activation IWorkbenchPage page = (IWorkbenchPage) e4Context.get(IWorkbenchPage.class.getName()); if (page != null) { String id = ((MPerspective) newPart).getId(); IPerspectiveDescriptor[] descriptors = page.getOpenPerspectives(); for (IPerspectiveDescriptor desc : descriptors) { if (!id.equals(desc.getId())) continue; page.setPerspective(desc); } } } if (object instanceof MPart) { IWorkbenchPartReference ref = toPartRef((MPart) object); if (ref != null) { // set the Focus to the newly active part IWorkbenchPart part = ref.getPart(true); part.setFocus(); // Update the action bars SubActionBars bars = (SubActionBars) ((PartSite) part.getSite()).getActionBars(); bars.partChanged(part); partList.setActivePart(ref); if (ref instanceof IEditorReference) { IEditorReference editorReference = (IEditorReference) ref; partList.setActiveEditor(editorReference); final IEditorPart editor = editorReference.getEditor(true); e4Context.set(ISources.ACTIVE_EDITOR_NAME, editor); e4Context.set(ISources.ACTIVE_EDITOR_ID_NAME, editor.getSite().getId()); e4Context.set(ISources.ACTIVE_EDITOR_INPUT_NAME, editor.getEditorInput()); } } } else { partList.setActiveEditor(null); e4Context.set(ISources.ACTIVE_EDITOR_NAME, null); e4Context.set(ISources.ACTIVE_EDITOR_ID_NAME, null); e4Context.set(ISources.ACTIVE_EDITOR_INPUT_NAME, null); partList.setActivePart(null); } }