changelist conflict dialog refactored
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / conflicts / ChangelistConflictAccessProvider.java
blobb8fc2fcbe11ff9ab99952e5344b1c064eaac5711
1 package com.intellij.openapi.vcs.changes.conflicts;
3 import com.intellij.openapi.project.Project;
4 import com.intellij.openapi.vcs.changes.Change;
5 import com.intellij.openapi.vcs.changes.ChangeList;
6 import com.intellij.openapi.vcs.changes.ChangeListManagerImpl;
7 import com.intellij.openapi.vcs.readOnlyHandler.WritingAccessProvider;
8 import com.intellij.openapi.vfs.VirtualFile;
9 import org.jetbrains.annotations.NotNull;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.HashSet;
14 import java.util.Collections;
16 /**
17 * @author Dmitry Avdeev
19 public class ChangelistConflictAccessProvider implements WritingAccessProvider {
21 private final Project myProject;
22 private final ChangeListManagerImpl myManager;
24 public ChangelistConflictAccessProvider(Project project, ChangeListManagerImpl manager) {
25 myProject = project;
26 myManager = manager;
29 @NotNull
30 public Collection<VirtualFile> requestWriting(VirtualFile... files) {
31 ChangelistConflictTracker.Options options = myManager.getConflictTracker().getOptions();
32 if (!options.TRACKING_ENABLED || !options.SHOW_DIALOG) {
33 return Collections.emptyList();
35 ArrayList<VirtualFile> denied = new ArrayList<VirtualFile>();
36 for (VirtualFile file : files) {
37 if (file != null && !myManager.getConflictTracker().isWritingAllowed(file)) {
38 denied.add(file);
42 if (!denied.isEmpty()) {
43 HashSet<ChangeList> changeLists = new HashSet<ChangeList>();
44 ArrayList<Change> changes = new ArrayList<Change>();
45 for (VirtualFile file : denied) {
46 changeLists.add(myManager.getChangeList(file));
47 changes.add(myManager.getChange(file));
50 ChangelistConflictDialog dialog;
51 do {
52 dialog = new ChangelistConflictDialog(myProject, new ArrayList<ChangeList>(changeLists), denied);
53 dialog.show();
54 } while (dialog.isOK() && !dialog.getResolution().resolveConflict(myProject, changes));
56 if (dialog.isOK()) {
57 options.LAST_RESOLUTION = dialog.getResolution();
58 return Collections.emptyList();
61 return denied;