1 package org.jetbrains.idea.svn.difftool;
3 import com.intellij.diff.DiffContext;
4 import com.intellij.diff.FrameDiffTool;
5 import com.intellij.diff.chains.DiffRequestProducerException;
6 import com.intellij.diff.requests.DiffRequest;
7 import com.intellij.openapi.progress.BackgroundTaskQueue;
8 import com.intellij.openapi.progress.ProcessCanceledException;
9 import com.intellij.openapi.progress.ProgressIndicator;
10 import com.intellij.openapi.project.Project;
11 import com.intellij.openapi.util.Disposer;
12 import com.intellij.openapi.util.UserDataHolder;
13 import com.intellij.openapi.vcs.changes.Change;
14 import com.intellij.openapi.vcs.changes.actions.diff.ChangeDiffRequestProducer;
15 import com.intellij.openapi.vcs.changes.actions.diff.ChangeDiffRequestProvider;
16 import com.intellij.ui.components.panels.Wrapper;
17 import com.intellij.util.ThreeState;
18 import org.jetbrains.annotations.NotNull;
19 import org.jetbrains.annotations.Nullable;
20 import org.jetbrains.idea.svn.ConflictedSvnChange;
21 import org.jetbrains.idea.svn.conflict.TreeConflictDescription;
22 import org.jetbrains.idea.svn.treeConflict.TreeConflictRefreshablePanel;
26 public class SvnTreeConflictDiffRequestProvider implements ChangeDiffRequestProvider {
29 public ThreeState isEquals(@NotNull Change change1, @NotNull Change change2) {
30 if (change1 instanceof ConflictedSvnChange && change2 instanceof ConflictedSvnChange) {
31 if (!change1.isTreeConflict() && !change2.isTreeConflict()) return ThreeState.UNSURE;
32 if (!change1.isTreeConflict() || !change2.isTreeConflict()) return ThreeState.NO;
34 TreeConflictDescription description1 = ((ConflictedSvnChange)change1).getBeforeDescription();
35 TreeConflictDescription description2 = ((ConflictedSvnChange)change2).getBeforeDescription();
36 return TreeConflictRefreshablePanel.descriptionsEqual(description1, description2) ? ThreeState.YES : ThreeState.NO;
38 return ThreeState.UNSURE;
42 public boolean canCreate(@Nullable Project project, @NotNull Change change) {
43 return change instanceof ConflictedSvnChange && ((ConflictedSvnChange)change).getConflictState().isTree();
48 public DiffRequest process(@NotNull ChangeDiffRequestProducer presentable,
49 @NotNull UserDataHolder context,
50 @NotNull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException {
51 return new SvnTreeConflictDiffRequest(((ConflictedSvnChange)presentable.getChange()));
54 public static class SvnTreeConflictDiffRequest extends DiffRequest {
55 @NotNull private final ConflictedSvnChange myChange;
57 public SvnTreeConflictDiffRequest(@NotNull ConflictedSvnChange change) {
62 public ConflictedSvnChange getChange() {
68 public String getTitle() {
69 return ChangeDiffRequestProducer.getRequestTitle(myChange);
73 public static class SvnTreeConflictDiffTool implements FrameDiffTool {
76 public String getName() {
77 return "SVN tree conflict viewer";
81 public boolean canShow(@NotNull DiffContext context, @NotNull DiffRequest request) {
82 return request instanceof SvnTreeConflictDiffRequest;
87 public DiffViewer createComponent(@NotNull DiffContext context, @NotNull DiffRequest request) {
88 return new SvnTreeConflictDiffViewer(context, (SvnTreeConflictDiffRequest)request);
92 private static class SvnTreeConflictDiffViewer implements FrameDiffTool.DiffViewer {
93 @NotNull private final DiffContext myContext;
94 @NotNull private final SvnTreeConflictDiffRequest myRequest;
95 @NotNull private final Wrapper myPanel = new Wrapper();
97 @NotNull private final BackgroundTaskQueue myQueue;
98 @NotNull private final TreeConflictRefreshablePanel myDelegate;
100 public SvnTreeConflictDiffViewer(@NotNull DiffContext context, @NotNull SvnTreeConflictDiffRequest request) {
104 myQueue = new BackgroundTaskQueue(myContext.getProject(), "Loading change details");
106 // We don't need to listen on File/Document, because panel always will be the same for a single change.
107 // And if Change will change - we'll create new DiffRequest and DiffViewer
109 new TreeConflictRefreshablePanel(myContext.getProject(), "Loading tree conflict details", myQueue, myRequest.getChange());
110 myDelegate.refresh();
111 myPanel.setContent(myDelegate.getPanel());
116 public JComponent getComponent() {
122 public JComponent getPreferredFocusedComponent() {
128 public FrameDiffTool.ToolbarComponents init() {
129 return new FrameDiffTool.ToolbarComponents();
133 public void dispose() {
135 Disposer.dispose(myDelegate);