Search in sources :

Example 96 with PartInitException

use of org.eclipse.ui.PartInitException in project linuxtools by eclipse.

the class GcovTest method testGcovSummaryByLaunch.

@Test
public void testGcovSummaryByLaunch() {
    display.syncExec(() -> {
        try {
            CommonNavigator vc = (CommonNavigator) window.getActivePage().showView(ProjectExplorer.VIEW_ID);
            vc.selectReveal(new StructuredSelection(project.getFile(getBinName())));
            Menu menu = new MenuManager().createContextMenu(vc.getCommonViewer().getControl());
            new ProfileContextualLaunchAction(menu);
            for (MenuItem item : menu.getItems()) {
                if (item.getText().endsWith("Profile Code Coverage")) {
                    ((ActionContributionItem) item.getData()).getAction().run();
                    break;
                }
            }
        } catch (PartInitException e1) {
            Assert.fail("Cannot show Project Explorer.");
        }
        try {
            window.getActivePage().showView("org.eclipse.linuxtools.gcov.view");
        } catch (PartInitException e2) {
            Assert.fail("Cannot show GCov View.");
        }
    });
    // Wait for the build job to finish (note: DebugUIPlugin doesn't put launch jobs in a family)
    Job[] jobs = Job.getJobManager().find(null);
    for (Job job : jobs) {
        if (job.getName().contains("Gcov")) {
            try {
                job.join();
            } catch (InterruptedException e) {
            }
            break;
        }
    }
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MenuManager(org.eclipse.jface.action.MenuManager) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) Job(org.eclipse.core.runtime.jobs.Job) Test(org.junit.Test) AbstractTest(org.eclipse.linuxtools.profiling.tests.AbstractTest)

Example 97 with PartInitException

use of org.eclipse.ui.PartInitException in project linuxtools by eclipse.

the class OpenFileHandler method runActions.

private void runActions(File file) {
    successful = false;
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toURI());
    IWorkbenchPage page = window.getActivePage();
    try {
        IDE.openEditorOnFileStore(page, fileStore);
        successful = true;
    } catch (PartInitException e) {
        ErrorDialog.openError(window.getShell(), // $NON-NLS-1$
        Localization.getString("OpenFileHandler.Problem"), // $NON-NLS-1$
        Localization.getString("OpenFileHandler.ProblemMessage"), new Status(IStatus.ERROR, IDEPlugin.PLUGIN_ID, e.getMessage(), e));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IFileStore(org.eclipse.core.filesystem.IFileStore) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException)

Example 98 with PartInitException

use of org.eclipse.ui.PartInitException in project linuxtools by eclipse.

the class CreaterepoResourceChangeListener method closeEditors.

/**
 * Close the editors thats resource has been affected by a change in the
 * workspace. E.g. if an editor's project has been closed/deleted, close the
 * editor.
 */
private void closeEditors() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IResource repomdFile = project.getRepoFile();
    // deleted, or the file was deleted. If so, close the editor of the file.
    if (!repomdFile.exists()) {
        for (IWorkbenchPage page : workbench.getActiveWorkbenchWindow().getPages()) {
            for (IEditorReference ref : page.getEditorReferences()) {
                try {
                    // get the resource from the editor part and exit the editor if
                    // it is within the project(s) being closed/deleted
                    IResource resource = ResourceUtil.getResource(ref.getEditorInput());
                    if (ref.getId().equals(RepoFormEditor.EDITOR_ID) && resource.getProject().equals(project.getProject())) {
                        page.closeEditor(ref.getEditor(false), false);
                    }
                } catch (PartInitException e) {
                    Activator.logError(Messages.CreaterepoResourceChangeListener_errorGettingResource, e);
                }
            }
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IResource(org.eclipse.core.resources.IResource)

Example 99 with PartInitException

use of org.eclipse.ui.PartInitException in project linuxtools by eclipse.

the class CreaterepoWizard method createProject.

/**
 * Create a createrepo project that contains an empty content folder and
 * a quickly initialized .repo file with the mandatory options.
 *
 * @param monitor The progress monitor.
 */
private void createProject(IProgressMonitor monitor) {
    try {
        String fileName = pageTwo.getRepositoryID().concat("." + // $NON-NLS-1$
        ICreaterepoConstants.REPO_FILE_EXTENSION);
        // create the project
        IProject project = CreaterepoProjectCreator.create(pageOne.getProjectName(), pageOne.getLocationPath(), fileName, monitor);
        // get a handle on the content folder
        IFolder folder = project.getFolder(ICreaterepoConstants.CONTENT_FOLDER);
        if (!folder.exists()) {
            folder.create(false, true, monitor);
        }
        // get a handle on the .repo file
        final IFile file = project.getFile(fileName);
        final String repoFileContents = initializeRepoContents(pageTwo.getRepositoryID(), pageTwo.getRepositoryName(), pageTwo.getRepositoryURL());
        InputStream stream = new ByteArrayInputStream(repoFileContents.getBytes());
        if (file.exists()) {
            file.setContents(stream, true, true, monitor);
        } else {
            file.create(stream, true, monitor);
        }
        monitor.worked(1);
        monitor.setTaskName(Messages.CreaterepoWizard_openFileOnCreation);
        getShell().getDisplay().asyncExec(() -> {
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            try {
                IDE.openEditor(page, file, true);
            } catch (PartInitException e) {
                Activator.logError(Messages.CreaterepoWizard_errorOpeningNewlyCreatedFile, e);
            }
        });
        monitor.worked(1);
    } catch (CoreException e) {
        Activator.logError(Messages.CreaterepoWizard_errorCreatingProject, e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 100 with PartInitException

use of org.eclipse.ui.PartInitException in project linuxtools by eclipse.

the class ARpmlintResolution method getEditor.

/**
 * Returns the SpecfileEditor for the given IMarker if any.
 *
 * @param marker The marker to use for retrieving the editor.
 * @return The IEditorPart this marker is from or null.
 */
protected IEditorPart getEditor(IMarker marker) {
    // Open or activate the editor.
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart part;
    try {
        part = IDE.openEditor(page, marker);
    } catch (PartInitException e) {
        RpmlintLog.logError(e);
        return null;
    }
    return part;
}
Also used : IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

PartInitException (org.eclipse.ui.PartInitException)720 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)300 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)177 IFile (org.eclipse.core.resources.IFile)146 IEditorPart (org.eclipse.ui.IEditorPart)141 CoreException (org.eclipse.core.runtime.CoreException)94 FileEditorInput (org.eclipse.ui.part.FileEditorInput)88 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)82 IEditorInput (org.eclipse.ui.IEditorInput)74 ISelection (org.eclipse.jface.viewers.ISelection)62 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)60 IResource (org.eclipse.core.resources.IResource)59 IEditorReference (org.eclipse.ui.IEditorReference)53 IViewPart (org.eclipse.ui.IViewPart)53 IOException (java.io.IOException)42 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)41 Point (org.eclipse.swt.graphics.Point)40 IWorkbench (org.eclipse.ui.IWorkbench)40 Path (org.eclipse.core.runtime.Path)39 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)39