Java Code Examples for org.eclipse.ui.IWorkbenchPage#getPerspective()

The following examples show how to use org.eclipse.ui.IWorkbenchPage#getPerspective() . 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: UIHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Closes all windows with a perspective
 * 
 * @param perspectiveId
 *            a perspective Id pointing the perspective
 */
public static void closeWindow(String perspectiveId) {
	IWorkbench workbench = Activator.getDefault().getWorkbench();
	// hide intro
	if (InitialPerspective.ID.equals(perspectiveId)) {
		workbench.getIntroManager().closeIntro(workbench.getIntroManager().getIntro());
	}

	IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();

	// closing the perspective opened in a window
	for (int i = 0; i < windows.length; i++) {
		IWorkbenchPage page = windows[i].getActivePage();
		if (page != null && page.getPerspective() != null && perspectiveId.equals(page.getPerspective().getId())) {
			windows[i].close();
		}
	}
}
 
Example 2
Source File: BonitaPerspectivesUtils.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Switch to the perspective with id given as parameter
 * 
 * @param perspectiveID
 */
public static synchronized void switchToPerspective(final String perspectiveID) {
    final IWorkbench workbench = PlatformUI.getWorkbench();
    final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    if (window != null) {
        final IWorkbenchPage activePage = window.getActivePage();
        if (activePage != null) {
            final IPerspectiveDescriptor activePerspective = activePage.getPerspective();
            if (activePerspective == null || !activePerspective.getId().equals(perspectiveID)) {
                final IPerspectiveRegistry registry = workbench.getPerspectiveRegistry();
                final IWorkbenchPage page = window.getActivePage();
                final IPerspectiveDescriptor desc = registry.findPerspectiveWithId(perspectiveID);
                page.setPerspective(desc);
            }
        }
    }
}
 
Example 3
Source File: AllInOneWorkbenchListener.java    From typescript.java with MIT License 5 votes vote down vote up
private void hookListeners(IWorkbenchPage page) {
	IPerspectiveDescriptor perspective = page.getPerspective();
	if (perspective != null) {
		perspectiveActivated(page, perspective);
	}
	page.addPartListener(this);
}
 
Example 4
Source File: TmfPerspectiveManager.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns whether the given perspective identifier matches the identifier
 * of the current perspective.
 *
 * @param window
 *            the workbench window
 *
 * @param perspectiveId
 *            the identifier
 * @return whether the given perspective identifier matches the identifier
 *         of the current perspective
 */
private static boolean isCurrentPerspective(IWorkbenchWindow window, String perspectiveId) {
    boolean isCurrent= false;
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            IPerspectiveDescriptor perspectiveDescriptor = page.getPerspective();
            if (perspectiveDescriptor != null) {
                isCurrent= perspectiveId.equals(perspectiveDescriptor.getId());
            }
        }
    }
    return isCurrent;
}
 
Example 5
Source File: PerspectiveUtil.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public static void switchToModelingPerspective(IWorkbenchWindow window) {
	IPreferenceStore prefs = UIPluginActivator.getDefault()
			.getPreferenceStore();
	boolean hide = prefs.getBoolean(AUTO_SWITCH_PERSPECTIVE);
	IWorkbenchPage page = window.getActivePage();
	if (!hide) {
		IWorkbench workbench = window.getWorkbench();
		IPerspectiveRegistry registry = workbench.getPerspectiveRegistry();
		IPerspectiveDescriptor descriptor = registry
				.findPerspectiveWithId(IYakinduSctPerspectives.ID_PERSPECTIVE_SCT_MODELING);
		if ((page != null) && (page.getPerspective() != descriptor)) {
			MessageDialogWithToggle dialog = MessageDialogWithToggle
					.openYesNoQuestion(
							window.getShell(),
							"Confirm Perspective Switch",
							"This kind of editor is associated with the YAKINDU Modeling perspective. Do you want to switch to this perspective now?",
							"Do not offer to switch perspective in the future",
							hide, prefs, AUTO_SWITCH_PERSPECTIVE);
			if (dialog.getReturnCode() == 2)
				page.setPerspective(descriptor);
			hide = dialog.getToggleState();
			prefs.setValue(AUTO_SWITCH_PERSPECTIVE, hide);
			try {
				InstanceScope.INSTANCE.getNode(UIPluginActivator.PLUGIN_ID)
						.flush();
			} catch (BackingStoreException e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 6
Source File: UIUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the active perspective descriptor if there is one.
 * 
 * @return the active perspective descriptor; <code>null</code> in case it could not be resolved.
 */
public static IPerspectiveDescriptor getActivePerspectiveDescriptor()
{
	IWorkbenchPage activePage = getActivePage();
	if (activePage != null)
	{
		return activePage.getPerspective();
	}
	return null;
}
 
Example 7
Source File: BonitaPerspectivesUtils.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param perspectiveID
 * @return if the active perspective is the one with the ID perspectiveID
 */
public static boolean isPerspectiveWithIDActive(final String perspectiveID) {
    final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWorkbenchWindow != null) {
        final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
        if (activePage != null) {
            final IPerspectiveDescriptor perspective = activePage.getPerspective();
            if (perspective != null) {
                return perspective.getId().equals(perspectiveID);
            }
        }
    }
    return false;
}
 
Example 8
Source File: RcpWindowAdvisor.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private boolean isStandardPerspective() {
	IWorkbench wb = PlatformUI.getWorkbench();
	IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
	IWorkbenchPage page = win.getActivePage();
	IPerspectiveDescriptor perspective = page.getPerspective();
	return perspective.getId().equals(RcpPerspective.ID);
}
 
Example 9
Source File: PerspectiveHelper.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public final static IPerspectiveDescriptor getActivePerspective() {
	final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	final IPerspectiveDescriptor currentDescriptor = activePage.getPerspective();
	return currentDescriptor;

}
 
Example 10
Source File: CreateESBAction.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
private void selectRootObject(Properties params) {

        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (null == workbenchWindow) {
            return;
        }
        IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
        if (null == workbenchPage) {
            return;
        }

        IPerspectiveDescriptor currentPerspective = workbenchPage.getPerspective();
        if (!IBrandingConfiguration.PERSPECTIVE_DI_ID.equals(currentPerspective.getId())) {
            // show Integration perspective
            try {
                workbenchWindow.getWorkbench().showPerspective(IBrandingConfiguration.PERSPECTIVE_DI_ID, workbenchWindow);
                workbenchPage = workbenchWindow.getActivePage();
            } catch (WorkbenchException e) {
                ExceptionHandler.process(e);
                return;
            }
        }

        IRepositoryView view = RepositoryManagerHelper.getRepositoryView();
        if (view != null) {

            Object type = params.get("type");

            if (ESBRepositoryNodeType.SERVICES.name().equals(type)) {
                RepositoryNode servicesNode = ((ProjectRepositoryNode) view.getRoot())
                        .getRootRepositoryNode(ESBRepositoryNodeType.SERVICES);
                if (servicesNode != null) {
                    setWorkbenchPart(view);
                    final StructuredViewer viewer = view.getViewer();
                    if (viewer instanceof TreeViewer) {
                        ((TreeViewer) viewer).expandToLevel(servicesNode, 1);
                    }
                    viewer.setSelection(new StructuredSelection(servicesNode));
                }
            }
        }
    }