Search in sources :

Example 1 with SVNLocalCompareInput

use of org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput in project subclipse by subclipse.

the class SvnWizardCommitPage method addResourcesArea.

private void addResourcesArea(Composite composite) {
    // get the toolbar actions from any contributing plug-in
    final SVNPluginAction[] toolbarActions = SVNUIPlugin.getCommitDialogToolBarActions();
    final SVNPluginAction[] alternateCompareActions = SVNUIPlugin.getCommitDialogCompareActions();
    ResourceSelectionTree.IToolbarControlCreator toolbarControlCreator = new ResourceSelectionTree.IToolbarControlCreator() {

        public void createToolbarControls(ToolBarManager toolbarManager) {
            toolbarManager.add(new // $NON-NLS-1$
            ControlContribution(// $NON-NLS-1$
            "ignoreUnversioned") {

                protected Control createControl(Composite parent) {
                    includeUnversionedButton = new Button(parent, SWT.CHECK);
                    includeUnversionedButton.setText(// $NON-NLS-1$
                    Policy.bind("CommitDialog.includeUnversioned"));
                    includeUnversionedButton.setSelection(includeUnversioned);
                    includeUnversionedButton.addSelectionListener(new SelectionListener() {

                        public void widgetSelected(SelectionEvent e) {
                            includeUnversioned = includeUnversionedButton.getSelection();
                            includeUnversionedAction.setChecked(includeUnversioned);
                            toggleIncludeUnversioned();
                        }

                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
                    });
                    return includeUnversionedButton;
                }
            });
            toolbarManager.add(new ControlContribution("keepLocks") {

                protected Control createControl(Composite parent) {
                    keepLocksButton = new Button(parent, SWT.CHECK);
                    // $NON-NLS-1$
                    keepLocksButton.setText(Policy.bind("CommitDialog.keepLocks"));
                    keepLocksButton.addSelectionListener(new SelectionListener() {

                        public void widgetSelected(SelectionEvent e) {
                            keepLocks = keepLocksButton.getSelection();
                            keepLocksAction.setChecked(keepLocksButton.getSelection());
                        }

                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
                    });
                    return keepLocksButton;
                }
            });
            toolbarManager.add(new Separator());
            toolbarManager.add(new ControlContribution("showCompare") {

                protected Control createControl(Composite parent) {
                    showCompareButton = new Button(parent, SWT.TOGGLE | SWT.FLAT);
                    showCompareButton.setImage(// $NON-NLS-1$
                    SVNUIPlugin.getImage(ISVNUIConstants.IMG_SYNCPANE));
                    showCompareButton.setToolTipText(Policy.bind("CommitDialog.showCompare"));
                    showCompareButton.setSelection(showCompare);
                    showCompareButton.addSelectionListener(new SelectionListener() {

                        public void widgetSelected(SelectionEvent e) {
                            showComparePane(!showCompare);
                            if (showCompare) {
                                IStructuredSelection selection = (IStructuredSelection) resourceSelectionTree.getTreeViewer().getSelection();
                                if (!selection.isEmpty()) {
                                    Object sel0 = selection.getFirstElement();
                                    if (sel0 instanceof IFile) {
                                        final ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor((IFile) sel0);
                                        try {
                                            // compare dialog
                                            if (alternateCompareActions.length > 0) {
                                                StructuredSelection localResourceSelection = new StructuredSelection(localResource);
                                                for (int i = 0; i < alternateCompareActions.length; i++) {
                                                    // make sure the selection is up to date
                                                    alternateCompareActions[i].selectionChanged(localResourceSelection);
                                                    alternateCompareActions[i].run();
                                                }
                                            } else {
                                                setCompareInput(new SVNLocalCompareInput(localResource, SVNRevision.BASE, true));
                                            }
                                        } catch (Exception e1) {
                                        }
                                    }
                                }
                            }
                        }

                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
                    });
                    return showCompareButton;
                }
            });
            // add any contributing actions from the extension point
            if (toolbarActions.length > 0) {
                toolbarManager.add(new Separator());
                for (int i = 0; i < toolbarActions.length; i++) {
                    SVNPluginAction action = toolbarActions[i];
                    toolbarManager.add(action);
                }
            }
        }

        public int getControlCount() {
            return 1;
        }
    };
    resourceSelectionTree = new ResourceSelectionTree(composite, SWT.NONE, Policy.bind("GenerateSVNDiff.Changes"), ResourceSelectionTree.dedupeResources(resourcesToCommit), statusMap, null, true, toolbarControlCreator, // $NON-NLS-1$
    syncInfoSet);
    if (!resourceSelectionTree.showIncludeUnversionedButton())
        includeUnversionedButton.setVisible(false);
    resourceSelectionTree.setCustomOptions(getCustomOptions());
    resourceSelectionTree.setRemoveFromViewValidator(new ResourceSelectionTree.IRemoveFromViewValidator() {

        public boolean canRemove(ArrayList resourceList, IStructuredSelection selection) {
            return removalOk(resourceList, selection);
        }

        public String getErrorMessage() {
            return removalError;
        // return Policy.bind("CommitDialog.unselectedPropChangeChildren"); //$NON-NLS-1$
        }
    });
    resourceSelectionTree.getTreeViewer().getTree().addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            selectedResources = resourceSelectionTree.getSelectedResources();
            // need to update the toolbar actions too - but we use the tree viewer's selection
            IStructuredSelection selection = (IStructuredSelection) resourceSelectionTree.getTreeViewer().getSelection();
            if (toolbarActions.length > 0) {
                for (int i = 0; i < toolbarActions.length; i++) {
                    SVNPluginAction action = toolbarActions[i];
                    action.selectionChanged(selection);
                }
            }
            if (showCompare) {
                Object sel0 = selection.getFirstElement();
                if (sel0 instanceof IFile) {
                    final ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor((IFile) sel0);
                    try {
                        // then call those actions instead of showing the default compare dialog
                        if (alternateCompareActions.length > 0) {
                            StructuredSelection localResourceSelection = new StructuredSelection(localResource);
                            for (int i = 0; i < alternateCompareActions.length; i++) {
                                // make sure the selection is up to date
                                alternateCompareActions[i].selectionChanged(localResourceSelection);
                                alternateCompareActions[i].run();
                            }
                        } else {
                            setCompareInput(new SVNLocalCompareInput(localResource, SVNRevision.BASE, true));
                        }
                    } catch (Exception e1) {
                    }
                }
            }
        }
    });
    ((CheckboxTreeViewer) resourceSelectionTree.getTreeViewer()).addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            selectedResources = resourceSelectionTree.getSelectedResources();
        }
    });
    resourceSelectionTree.getTreeViewer().addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            Object sel0 = sel.getFirstElement();
            if (sel0 instanceof IFile) {
                final ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor((IFile) sel0);
                try {
                    // then call those actions instead of showing the default compare dialog
                    if (alternateCompareActions.length > 0) {
                        StructuredSelection selection = new StructuredSelection(localResource);
                        for (int i = 0; i < alternateCompareActions.length; i++) {
                            // make sure the selection is up to date
                            alternateCompareActions[i].selectionChanged(selection);
                            alternateCompareActions[i].run();
                        }
                    } else {
                        setCompareInput(new SVNLocalCompareInput(localResource, SVNRevision.BASE, true));
                        showComparePane(true);
                        showCompareButton.setSelection(true);
                    }
                } catch (Exception e1) {
                }
            }
        }
    });
    if (!includeUnversioned) {
        resourceSelectionTree.removeUnversioned();
    }
    selectedResources = resourceSelectionTree.getSelectedResources();
    setPageComplete(canFinish());
}
Also used : IFile(org.eclipse.core.resources.IFile) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) ControlContribution(org.eclipse.jface.action.ControlContribution) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ToolBarManager(org.eclipse.jface.action.ToolBarManager) Control(org.eclipse.swt.widgets.Control) ResourceSelectionTree(org.tigris.subversion.subclipse.ui.util.ResourceSelectionTree) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SVNLocalCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SVNException(org.tigris.subversion.subclipse.core.SVNException) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) SVNPluginAction(org.tigris.subversion.subclipse.ui.actions.SVNPluginAction) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Separator(org.eclipse.jface.action.Separator) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with SVNLocalCompareInput

