Example usage for com.intellij.openapi.diff DiffManager getInstance

List of usage examples for com.intellij.openapi.diff DiffManager getInstance

Introduction

In this page you can find the example usage for com.intellij.openapi.diff DiffManager getInstance.

Prototype

public static DiffManager getInstance() 

Source Link

Usage

From source file:com.dci.intellij.dbn.editor.code.SourceCodeEditorManager.java

License:Apache License

private void showSourceDiffDialog(final String databaseContent, final SourceCodeFile virtualFile,
        final Editor editor) {
    new SimpleLaterInvocator() {
        public void run() {
            DiffRequestFactory diffRequestFactory = new DiffRequestFactoryImpl();
            MergeRequest mergeRequest = diffRequestFactory.createMergeRequest(databaseContent,
                    virtualFile.getContent(), virtualFile.getLastSavedContent(), virtualFile,
                    virtualFile.getProject(), ActionButtonPresentation.APPLY,
                    ActionButtonPresentation.CANCEL_WITH_PROMPT);
            mergeRequest.setVersionTitles(new String[] { "Database version", "Merge result", "Your version" });
            final DBSchemaObject object = virtualFile.getObject();
            mergeRequest.setWindowTitle("Version conflict resolution for " + object.getQualifiedNameWithType());

            DiffManager.getInstance().getDiffTool().show(mergeRequest);

            int result = mergeRequest.getResult();
            if (result == 0) {
                doUpdateSourceToDatabase(object, virtualFile, editor);
                //sourceCodeEditor.afterSave();
            } else if (result == 1) {
                new WriteActionRunner() {
                    public void run() {
                        editor.getDocument().setText(virtualFile.getContent());
                        object.getStatus().set(DBObjectStatus.SAVING, false);
                    }/*www  . ja v a 2 s.  co  m*/
                }.start();
            }
        }
    }.start();
}

From source file:com.intellij.debugger.actions.CompareValueWithClipboardAction.java

License:Apache License

protected void processText(final Project project, final String text, DebuggerTreeNodeImpl node,
        DebuggerContextImpl debuggerContext) {
    DiffManager.getInstance().getDiffTool().show(new ClipboardVsValueContents(text, project));
}

From source file:com.intellij.diff.actions.impl.ShowOldDiffAction.java

License:Apache License

@RequiredDispatchThread
@Override/*  w w  w. j  av  a 2  s . c  om*/
public void actionPerformed(AnActionEvent e) {
    ContentDiffRequest request = (ContentDiffRequest) e.getRequiredData(DiffDataKeys.DIFF_REQUEST);
    List<DiffContent> contents = request.getContents();
    List<String> titles = request.getContentTitles();

    SimpleDiffRequest newRequest = new SimpleDiffRequest(e.getProject(), request.getTitle());
    newRequest.setContentTitles(titles.get(0), titles.get(1));
    newRequest.setContents(convert(e.getProject(), contents.get(0)), convert(e.getProject(), contents.get(1)));
    newRequest.addHint(DO_NOT_TRY_MIGRATE);

    DiffManager.getInstance().getDiffTool().show(newRequest);
}

From source file:com.intellij.execution.testframework.stacktrace.DiffHyperlink.java

License:Apache License

public void openDiff(final Project project) {
    String expectedTitle = ExecutionBundle.message("diff.content.expected.title");
    final DiffContent expectedContent;
    final VirtualFile vFile;
    if (myFilePath != null && (vFile = LocalFileSystem.getInstance().findFileByPath(myFilePath)) != null) {
        expectedContent = DiffContent.fromFile(project, vFile);
        expectedTitle += " (" + vFile.getPresentableUrl() + ")";
    } else/*from  w ww. ja  v  a 2 s  .com*/
        expectedContent = new SimpleContent(myExpected);
    final SimpleDiffRequest diffData = new SimpleDiffRequest(project, getTitle());
    diffData.setContents(expectedContent, new SimpleContent(myActual));
    diffData.setContentTitles(expectedTitle, ExecutionBundle.message("diff.content.actual.title"));
    diffData.addHint(DiffTool.HINT_SHOW_FRAME);
    diffData.addHint(DiffTool.HINT_DO_NOT_IGNORE_WHITESPACES);
    diffData.setGroupKey("#com.intellij.execution.junit2.states.ComparisonFailureState$DiffDialog");
    DiffManager.getInstance().getIdeaDiffTool().show(diffData);
}

From source file:com.intellij.history.integration.ui.views.FileHistoryDialog.java

License:Apache License

@Override
protected Pair<JComponent, Dimension> createDiffPanel(JPanel root, ExcludingTraversalPolicy traversalPolicy) {
    myDiffPanel = DiffManager.getInstance().createDiffPanel(getFrame(), myProject, this, null);
    DiffPanelOptions o = ((DiffPanelEx) myDiffPanel).getOptions();
    o.setRequestFocusOnNewContent(false);
    return Pair.create((JComponent) myDiffPanel.getComponent(), null);
}

From source file:com.intellij.ide.diff.DiffElement.java

License:Apache License

