com.intellij.util.xml.ui.TooltipUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dom-openapi Show documentation
Show all versions of dom-openapi Show documentation
A packaging of the IntelliJ Community Edition dom-openapi library.
This is release number 1 of trunk branch 142.
The newest version!
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.util.xml.ui;
import com.intellij.util.ArrayUtil;
import com.intellij.util.xml.highlighting.DomElementProblemDescriptor;
import org.jetbrains.annotations.NonNls;
import java.util.List;
/**
* User: Sergey.Vasiliev
*/
public class TooltipUtils {
@NonNls private static final String MESSAGE_DELIMITER = "
";
public static String getTooltipText(List annotations) {
if (annotations.size() == 0) return null;
return getTooltipText(getMessages(annotations));
}
public static String getTooltipText(List annotations, String[] messages) {
return getTooltipText(ArrayUtil.mergeArrays(getMessages(annotations), messages));
}
private static String[] getMessages(final List problems) {
String[] messages = new String[problems.size()];
for (int i = 0; i < problems.size(); i++) {
messages[i] = problems.get(i).getDescriptionTemplate();
}
return messages;
}
public static String getTooltipText(String[] messages) {
if (messages.length == 0) return null;
StringBuilder text = new StringBuilder(" ");
int len = messages.length > 10 ? 10 : messages.length;
for (int i = 0; i < len; i++) {
if (i != 0) {
text.append(MESSAGE_DELIMITER);
}
text.append(messages[i]);
}
if (messages.length > 10) {
text.append(MESSAGE_DELIMITER);
text.append("...");
}
text.append("
");
return text.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy