add file color for navigation list items which are not PsiElements but could fetch...
[fedora-idea.git] / platform / lang-impl / src / com / intellij / ide / util / DeleteUtil.java
blobade77399a9f2f434b2496a73b441be0fd75d940f
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.
17 package com.intellij.ide.util;
19 import com.intellij.ide.IdeBundle;
20 import com.intellij.psi.ElementDescriptionUtil;
21 import com.intellij.psi.PsiDirectoryContainer;
22 import com.intellij.psi.PsiElement;
23 import com.intellij.util.containers.FactoryMap;
24 import com.intellij.util.containers.HashMap;
25 import org.jetbrains.annotations.NonNls;
27 import java.text.MessageFormat;
28 import java.util.Map;
30 /**
31 * @author dsl
33 public class DeleteUtil {
34 private DeleteUtil() {}
36 public static void appendMessage(int count, @NonNls String propertyKey, StringBuffer buffer) {
37 if (count > 0) {
38 if (buffer.length() > 0) {
39 buffer.append(" ").append(IdeBundle.message("prompt.delete.and")).append(" ");
41 buffer.append(count);
42 buffer.append(' ');
43 buffer.append(IdeBundle.message(propertyKey, count));
47 public static String generateWarningMessage(String messageTemplate, final PsiElement[] elements) {
48 if (elements.length == 1) {
49 String name = ElementDescriptionUtil.getElementDescription(elements [0], DeleteNameDescriptionLocation.INSTANCE);
50 String type = ElementDescriptionUtil.getElementDescription(elements [0], DeleteTypeDescriptionLocation.SINGULAR);
51 return MessageFormat.format(messageTemplate, type + " \"" + name + "\"");
54 FactoryMap<String, Integer> countMap = new FactoryMap<String, Integer>() {
55 protected Integer create(final String key) {
56 return 0;
59 Map<String, String> pluralToSingular = new HashMap<String, String>();
60 int directoryCount = 0;
61 String containerType = null;
63 for (final PsiElement elementToDelete : elements) {
64 String type = ElementDescriptionUtil.getElementDescription(elementToDelete, DeleteTypeDescriptionLocation.PLURAL);
65 pluralToSingular.put(type, ElementDescriptionUtil.getElementDescription(elementToDelete, DeleteTypeDescriptionLocation.SINGULAR));
66 int oldCount = countMap.get(type).intValue();
67 countMap.put(type, oldCount+1);
68 if (elementToDelete instanceof PsiDirectoryContainer) {
69 containerType = type;
70 directoryCount += ((PsiDirectoryContainer) elementToDelete).getDirectories().length;
74 StringBuffer buffer = new StringBuffer();
75 for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
76 if (buffer.length() > 0) {
77 if (buffer.length() > 0) {
78 buffer.append(" ").append(IdeBundle.message("prompt.delete.and")).append(" ");
81 final int count = entry.getValue().intValue();
83 buffer.append(count).append(" ");
84 if (count == 1) {
85 buffer.append(pluralToSingular.get(entry.getKey()));
87 else {
88 buffer.append(entry.getKey());
91 if (entry.getKey().equals(containerType)) {
92 buffer.append(" ").append(IdeBundle.message("prompt.delete.directory.paren", directoryCount));
95 return MessageFormat.format(messageTemplate, buffer.toString());