Search in sources :

Example 1 with CompareEditorInput

use of org.eclipse.compare.CompareEditorInput in project egit by eclipse.

the class CompareUtils method compareLocalWithRef.

/**
 * Opens a compare editor comparing the working directory version of the
 * file at the given location with the version corresponding to
 * {@code refName} of the same file.
 *
 * @param repository
 *            The repository to load file revisions from.
 * @param location
 *            Location of the file to compare revisions for.
 * @param refName
 *            Reference to compare with the workspace version of
 *            {@code file}. Can be either a commit ID, a reference or a
 *            branch name.
 * @param page
 *            If not {@null} try to re-use a compare editor on this
 *            page if any is available. Otherwise open a new one.
 */
private static void compareLocalWithRef(@NonNull final Repository repository, @NonNull final IPath location, final String refName, final IWorkbenchPage page) {
    Job job = new Job(UIText.CompareUtils_jobName) {

        @Override
        public IStatus run(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            final String gitPath = getRepoRelativePath(location, repository);
            final ITypedElement base = new LocalNonWorkspaceTypedElement(repository, location);
            CompareEditorInput in;
            try {
                in = prepareCompareInput(repository, gitPath, base, refName);
            } catch (IOException e) {
                return Activator.createErrorStatus(UIText.CompareWithRefAction_errorOnSynchronize, e);
            }
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            openCompareEditorRunnable(page, in);
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompareEditorInput(org.eclipse.compare.CompareEditorInput) GitCompareEditorInput(org.eclipse.egit.ui.internal.merge.GitCompareEditorInput) SaveableCompareEditorInput(org.eclipse.team.ui.synchronize.SaveableCompareEditorInput) ITypedElement(org.eclipse.compare.ITypedElement) LocalNonWorkspaceTypedElement(org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job)

Example 2 with CompareEditorInput

use of org.eclipse.compare.CompareEditorInput in project egit by eclipse.

the class RebaseResultDialog method buttonPressed.

@Override
protected void buttonPressed(int buttonId) {
    // store the preference to hide these dialogs
    if (toggleButton != null)
        Activator.getDefault().getPreferenceStore().setValue(UIPreferences.SHOW_REBASE_CONFIRM, !toggleButton.getSelection());
    if (buttonId == IDialogConstants.OK_ID) {
        if (result.getStatus() != Status.STOPPED) {
            super.buttonPressed(buttonId);
            return;
        }
        if (startMergeButton.getSelection()) {
            super.buttonPressed(buttonId);
            // open the merge tool
            IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
            for (IProject project : projects) {
                RepositoryMapping mapping = RepositoryMapping.getMapping(project);
                if (mapping != null && mapping.getRepository().equals(repo)) {
                    try {
                        // make sure to refresh before opening the merge
                        // tool
                        project.refreshLocal(IResource.DEPTH_INFINITE, null);
                    } catch (CoreException e) {
                        Activator.handleError(e.getMessage(), e, false);
                    }
                }
            }
            List<IPath> locationList = new ArrayList<>();
            IPath repoWorkdirPath = new Path(repo.getWorkTree().getPath());
            for (String repoPath : conflictPaths) {
                IPath location = repoWorkdirPath.append(repoPath);
                locationList.add(location);
            }
            IPath[] locations = locationList.toArray(new IPath[locationList.size()]);
            int mergeMode = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.MERGE_MODE);
            CompareEditorInput input;
            if (mergeMode == 0) {
                MergeModeDialog dlg = new MergeModeDialog(getParentShell());
                if (dlg.open() != Window.OK)
                    return;
                input = new GitMergeEditorInput(dlg.useWorkspace(), locations);
            } else {
                boolean useWorkspace = mergeMode == 1;
                input = new GitMergeEditorInput(useWorkspace, locations);
            }
            CompareUI.openCompareEditor(input);
            return;
        } else if (skipCommitButton.getSelection()) {
            // skip the rebase
            SkipRebaseCommand skipCommand = new SkipRebaseCommand();
            execute(skipCommand);
        } else if (abortRebaseButton.getSelection()) {
            // abort the rebase
            AbortRebaseCommand abortCommand = new AbortRebaseCommand();
            execute(abortCommand);
        } else if (doNothingButton.getSelection()) {
        // nothing
        }
    }
    super.buttonPressed(buttonId);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) GitMergeEditorInput(org.eclipse.egit.ui.internal.merge.GitMergeEditorInput) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) AbortRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.AbortRebaseCommand) CompareEditorInput(org.eclipse.compare.CompareEditorInput) CoreException(org.eclipse.core.runtime.CoreException) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) MergeModeDialog(org.eclipse.egit.ui.internal.merge.MergeModeDialog) SkipRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.SkipRebaseCommand)

