Search in sources :

Example 11 with ISVNRemoteFile

use of org.tigris.subversion.subclipse.core.ISVNRemoteFile in project subclipse by subclipse.

the class CompareWithRemoteAction method execute.

public void execute(IAction action) {
    refresh = false;
    fileSelected = false;
    final IResource[] resources = getSelectedResources();
    if (resources.length != 1 && !SVNRevision.BASE.equals(revision) && !SVNRevision.HEAD.equals(revision)) {
        return;
    }
    for (int i = 0; i < resources.length; i++) {
        if (resources[i] instanceof IFile) {
            fileSelected = true;
            if (!resources[i].isSynchronized(Depth.immediates)) {
                refresh = MessageDialog.openQuestion(getShell(), Policy.bind("DifferencesDialog.compare"), Policy.bind("CompareWithRemoteAction.fileChanged"));
                break;
            }
        }
    }
    try {
        final ISVNLocalResource[] localResources = new ISVNLocalResource[resources.length];
        for (int i = 0; i < resources.length; i++) {
            localResources[i] = SVNWorkspaceRoot.getSVNResourceFor(resources[i]);
        }
        final ISVNLocalResource localResource = localResources[0];
        run(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) {
                try {
                    if (refresh) {
                        for (int i = 0; i < localResources.length; i++) {
                            if (resources[i] instanceof IFile) {
                                localResources[i].getResource().refreshLocal(Depth.immediates, monitor);
                            }
                        }
                    }
                    if (SVNRevision.BASE.equals(revision)) {
                        if (localResources.length == 1 && localResource.getResource() instanceof IFile) {
                            SVNLocalCompareInput compareInput = new SVNLocalCompareInput(localResource, revision);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        } else {
                            SVNLocalBaseCompareInput compareInput = new SVNLocalBaseCompareInput(localResources, revision);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        }
                    } else {
                        if (!fileSelected) {
                            SVNLocalCompareSummaryInput compareInput = new SVNLocalCompareSummaryInput(localResources, revision);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        } else {
                            ISVNRemoteFile remoteFile = new RemoteFile(localResource.getRepository(), localResource.getUrl(), revision);
                            ((RemoteFile) remoteFile).setPegRevision(revision);
                            SVNLocalCompareInput compareInput = new SVNLocalCompareInput(localResource, remoteFile);
                            ShowDifferencesAsUnifiedDiffOperationWC operation = null;
                            if (SVNRevision.HEAD.equals(revision)) {
                                File file = File.createTempFile("revision", ".diff");
                                file.deleteOnExit();
                                operation = new ShowDifferencesAsUnifiedDiffOperationWC(getTargetPart(), localResource.getFile(), localResource.getUrl(), SVNRevision.HEAD, file);
                                operation.setGraphicalCompare(true);
                                operation.run();
                            }
                            compareInput.setDiffOperation(operation);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        }
                    }
                } catch (Exception e) {
                    handle(e, null, null);
                }
            }
        }, false, /* cancelable */
        PROGRESS_BUSYCURSOR);
    } catch (Exception e) {
        handle(e, null, null);
    }
}
Also used : SVNLocalCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput) IFile(org.eclipse.core.resources.IFile) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) SVNException(org.tigris.subversion.subclipse.core.SVNException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ShowDifferencesAsUnifiedDiffOperationWC(org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) SVNLocalBaseCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalBaseCompareInput) SVNLocalCompareSummaryInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareSummaryInput) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) File(java.io.File) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile)

Example 12 with ISVNRemoteFile

use of org.tigris.subversion.subclipse.core.ISVNRemoteFile 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)

Example 13 with ISVNRemoteFile

use of org.tigris.subversion.subclipse.core.ISVNRemoteFile in project subclipse by subclipse.

the class SVNCompareRevisionsInput method initializeActions.

/**
 * initialize the actions : - getContentsAction : get the contents for the selected revision -
 * getRevisionAction : updates to the given revision
 */
