Search in sources :

Example 1 with CompareRemoteResourcesAction

use of org.tigris.subversion.subclipse.ui.actions.CompareRemoteResourcesAction in project subclipse by subclipse.

the class SVNHistoryPage method getCompareWithPreviousChangedPathAction.

private IAction getCompareWithPreviousChangedPathAction() {
    if (compareWithPreviousChangedPathAction == null) {
        compareWithPreviousChangedPathAction = new Action() {

            public void run() {
                CompareRemoteResourcesAction delegate = new CompareRemoteResourcesAction();
                delegate.init(this);
                ISVNRemoteResource remoteResource1 = null;
                Object firstSelection = ((IStructuredSelection) changePathsViewer.getSelection()).getFirstElement();
                if (firstSelection instanceof LogEntryChangePath) {
                    LogEntryChangePath logEntryChangePath = (LogEntryChangePath) firstSelection;
                    try {
                        remoteResource1 = logEntryChangePath.getRemoteResource();
                    } catch (SVNException e1) {
                        SVNUIPlugin.openError(getSite().getShell(), null, null, e1, SVNUIPlugin.LOG_TEAM_EXCEPTIONS);
                        return;
                    }
                } else if (firstSelection instanceof HistoryFolder) {
                    HistoryFolder historyFolder = (HistoryFolder) firstSelection;
                    Object[] children = historyFolder.getChildren();
                    if (children != null && children.length > 0 && children[0] instanceof LogEntryChangePath) {
                        LogEntryChangePath logEntryChangePath = (LogEntryChangePath) children[0];
                        try {
                            SVNUrl svnUrl = logEntryChangePath.getRemoteResource().getRepository().getRemoteFolder(historyFolder.getPath()).getUrl();
                            SVNRevision.Number selectedRevision = (SVNRevision.Number) getSelectedRevision();
                            remoteResource1 = new RemoteFolder(null, logEntryChangePath.getLogEntry().getRemoteResource().getRepository(), svnUrl, selectedRevision, selectedRevision, null, null);
                        } catch (Exception e) {
                        }
                    }
                }
                if (remoteResource1 == null) {
                    return;
                }
                int from = Integer.parseInt(remoteResource1.getRevision().toString());
                from--;
                String to = Integer.toString(from);
                SVNRevision toRevision = null;
                try {
                    toRevision = SVNRevision.getRevision(to);
                } catch (ParseException e) {
                }
                ISVNRemoteResource[] remoteResources = new ISVNRemoteResource[2];
                ISVNRemoteResource remoteResource2;
                if (firstSelection instanceof HistoryFolder || remoteResource1.getResource() instanceof IContainer) {
                    remoteResource2 = new RemoteFolder(null, remoteResource1.getRepository(), remoteResource1.getUrl(), (SVNRevision.Number) toRevision, (SVNRevision.Number) toRevision, null, null);
                } else {
                    remoteResource2 = new RemoteFile(null, remoteResource1.getRepository(), remoteResource1.getUrl(), (SVNRevision.Number) toRevision, (SVNRevision.Number) toRevision, null, null);
                }
                remoteResources[0] = remoteResource1;
                remoteResources[1] = remoteResource2;
                delegate.selectionChanged(this, new StructuredSelection(remoteResources));
                delegate.setRemoteResources(remoteResources);
                delegate.setLocalResource(remoteResource1.getResource());
                delegate.setLocalResources(remoteResources);
                SVNRevision[] pegRevisions = { remoteResource1.getRevision() };
                delegate.setPegRevisions(pegRevisions);
                delegate.run(this);
            }
        };
    }
    return compareWithPreviousChangedPathAction;
}
Also used : CompareRemoteResourcesAction(org.tigris.subversion.subclipse.ui.actions.CompareRemoteResourcesAction) ExportRemoteFolderAction(org.tigris.subversion.subclipse.ui.actions.ExportRemoteFolderAction) ShowDifferencesAsUnifiedDiffAction(org.tigris.subversion.subclipse.ui.actions.ShowDifferencesAsUnifiedDiffAction) TextViewerAction(org.tigris.subversion.subclipse.ui.console.TextViewerAction) ShowAnnotationAction(org.tigris.subversion.subclipse.ui.actions.ShowAnnotationAction) ShowHistoryAction(org.tigris.subversion.subclipse.ui.actions.ShowHistoryAction) WorkspaceAction(org.tigris.subversion.subclipse.ui.actions.WorkspaceAction) IAction(org.eclipse.jface.action.IAction) OpenRemoteFileAction(org.tigris.subversion.subclipse.ui.actions.OpenRemoteFileAction) GenerateChangeLogAction(org.tigris.subversion.subclipse.ui.actions.GenerateChangeLogAction) Action(org.eclipse.jface.action.Action) CompareRemoteResourcesAction(org.tigris.subversion.subclipse.ui.actions.CompareRemoteResourcesAction) LogEntryChangePath(org.tigris.subversion.subclipse.core.history.LogEntryChangePath) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) RemoteFolder(org.tigris.subversion.subclipse.core.resources.RemoteFolder) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) SVNException(org.tigris.subversion.subclipse.core.SVNException) CoreException(org.eclipse.core.runtime.CoreException) SVNException(org.tigris.subversion.subclipse.core.SVNException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) ParseException(java.text.ParseException) ParseException(java.text.ParseException) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) IContainer(org.eclipse.core.resources.IContainer) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile)

