Package com.intellij.openapi.ui.popup

Examples of com.intellij.openapi.ui.popup.JBPopup


    setTableModel(table, usageView, data);

    SpeedSearchBase<JTable> speedSearch = new MySpeedSearch(table);
    speedSearch.setComparator(new SpeedSearchComparator(false));

    final JBPopup popup =
        createUsagePopup(usages, descriptor, visibleNodes, handler, editor, popupPosition,
            maxUsages, usageView, options, table, presentation, processIcon, hadMoreSeparator);

    Disposer.register(popup, usageView);

    // show popup only if find usages takes more than 300ms, otherwise it would flicker needlessly
    Alarm alarm = new Alarm(usageView);
    alarm.addRequest(new Runnable() {
      @Override
      public void run() {
        showPopupIfNeedTo(popup, popupPosition);
      }
    }, 300);

    final PingEDT pingEDT = new PingEDT("Rebuild popup in EDT", new Condition<Object>() {
      @Override
      public boolean value(Object o) {
        return popup.isDisposed();
      }
    }, 100, new Runnable() {
      @Override
      public void run() {
        if (popup.isDisposed()) return;

        final List<UsageNode> nodes = new ArrayList<UsageNode>();
        List<Usage> copy;
        synchronized (usages) {
          // open up popup as soon as several usages 've been found
          if (!popup.isVisible() && (usages.size() <= 1 || !showPopupIfNeedTo(popup,
              popupPosition))) {
            return;
          }
          addUsageNodes(usageView.getRoot(), usageView, nodes);
          copy = new ArrayList<Usage>(usages);
        }

        rebuildPopup(usageView, copy, nodes, table, popup, presentation, popupPosition,
            !processIcon.isDisposed());
      }
    }
    );

    final MessageBusConnection messageBusConnection = project.getMessageBus().connect(usageView);
    messageBusConnection.subscribe(UsageFilteringRuleProvider.RULES_CHANGED, new Runnable() {
      @Override
      public void run() {
        pingEDT.ping();
      }
    });

    Processor<Usage> collect = new Processor<Usage>() {
      private UsageTarget myUsageTarget =
          new PsiElement2UsageTargetAdapter(handler.getPsiElement());

      @Override
      public boolean process(@NotNull Usage usage) {
        synchronized (usages) {
          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);
                            popup.cancel();
                          }
                        }
                      } else {
                        String title = presentation.getTabText();
                        boolean shouldShowMoreSeparator =
View Full Code Here


        return mainPanel;
    }

    public void showPopup(Project project) {
        ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(mainPanel, null);
        JBPopup popup = popupBuilder.createPopup();
        popup.showCenteredInCurrentWindow(project);
    }
View Full Code Here

            }
        }
    };

    public JBPopup show(Component component) {
        JBPopup popup = createPopup();
        popup.showInScreenCoordinates(component,
                new Point(
                        (int) (component.getLocationOnScreen().getX() + component.getWidth() + 8),
                        (int) component.getLocationOnScreen().getY()));
        return popup;
    }
View Full Code Here

                        (int) component.getLocationOnScreen().getY()));
        return popup;
    }

    public JBPopup show(Component component, Point point) {
        JBPopup popup = createPopup();
        point.setLocation(
                point.getX() + component.getLocationOnScreen().getX(),
                point.getY() + component.getLocationOnScreen().getY());

        popup.showInScreenCoordinates(component, point);
        return popup;
    }
