Search in sources :

Example 11 with CompositeAppearance

use of com.intellij.openapi.roots.ui.util.CompositeAppearance in project intellij-community by JetBrains.

the class OrderEntryAppearanceServiceImpl method forJdk.

@NotNull
@Override
public CellAppearanceEx forJdk(@Nullable final Sdk jdk, final boolean isInComboBox, final boolean selected, final boolean showVersion) {
    if (jdk == null) {
        return FileAppearanceService.getInstance().forInvalidUrl(NO_JDK);
    }
    String name = jdk.getName();
    CompositeAppearance appearance = new CompositeAppearance();
    SdkType sdkType = (SdkType) jdk.getSdkType();
    appearance.setIcon(sdkType.getIcon());
    SimpleTextAttributes attributes = getTextAttributes(sdkType.sdkHasValidPath(jdk), selected);
    CompositeAppearance.DequeEnd ending = appearance.getEnding();
    ending.addText(name, attributes);
    if (showVersion) {
        String versionString = jdk.getVersionString();
        if (versionString != null && !versionString.equals(name)) {
            SimpleTextAttributes textAttributes = isInComboBox && !selected ? SimpleTextAttributes.SYNTHETIC_ATTRIBUTES : SystemInfo.isMac && selected ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, Color.WHITE) : SimpleTextAttributes.GRAY_ATTRIBUTES;
            ending.addComment(versionString, textAttributes);
        }
    }
    return ending.getAppearance();
}
Also used : SdkType(com.intellij.openapi.projectRoots.SdkType) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) CompositeAppearance(com.intellij.openapi.roots.ui.util.CompositeAppearance) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with CompositeAppearance

use of com.intellij.openapi.roots.ui.util.CompositeAppearance in project intellij-community by JetBrains.

the class CallHierarchyNodeDescriptor method update.

public final boolean update() {
    final CompositeAppearance oldText = myHighlightedText;
    final Icon oldIcon = getIcon();
    int flags = Iconable.ICON_FLAG_VISIBILITY;
    if (isMarkReadOnly()) {
        flags |= Iconable.ICON_FLAG_READ_STATUS;
    }
    boolean changes = super.update();
    final PsiElement enclosingElement = getEnclosingElement();
    if (enclosingElement == null) {
        final String invalidPrefix = IdeBundle.message("node.hierarchy.invalid");
        if (!myHighlightedText.getText().startsWith(invalidPrefix)) {
            myHighlightedText.getBeginning().addText(invalidPrefix, HierarchyNodeDescriptor.getInvalidPrefixAttributes());
        }
        return true;
    }
    Icon newIcon = enclosingElement.getIcon(flags);
    if (changes && myIsBase) {
        final LayeredIcon icon = new LayeredIcon(2);
        icon.setIcon(newIcon, 0);
        icon.setIcon(AllIcons.Hierarchy.Base, 1, -AllIcons.Hierarchy.Base.getIconWidth() / 2, 0);
        newIcon = icon;
    }
    setIcon(newIcon);
    myHighlightedText = new CompositeAppearance();
    TextAttributes mainTextAttributes = null;
    if (myColor != null) {
        mainTextAttributes = new TextAttributes(myColor, null, null, null, Font.PLAIN);
    }
    if (enclosingElement instanceof PsiMethod) {
        if (enclosingElement instanceof SyntheticElement) {
            PsiFile file = enclosingElement.getContainingFile();
            myHighlightedText.getEnding().addText(file != null ? file.getName() : IdeBundle.message("node.call.hierarchy.unknown.jsp"), mainTextAttributes);
        } else {
            final PsiMethod method = (PsiMethod) enclosingElement;
            final StringBuilder buffer = new StringBuilder(128);
            final PsiClass containingClass = method.getContainingClass();
            if (containingClass != null) {
                buffer.append(ClassPresentationUtil.getNameForClass(containingClass, false));
                buffer.append('.');
            }
            final String methodText = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
            buffer.append(methodText);
            myHighlightedText.getEnding().addText(buffer.toString(), mainTextAttributes);
        }
    } else if (FileTypeUtils.isInServerPageFile(enclosingElement) && enclosingElement instanceof PsiFile) {
        final PsiFile file = PsiUtilCore.getTemplateLanguageFile(enclosingElement);
        myHighlightedText.getEnding().addText(file.getName(), mainTextAttributes);
    } else {
        myHighlightedText.getEnding().addText(ClassPresentationUtil.getNameForClass((PsiClass) enclosingElement, false), mainTextAttributes);
    }
    if (myUsageCount > 1) {
        myHighlightedText.getEnding().addText(IdeBundle.message("node.call.hierarchy.N.usages", myUsageCount), HierarchyNodeDescriptor.getUsageCountPrefixAttributes());
    }
    if (!(FileTypeUtils.isInServerPageFile(enclosingElement) && enclosingElement instanceof PsiFile)) {
        final PsiClass containingClass = enclosingElement instanceof PsiMethod ? ((PsiMethod) enclosingElement).getContainingClass() : (PsiClass) enclosingElement;
        if (containingClass != null) {
            final String packageName = JavaHierarchyUtil.getPackageName(containingClass);
            myHighlightedText.getEnding().addText("  (" + packageName + ")", HierarchyNodeDescriptor.getPackageNameAttributes());
        }
    }
    myName = myHighlightedText.getText();
    if (!Comparing.equal(myHighlightedText, oldText) || !Comparing.equal(getIcon(), oldIcon)) {
        changes = true;
    }
    return changes;
}
Also used : LayeredIcon(com.intellij.ui.LayeredIcon) CompositeAppearance(com.intellij.openapi.roots.ui.util.CompositeAppearance) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) LayeredIcon(com.intellij.ui.LayeredIcon)

Aggregations

CompositeAppearance (com.intellij.openapi.roots.ui.util.CompositeAppearance)12 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)6 LayeredIcon (com.intellij.ui.LayeredIcon)6 ItemPresentation (com.intellij.navigation.ItemPresentation)3 PsiClass (com.intellij.psi.PsiClass)3 PsiElement (com.intellij.psi.PsiElement)3 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)3 DartClass (com.jetbrains.lang.dart.psi.DartClass)3 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 RowIcon (com.intellij.ui.RowIcon)2 RunManagerEx (com.intellij.execution.RunManagerEx)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1 AntBuildModelBase (com.intellij.lang.ant.config.AntBuildModelBase)1 AntBeforeRunTask (com.intellij.lang.ant.config.impl.AntBeforeRunTask)1 ExecuteCompositeTargetEvent (com.intellij.lang.ant.config.impl.ExecuteCompositeTargetEvent)1 MetaTarget (com.intellij.lang.ant.config.impl.MetaTarget)1 SdkType (com.intellij.openapi.projectRoots.SdkType)1 ModifiableCellAppearanceEx (com.intellij.openapi.roots.ui.ModifiableCellAppearanceEx)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1