com.intellij.ide.util.DefaultPsiElementCellRenderer Java Examples

The following examples show how to use com.intellij.ide.util.DefaultPsiElementCellRenderer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HaxeGotoSuperHandler.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private static void tryNavigateToSuperMethod(Editor editor,
                                             HaxeMethod methodDeclaration,
                                             List<HaxeNamedComponent> superItems) {
  final String methodName = methodDeclaration.getName();
  if (methodName == null) {
    return;
  }
  final List<HaxeNamedComponent> filteredSuperItems = ContainerUtil.filter(superItems, new Condition<HaxeNamedComponent>() {
    @Override
    public boolean value(HaxeNamedComponent component) {
      return methodName.equals(component.getName());
    }
  });
  if (!filteredSuperItems.isEmpty()) {
    PsiElementListNavigator.openTargets(editor, HaxeResolveUtil.getComponentNames(filteredSuperItems)
      .toArray(new NavigatablePsiElement[filteredSuperItems.size()]),
                                        DaemonBundle.message("navigation.title.super.method", methodName),
                                        null,
                                        new DefaultPsiElementCellRenderer());
  }
}
 
Example #2
Source File: GenerateDialog.java    From android-parcelable-intellij-plugin with Apache License 2.0 6 votes vote down vote up
protected GenerateDialog(final PsiClass psiClass) {
    super(psiClass.getProject());
    setTitle("Select Fields for Parcelable Generation");

    fieldsCollection = new CollectionListModel<PsiField>();
    final JBList fieldList = new JBList(fieldsCollection);
    fieldList.setCellRenderer(new DefaultPsiElementCellRenderer());
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(fieldList).disableAddAction();
    final JPanel panel = decorator.createPanel();

    fieldsComponent = LabeledComponent.create(panel, "Fields to include in Parcelable");

    includeSubclasses = new JBCheckBox("Include fields from base classes");
    setupCheckboxClickAction(psiClass);
    showCheckbox = psiClass.getFields().length != psiClass.getAllFields().length;

    updateFieldsDisplay(psiClass);
    init();
}
 
Example #3
Source File: GraphQLEditConfigAction.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
protected JComponent createCenterPanel() {
    comboBox = new ComboBox<>(new CollectionComboBoxModel<>(configDirectoryCandidates));
    comboBox.setRenderer(new DefaultPsiElementCellRenderer());
    comboBox.setMinimumAndPreferredWidth(450);
    if (comboBox.getItemCount() > 0) {
        comboBox.setSelectedIndex(0);
    }
    final NonOpaquePanel panel = new NonOpaquePanel();
    panel.add(comboBox, BorderLayout.NORTH);
    return panel;
}
 
Example #4
Source File: HaxeGotoSuperHandler.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
  final PsiElement at = file.findElementAt(editor.getCaretModel().getOffset());
  final HaxeComponentName componentName = PsiTreeUtil.getParentOfType(at, HaxeComponentName.class);

  final HaxeClass haxeClass = PsiTreeUtil.getParentOfType(at, HaxeClass.class);
  final HaxeNamedComponent namedComponent = componentName == null ? haxeClass : (HaxeNamedComponent)componentName.getParent();
  if (at == null || haxeClass == null || namedComponent == null) return;

  final List<HaxeClass> supers = HaxeResolveUtil.tyrResolveClassesByQName(haxeClass.getHaxeExtendsList());
  supers.addAll(HaxeResolveUtil.tyrResolveClassesByQName(haxeClass.getHaxeImplementsList()));
  final List<HaxeNamedComponent> superItems = HaxeResolveUtil.findNamedSubComponents(false, supers.toArray(new HaxeClass[supers.size()]));

  final HaxeComponentType type = HaxeComponentType.typeOf(namedComponent);
  if (type == HaxeComponentType.METHOD) {
    final HaxeMethod methodDeclaration = (HaxeMethod)namedComponent;
    tryNavigateToSuperMethod(editor, methodDeclaration, superItems);
  }
  else if (!supers.isEmpty() && namedComponent instanceof HaxeClass) {
    PsiElementListNavigator.openTargets(
      editor,
      HaxeResolveUtil.getComponentNames(supers).toArray(new NavigatablePsiElement[supers.size()]),
      DaemonBundle.message("navigation.title.subclass", namedComponent.getName(), supers.size()),
      "Subclasses of " + namedComponent.getName(),
      new DefaultPsiElementCellRenderer()
    );
  }
}
 
Example #5
Source File: HaxeLineMarkerProvider.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Nullable
private static LineMarkerInfo createImplementationMarker(final HaxeClass componentWithDeclarationList,
                                                         final List<HaxeClass> items) {
  final HaxeComponentName componentName = componentWithDeclarationList.getComponentName();
  if (componentName == null) {
    return null;
  }
  final PsiElement element = componentName.getIdentifier().getFirstChild();
  return new LineMarkerInfo<>(
    element,
    element.getTextRange(),
    componentWithDeclarationList instanceof HaxeInterfaceDeclaration
    ? AllIcons.Gutter.ImplementedMethod
    : AllIcons.Gutter.OverridenMethod,
    Pass.UPDATE_ALL,
    item -> DaemonBundle.message("method.is.implemented.too.many"),
    new GutterIconNavigationHandler<PsiElement>() {
      @Override
      public void navigate(MouseEvent e, PsiElement elt) {
        PsiElementListNavigator.openTargets(
          e, HaxeResolveUtil.getComponentNames(items).toArray(new NavigatablePsiElement[items.size()]),
          DaemonBundle.message("navigation.title.subclass", componentWithDeclarationList.getName(), items.size()),
          "Subclasses of " + componentWithDeclarationList.getName(),
          new DefaultPsiElementCellRenderer()
        );
      }
    },
    GutterIconRenderer.Alignment.RIGHT
  );
}
 