use of org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput in project subclipse by subclipse.

the class SvnWizardRevertPage method createControls.

public void createControls(Composite outerContainer) {
    Composite composite = new Composite(outerContainer, SWT.NULL);
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    ResourceSelectionTree.IToolbarControlCreator toolbarControlCreator = new ResourceSelectionTree.IToolbarControlCreator() {

        public void createToolbarControls(ToolBarManager toolbarManager) {
            toolbarManager.add(new // $NON-NLS-1$
            ControlContribution(// $NON-NLS-1$
            "ignoreUnversioned") {

                protected Control createControl(Composite parent) {
                    includeUnversionedButton = new Button(parent, SWT.CHECK);
                    includeUnversionedButton.setText(// $NON-NLS-1$
                    Policy.bind("CommitDialog.includeUnversioned"));
                    includeUnversionedButton.setSelection(includeUnversioned);
                    includeUnversionedButton.addSelectionListener(new SelectionListener() {

                        public void widgetSelected(SelectionEvent e) {
                            includeUnversioned = includeUnversionedButton.getSelection();
                            if (!includeUnversioned) {
                                resourceSelectionTree.removeUnversioned();
                            } else {
                                resourceSelectionTree.addUnversioned();
                            }
                            selectedResources = resourceSelectionTree.getSelectedResources();
                            setPageComplete(canFinish());
                            if (!fromSyncView)
                                updatePreference(includeUnversioned);
                        }

                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
                    });
                    return includeUnversionedButton;
                }
            });
        }

        public int getControlCount() {
            return 1;
        }
    };
    IResource[] dedupedResourcesToRevert = ResourceSelectionTree.dedupeResources(resourcesToRevert);
    if (dedupedResourcesToRevert.length != resourcesToRevert.length) {
        resourceRemoved = true;
    }
    resourceSelectionTree = new ResourceSelectionTree(composite, SWT.NONE, Policy.bind("GenerateSVNDiff.Changes"), dedupedResourcesToRevert, statusMap, null, true, toolbarControlCreator, // $NON-NLS-1$
    null);
    if (!resourceSelectionTree.showIncludeUnversionedButton())
        includeUnversionedButton.setVisible(false);
    // resourceSelectionTree.getTreeViewer().setAllChecked(true);
    resourceSelectionTree.getTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            selectedResources = resourceSelectionTree.getSelectedResources();
        }
    });
    ((CheckboxTreeViewer) resourceSelectionTree.getTreeViewer()).addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            selectedResources = resourceSelectionTree.getSelectedResources();
        }
    });
    resourceSelectionTree.getTreeViewer().addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            Object sel0 = sel.getFirstElement();
            if (sel0 instanceof IFile) {
                final ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor((IFile) sel0);
                try {
                    new CompareDialog(getShell(), new SVNLocalCompareInput(localResource, SVNRevision.BASE, true)).open();
                } catch (Exception e1) {
                }
            }
        }
    });
    if (!includeUnversioned) {
        resourceSelectionTree.removeUnversioned();
    }
    resourceSelectionTree.getTreeViewer().getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    // Composite composite_1 = new Composite(composite, SWT.NONE);
    // composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    // composite_1.setLayout(new GridLayout());
    selectedResources = resourceSelectionTree.getSelectedResources();
    setPageComplete(canFinish());
    PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.REVERT_DIALOG);
}
Also used : IFile(org.eclipse.core.resources.IFile) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ToolBarManager(org.eclipse.jface.action.ToolBarManager) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) ResourceSelectionTree(org.tigris.subversion.subclipse.ui.util.ResourceSelectionTree) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SVNLocalCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CompareDialog(org.tigris.subversion.subclipse.ui.dialogs.CompareDialog) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) IResource(org.eclipse.core.resources.IResource) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with SVNLocalCompareInput

