Package com.intellij.usages

Examples of com.intellij.usages.Usage


  @Override
  public Component getTableCellRendererComponent(JTable list, Object value, boolean isSelected,
      boolean hasFocus, int row, int column) {
    UsageNode usageNode = value instanceof UsageNode ? (UsageNode) value : null;

    Usage usage = usageNode == null ? null : usageNode.getUsage();

    JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    Color fileBgColor = getBackgroundColor(isSelected, usage);
    final Color bg = UIUtil.getListSelectionBackground();
    final Color fg = UIUtil.getListSelectionForeground();
    panel.setBackground(isSelected ? bg : fileBgColor == null ? list.getBackground() : fileBgColor);
    panel.setForeground(isSelected ? fg : list.getForeground());

    if (usage == null || usageNode instanceof ShowUsagesAction.StringNode) {
      panel.setLayout(new BorderLayout());
      if (column == 0) {
        panel.add(
            new JLabel("<html><body><b>" + value + "</b></body></html>", SwingConstants.CENTER));
      }
      return panel;
    }

    SimpleColoredComponent textChunks = new SimpleColoredComponent();
    textChunks.setIpad(new Insets(0, 0, 0, 0));
    textChunks.setBorder(null);

    if (column == 0) {
      GroupNode parent = (GroupNode) usageNode.getParent();
      appendGroupText(parent, panel, fileBgColor);
      if (usage == ShowUsagesAction.MORE_USAGES_SEPARATOR) {
        textChunks.append("...<");
        textChunks.append("more usages", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
        textChunks.append(">...");
      }
    } else if (usage != ShowUsagesAction.MORE_USAGES_SEPARATOR) {
      UsagePresentation presentation = usage.getPresentation();
      TextChunk[] text = presentation.getText();

      if (column == 1) {
        final Icon icon = presentation.getIcon();
        textChunks.setIcon(icon == null ? EmptyIcon.ICON_16 : icon);
View Full Code Here


          if (visibleNodes.size() >= maxUsages) return false;
          if (UsageViewManager.isSelfUsage(usage, new UsageTarget[] { myUsageTarget })) {
            return true;
          }

          Usage usageToAdd = decider.shouldShow(myUsageTarget, usage) ? usage : null;
          if (usageToAdd == null) return true;

          UsageNode node = usageView.doAppendUsage(usageToAdd);
          usages.add(usageToAdd);

          if (node != null) {
            visibleNodes.add(node);
            boolean continueSearch = true;
            if (visibleNodes.size() == maxUsages) {
              visibleNodes.add(MORE_USAGES_SEPARATOR_NODE);
              usages.add(MORE_USAGES_SEPARATOR);
              continueSearch = false;
            }
            pingEDT.ping();

            return continueSearch;
          }

          return true;
        }
      }
    };

    final ProgressIndicator indicator =
        FindUsagesManager.startProcessUsages(handler, handler.getPrimaryElements(),
            handler.getSecondaryElements(), collect, options, new Runnable() {
              @Override
              public void run() {
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                  @Override
                  public void run() {
                    Disposer.dispose(processIcon);
                    Container parent = processIcon.getParent();
                    parent.remove(processIcon);
                    parent.repaint();
                    pingEDT.ping(); // repaint title
                    synchronized (usages) {
                      if (visibleNodes.isEmpty()) {
                        if (usages.isEmpty()) {
                          String text = UsageViewBundle.message("no.usages.found.in",
                              searchScopePresentableName(options, project));
                          showHint(text, editor, popupPosition, handler, maxUsages, options);
                          popup.cancel();
                        } else {
                          // all usages filtered out
                        }
                      } else if (visibleNodes.size() == 1) {
                        if (usages.size() == 1) {
                          //the only usage
                          Usage usage = visibleNodes.iterator().next().getUsage();
                          usage.navigate(true);
                          //String message = UsageViewBundle.message("show.usages.only.usage", searchScopePresentableName(options, project));
                          //navigateAndHint(usage, message, handler, popupPosition, maxUsages, options);
                          popup.cancel();
                        } else {
                          assert usages.size() > 1 : usages;
                          // usage view can filter usages down to one
                          Usage visibleUsage = visibleNodes.iterator().next().getUsage();
                          if (areAllUsagesInOneLine(visibleUsage, usages)) {
                            String hint = UsageViewBundle.message("all.usages.are.in.this.line",
                                usages.size(), searchScopePresentableName(options, project));
                            navigateAndHint(visibleUsage, hint, handler, popupPosition, maxUsages,
                                options);
View Full Code Here

      public void run() {
        int[] selected = table.getSelectedRows();
        for (int i : selected) {
          Object value = table.getValueAt(i, 0);
          if (value instanceof UsageNode) {
            Usage usage = ((UsageNode) value).getUsage();
            if (usage == MORE_USAGES_SEPARATOR) {
              appendMoreUsages(editor, popupPosition, handler, maxUsages);
              return;
            }
            navigateAndHint(usage, null, handler, popupPosition, maxUsages, options);
View Full Code Here

  }

  private void addUsageNodes(@NotNull GroupNode root, @NotNull final UsageViewImpl usageView,
      @NotNull List<UsageNode> outNodes) {
    for (UsageNode node : root.getUsageNodes()) {
      Usage usage = node.getUsage();
      if (usageView.isVisible(usage)) {
        node.setParent(root);
        outNodes.add(node);
      }
    }
View Full Code Here

    }

    @Override @Nullable
    protected PsiElement getPsiElementForHint(Object selectedValue) {
      if (selectedValue instanceof UsageNode) {
        final Usage usage = ((UsageNode) selectedValue).getUsage();
        if (usage instanceof UsageInfo2UsageAdapter) {
          final PsiElement element = ((UsageInfo2UsageAdapter) usage).getElement();
          if (element != null) {
            final PsiElement view = UsageToPsiElementProvider.findAppropriateParentFrom(element);
            return view == null ? element : view;
View Full Code Here

    @Override
    protected String getElementText(@NotNull Object element) {
      if (!(element instanceof UsageNode)) return element.toString();
      UsageNode node = (UsageNode) element;
      if (node instanceof StringNode) return "";
      Usage usage = node.getUsage();
      if (usage == MORE_USAGES_SEPARATOR) return "";
      GroupNode group = (GroupNode) node.getParent();
      return usage.getPresentation().getPlainText() + group;
    }
View Full Code Here

  @Override
  public Component getTableCellRendererComponent(JTable list, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    UsageNode usageNode = value instanceof UsageNode ? (UsageNode)value : null;

    Usage usage = usageNode == null ? null : usageNode.getUsage();

    JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0,0));
    Color fileBgColor = getBackgroundColor(isSelected, usage);
    final Color bg = UIUtil.getListSelectionBackground();
    final Color fg = UIUtil.getListSelectionForeground();
    panel.setBackground(isSelected ? bg : fileBgColor == null ? list.getBackground() : fileBgColor);
    panel.setForeground(isSelected ? fg : list.getForeground());

    if (usage == null || usageNode instanceof ShowUsagesAction.StringNode) {
      panel.setLayout(new BorderLayout());
      if (column == 0) {
        panel.add(new JLabel("<html><body><b>" + value + "</b></body></html>", SwingConstants.CENTER));
      }
      return panel;
    }


    SimpleColoredComponent textChunks = new SimpleColoredComponent();
    textChunks.setIpad(new Insets(0,0,0,0));
    textChunks.setBorder(null);

    if (column == 0) {
      GroupNode parent = (GroupNode)usageNode.getParent();
      appendGroupText(parent, panel, fileBgColor);
      if (usage == ShowUsagesAction.MORE_USAGES_SEPARATOR) {
        textChunks.append("...<");
        textChunks.append("more usages", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
        textChunks.append(">...");
      }
    }
    else if (usage != ShowUsagesAction.MORE_USAGES_SEPARATOR) {
      UsagePresentation presentation = usage.getPresentation();
      TextChunk[] text = presentation.getText();

      if (column == 1) {
        final Icon icon = presentation.getIcon();
        textChunks.setIcon(icon == null ? EmptyIcon.ICON_16 : icon);
View Full Code Here

    @Override
    @Nullable
    protected PsiElement getPsiElementForHint(Object selectedValue) {
      if (selectedValue instanceof UsageNode) {
        final Usage usage = ((UsageNode)selectedValue).getUsage();
        if (usage instanceof UsageInfo2UsageAdapter) {
          final PsiElement element = ((UsageInfo2UsageAdapter)usage).getElement();
          if (element != null) {
            final PsiElement view = UsageToPsiElementProvider.findAppropriateParentFrom(element);
            return view == null ? element : view;
View Full Code Here

    @Override
    protected String getElementText(@NotNull Object element) {
      if (!(element instanceof UsageNode)) return element.toString();
      UsageNode node = (UsageNode)element;
      if (node instanceof StringNode) return "";
      Usage usage = node.getUsage();
      if (usage == MORE_USAGES_SEPARATOR) return "";
      GroupNode group = (GroupNode)node.getParent();
      return usage.getPresentation().getPlainText() + group;
    }
View Full Code Here

          if (visibleNodes.size() >= maxUsages) return false;
          if (UsageViewManager.isSelfUsage(usage, myUsageTarget)) {
            return true;
          }

          Usage usageToAdd = transform(usage);
          if (usageToAdd == null) return true;

          UsageNode node = usageView.doAppendUsage(usageToAdd);
          usages.add(usageToAdd);
          if (node != null) {
            visibleNodes.add(node);
            boolean continueSearch = true;
            if (visibleNodes.size() == maxUsages) {
              visibleNodes.add(MORE_USAGES_SEPARATOR_NODE);
              usages.add(MORE_USAGES_SEPARATOR);
              continueSearch = false;
            }
            pingEDT.ping();

            return continueSearch;
          }
          return true;
        }
      }
    };

    final ProgressIndicator indicator = FindUsagesManager.startProcessUsages(handler, handler.getPrimaryElements(), handler.getSecondaryElements(), collect, options, new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
          @Override
          public void run() {
            Disposer.dispose(processIcon);
            Container parent = processIcon.getParent();
            parent.remove(processIcon);
            parent.repaint();
            pingEDT.ping(); // repaint title
            synchronized (usages) {
              if (visibleNodes.isEmpty()) {
                if (usages.isEmpty()) {
                  String text = UsageViewBundle.message("no.usages.found.in", searchScopePresentableName(options, project));
                  showHint(text, editor, popupPosition, handler, maxUsages, options);
                  popup.cancel();
                }
                else {
                  // all usages filtered out
                }
              }
              else if (visibleNodes.size() == 1) {
                if (usages.size() == 1) {
                  //the only usage
                  Usage usage = visibleNodes.iterator().next().getUsage();
                  usage.navigate(true);
                  //String message = UsageViewBundle.message("show.usages.only.usage", searchScopePresentableName(options, project));
                  //navigateAndHint(usage, message, handler, popupPosition, maxUsages, options);
                  popup.cancel();
                }
                else {
                  assert usages.size() > 1 : usages;
                  // usage view can filter usages down to one
                  Usage visibleUsage = visibleNodes.iterator().next().getUsage();
                  if (areAllUsagesInOneLine(visibleUsage, usages)) {
                    String hint = UsageViewBundle.message("all.usages.are.in.this.line", usages.size(), searchScopePresentableName(options, project));
                    navigateAndHint(visibleUsage, hint, handler, popupPosition, maxUsages, options);
                    popup.cancel();
                  }
View Full Code Here

TOP

Related Classes of com.intellij.usages.Usage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.