示例#1
0
 private void openView(final UsageViewImpl usageView) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           addContent(usageView, myPresentation);
           if (myListener != null) {
             myListener.usageViewCreated(usageView);
           }
           showToolWindow(false);
         }
       });
 }
  private void setSizeAndDimensions(
      @NotNull JTable table,
      @NotNull JBPopup popup,
      @NotNull RelativePoint popupPosition,
      @NotNull List<UsageNode> data) {
    JComponent content = popup.getContent();
    Window window = SwingUtilities.windowForComponent(content);
    Dimension d = window.getSize();

    int width = calcMaxWidth(table);
    width = (int) Math.max(d.getWidth(), width);
    Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize();
    width = Math.max((int) headerSize.getWidth(), width);
    width = Math.max(myWidth, width);

    if (myWidth == -1) myWidth = width;
    int newWidth = Math.max(width, d.width + width - myWidth);

    myWidth = newWidth;

    int rowsToShow = Math.min(30, data.size());
    Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
    Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
    dimension = rectangle.getSize();
    Point location = window.getLocation();
    if (!location.equals(rectangle.getLocation())) {
      window.setLocation(rectangle.getLocation());
    }

    if (!data.isEmpty()) {
      TableScrollingUtil.ensureSelectionExists(table);
    }
    table.setSize(dimension);
    // table.setPreferredSize(dimension);
    // table.setMaximumSize(dimension);
    // table.setPreferredScrollableViewportSize(dimension);

    Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize();

    int newHeight =
        (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight())
            + 4 /* invisible borders, margins etc*/;
    Dimension newDim = new Dimension(dimension.width, newHeight);
    window.setSize(newDim);
    window.setMinimumSize(newDim);
    window.setMaximumSize(newDim);

    window.validate();
    window.repaint();
    table.revalidate();
    table.repaint();
  }
  private void reset() {
    ApplicationManager.getApplication().assertIsDispatchThread();

    myUsageNodes.clear();
    myIsFirstVisibleUsageFound = false;

    myModel.reset();
    if (!myPresentation.isDetachedMode()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              if (isDisposed) return;
              TreeUtil.expand(myTree, 2);
            }
          });
    }
  }
 private void rulesChanged() {
   ApplicationManager.getApplication().assertIsDispatchThread();
   final ArrayList<UsageState> states = new ArrayList<UsageState>();
   captureUsagesExpandState(new TreePath(myTree.getModel().getRoot()), states);
   final List<Usage> allUsages = new ArrayList<Usage>(myUsageNodes.keySet());
   Collections.sort(allUsages, USAGE_COMPARATOR);
   final Set<Usage> excludedUsages = getExcludedUsages();
   reset();
   myBuilder.setGroupingRules(getActiveGroupingRules(myProject));
   myBuilder.setFilteringRules(getActiveFilteringRules(myProject));
   ApplicationManager.getApplication()
       .runReadAction(
           new Runnable() {
             @Override
             public void run() {
               for (Usage usage : allUsages) {
                 if (!usage.isValid()) {
                   continue;
                 }
                 if (usage instanceof MergeableUsage) {
                   ((MergeableUsage) usage).reset();
                 }
                 appendUsage(usage);
               }
             }
           });
   excludeUsages(excludedUsages.toArray(new Usage[excludedUsages.size()]));
   if (myCentralPanel != null) {
     setupCentralPanel();
   }
   SwingUtilities.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           if (isDisposed) return;
           restoreUsageExpandState(states);
           updateImmediately();
         }
       });
 }
示例#5
0
    private void endSearchForUsages() {
      int usageCount = myUsageCountWithoutDefinition.get();
      if (usageCount == 0 && myProcessPresentation.isShowNotFoundMessage()) {
        ApplicationManager.getApplication()
            .invokeLater(
                new Runnable() {
                  public void run() {
                    final List<Action> notFoundActions = myProcessPresentation.getNotFoundActions();
                    final String message =
                        UsageViewBundle.message(
                            "dialog.no.usages.found.in",
                            StringUtil.decapitalize(myPresentation.getUsagesString()),
                            myPresentation.getScopeText());

                    if (notFoundActions == null || notFoundActions.isEmpty()) {
                      ToolWindowManager.getInstance(myProject)
                          .notifyByBalloon(
                              ToolWindowId.FIND,
                              MessageType.INFO,
                              XmlStringUtil.escapeString(message),
                              IconLoader.getIcon("/actions/find.png"),
                              null);
                    } else {
                      List<String> titles = new ArrayList<String>(notFoundActions.size() + 1);
                      titles.add(UsageViewBundle.message("dialog.button.ok"));
                      for (Action action : notFoundActions) {
                        Object value =
                            action.getValue(FindUsagesProcessPresentation.NAME_WITH_MNEMONIC_KEY);
                        if (value == null) value = action.getValue(Action.NAME);

                        titles.add((String) value);
                      }

                      int option =
                          Messages.showDialog(
                              myProject,
                              message,
                              UsageViewBundle.message("dialog.title.information"),
                              titles.toArray(new String[titles.size()]),
                              0,
                              Messages.getInformationIcon());

                      if (option > 0) {
                        notFoundActions
                            .get(option - 1)
                            .actionPerformed(new ActionEvent(this, 0, titles.get(option)));
                      }
                    }
                  }
                },
                ModalityState.NON_MODAL,
                myProject.getDisposed());
      } else if (usageCount == 1 && !myProcessPresentation.isShowPanelIfOnlyOneUsage()) {
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                Usage usage = myFirstUsage.get();
                if (usage.canNavigate()) {
                  usage.navigate(true);
                  flashUsageScriptaculously(usage);
                }
              }
            });
      } else {
        final UsageViewImpl usageView = myUsageViewRef.get();
        if (usageView != null) usageView.setSearchInProgress(false);
      }

      if (myListener != null) {
        myListener.findingUsagesFinished(myUsageViewRef.get());
      }
    }