Example 3 with CompareEditorInput

use of org.eclipse.compare.CompareEditorInput in project InformationSystem by ObeoNetwork.

the class ExportAsSQLScriptsAction method setActiveEditor.

@Override
public void setActiveEditor(final IAction action, final IEditorPart activeEditor) {
    this.activeEditor = activeEditor;
    editorPluginAction = action;
    action.setEnabled(false);
    if (activeEditor != null && activeEditor.getEditorSite() != null && COMPARE_EDITOR_ID.equals(activeEditor.getEditorSite().getId())) {
        final IEditorInput editorInput = activeEditor.getEditorInput();
        if (editorInput instanceof CompareEditorInput) {
            final CompareConfiguration config = ((CompareEditorInput) editorInput).getCompareConfiguration();
            if (propertyChangeListener == null) {
                propertyChangeListener = new IPropertyChangeListener() {

                    @Override
                    public void propertyChange(PropertyChangeEvent event) {
                        // FIX for EMFCompare 2.2
                        if (isInitEventBus(event) && eventBusChangeRecorder == null) {
                            eventBusChangeRecorder = new EventBusChangeRecorder();
                            ((EventBus) event.getNewValue()).register(eventBusChangeRecorder);
                        }
                    }
                };
                config.addPropertyChangeListener(propertyChangeListener);
            }
            if (comparison != null) {
                editorPluginAction.setEnabled(areDatabaseDifferences(comparison));
            }
        }
    }
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) CompareEditorInput(org.eclipse.compare.CompareEditorInput) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) CompareConfiguration(org.eclipse.compare.CompareConfiguration) IEditorInput(org.eclipse.ui.IEditorInput)

Example 4 with CompareEditorInput

use of org.eclipse.compare.CompareEditorInput in project cubrid-manager by CUBRID.

the class TableSchemaCompareInfoPart method showEntireSchemaCompareEditor.

/**
	 * Display entire schemas comparison
	 */
private void showEntireSchemaCompareEditor(String leftDatabase, String rightDatabase, final String leftContent, final String rightContent) {
    CompareConfiguration config = new CompareConfiguration();
    config.setProperty(CompareConfiguration.SHOW_PSEUDO_CONFLICTS, Boolean.FALSE);
    config.setProperty(CompareConfiguration.IGNORE_WHITESPACE, Boolean.TRUE);
    config.setLeftEditable(false);
    config.setLeftLabel(leftDatabase);
    config.setRightEditable(false);
    config.setRightLabel(rightDatabase);
    CompareEditorInput editorInput = new CompareEditorInput(config) {

        protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            return new DiffNode(null, Differencer.CHANGE, null, new TextCompareInput(leftContent), new TextCompareInput(rightContent));
        }

        public void saveChanges(IProgressMonitor pm) throws CoreException {
            super.saveChanges(pm);
        }
    };
    editorInput.setTitle(Messages.entireDbSchemaComparison);
    CompareUI.openCompareEditor(editorInput);
}
Also used : CompareEditorInput(org.eclipse.compare.CompareEditorInput) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompareConfiguration(org.eclipse.compare.CompareConfiguration) DiffNode(org.eclipse.compare.structuremergeviewer.DiffNode)