Example #6
Source File: HaxeTypeAddImportIntentionAction.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException {
  if (candidates.size() > 1) {
    NavigationUtil.getPsiElementPopup(
      candidates.toArray(new PsiElement[candidates.size()]),
      new DefaultPsiElementCellRenderer(),
      HaxeBundle.message("choose.class.to.import.title"),
      new PsiElementProcessor<PsiElement>() {
        public boolean execute(@NotNull final PsiElement element) {
          CommandProcessor.getInstance().executeCommand(
            project,
            new Runnable() {
              public void run() {
                doImport(editor, element);
              }
            },
            getClass().getName(),
            this
          );
          return false;
        }
      }
    ).showInBestPositionFor(editor);
  }
  else {
    doImport(editor, candidates.iterator().next());
  }
}
 
Example #7
Source File: ThriftLineMarkerProvider.java    From intellij-thrift with Apache License 2.0 5 votes vote down vote up
@Nullable
private LineMarkerInfo findImplementationsAndCreateMarker(final ThriftDefinitionName definitionName) {
  final List<NavigatablePsiElement> implementations = ThriftPsiUtil.findImplementations(definitionName);
  if (implementations.isEmpty()) {
    return null;
  }
  return new LineMarkerInfo<PsiElement>(
    definitionName,
    definitionName.getTextRange(),
    AllIcons.Gutter.ImplementedMethod,
    Pass.UPDATE_ALL,
    new Function<PsiElement, String>() {
      @Override
      public String fun(PsiElement element) {
        return DaemonBundle.message("interface.is.implemented.too.many");
      }
    },
    new GutterIconNavigationHandler<PsiElement>() {
      @Override
      public void navigate(MouseEvent e, PsiElement elt) {
        PsiElementListNavigator.openTargets(
          e,
          implementations.toArray(new NavigatablePsiElement[implementations.size()]),
          DaemonBundle.message("navigation.title.implementation.method", definitionName.getText(), implementations.size()),
          "Implementations of " + definitionName.getText(),
          new DefaultPsiElementCellRenderer()
        );
      }
    },
    GutterIconRenderer.Alignment.RIGHT
  );
}
 
Example #8
Source File: NavigationUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static JBPopup getPsiElementPopup(@Nonnull PsiElement[] elements, String title) {
  return getPsiElementPopup(elements, new DefaultPsiElementCellRenderer(), title);
}
 
Example #9
Source File: NavigationGutterIconBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
private MyNavigationGutterIconRenderer createGutterIconRenderer(@Nonnull Project project) {
  checkBuilt();
  final SmartPointerManager manager = SmartPointerManager.getInstance(project);

  NotNullLazyValue<List<SmartPsiElementPointer>> pointers = new NotNullLazyValue<List<SmartPsiElementPointer>>() {
    @Override
    @Nonnull
    public List<SmartPsiElementPointer> compute() {
      Set<PsiElement> elements = new THashSet<PsiElement>();
      Collection<? extends T> targets = myTargets.getValue();
      final List<SmartPsiElementPointer> list = new ArrayList<SmartPsiElementPointer>(targets.size());
      for (final T target : targets) {
        for (final PsiElement psiElement : myConverter.fun(target)) {
          if (elements.add(psiElement) && psiElement.isValid()) {
            list.add(manager.createSmartPsiElementPointer(psiElement));
          }
        }
      }
      return list;
    }
  };

  final boolean empty = isEmpty();

  if (myTooltipText == null && !myLazy) {
    final SortedSet<String> names = new TreeSet<String>();
    for (T t : myTargets.getValue()) {
      final String text = myNamer.fun(t);
      if (text != null) {
        names.add(MessageFormat.format(PATTERN, text));
      }
    }
    @NonNls StringBuilder sb = new StringBuilder("<html><body>");
    if (myTooltipTitle != null) {
      sb.append(myTooltipTitle).append("<br>");
    }
    for (String name : names) {
      sb.append(name).append("<br>");
    }
    sb.append("</body></html>");
    myTooltipText = sb.toString();
  }

  Computable<PsiElementListCellRenderer> renderer =
    myCellRenderer == null ? new Computable<PsiElementListCellRenderer>() {
      @Override
      public PsiElementListCellRenderer compute() {
        return new DefaultPsiElementCellRenderer();
      }
    } : myCellRenderer;
  return new MyNavigationGutterIconRenderer(this, myAlignment, myIcon, myTooltipText, pointers, renderer, empty);
}
 
Example #10
Source File: DefaultGutterIconNavigationHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected ListCellRenderer createListCellRenderer() {
  return new DefaultPsiElementCellRenderer();
}