use of org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput in project subclipse by subclipse.

the class ShowDifferencesAsUnifiedDiffActionWC method execute.

protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    IResource[] resources = getSelectedResources();
    boolean refreshFile = false;
    for (int i = 0; i < resources.length; i++) {
        if (resources[i] instanceof IFile && !resources[i].isSynchronized(Depth.immediates)) {
            if (refreshFile || MessageDialog.openQuestion(getShell(), Policy.bind("DifferencesDialog.compare"), Policy.bind("CompareWithRemoteAction.fileChanged"))) {
                refreshFile = true;
                try {
                    resources[i].refreshLocal(Depth.immediates, new NullProgressMonitor());
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            } else {
                break;
            }
        }
    }
    if (resources.length > 1) {
        SvnWizardCompareMultipleResourcesWithBranchTagPage comparePage = new SvnWizardCompareMultipleResourcesWithBranchTagPage(resources);
        SvnWizard wizard = new SvnWizard(comparePage);
        SvnWizardDialog dialog = new SvnWizardDialog(getShell(), wizard);
        if (dialog.open() == SvnWizardDialog.OK) {
            ISVNLocalResource[] localResources = new ISVNLocalResource[resources.length];
            for (int i = 0; i < resources.length; i++) {
                localResources[i] = SVNWorkspaceRoot.getSVNResourceFor(resources[i]);
            }
            try {
                SVNLocalBranchTagCompareInput compareInput = new SVNLocalBranchTagCompareInput(localResources, comparePage.getUrls(), comparePage.getRevision(), getTargetPart());
                CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
            } catch (SVNException e) {
                MessageDialog.openError(getShell(), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.branchTag"), e.getMessage());
            }
        }
        return;
    }
    ShowDifferencesAsUnifiedDiffDialogWC dialog = new ShowDifferencesAsUnifiedDiffDialogWC(getShell(), resources[0], getTargetPart());
    if (dialog.open() == ShowDifferencesAsUnifiedDiffDialogWC.OK) {
        try {
            if (dialog.isDiffToOutputFile())
                dialog.getOperation().run();
            if (!dialog.isDiffToOutputFile()) {
                SVNRevision pegRevision = dialog.getPegRevision();
                if (pegRevision == null) {
                    pegRevision = SVNRevision.HEAD;
                }
                if (resources[0] instanceof IContainer) {
                    ISVNRemoteFolder remoteFolder = new RemoteFolder(dialog.getSvnResource().getRepository(), dialog.getToUrl(), dialog.getToRevision());
                    ((RemoteFolder) remoteFolder).setPegRevision(pegRevision);
                    SVNLocalCompareInput compareInput = new SVNLocalCompareInput(dialog.getSvnResource(), remoteFolder, pegRevision);
                    compareInput.setDiffOperation(dialog.getOperation());
                    CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                } else {
                    ISVNRemoteFile remoteFile = new RemoteFile(dialog.getSvnResource().getRepository(), dialog.getToUrl(), dialog.getToRevision());
                    ((RemoteFile) remoteFile).setPegRevision(pegRevision);
                    SVNLocalCompareInput compareInput = new SVNLocalCompareInput(dialog.getSvnResource(), remoteFile, pegRevision);
                    CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                }
            }
        } catch (SVNException e) {
            MessageDialog.openError(getShell(), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.branchTag"), e.getMessage());
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SVNLocalCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput) IFile(org.eclipse.core.resources.IFile) RemoteFolder(org.tigris.subversion.subclipse.core.resources.RemoteFolder) ISVNRemoteFolder(org.tigris.subversion.subclipse.core.ISVNRemoteFolder) SvnWizardDialog(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardDialog) SvnWizard(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizard) ShowDifferencesAsUnifiedDiffDialogWC(org.tigris.subversion.subclipse.ui.dialogs.ShowDifferencesAsUnifiedDiffDialogWC) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ISVNRemoteFolder(org.tigris.subversion.subclipse.core.ISVNRemoteFolder) InvocationTargetException(java.lang.reflect.InvocationTargetException) SVNLocalBranchTagCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalBranchTagCompareInput) CoreException(org.eclipse.core.runtime.CoreException) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) SvnWizardCompareMultipleResourcesWithBranchTagPage(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardCompareMultipleResourcesWithBranchTagPage) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile)

Example 4 with SVNLocalCompareInput

use of org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput 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 5 with SVNLocalCompareInput

use of org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput in project subclipse by subclipse.

the class ResolveTreeConflictWizard method performFinish.

public boolean performFinish() {
    if (mainPage.getReplace()) {
        mergeException = null;
        try {
            BusyIndicator.showWhile(Display.getDefault(), new Runnable() {

                public void run() {
                    try {
                        svnClient = svnResource.getRepository().getSVNClient();
                        File file = svnResource.getResource().getLocation().toFile();
                        svnClient.remove(new File[] { file }, true);
                        SVNUrl url = new SVNUrl(treeConflict.getConflictDescriptor().getSrcRightVersion().getReposURL() + "/" + treeConflict.getConflictDescriptor().getSrcRightVersion().getPathInRepos());
                        SVNRevision revision;
                        int index = treeConflict.getConflictDescriptor().getSrcRightVersion().toString().lastIndexOf(// $NON-NLS-1$
                        "@");
                        if (index == -1) {
                            revision = SVNRevision.HEAD;
                        } else {
                            long number = Long.parseLong(treeConflict.getConflictDescriptor().getSrcRightVersion().toString().substring(index + 1));
                            revision = new SVNRevision.Number(number);
                        }
                        svnClient.copy(url, file, revision);
                    } catch (Exception e) {
                        mergeException = e;
                    }
                }
            });
            if (mergeException != null) {
                SVNUIPlugin.log(IStatus.ERROR, mergeException.getMessage(), mergeException);
                MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_2, mergeException.getMessage());
                return false;
            }
            svnResource.getResource().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        } catch (Exception e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
            MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_2, e.getMessage());
            return false;
        }
        return true;
    }
    compare = mainPage.getCompare();
    if (mainPage.getMergeFromRepository()) {
        try {
            final SVNUrl url = new SVNUrl(mainPage.getMergeFromUrl());
            SVNRevision revision1;
            if (treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() == treeConflict.getConflictDescriptor().getSrcRightVersion().getPegRevision())
                revision1 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() - 1);
            else
                revision1 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision());
            final SVNRevision revision2 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcRightVersion().getPegRevision());
            if (treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() == treeConflict.getConflictDescriptor().getSrcRightVersion().getPegRevision())
                revision1 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() - 1);
            final IResource mergeTarget = mainPage.getMergeTarget();
            final SVNRevision rev1 = revision1;
            svnClient = svnResource.getRepository().getSVNClient();
            mergeException = null;
            BusyIndicator.showWhile(Display.getDefault(), new Runnable() {

                public void run() {
                    try {
                        mergePath = mergeTarget.getLocation().toFile();
                        svnClient.merge(url, rev1, url, revision2, mergePath, true, false, false, true);
                        try {
                            // Refresh the resource after merge
                            if (mergeTarget.getParent() != null)
                                mergeTarget.getParent().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
                            else
                                mergeTarget.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
                        } catch (CoreException e1) {
                        }
                    } catch (Exception e) {
                        mergeException = e;
                    }
                }
            });
            if (mergeException != null) {
                SVNUIPlugin.log(IStatus.ERROR, mergeException.getMessage(), mergeException);
                MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_mergeError, mergeException.getMessage());
                return false;
            }
        } catch (Exception e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
            MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_mergeError, e.getMessage());
            return false;
        } finally {
            svnResource.getRepository().returnSVNClient(svnClient);
        }
    }
    if (mainPage.getCompare()) {
        if (mainPage.getCompareResource2() == null) {
            ISVNLocalResource svnCompareResource = mainPage.getSvnCompareResource();
            if (svnCompareResource == null)
                svnCompareResource = svnResource;
            ISVNRemoteResource remoteResource = mainPage.getRemoteResource();
            try {
                // $NON-NLS-1$ //$NON-NLS-2$
                File file = File.createTempFile("revision", ".diff");
                file.deleteOnExit();
                File path = new File(svnCompareResource.getResource().getLocation().toString());
                SVNUrl toUrl = remoteResource.getUrl();
                SVNRevision toRevision = remoteResource.getRevision();
                ShowDifferencesAsUnifiedDiffOperationWC operation = new ShowDifferencesAsUnifiedDiffOperationWC(targetPart, path, toUrl, toRevision, file);
                SVNLocalCompareInput compareInput = new SVNLocalCompareInput(svnCompareResource, remoteResource);
                compareInput.setDiffOperation(operation);
                CompareUI.openCompareEditorOnPage(compareInput, targetPart.getSite().getPage());
                CompareCloseListener closeListener = new CompareCloseListener(Messages.ResolveTreeConflictWizard_compare + svnCompareResource.getName() + // $NON-NLS-1$
                " <workspace>");
                targetPart.getSite().getPage().addPartListener(closeListener);
            } catch (Exception e) {
                SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
                MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_compareError, e.getMessage());
                return false;
            }
        } else {
            ISelection selection = new IStructuredSelection() {

                public Object getFirstElement() {
                    return mainPage.getCompareResource1();
                }

                public Iterator iterator() {
                    return toList().iterator();
                }

                public int size() {
                    return 2;
                }

                public Object[] toArray() {
                    IResource[] compareResources = { mainPage.getCompareResource1(), mainPage.getCompareResource2() };
                    return compareResources;
                }

                public List toList() {
                    List compareList = new ArrayList();
                    compareList.add(mainPage.getCompareResource1());
                    compareList.add(mainPage.getCompareResource2());
                    return compareList;
                }

                public boolean isEmpty() {
                    return false;
                }
            };
            CompareAction compareAction = new CompareAction();
            compareAction.setActivePart(null, targetPart);
            IAction action = new Action() {
            };
            compareAction.selectionChanged(action, selection);
            compareAction.run(selection);
            CompareCloseListener closeListener = new CompareCloseListener(Messages.ResolveTreeConflictWizard_compare2 + mainPage.getCompareResource1().getName() + "' - '" + mainPage.getCompareResource2().getName() + // $NON-NLS-1$ //$NON-NLS-2$
            "')");
            targetPart.getSite().getPage().addPartListener(closeListener);
        }
    }
    if (mainPage.getRevertResource() != null) {
        revertException = null;
        BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

            public void run() {
                try {
                    IResource[] revertResources = { mainPage.getRevertResource() };
                    RevertResourcesCommand revertCommand = new RevertResourcesCommand(svnResource.getWorkspaceRoot(), revertResources);
                    revertCommand.run(new NullProgressMonitor());
                } catch (Exception e) {
                    revertException = e;
                }
            }
        });
        if (revertException != null) {
            SVNUIPlugin.log(IStatus.ERROR, revertException.getMessage(), revertException);
            MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_revertError, revertException.getMessage());
            return false;
        }
    }
    if (mainPage.getDeleteResource() != null) {
        try {
            mainPage.getDeleteResource().delete(true, new NullProgressMonitor());
        } catch (CoreException e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
            MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_deleteError, e.getMessage());
            return false;
        }
    }
    if (mainPage.getMarkResolved() || mainPage.refreshConflicts()) {
        try {
            if (mainPage.getMarkResolved()) {
                IResource[] resolvedResources = { treeConflict.getResource() };
                ResolveOperation resolveOperation = new ResolveOperation(targetPart, resolvedResources, ISVNConflictResolver.Choice.chooseMerged) {

                    protected boolean canRunAsJob() {
                        return false;
                    }
                };
                resolveOperation.run();
            }
            if (mainPage.refreshConflicts()) {
                IResource[] refreshResources = { svnResource.getResource() };
                TreeConflictsView.refresh(refreshResources);
            }
        } catch (Exception e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
            MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_markResolvedError, e.getMessage());
            return false;
        }
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CompareAction(org.eclipse.compare.internal.CompareAction) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ShowDifferencesAsUnifiedDiffOperationWC(org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC) RevertResourcesCommand(org.tigris.subversion.subclipse.core.commands.RevertResourcesCommand) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) List(java.util.List) SVNLocalCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput) IAction(org.eclipse.jface.action.IAction) ResolveOperation(org.tigris.subversion.subclipse.ui.operations.ResolveOperation) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) CompareAction(org.eclipse.compare.internal.CompareAction) CoreException(org.eclipse.core.runtime.CoreException) SVNException(org.tigris.subversion.subclipse.core.SVNException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) CoreException(org.eclipse.core.runtime.CoreException) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Aggregations

ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)7 SVNLocalCompareInput (org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput)7 IFile (org.eclipse.core.resources.IFile)6 SVNException (org.tigris.subversion.subclipse.core.SVNException)6 IResource (org.eclipse.core.resources.IResource)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 ISVNRemoteFile (org.tigris.subversion.subclipse.core.ISVNRemoteFile)3 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ToolBarManager (org.eclipse.jface.action.ToolBarManager)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)2 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)2