@Nullable
public JComponent getDiffComponent(DiffElement element, Project project, Window parentWindow,
        Disposable disposableParent) throws FilesTooBigForDiffException {
    disposeDiffComponent();/*ww  w. j  av a2s . co  m*/

    DiffRequest request;
    try {
        request = createRequest(project, element);
    } catch (IOException e) {
        // TODO
        LOG.error(e);
        return null;
    }
    if (request != null) {
        myDiffPanel = DiffManager.getInstance().createDiffPanel(parentWindow, project, disposableParent, null);
        myDiffPanel.setRequestFocus(false);
        myDiffPanel.setDiffRequest(request);
        myDiffPanel.setTitle1(getName());
        myDiffPanel.setTitle2(element.getName());
        return myDiffPanel.getComponent();
    }

    return null;
}

From source file:com.intellij.xdebugger.impl.ui.tree.actions.XCompareWithClipboardAction.java

License:Apache License

@Override
protected void handle(final Project project, final String value) {
    UIUtil.invokeLaterIfNeeded(new Runnable() {
        @Override//from  ww  w.  j ava 2 s . c  o m
        public void run() {
            DiffManager.getInstance().getDiffTool().show(new ClipboardVsValueContents(value, project));
        }
    });
}

From source file:com.microsoft.alm.plugin.idea.tfvc.core.tfs.conflicts.DialogContentMerger.java

License:Open Source License

public boolean mergeContent(final ContentTriplet contentTriplet, final Project project,
        final VirtualFile localFile, final VcsRevisionNumber serverVersion) {
    ArgumentHelper.checkIfFileWriteable(new File(localFile.getPath()));

    final MergeDialogCustomizer c = new MergeDialogCustomizer();
    final MergeRequest request = DiffRequestFactory.getInstance().createMergeRequest(
            StreamUtil.convertSeparators(contentTriplet.localContent),
            StreamUtil.convertSeparators(contentTriplet.serverContent),
            StreamUtil.convertSeparators(contentTriplet.baseContent), localFile, project,
            ActionButtonPresentation.APPLY, ActionButtonPresentation.CANCEL_WITH_PROMPT);

    request.setWindowTitle(c.getMergeWindowTitle(localFile));
    request.setVersionTitles(new String[] { c.getLeftPanelTitle(localFile), c.getCenterPanelTitle(localFile),
            c.getRightPanelTitle(localFile, serverVersion) });

    // TODO (Jetbrains) call canShow() first
    DiffManager.getInstance().getDiffTool().show(request);
    if (request.getResult() == DialogWrapper.OK_EXIT_CODE) {
        return true;
    } else {//  w  ww. ja  v a 2 s  .  c  o  m
        request.restoreOriginalContent();
        // TODO (Jetbrains) maybe MergeVersion.MergeDocumentVersion.restoreOriginalContent() should save document itself?
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
            public void run() {
                final Document document = FileDocumentManager.getInstance().getDocument(localFile);
                if (document != null) {
                    FileDocumentManager.getInstance().saveDocument(document);
                }
            }
        });
        return false;
    }
}

From source file:com.urswolfer.intellij.plugin.gerrit.OpenIdeDependenciesModule.java

License:Apache License

@Override
protected void configure() {
    bind(Logger.class).toInstance(LOG);
    bind(Application.class).toInstance(ApplicationManager.getApplication());

    bind(DiffManager.class).toInstance(DiffManager.getInstance());
    bind(LocalFileSystem.class).toInstance(LocalFileSystem.getInstance());

    bind(Git.class).toInstance(ServiceManager.getService(Git.class));
    bind(GitPlatformFacade.class).toInstance(ServiceManager.getService(GitPlatformFacade.class));
    bind(FileDocumentManager.class).toInstance(FileDocumentManager.getInstance());
    bind(VirtualFileManager.class).toInstance(VirtualFileManager.getInstance());

    bind(ShowSettingsUtil.class).toInstance(ShowSettingsUtil.getInstance());
    bind(DataManager.class).toInstance(DataManager.getInstance());

    bind(JBPopupFactory.class).toInstance(JBPopupFactory.getInstance());
}

From source file:com.urswolfer.intellij.plugin.gerrit.ui.diff.CustomizableFrameDiffTool.java

License:Apache License

private boolean checkNoDifferenceAndNotify(DiffPanel diffPanel, DiffRequest data, final Window window,
        final boolean showMessage) {
    if (!diffPanel.hasDifferences() && !data.getHints().contains(HINT_ALLOW_NO_DIFFERENCES)) {
        DiffManagerImpl manager = (DiffManagerImpl) DiffManager.getInstance();
        if (!Comparing.equal(manager.getComparisonPolicy(), ComparisonPolicy.DEFAULT)) {
            ComparisonPolicy oldPolicy = manager.getComparisonPolicy();
            manager.setComparisonPolicy(ComparisonPolicy.DEFAULT);
            Disposable parentDisposable = Disposer.newDisposable();
            DiffPanel maybeDiffPanel = createDiffPanel(data, window, parentDisposable, this);
            manager.setComparisonPolicy(oldPolicy);

            boolean hasDiffs = maybeDiffPanel.hasDifferences();
            Disposer.dispose(parentDisposable);

            if (hasDiffs)
                return false;
        }/*w w w. ja  va 2  s.  com*/

        if (!showMessage) {
            return true;
        }
        return !askForceOpenDiff(data);
    }
    return false;
}