Example 5 with CompareEditorInput

use of org.eclipse.compare.CompareEditorInput in project linuxtools by eclipse.

the class ChangeLogAction method getDocumentLocation.

protected String getDocumentLocation(IEditorPart currentEditor, boolean appendRoot) {
    IFile loc = getDocumentIFile(currentEditor);
    IEditorInput cc = null;
    String WorkspaceRoot;
    IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
    WorkspaceRoot = myWorkspaceRoot.getLocation().toOSString();
    if (currentEditor instanceof MultiPageEditorPart) {
        Object ed = ((MultiPageEditorPart) currentEditor).getSelectedPage();
        if (ed instanceof IEditorPart)
            cc = ((IEditorPart) ed).getEditorInput();
        if (cc instanceof FileEditorInput)
            return (appendRoot) ? WorkspaceRoot + ((FileEditorInput) cc).getFile().getFullPath().toOSString() : ((FileEditorInput) cc).getFile().getFullPath().toOSString();
    }
    cc = currentEditor.getEditorInput();
    if (cc == null)
        return "";
    if ((cc instanceof SyncInfoCompareInput) || (cc instanceof CompareEditorInput)) {
        CompareEditorInput test = (CompareEditorInput) cc;
        if (test.getCompareResult() == null) {
            return "";
        } else if (test.getCompareResult() instanceof ICompareInput) {
            ITypedElement leftCompare = ((ICompareInput) test.getCompareResult()).getLeft();
            if (leftCompare instanceof IResourceProvider) {
                String localPath = ((IResourceProvider) leftCompare).getResource().getFullPath().toString();
                if (appendRoot) {
                    return WorkspaceRoot + localPath;
                }
                return localPath;
            }
        } else {
            if (appendRoot)
                return WorkspaceRoot + test.getCompareResult().toString();
            return test.getCompareResult().toString();
        }
    } else if (cc instanceof FileStoreEditorInput) {
        return ((FileStoreEditorInput) cc).getName();
    }
    if (appendRoot) {
        return WorkspaceRoot + loc.getFullPath().toOSString();
    } else if (loc != null) {
        return loc.getFullPath().toOSString();
    } else {
        return "";
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) ITypedElement(org.eclipse.compare.ITypedElement) ICompareInput(org.eclipse.compare.structuremergeviewer.ICompareInput) IEditorPart(org.eclipse.ui.IEditorPart) IResourceProvider(org.eclipse.compare.IResourceProvider) CompareEditorInput(org.eclipse.compare.CompareEditorInput) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SyncInfoCompareInput(org.eclipse.team.ui.synchronize.SyncInfoCompareInput) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Aggregations

CompareEditorInput (org.eclipse.compare.CompareEditorInput)12 CompareConfiguration (org.eclipse.compare.CompareConfiguration)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 ITypedElement (org.eclipse.compare.ITypedElement)5 DiffNode (org.eclipse.compare.structuremergeviewer.DiffNode)4 IPath (org.eclipse.core.runtime.IPath)3 GitCompareEditorInput (org.eclipse.egit.ui.internal.merge.GitCompareEditorInput)3 SaveableCompareEditorInput (org.eclipse.team.ui.synchronize.SaveableCompareEditorInput)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 Job (org.eclipse.core.runtime.jobs.Job)2 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)2 GitMergeEditorInput (org.eclipse.egit.ui.internal.merge.GitMergeEditorInput)2 MergeModeDialog (org.eclipse.egit.ui.internal.merge.MergeModeDialog)2 LocalNonWorkspaceTypedElement (org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement)2 ArrayList (java.util.ArrayList)1 IResourceProvider (org.eclipse.compare.IResourceProvider)1 ICompareInput (org.eclipse.compare.structuremergeviewer.ICompareInput)1