IDEA-27603 (Indicate which branch is being worked on)
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / ui / ChangesBrowserLockedFoldersNode.java
bloba9d512668392b558e1c0adbcb10a597c0a887d4c
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.ui;
18 import com.intellij.openapi.project.Project;
19 import com.intellij.openapi.vcs.AbstractVcs;
20 import com.intellij.openapi.vcs.ProjectLevelVcsManager;
21 import com.intellij.openapi.vcs.VcsBundle;
22 import com.intellij.openapi.vcs.changes.ChangeListOwner;
23 import com.intellij.openapi.vcs.changes.ChangeProvider;
24 import com.intellij.openapi.vcs.changes.issueLinks.TreeLinkMouseListener;
25 import com.intellij.openapi.vfs.VirtualFile;
26 import com.intellij.ui.SimpleTextAttributes;
28 import java.awt.*;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
34 public class ChangesBrowserLockedFoldersNode extends ChangesBrowserNode implements TreeLinkMouseListener.HaveTooltip {
35 private final Project myProject;
37 public ChangesBrowserLockedFoldersNode(final Project project, final Object userObject) {
38 super(userObject);
39 myProject = project;
42 public boolean canAcceptDrop(final ChangeListDragBean dragBean) {
43 return false;
46 public void acceptDrop(final ChangeListOwner dragOwner, final ChangeListDragBean dragBean) {
49 public String getTooltip() {
50 return VcsBundle.message("changes.nodetitle.locked.folders.tooltip");
53 public void render(final ChangesBrowserNodeRenderer renderer, final boolean selected, final boolean expanded, final boolean hasFocus) {
54 renderer.append(userObject.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
55 renderer.append(getCountText(), SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES);
56 renderer.append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
57 final CleanupStarter starter = new CleanupStarter(myProject, this);
58 renderer.append("do cleanup...", new SimpleTextAttributes(SimpleTextAttributes.STYLE_UNDERLINE, Color.red), starter);
61 private static class CleanupStarter implements Runnable {
62 private final Project myProject;
63 private final ChangesBrowserLockedFoldersNode myParentNode;
65 private CleanupStarter(final Project project, final ChangesBrowserLockedFoldersNode parentNode) {
66 myProject = project;
67 myParentNode = parentNode;
70 public void run() {
71 final List<VirtualFile> files = myParentNode.getAllFilesUnder();
72 final ProjectLevelVcsManager plVcsManager = ProjectLevelVcsManager.getInstance(myProject);
73 final Map<String, List<VirtualFile>> byVcs = new HashMap<String, List<VirtualFile>>();
74 for (VirtualFile file : files) {
75 final AbstractVcs vcs = plVcsManager.getVcsFor(file);
76 if (vcs != null) {
77 List<VirtualFile> list = byVcs.get(vcs.getName());
78 if (list == null) {
79 list = new ArrayList<VirtualFile>();
80 byVcs.put(vcs.getName(), list);
82 list.add(file);
85 for (Map.Entry<String, List<VirtualFile>> entry : byVcs.entrySet()) {
86 final AbstractVcs vcs = plVcsManager.findVcsByName(entry.getKey());
87 if (vcs != null) {
88 final ChangeProvider changeProvider = vcs.getChangeProvider();
89 if (changeProvider != null) {
90 changeProvider.doCleanup(entry.getValue());