private void initializeActions() {
    getContentsAction = new // $NON-NLS-1$
    Action(// $NON-NLS-1$
    Policy.bind("HistoryView.getContentsAction"), // $NON-NLS-1$
    null) {

        public void run() {
            try {
                new ProgressMonitorDialog(shell).run(false, true, new WorkspaceModifyOperation() {

                    protected void execute(IProgressMonitor monitor) throws InvocationTargetException {
                        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                        if (selection.size() != 1)
                            return;
                        VersionCompareDiffNode node = (VersionCompareDiffNode) selection.getFirstElement();
                        ResourceEditionNode right = (ResourceEditionNode) node.getRight();
                        ISVNRemoteResource edition = right.getRemoteResource();
                        // actually want to change the base.
                        try {
                            monitor.beginTask(null, 100);
                            InputStream in = ((IResourceVariant) edition).getStorage(new SubProgressMonitor(monitor, 50)).getContents();
                            resource.setContents(in, false, true, new SubProgressMonitor(monitor, 50));
                        } catch (TeamException e) {
                            throw new InvocationTargetException(e);
                        } catch (CoreException e) {
                            throw new InvocationTargetException(e);
                        } finally {
                            monitor.done();
                        }
                    }
                });
            } catch (InterruptedException e) {
                // Do nothing
                return;
            } catch (InvocationTargetException e) {
                handle(e);
            }
            // recompute the labels on the viewer
            updateCurrentEdition();
            viewer.refresh();
        }
    };
    getRevisionAction = new // $NON-NLS-1$
    Action(// $NON-NLS-1$
    Policy.bind("HistoryView.getRevisionAction"), // $NON-NLS-1$
    null) {

        public void run() {
            try {
                new ProgressMonitorDialog(shell).run(false, true, new WorkspaceModifyOperation(null) {

                    protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                        if (selection.size() != 1)
                            return;
                        VersionCompareDiffNode node = (VersionCompareDiffNode) selection.getFirstElement();
                        ResourceEditionNode right = (ResourceEditionNode) node.getRight();
                        final ISVNRemoteFile edition = (ISVNRemoteFile) right.getRemoteResource();
                        new UpdateOperation(null, resource, edition.getLastChangedRevision()).run(monitor);
                        // recompute the labels on the viewer
                        getHistoryTableProvider().setRemoteResource(edition);
                        viewer.refresh();
                    }
                });
            } catch (InterruptedException e) {
                // Do nothing
                return;
            } catch (InvocationTargetException e) {
                handle(e);
            }
        }
    };
}
Also used : WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) UpdateOperation(org.tigris.subversion.subclipse.ui.operations.UpdateOperation)

Example 14 with ISVNRemoteFile

use of org.tigris.subversion.subclipse.core.ISVNRemoteFile in project subclipse by subclipse.

the class LogEntry method createLogEntriesFrom.

/**
 * create the LogEntry for the logMessages
 *
 * @param logMessages
 * @return
 */
public static ILogEntry[] createLogEntriesFrom(ISVNRemoteFile remoteFile, ISVNLogMessage[] logMessages, Tags[] tags, SVNUrl[] urls) {
    ILogEntry[] result = new ILogEntry[logMessages.length];
    for (int i = 0; i < logMessages.length; i++) {
        ISVNLogMessage logMessage = logMessages[i];
        ISVNRemoteResource correspondingResource;
        correspondingResource = new RemoteFile(null, remoteFile.getRepository(), urls[i], logMessage.getRevision(), logMessage.getRevision(), logMessage.getDate(), logMessage.getAuthor());
        result[i] = new LogEntry(logMessage, remoteFile, correspondingResource, (tags[i] != null) ? tags[i].getTags() : null);
    }
    return result;
}
Also used : ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile)

Example 15 with ISVNRemoteFile

use of org.tigris.subversion.subclipse.core.ISVNRemoteFile in project subclipse by subclipse.

the class MergeResultsView method createPartControl.

