VCS: fix group by structure for Changes | Local
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / ChangesDelta.java
blob692f9b629c8d0f618ce82923eb46e94206f51fe4
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.vcs.changes;
18 import com.intellij.openapi.project.Project;
19 import com.intellij.openapi.util.Pair;
20 import com.intellij.openapi.vcs.AbstractVcs;
21 import com.intellij.openapi.vcs.ProjectLevelVcsManager;
22 import com.intellij.openapi.vcs.VcsKey;
23 import com.intellij.openapi.vcs.impl.CollectionsDelta;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.Set;
29 public class ChangesDelta {
30 private final PlusMinus<Pair<String, AbstractVcs>> myDeltaListener;
31 private ProjectLevelVcsManager myVcsManager;
32 private boolean myInitialized;
34 public ChangesDelta(final Project project, final PlusMinus<Pair<String, AbstractVcs>> deltaListener) {
35 myDeltaListener = deltaListener;
36 myVcsManager = ProjectLevelVcsManager.getInstance(project);
39 public void step(final ChangeListsIndexes was, final ChangeListsIndexes became) {
40 List<Pair<String, VcsKey>> wasAffected = was.getAffectedFilesUnderVcs();
41 if (! myInitialized) {
42 sendPlus(wasAffected);
43 myInitialized = true;
44 return;
46 final List<Pair<String, VcsKey>> becameAffected = became.getAffectedFilesUnderVcs();
48 final Set<Pair<String,VcsKey>> toRemove = CollectionsDelta.notInSecond(wasAffected, becameAffected);
49 final Set<Pair<String, VcsKey>> toAdd = CollectionsDelta.notInSecond(becameAffected, wasAffected);
51 if (toRemove != null) {
52 for (Pair<String, VcsKey> pair : toRemove) {
53 myDeltaListener.minus(convertPair(pair));
56 sendPlus(toAdd);
59 private void sendPlus(final Collection<Pair<String, VcsKey>> toAdd) {
60 if (toAdd != null) {
61 for (Pair<String, VcsKey> pair : toAdd) {
62 myDeltaListener.plus(convertPair(pair));
67 private Pair<String, AbstractVcs> convertPair(final Pair<String, VcsKey> pair) {
68 final VcsKey vcsKey = pair.getSecond();
69 return new Pair<String, AbstractVcs>(pair.getFirst(), (vcsKey == null) ? null : myVcsManager.findVcsByName(vcsKey.getName()));