Search in sources :

Example 1 with IPerspectiveRegistry

use of org.eclipse.ui.IPerspectiveRegistry in project eclipse.platform.text by eclipse.

the class SearchPreferencePage method getPerspectiveNamesAndIds.

/*
	 * Return a 2-dimensional array of perspective names and ids.
	 */
private String[][] getPerspectiveNamesAndIds() {
    IPerspectiveRegistry registry = PlatformUI.getWorkbench().getPerspectiveRegistry();
    IPerspectiveDescriptor[] perspectiveDescriptors = registry.getPerspectives();
    Arrays.sort(perspectiveDescriptors, new PerspectiveDescriptorComparator());
    String[][] table = new String[perspectiveDescriptors.length + 1][2];
    table[0][0] = SearchMessages.SearchPreferencePage_defaultPerspective_none;
    table[0][1] = NO_DEFAULT_PERSPECTIVE;
    for (int i = 0; i < perspectiveDescriptors.length; i++) {
        table[i + 1][0] = perspectiveDescriptors[i].getLabel();
        table[i + 1][1] = perspectiveDescriptors[i].getId();
    }
    return table;
}
Also used : IPerspectiveRegistry(org.eclipse.ui.IPerspectiveRegistry) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor)

Example 2 with IPerspectiveRegistry

use of org.eclipse.ui.IPerspectiveRegistry in project tmdm-studio-se by Talend.

the class TreeViewerListener method switchToPerspective.

public void switchToPerspective(final String perspectiveId) {
    // Display.getDefault().asyncExec(new Runnable() {
    // 
    // public void run() {
    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);
            }
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IPerspectiveRegistry(org.eclipse.ui.IPerspectiveRegistry) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor)

Example 3 with IPerspectiveRegistry

use of org.eclipse.ui.IPerspectiveRegistry in project liferay-ide by liferay.

the class ImportLiferayWorkspaceFromInstallerAction method _openLiferayPerspective.

private void _openLiferayPerspective() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
    IPerspectiveDescriptor perspective = activeWorkbenchWindow.getActivePage().getPerspective();
    if (!perspective.getId().equals(LiferayWorkspacePerspectiveFactory.ID)) {
        IPerspectiveRegistry reg = PlatformUI.getWorkbench().getPerspectiveRegistry();
        IPerspectiveDescriptor finalPersp = reg.findPerspectiveWithId(LiferayWorkspacePerspectiveFactory.ID);
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window == null) {
            return;
        }
        IWorkbenchPage page = window.getActivePage();
        if (page == null) {
            return;
        }
        page.setPerspective(finalPersp);
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IPerspectiveRegistry(org.eclipse.ui.IPerspectiveRegistry) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor)

Example 4 with IPerspectiveRegistry

use of org.eclipse.ui.IPerspectiveRegistry in project statecharts by Yakindu.

the class PerspectiveUtil method switchToModelingPerspective.

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();
            }
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IPerspectiveRegistry(org.eclipse.ui.IPerspectiveRegistry) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 5 with IPerspectiveRegistry

use of org.eclipse.ui.IPerspectiveRegistry in project eclipse-integration-commons by spring-projects.

the class PerspectiveMigrator method migratePerspective.

public IStatus migratePerspective(String oldPerspectiveId, String newPerspectiveId, IProgressMonitor monitor) {
    try {
        monitor = SubMonitor.convert(monitor, "Migrating legacy perspectives", 3);
        IPerspectiveRegistry registry = PlatformUI.getWorkbench().getPerspectiveRegistry();
        monitor.worked(1);
        IWorkbenchPage page = null;
        try {
            page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        } catch (NullPointerException e) {
        // something wasn't initialized...ignore
        }
        if (page != null) {
            if (page.getPerspective() == null || page.getPerspective().getId().equals(oldPerspectiveId)) {
                IPerspectiveDescriptor newPerspective = registry.findPerspectiveWithId(newPerspectiveId);
                page.setPerspective(newPerspective);
                IPerspectiveDescriptor oldPerspective = registry.findPerspectiveWithId(oldPerspectiveId);
                monitor.worked(1);
                if (oldPerspective != null) {
                    page.closePerspective(oldPerspective, false, false);
                    registry.deletePerspective(oldPerspective);
                }
            }
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=381473
            if (page instanceof WorkbenchPage) {
                try {
                    Method closePerspectiveMethod = WorkbenchPage.class.getDeclaredMethod("closePerspective", IPerspectiveDescriptor.class, String.class, boolean.class, boolean.class);
                    closePerspectiveMethod.invoke(page, null, IConversionConstants.GRAILS_OLD_PERSPECTIVE_ID, true, false);
                } catch (Exception e) {
                // this method doesn't exist on e37. OK to ignore
                // FrameworkUIActivator.getDefault().getLog().log(new Status(IStatus.INFO, FrameworkUIActivator.PLUGIN_ID, "Cannot use reflection to close legacy perspective on Eclipse 3.7.", e));
                }
            }
        }
        monitor.worked(1);
        monitor.done();
        return new Status(IStatus.OK, FrameworkUIActivator.PLUGIN_ID, "Migrate legacy perspectives.");
    } catch (Exception e) {
        return new Status(IStatus.ERROR, FrameworkUIActivator.PLUGIN_ID, "Problem migrating legacy perspectives.", e);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) WorkbenchPage(org.eclipse.ui.internal.WorkbenchPage) IPerspectiveRegistry(org.eclipse.ui.IPerspectiveRegistry) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) Method(java.lang.reflect.Method)

Aggregations

IPerspectiveRegistry (org.eclipse.ui.IPerspectiveRegistry)7 IPerspectiveDescriptor (org.eclipse.ui.IPerspectiveDescriptor)6 IWorkbench (org.eclipse.ui.IWorkbench)5 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)5 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 Method (java.lang.reflect.Method)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 WorkbenchPage (org.eclipse.ui.internal.WorkbenchPage)1 IDEWorkbenchPlugin (org.eclipse.ui.internal.ide.IDEWorkbenchPlugin)1 BackingStoreException (org.osgi.service.prefs.BackingStoreException)1