public void createPartControl(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.verticalSpacing = 2;
    layout.marginWidth = 0;
    layout.marginHeight = 2;
    parent.setLayout(layout);
    treeViewer = new TreeViewer(parent);
    treeViewer.setLabelProvider(labelProvider);
    treeViewer.setContentProvider(new MergeResultsViewContentProvider());
    treeViewer.setUseHashlookup(true);
    GridData layoutData = new GridData();
    layoutData.grabExcessHorizontalSpace = true;
    layoutData.grabExcessVerticalSpace = true;
    layoutData.horizontalAlignment = GridData.FILL;
    layoutData.verticalAlignment = GridData.FILL;
    treeViewer.getControl().setLayoutData(layoutData);
    treeViewer.setInput(this);
    treeViewer.addOpenListener(new IOpenListener() {

        public void open(OpenEvent event) {
            treeConflict = null;
            IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
            Object selectedItem = selection.getFirstElement();
            MergeResult mergeResult = null;
            if (selectedItem instanceof AdaptableMergeResult)
                mergeResult = (MergeResult) selectedItem;
            if (selectedItem instanceof AdaptableMergeResultsFolder) {
                MergeResultsFolder mergeResultsFolder = (MergeResultsFolder) selectedItem;
                mergeResult = mergeResultsFolder.getMergeResult();
            }
            if (mergeResult != null) {
                if (mergeResult.getResource() instanceof IFile && mergeResult.isConflicted() && !mergeResult.isResolved()) {
                    editConflicts(mergeResult);
                    return;
                }
                if (mergeResult.getResource() instanceof IFile && mergeResult.hasTreeConflict() && !mergeResult.isTreeConflictResolved()) {
                    boolean addAddConflict = false;
                    if (mergeResult.getResource() != null && mergeResult.getResource().exists()) {
                        treeConflict = getTreeConflict(mergeResult.getResource());
                        if (treeConflict != null && treeConflict.getDescription() != null && treeConflict.getDescription().contains("local add") && treeConflict.getDescription().contains("incoming add")) {
                            // $NON-NLS-1$ //$NON-NLS-2$
                            addAddConflict = true;
                        }
                        if (!addAddConflict) {
                            openAction.run();
                        }
                    }
                    if (!addAddConflict) {
                        return;
                    }
                }
                if (!mergeResult.getAction().equals(MergeResult.ACTION_DELETE)) {
                    final ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor(mergeResult.getResource());
                    if (!localResource.exists()) {
                        return;
                    }
                    BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

                        public void run() {
                            try {
                                if (treeConflict != null) {
                                    if (!localResource.isFolder()) {
                                        SVNConflictDescriptor descriptor = treeConflict.getConflictDescriptor();
                                        SVNConflictVersion rightVersion = descriptor.getSrcRightVersion();
                                        try {
                                            ISVNRemoteFile remoteFile = new RemoteFile(localResource.getRepository(), new SVNUrl(rightVersion.getReposURL() + "/" + rightVersion.getPathInRepos()), new SVNRevision.Number(rightVersion.getPegRevision()));
                                            SVNLocalCompareInput compareInput = new SVNLocalCompareInput(localResource, remoteFile);
                                            CompareUI.openCompareEditorOnPage(compareInput, getSite().getPage());
                                        } catch (Exception e) {
                                        }
                                    }
                                    return;
                                }
                                CompareUI.openCompareEditorOnPage(new SVNLocalCompareInput(localResource, SVNRevision.BASE), getSite().getPage());
                            } catch (SVNException e) {
                                if (!e.operationInterrupted()) {
                                    Activator.handleError(Messages.MergeResultsView_compareError, e);
                                    MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.MergeResultsView_compareWithLatest, e.getLocalizedMessage());
                                }
                            } catch (SVNClientException e) {
                                Activator.handleError(Messages.MergeResultsView_compareError, e);
                                MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.MergeResultsView_compareWithLatest, e.getLocalizedMessage());
                            }
                        }
                    });
                }
            }
        }
    });
    treeViewer.getTree().addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            boolean mergeOutputSelected = false;
            IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
            Iterator iter = selection.iterator();
            while (iter.hasNext()) {
                if (iter.next() instanceof MergeOutput) {
                    mergeOutputSelected = true;
                    break;
                }
            }
            removeAction.setEnabled(mergeOutputSelected);
        }
    });
    createMenus();
    createToolbar();
    getSite().setSelectionProvider(treeViewer);
    if (Activator.getDefault().getPreferenceStore().getBoolean(CONFLICTS_ONLY_PREFERENCE))
        setContentDescription(Messages.MergeResultsView_conflictsMode);
}
Also used : IFile(org.eclipse.core.resources.IFile) TreeViewer(org.eclipse.jface.viewers.TreeViewer) MergeResult(com.collabnet.subversion.merge.MergeResult) AdaptableMergeResult(com.collabnet.subversion.merge.AdaptableMergeResult) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) GridLayout(org.eclipse.swt.layout.GridLayout) AdaptableMergeResultsFolder(com.collabnet.subversion.merge.AdaptableMergeResultsFolder) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) MergeOutput(com.collabnet.subversion.merge.MergeOutput) SVNConflictVersion(org.tigris.subversion.svnclientadapter.SVNConflictVersion) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) AdaptableMergeResultsFolder(com.collabnet.subversion.merge.AdaptableMergeResultsFolder) MergeResultsFolder(com.collabnet.subversion.merge.MergeResultsFolder) AdaptableMergeResult(com.collabnet.subversion.merge.AdaptableMergeResult) SVNLocalCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SVNConflictDescriptor(org.tigris.subversion.svnclientadapter.SVNConflictDescriptor) SVNException(org.tigris.subversion.subclipse.core.SVNException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) IOpenListener(org.eclipse.jface.viewers.IOpenListener) GridData(org.eclipse.swt.layout.GridData) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Aggregations

ISVNRemoteFile (org.tigris.subversion.subclipse.core.ISVNRemoteFile)20 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IFile (org.eclipse.core.resources.IFile)5 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)5 RemoteFile (org.tigris.subversion.subclipse.core.resources.RemoteFile)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 CoreException (org.eclipse.core.runtime.CoreException)4 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)4 SVNException (org.tigris.subversion.subclipse.core.SVNException)4 InputStream (java.io.InputStream)3 ISelection (org.eclipse.jface.viewers.ISelection)3 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)3 Iterator (java.util.Iterator)2 IResource (org.eclipse.core.resources.IResource)2 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2