Search in sources :

Example 1 with IPerspectiveDescriptor

use of org.eclipse.ui.IPerspectiveDescriptor in project tdi-studio-se by Talend.

the class CreateDiagramAction method setRepositoryNode.

private void setRepositoryNode(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 di perspective
        try {
            workbenchWindow.getWorkbench().showPerspective(IBrandingConfiguration.PERSPECTIVE_DI_ID, workbenchWindow);
            workbenchPage = workbenchWindow.getActivePage();
        } catch (WorkbenchException e) {
            ExceptionHandler.process(e);
            return;
        }
    }
    // bug 16594
    IRepositoryView view = RepositoryManagerHelper.getRepositoryView();
    if (view != null) {
        Object type = params.get("type");
        if (ERepositoryObjectType.BUSINESS_PROCESS != null && ERepositoryObjectType.BUSINESS_PROCESS.name().equals(type)) {
            RepositoryNode processNode = ((ProjectRepositoryNode) view.getRoot()).getRootRepositoryNode(ERepositoryObjectType.BUSINESS_PROCESS);
            final StructuredViewer viewer = view.getViewer();
            if (viewer instanceof TreeViewer) {
                ((TreeViewer) viewer).expandToLevel(processNode, 1);
            }
            this.repositoryNode = processNode;
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) WorkbenchException(org.eclipse.ui.WorkbenchException) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 2 with IPerspectiveDescriptor

use of org.eclipse.ui.IPerspectiveDescriptor in project bndtools by bndtools.

the class WorkspaceSetupWizard method performFinish.

@Override
public boolean performFinish() {
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final File targetDir = previewPage.getTargetDir();
    final Set<String> checkedPaths = previewPage.getCheckedPaths();
    final boolean cleanBuild = setupPage.isCleanBuild();
    try {
        // Expand the template
        ResourceMap outputs = previewPage.getTemplateOutputs();
        final Set<File> topLevelFolders = new HashSet<>();
        for (Entry<String, Resource> entry : outputs.entries()) {
            String path = entry.getKey();
            if (checkedPaths.contains(path)) {
                Resource resource = entry.getValue();
                // Create the folder or file resource
                File file = new File(targetDir, path);
                switch(resource.getType()) {
                    case Folder:
                        Files.createDirectories(file.toPath());
                        break;
                    case File:
                        File parentDir = file.getParentFile();
                        Files.createDirectories(parentDir.toPath());
                        try (InputStream in = resource.getContent()) {
                            IO.copy(in, file);
                        }
                        break;
                    default:
                        throw new IllegalArgumentException("Unknown resource type " + resource.getType());
                }
                // Remember the top-level folders we create, for importing below
                if (file.getParentFile().equals(targetDir))
                    topLevelFolders.add(file);
            }
        }
        // Import anything that looks like an Eclipse project & do a full rebuild
        final IWorkspaceRunnable importProjectsRunnable = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                File[] children = targetDir.listFiles();
                if (children != null) {
                    int work = children.length;
                    if (cleanBuild)
                        work += 2;
                    SubMonitor progress = SubMonitor.convert(monitor, work);
                    for (File folder : children) {
                        if (folder.isDirectory() && topLevelFolders.contains(folder)) {
                            String projectName = folder.getName();
                            File projectFile = new File(folder, IProjectDescription.DESCRIPTION_FILE_NAME);
                            if (projectFile.exists()) {
                                IProject project = workspace.getRoot().getProject(projectName);
                                if (!project.exists()) {
                                    // No existing project in the workspace, so import the generated project.
                                    SubMonitor subProgress = progress.newChild(1);
                                    project.create(subProgress.newChild(1));
                                    project.open(subProgress.newChild(1));
                                    // Now make sure it is associated with the right location
                                    IProjectDescription description = project.getDescription();
                                    IPath path = Path.fromOSString(projectFile.getParentFile().getAbsolutePath());
                                    description.setLocation(path);
                                    project.move(description, IResource.REPLACE, progress);
                                } else {
                                    // If a project with the same name exists, does it live in the same location? If not, we can't import the generated project.
                                    File existingLocation = project.getLocation().toFile();
                                    if (!existingLocation.equals(folder)) {
                                        String message = String.format("Cannot import generated project from %s. A project named %s already exists in the workspace and is mapped to location %s", folder.getAbsolutePath(), projectName, existingLocation);
                                        throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, message, null));
                                    }
                                    SubMonitor subProgress = progress.newChild(1);
                                    // Open it if closed
                                    project.open(subProgress.newChild(1));
                                    // Refresh, as the template may have generated new content
                                    project.refreshLocal(IResource.DEPTH_INFINITE, subProgress.newChild(1));
                                }
                            }
                        }
                    }
                    if (cleanBuild)
                        workspace.build(IncrementalProjectBuilder.CLEAN_BUILD, progress.newChild(2));
                }
            }
        };
        getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    workspace.run(importProjectsRunnable, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                new WorkspaceJob("Load Repositories") {

                    @Override
                    public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                        try {
                            Central.refreshPlugins();
                        } catch (Exception e) {
                        // There may be no workspace yet
                        }
                        return Status.OK_STATUS;
                    }
                }.schedule();
            }
        });
        // Prompt to switch to the bndtools perspective
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        IPerspectiveDescriptor currentPerspective = window.getActivePage().getPerspective();
        if (!"bndtools.perspective".equals(currentPerspective.getId())) {
            if (MessageDialog.openQuestion(getShell(), "Bndtools Perspective", "Switch to the Bndtools perspective?")) {
                workbench.showPerspective("bndtools.perspective", window);
            }
        }
        return true;
    } catch (InvocationTargetException e) {
        ErrorDialog.openError(getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error generating template output", e.getTargetException()));
        return false;
    } catch (Exception e) {
        ErrorDialog.openError(getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error generating template output", e));
        return false;
    }
}
Also used : IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) HashSet(java.util.HashSet) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IPath(org.eclipse.core.runtime.IPath) InputStream(java.io.InputStream) Resource(org.bndtools.templating.Resource) IResource(org.eclipse.core.resources.IResource) SubMonitor(org.eclipse.core.runtime.SubMonitor) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ResourceMap(org.bndtools.templating.ResourceMap) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) File(java.io.File)