View Full Code Here

    setTableModel(table, usageView, data);

    SpeedSearchBase<JTable> speedSearch = new MySpeedSearch(table);
    speedSearch.setComparator(new SpeedSearchComparator(false));

    final JBPopup popup = createUsagePopup(usages, descriptor, visibleNodes, handler, editor, popupPosition,
        maxUsages, usageView, options, table, presentation, processIcon, hadMoreSeparator);

    Disposer.register(popup, usageView);

    // show popup only if find usages takes more than 300ms, otherwise it would flicker needlessly
    Alarm alarm = new Alarm(usageView);
    alarm.addRequest(new Runnable() {
      @Override
      public void run() {
        showPopupIfNeedTo(popup, popupPosition);
      }
    }, 300);

    final PingEDT pingEDT = new PingEDT("Rebuild popup in EDT", new Condition<Object>() {
      @Override
      public boolean value(Object o) {
        return popup.isDisposed();
      }
    }, 100, new Runnable() {
      @Override
      public void run() {
        if (popup.isDisposed()) return;

        final List<UsageNode> nodes = new ArrayList<UsageNode>();
        List<Usage> copy;
        synchronized (usages) {
          // open up popup as soon as several usages 've been found
          if (!popup.isVisible() && (usages.size() <= 1 || !showPopupIfNeedTo(popup, popupPosition))) {
            return;
          }
          addUsageNodes(usageView.getRoot(), usageView, nodes);
          copy = new ArrayList<Usage>(usages);
        }

        rebuildPopup(usageView, copy, nodes, table, popup, presentation, popupPosition, !processIcon.isDisposed());
      }
    });

    final MessageBusConnection messageBusConnection = project.getMessageBus().connect(usageView);
    messageBusConnection.subscribe(UsageFilteringRuleProvider.RULES_CHANGED, new Runnable() {
      @Override
      public void run() {
        pingEDT.ping();
      }
    });


    Processor<Usage> collect = new Processor<Usage>() {
      private final UsageTarget[] myUsageTarget = {new PsiElement2UsageTargetAdapter(handler.getPsiElement())};
      @Override
      public boolean process(@NotNull Usage usage) {
        synchronized (usages) {
          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();
                  }
                }
              }
              else {
                String title = presentation.getTabText();
View Full Code Here

                if (!progressIndicator.isCanceled()) {
                    if (objects.size() > 0) {
                        final ObjectListActionGroup actionGroup = new ObjectListActionGroup(ObjectListShowAction.this, objects);
                        new SimpleLaterInvocator() {
                            public void execute() {
                                JBPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(
                                        ObjectListShowAction.this.getTitle(),
                                        actionGroup,
                                        e.getDataContext(),
                                        JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
                                        true, null, 10);

                                popup.getContent().setBackground(Colors.LIGHT_BLUE);
                                showPopup(popup);
                            }
                        }.start();

                    }
                    else {
                        new SimpleLaterInvocator() {
                            public void execute() {
                                JLabel label = new JLabel(getEmptyListMessage(), Icons.EXEC_MESSAGES_INFO, SwingConstants.LEFT);
                                label.setBorder(new EmptyBorder(3, 3, 3, 3));
                                JPanel panel = new JPanel(new BorderLayout());
                                panel.add(label);
                                panel.setBackground(Colors.LIGHT_BLUE);
                                ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
                                JBPopup popup = popupBuilder.createPopup();
                                showPopup(popup);
                            }
                        }.start();
                    }
                }
View Full Code Here

        executionResult.setStatementViewerPopup(this);

    }

    public void show(Component component) {
        JBPopup popup = createPopup();
        popup.showInScreenCoordinates(component,
                new Point(
                        (int) (component.getLocationOnScreen().getX() + component.getWidth() +8),
                        (int) component.getLocationOnScreen().getY()));
    }
View Full Code Here

                        (int) (component.getLocationOnScreen().getX() + component.getWidth() +8),
                        (int) component.getLocationOnScreen().getY()));
    }

    public void show(Component component, Point point) {
        JBPopup popup = createPopup();
        point.setLocation(
                point.getX() + component.getLocationOnScreen().getX() + 16,
                point.getY() + component.getLocationOnScreen().getY() + 16);

        popup.showInScreenCoordinates(component, point);
    }
View Full Code Here

        ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(viewer.getComponent(), viewer.getContentComponent());
        popupBuilder.setMovable(true);
        popupBuilder.setResizable(true);
        popupBuilder.setRequestFocus(true);
        popupBuilder.setTitle("<html>" + resultName + "</html>");
        JBPopup popup = popupBuilder.createPopup();

        Dimension dimension = EditorUtil.calculatePreferredSize(viewer);
        //Dimension dimension = ((EditorImpl) viewer).getPreferredSize();
        dimension.setSize(Math.min(dimension.getWidth() + 20, 1000), Math.min(dimension.getHeight() + 70, 800) );
        popup.setSize(dimension);

        popup.addListener(new JBPopupAdapter() {
            @Override
            public void onClosed(LightweightWindowEvent event) {
                dispose();
            }
        });
View Full Code Here

                return;
            }

            final JBList viewList = buildViewList(views, browserPanel);

            JBPopup popup = new PopupChooserBuilder(viewList)
                    .setMovable(false)
                    .setCancelKeyEnabled(true)
                    .setItemChoosenCallback(new Runnable() {
                        public void run() {
                            final View view = (View) viewList.getSelectedValue();
                            if (view == null || view.hasNestedView()) return;

                            browserPanel.loadView(view);
                        }
                    })
                    .createPopup();

            if (e != null) {
                popup.show(new RelativePoint(e));
            } else {
                final Dimension dimension = popup.getContent().getPreferredSize();
                final Point at = new Point(-dimension.width / 2, -dimension.height);
                popup.show(new RelativePoint(myLabel, at));
            }
        }
View Full Code Here

TOP

Related Classes of com.intellij.openapi.ui.popup.JBPopup

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.