Search in sources :

Example 81 with PartInitException

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

the class FileSearchPage method handleOpen.

@Override
protected void handleOpen(OpenEvent event) {
    if (showLineMatches()) {
        Object firstElement = ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (firstElement instanceof IFile) {
            if (getDisplayedMatchCount(firstElement) == 0) {
                try {
                    open(getSite().getPage(), (IFile) firstElement, false);
                } catch (PartInitException e) {
                    ErrorDialog.openError(getSite().getShell(), SearchMessages.FileSearchPage_open_file_dialog_title, SearchMessages.FileSearchPage_open_file_failed, e.getStatus());
                }
                return;
            }
        }
    }
    super.handleOpen(event);
    Object firstElement = ((IStructuredSelection) event.getSelection()).getFirstElement();
    if (firstElement == null) {
        return;
    }
    Viewer viewer = event.getViewer();
    if (viewer instanceof TreeViewer) {
        TreeViewer treeViewer = (TreeViewer) viewer;
        if (treeViewer.getExpandedState(firstElement)) {
            autoExpand(treeViewer, firstElement);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TableViewer(org.eclipse.jface.viewers.TableViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException)

Example 82 with PartInitException

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

the class AbstractTextEditor method internalInit.

/**
 * Implements the <code>init</code> method of <code>IEditorPart</code>.
 * Subclasses replacing <code>init</code> may choose to call this method in
 * their implementation.
 *
 * @param window the workbench window
 * @param site the editor's site
 * @param input the editor input for the editor being created
 * @throws PartInitException if {@link #doSetInput(IEditorInput)} fails or gets canceled
 *
 * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
 * @since 2.1
 */
protected final void internalInit(IWorkbenchWindow window, final IEditorSite site, final IEditorInput input) throws PartInitException {
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                if (getDocumentProvider() instanceof IDocumentProviderExtension2) {
                    IDocumentProviderExtension2 extension = (IDocumentProviderExtension2) getDocumentProvider();
                    extension.setProgressMonitor(monitor);
                }
                doSetInput(input);
            } catch (CoreException x) {
                throw new InvocationTargetException(x);
            } finally {
                if (getDocumentProvider() instanceof IDocumentProviderExtension2) {
                    IDocumentProviderExtension2 extension = (IDocumentProviderExtension2) getDocumentProvider();
                    extension.setProgressMonitor(null);
                }
            }
        }
    };
    try {
        // When using the progress service always a modal dialog pops up. The site should be asked for a runnable context
        // which could be the workbench window or the progress service, depending on what the site represents.
        // getSite().getWorkbenchWindow().getWorkbench().getProgressService().run(false, true, runnable);
        getSite().getWorkbenchWindow().run(false, true, runnable);
    } catch (InterruptedException x) {
    } catch (InvocationTargetException x) {
        Throwable t = x.getTargetException();
        if (t instanceof CoreException) {
            /*
                /* XXX: Remove unpacking of CoreException once the following bug is
                 *		fixed: https://bugs.eclipse.org/bugs/show_bug.cgi?id=81640
                 */
            CoreException e = (CoreException) t;
            IStatus status = e.getStatus();
            if (status.getException() != null)
                throw new PartInitException(status);
            throw new PartInitException(new Status(status.getSeverity(), status.getPlugin(), status.getCode(), status.getMessage(), t));
        }
        throw new PartInitException(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, EditorMessages.Editor_error_init, t));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 83 with PartInitException

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

the class URLHyperlink method open.

@Override
public void open() {
    // Create the browser
    IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
    IWebBrowser browser;
    try {
        browser = support.createBrowser(null);
    } catch (PartInitException e) {
        // $NON-NLS-1$
        EditorsPlugin.logErrorStatus("Could not create Web browser for URLHyperlink", e.getStatus());
        super.open();
        return;
    }
    try {
        browser.openURL(new URL(getURLString()));
    } catch (PartInitException e) {
        super.open();
    } catch (MalformedURLException e) {
        super.open();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL)

Example 84 with PartInitException

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

the class UntitledTextFileWizard method performFinish.

@Override
public boolean performFinish() {
    IFileStore fileStore = queryFileStore();
    IEditorInput input = createEditorInput(fileStore);
    String editorId = getEditorId(fileStore);
    IWorkbenchPage page = fWindow.getActivePage();
    try {
        page.openEditor(input, editorId);
    } catch (PartInitException e) {
        EditorsPlugin.log(e);
        return false;
    }
    return true;
}
Also used : IFileStore(org.eclipse.core.filesystem.IFileStore) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 85 with PartInitException

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

the class ChartView method createChartView.

/**
 * Create and open a new chart view <br/>
 * <br/>
 * <u><b>Note</b></u>: this method uses the UI thread to open the view and then it sets the input chart. The UI
 * thread execution is synchronized on internal Integer SEC_ID which is the secondary id of the chart view. Each new
 * chart view has a secondary id equal to SEC_ID++.
 *
 * @param chart The chart to create view for.
 */
public static void createChartView(final Chart chart) {
    PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
        try {
            synchronized (lock) {
                ChartView view = (ChartView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(VIEW_ID, String.valueOf(SEC_ID++), IWorkbenchPage.VIEW_ACTIVATE);
                view.setChart(chart);
            }
        } catch (PartInitException e) {
            Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
            Activator.getDefault().getLog().log(s);
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) 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