Java Code Examples for org.eclipse.ui.IWorkbench#showPerspective()

The following examples show how to use org.eclipse.ui.IWorkbench#showPerspective() . 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 File: RCPTestSetupHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Close all open windows, editors, perspectives. Open and reset default perspective.
 */
private static void resetWorkbench() {
    try {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        
        Shell activeShell = Display.getCurrent().getActiveShell();
        if (activeShell != null && activeShell != workbenchWindow.getShell()) {
            activeShell.close();
        }
        
        page.closeAllEditors(false);
        page.resetPerspective();
        
        String defaultPerspectiveId = workbench.getPerspectiveRegistry().getDefaultPerspective();
        workbench.showPerspective(defaultPerspectiveId, workbenchWindow);
        page.resetPerspective();
        
        page.showView("org.eclipse.ui.internal.introview");
    } catch (WorkbenchException e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: OpenJavaBrowsingPerspectiveAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
	IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
	IWorkbenchPage page= window.getActivePage();
	IAdaptable input;
	if (page != null)
		input= page.getInput();
	else
		input= ResourcesPlugin.getWorkspace().getRoot();
	try {
		workbench.showPerspective(JavaUI.ID_BROWSING_PERSPECTIVE, window, input);
	} catch (WorkbenchException e) {
		ExceptionHandler.handle(e, window.getShell(),
			ActionMessages.OpenJavaBrowsingPerspectiveAction_dialog_title,
			ActionMessages.OpenJavaBrowsingPerspectiveAction_error_open_failed);
	}
}
 
Example 3
Source File: OpenJavaPerspectiveAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
	IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
	IWorkbenchPage page= window.getActivePage();
	IAdaptable input;
	if (page != null)
		input= page.getInput();
	else
		input= ResourcesPlugin.getWorkspace().getRoot();
	try {
		workbench.showPerspective(JavaUI.ID_PERSPECTIVE, window, input);
	} catch (WorkbenchException e) {
		ExceptionHandler.handle(e, window.getShell(),
			ActionMessages.OpenJavaPerspectiveAction_dialog_title,
			ActionMessages.OpenJavaPerspectiveAction_error_open_failed);
	}
}
 
Example 4
Source File: OpenTypeHierarchyUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static TypeHierarchyViewPart openInPerspective(IWorkbenchWindow window, IJavaElement[] input) throws WorkbenchException, JavaModelException {
	IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
	IJavaElement perspectiveInput= input.length == 1 ? input[0] : null;

	if (perspectiveInput != null && input[0] instanceof IMember) {
		if (input[0].getElementType() != IJavaElement.TYPE) {
			perspectiveInput= ((IMember)input[0]).getDeclaringType();
		} else {
			perspectiveInput= input[0];
		}
	}
	IWorkbenchPage page= workbench.showPerspective(JavaUI.ID_HIERARCHYPERSPECTIVE, window, perspectiveInput);

	TypeHierarchyViewPart part= (TypeHierarchyViewPart) page.findView(JavaUI.ID_TYPE_HIERARCHY);
	if (part != null) {
		part.clearNeededRefresh(); // avoid refresh of old hierarchy on 'becomes visible'
	}
	part= (TypeHierarchyViewPart) page.showView(JavaUI.ID_TYPE_HIERARCHY);
	part.setInputElements(input);
	if (perspectiveInput != null) {
		if (page.getEditorReferences().length == 0) {
			JavaUI.openInEditor(input[0], false, false); // only open when the perspective has been created
		}
	}
	return part;
}
 
Example 5
Source File: GetStartedAction.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run() {
	// Close the Eclipse welcome page
	IIntroManager manager = PlatformUI.getWorkbench().getIntroManager();
	IIntroPart introPart = manager.getIntro();
	if (introPart != null) {
		manager.closeIntro(introPart);
	}
	
	// Open the J2EE perspective
	try {
		IWorkbench workbench = PlatformUI.getWorkbench();
		workbench.showPerspective("org.eclipse.jst.j2ee.J2EEPerspective", workbench.getActiveWorkbenchWindow());
	} catch (Exception e) {
		Logger.logError("An error occurred trying to open the J2EE perspective", e);
	}

	// Open the Codewind welcome page
	IEditorPart part = OpenWelcomePageAction.openWelcomePage();

	// Open the Codewind Explorer view
	ViewHelper.openCodewindExplorerViewNoExec();

	// Make the welcome page the focus
	if (part != null) {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (window != null) {
			IWorkbenchPage page = window.getActivePage();
			if (page != null) {
				page.activate(part);
			}
		}
	}
}
 
Example 6
Source File: PerspectiveUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static void promptAndOpenPerspective(IWorkbench workbench, String perspectiveId, String title, String message) throws WorkbenchException {
    IWorkbenchWindow activeWindow = workbench.getActiveWorkbenchWindow();

    if (!perspectiveId.equals(activeWindow.getActivePage().getPerspective().getId())) {
        if (MessageDialog.openConfirm(activeWindow.getShell(), title, message)) {
            workbench.showPerspective(perspectiveId, activeWindow);
        }
    }
}
 
Example 7
Source File: UIHelper.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Switch current perspective
 * 
 * @param perspectiveId
 * @return
 */
public static IWorkbenchPage switchPerspective(String perspectiveId) {
	Assert.isNotNull(perspectiveId, "PerspectiveId is null");
	IWorkbench workbench = PlatformUI.getWorkbench();
	IWorkbenchWindow window = getActiveWindow();
	Assert.isNotNull(workbench, "Workbench is null");
	Assert.isNotNull(window, "Window is null");
	try {
		IWorkbenchPage page = workbench.showPerspective(perspectiveId, window);

		// show intro
		if (InitialPerspective.ID.equals(perspectiveId) && workbench.getIntroManager().hasIntro()) {
			page.resetPerspective();
			// We are no longer showing the Intro view. The following will
			// probably
			// be replaced by something that shows the view we want. 09 Oct
			// 2009
			// workbench.getIntroManager().showIntro(window, false);
			openView(ToolboxWelcomeView.ID);

		}

		return page;
	} catch (WorkbenchException e) {
		Activator.getDefault().logError("Error switching a perspective to " + perspectiveId, e);
	}

	return null;
}