Example 3 with IPerspectiveDescriptor

use of org.eclipse.ui.IPerspectiveDescriptor in project translationstudio8 by heartsome.

the class ApplicationWorkbenchWindowAdvisor method setListenerToPespective.

/**
	 * 给默认透视图添加监听,当透视图发生改变时,触发相关事件	robert	2012-10-18
	 * @param commandService
	 */
private void setListenerToPespective(final ICommandService commandService) {
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IPerspectiveListener perspectiveListener = new IPerspectiveListener() {

        public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
        }

        public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
            // 改变透视图时,发出监听去检查品质检查结果视图的状态,从而让 视图 菜单的状态与之保持一致。
            commandService.refreshElements("net.heartsome.cat.ts.ui.qa.handlers.OpenQAResultViewCommand", null);
            // 显示状态栏与工具栏
            IHandlerService handlerService = (IHandlerService) window.getService(IHandlerService.class);
            IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
            boolean statusVisible = preferenceStore.getBoolean(TsPreferencesConstant.TS_statusBar_status);
            if (!statusVisible) {
                preferenceStore.setValue(TsPreferencesConstant.TS_statusBar_status, false);
                try {
                    handlerService.executeCommand("net.heartsome.cat.ts.command.openStatusBar", null);
                } catch (Exception ex) {
                    throw new RuntimeException("CommandTest.exitcommand not found");
                }
            }
            WorkbenchWindow window_1 = (WorkbenchWindow) window;
            if (!window_1.getCoolBarVisible()) {
                try {
                    window_1.toggleToolbarVisibility();
                    commandService.refreshElements("net.heartsome.cat.ts.command.openToolBar", null);
                } catch (Exception ex) {
                    throw new RuntimeException("CommandTest.exitcommand not found");
                }
            }
        }
    };
    window.addPerspectiveListener(perspectiveListener);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchWindow(org.eclipse.ui.internal.WorkbenchWindow) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IPerspectiveListener(org.eclipse.ui.IPerspectiveListener) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with IPerspectiveDescriptor

use of org.eclipse.ui.IPerspectiveDescriptor in project tdi-studio-se by Talend.

the class OpenDiagramAction method getSelectedObject.

private ISelection getSelectedObject() {
    if (params == null) {
        return getSelection();
    } else {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (null == workbenchWindow) {
            return null;
        }
        IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
        if (null == workbenchPage) {
            return null;
        }
        IPerspectiveDescriptor currentPerspective = workbenchPage.getPerspective();
        if (!IBrandingConfiguration.PERSPECTIVE_DI_ID.equals(currentPerspective.getId())) {
            // show di perspective
            try {
                workbenchWindow.getWorkbench().showPerspective(IBrandingConfiguration.PERSPECTIVE_DI_ID, workbenchWindow);
                workbenchPage = workbenchWindow.getActivePage();
            } catch (WorkbenchException e) {
                ExceptionHandler.process(e);
                return null;
            }
        }
        RepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(params.getProperty("nodeId"), false);
        IRepositoryView viewPart = getViewPart();
        if (repositoryNode != null && viewPart != null) {
            RepositoryNodeUtilities.expandParentNode(viewPart, repositoryNode);
            return new StructuredSelection(repositoryNode);
        }
        return null;
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) WorkbenchException(org.eclipse.ui.WorkbenchException) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryView(org.talend.repository.ui.views.IRepositoryView)

Example 5 with IPerspectiveDescriptor

use of org.eclipse.ui.IPerspectiveDescriptor in project tdi-studio-se by Talend.

the class CreateProcess method selectRootObject.

protected final 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 (!getPerspectiveId().equals(currentPerspective.getId())) {
        // show di perspective
        try {
            workbenchWindow.getWorkbench().showPerspective(getPerspectiveId(), workbenchWindow);
            workbenchPage = workbenchWindow.getActivePage();
        } catch (WorkbenchException e) {
            ExceptionHandler.process(e);
            return;
        }
    }
    IRepositoryView view = RepositoryManagerHelper.getRepositoryView();
    if (view != null) {
        Object type = params.get("type");
        if (getProcessType().name().equals(type)) {
            IRepositoryNode processNode = ((ProjectRepositoryNode) view.getRoot()).getRootRepositoryNode(getProcessType());
            if (processNode != null) {
                setWorkbenchPart(view);
                final StructuredViewer viewer = view.getViewer();
                if (viewer instanceof TreeViewer) {
                    ((TreeViewer) viewer).expandToLevel(processNode, 1);
                }
                viewer.setSelection(new StructuredSelection(processNode));
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IRepositoryNode(org.talend.repository.model.IRepositoryNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) WorkbenchException(org.eclipse.ui.WorkbenchException) IRepositoryView(org.talend.repository.ui.views.IRepositoryView)

Aggregations

IPerspectiveDescriptor (org.eclipse.ui.IPerspectiveDescriptor)10 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)7 WorkbenchException (org.eclipse.ui.WorkbenchException)7 IRepositoryView (org.talend.repository.ui.views.IRepositoryView)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 CoreException (org.eclipse.core.runtime.CoreException)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)3 RepositoryNode (org.talend.repository.model.RepositoryNode)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IRepositoryNode (org.talend.repository.model.IRepositoryNode)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1