update copyright
[fedora-idea.git] / plugins / properties / src / com / intellij / lang / properties / PropertyLookupRenderer.java
blobb55e25bea5fd92c627cdd77c95a82233af7672fd
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.lang.properties;
18 import com.intellij.codeInsight.lookup.LookupItem;
19 import com.intellij.codeInsight.lookup.LookupElementPresentation;
20 import com.intellij.codeInsight.lookup.impl.ElementLookupRenderer;
21 import com.intellij.lang.properties.psi.PropertiesFile;
22 import com.intellij.lang.properties.psi.Property;
23 import com.intellij.openapi.editor.colors.EditorColorsManager;
24 import com.intellij.openapi.editor.markup.TextAttributes;
25 import com.intellij.util.Icons;
27 /**
28 * @author yole
30 public class PropertyLookupRenderer implements ElementLookupRenderer<Property> {
31 public boolean handlesItem(final Object element) {
32 return element instanceof Property;
35 public void renderElement(final LookupItem item, final Property property, final LookupElementPresentation presentation) {
36 presentation.setIcon(Icons.PROPERTY_ICON);
37 presentation.setItemText(property.getUnescapedKey());
39 PropertiesFile propertiesFile = property.getContainingFile();
40 ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
41 String value = property.getValue();
42 boolean hasBundle = resourceBundle != ResourceBundleImpl.NULL;
43 if (hasBundle) {
44 PropertiesFile defaultPropertiesFile = resourceBundle.getDefaultPropertiesFile(propertiesFile.getProject());
45 Property defaultProperty = defaultPropertiesFile.findPropertyByKey(property.getUnescapedKey());
46 if (defaultProperty != null) {
47 value = defaultProperty.getValue();
51 if (presentation.isReal() && value != null && value.length() > 10) value = value.substring(0, 10) + "...";
53 TextAttributes attrs = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(PropertiesHighlighter.PROPERTY_VALUE);
54 presentation.setTailText("="+ value, attrs.getForegroundColor());
55 if (hasBundle) {
56 presentation.setTypeText(resourceBundle.getBaseName(), PropertiesFileType.FILE_ICON);