Example 2 with CompareRemoteResourcesAction

use of org.tigris.subversion.subclipse.ui.actions.CompareRemoteResourcesAction in project subclipse by subclipse.

the class DifferencesDialog method compare.

private void compare() {
    if (fromResource instanceof ISVNRemoteResource && toResource != null && toResource instanceof ISVNRemoteResource) {
        SVNUrl fromUrl = null;
        SVNUrl toUrl = null;
        SVNRevision fromRevision;
        SVNRevision toRevision;
        if (fromHeadButton.getSelection())
            fromRevision = SVNRevision.HEAD;
        else {
            int fromRevisionInt = Integer.parseInt(fromRevisionText.getText().trim());
            long fromRevisionLong = fromRevisionInt;
            fromRevision = new SVNRevision.Number(fromRevisionLong);
        }
        if (toHeadButton.getSelection())
            toRevision = SVNRevision.HEAD;
        else {
            int toRevisionInt = Integer.parseInt(toRevisionText.getText().trim());
            long toRevisionLong = toRevisionInt;
            toRevision = new SVNRevision.Number(toRevisionLong);
        }
        try {
            fromUrl = new SVNUrl(fromUrlText.getText().trim());
            toUrl = new SVNUrl(toUrlText.getText().trim());
        } catch (Exception e) {
            MessageDialog.openError(getShell(), Policy.bind("DifferencesDialog.compare"), e.getMessage());
            success = false;
            return;
        }
        ISVNRemoteResource resource1 = null;
        SVNRevision.Number lastChangedRevision1 = null;
        ISVNRemoteResource resource2 = null;
        SVNRevision.Number lastChangedRevision2 = null;
        if (fromRevision instanceof SVNRevision.Number) {
            lastChangedRevision1 = (SVNRevision.Number) fromRevision;
        } else {
            lastChangedRevision1 = ((ISVNRemoteResource) remoteResources[0]).getLastChangedRevision();
        }
        if (fromResource.isFolder()) {
            resource1 = new RemoteFolder(null, fromResource.getRepository(), fromUrl, fromRevision, lastChangedRevision1, null, null);
            if (!fromUrl.equals(fromResource.getUrl())) {
                try {
                    resource1.members(null);
                } catch (TeamException e) {
                    resource1 = new RemoteFile(null, fromResource.getRepository(), fromUrl, fromRevision, lastChangedRevision1, null, null);
                }
            }
        } else {
            resource1 = new RemoteFile(null, fromResource.getRepository(), fromUrl, fromRevision, lastChangedRevision1, null, null);
            if (!fromUrl.equals(fromResource.getUrl())) {
                IStorage storage = null;
                try {
                    storage = resource1.getStorage(null);
                } catch (TeamException e) {
                }
                if (storage == null) {
                    resource1 = new RemoteFolder(null, fromResource.getRepository(), fromUrl, fromRevision, lastChangedRevision1, null, null);
                }
            }
        }
        if (fromRevision instanceof SVNRevision.Number) {
            if (usePegRevision && resource1 instanceof RemoteResource) {
                ((RemoteResource) resource1).setPegRevision(fromRevision);
            }
        }
        if (toRevision instanceof SVNRevision.Number) {
            lastChangedRevision2 = (SVNRevision.Number) toRevision;
        } else {
            lastChangedRevision2 = ((ISVNRemoteResource) remoteResources[1]).getLastChangedRevision();
        }
        if (toResource.isFolder()) {
            resource2 = new RemoteFolder(null, toResource.getRepository(), toUrl, toRevision, lastChangedRevision2, null, null);
            if (!toUrl.equals(toResource.getUrl())) {
                try {
                    resource2.members(null);
                } catch (TeamException e) {
                    resource2 = new RemoteFile(null, toResource.getRepository(), toUrl, toRevision, lastChangedRevision2, null, null);
                }
            }
        } else {
            resource2 = new RemoteFile(null, toResource.getRepository(), toUrl, toRevision, lastChangedRevision2, null, null);
            if (!toUrl.equals(toResource.getUrl())) {
                IStorage storage = null;
                try {
                    storage = resource2.getStorage(null);
                } catch (TeamException e) {
                }
                if (storage == null) {
                    resource2 = new RemoteFolder(null, toResource.getRepository(), toUrl, toRevision, lastChangedRevision2, null, null);
                }
            }
        }
        if (toRevision instanceof SVNRevision.Number) {
            if (usePegRevision && resource2 instanceof RemoteResource) {
                ((RemoteResource) resource2).setPegRevision(toRevision);
            }
        }
        ISVNRemoteResource[] remotes = { resource1, resource2 };
        CompareRemoteResourcesAction compareAction = new CompareRemoteResourcesAction();
        compareAction.setLocalResource(localResource);
        compareAction.setRemoteResources(remotes);
        compareAction.setPegRevisions(pegRevisions);
        compareAction.setLocalResources(remoteResources);
        try {
            compareAction.execute(null);
        } catch (InvocationTargetException e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
        } catch (InterruptedException e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
        }
    }
}
Also used : RemoteResource(org.tigris.subversion.subclipse.core.resources.RemoteResource) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) CompareRemoteResourcesAction(org.tigris.subversion.subclipse.ui.actions.CompareRemoteResourcesAction) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) RemoteFolder(org.tigris.subversion.subclipse.core.resources.RemoteFolder) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) IStorage(org.eclipse.core.resources.IStorage) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 TeamException (org.eclipse.team.core.TeamException)2 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)2 RemoteFile (org.tigris.subversion.subclipse.core.resources.RemoteFile)2 RemoteFolder (org.tigris.subversion.subclipse.core.resources.RemoteFolder)2 CompareRemoteResourcesAction (org.tigris.subversion.subclipse.ui.actions.CompareRemoteResourcesAction)2 SVNRevision (org.tigris.subversion.svnclientadapter.SVNRevision)2 SVNUrl (org.tigris.subversion.svnclientadapter.SVNUrl)2 ParseException (java.text.ParseException)1 IContainer (org.eclipse.core.resources.IContainer)1 IStorage (org.eclipse.core.resources.IStorage)1 CoreException (org.eclipse.core.runtime.CoreException)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 PartInitException (org.eclipse.ui.PartInitException)1 ISVNRemoteFile (org.tigris.subversion.subclipse.core.ISVNRemoteFile)1 SVNException (org.tigris.subversion.subclipse.core.SVNException)1 LogEntryChangePath (org.tigris.subversion.subclipse.core.history.LogEntryChangePath)1