Search in sources :

Example 1 with RemoteFileEditorInput

use of org.tigris.subversion.subclipse.ui.editor.RemoteFileEditorInput in project subclipse by subclipse.

the class OpenRemoteFileAction method execute.

/*
   * @see SVNAction#execute(IAction)
   */
public void execute(IAction action) throws InterruptedException, InvocationTargetException {
    run(new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            IWorkbench workbench = SVNUIPlugin.getPlugin().getWorkbench();
            IEditorRegistry registry = workbench.getEditorRegistry();
            IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
            ISVNRemoteFile[] files = getSelectedRemoteFiles();
            for (int i = 0; i < files.length; i++) {
                ISVNRemoteFile file = files[i];
                String filename = file.getName();
                IEditorDescriptor descriptor = registry.getDefaultEditor(filename);
                String id;
                if (descriptor == null) {
                    descriptor = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
                }
                if (descriptor == null) {
                    // $NON-NLS-1$
                    id = "org.eclipse.ui.DefaultTextEditor";
                } else {
                    id = descriptor.getId();
                }
                try {
                    try {
                        if (usePegRevision && files[i] instanceof RemoteResource)
                            ((RemoteResource) files[i]).setPegRevision(files[i].getRevision());
                        else
                            ((RemoteResource) files[i]).setPegRevision(SVNRevision.HEAD);
                        RemoteFileEditorInput input = new RemoteFileEditorInput(files[i], monitor);
                        if (descriptor != null && descriptor.isOpenExternal()) {
                            input.writeToTempFile();
                        }
                        page.openEditor(input, id);
                    } catch (PartInitException e) {
                        if (id.equals("org.eclipse.ui.DefaultTextEditor")) {
                            // $NON-NLS-1$
                            throw e;
                        } else {
                            RemoteFileEditorInput input = new RemoteFileEditorInput(files[i], monitor);
                            // $NON-NLS-1$
                            page.openEditor(input, "org.eclipse.ui.DefaultTextEditor");
                        }
                    }
                } catch (Exception e) {
                    MessageDialog.openError(getShell(), Policy.bind("OpenRemoteFileAction.0"), // $NON-NLS-1$
                    e.getMessage());
                }
            }
        }
    }, false, // $NON-NLS-1$
    PROGRESS_BUSYCURSOR);
}
Also used : RemoteResource(org.tigris.subversion.subclipse.core.resources.RemoteResource) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PartInitException(org.eclipse.ui.PartInitException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IWorkbench(org.eclipse.ui.IWorkbench) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) RemoteFileEditorInput(org.tigris.subversion.subclipse.ui.editor.RemoteFileEditorInput) PartInitException(org.eclipse.ui.PartInitException) IEditorRegistry(org.eclipse.ui.IEditorRegistry)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)1 IEditorRegistry (org.eclipse.ui.IEditorRegistry)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 PartInitException (org.eclipse.ui.PartInitException)1 ISVNRemoteFile (org.tigris.subversion.subclipse.core.ISVNRemoteFile)1 RemoteResource (org.tigris.subversion.subclipse.core.resources.RemoteResource)1 RemoteFileEditorInput (org.tigris.subversion.subclipse.ui.editor.RemoteFileEditorInput)1