Java Code Examples for com.intellij.openapi.ui.popup.ListPopup#show()

The following examples show how to use com.intellij.openapi.ui.popup.ListPopup#show() . 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: LSPServerStatusWidget.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Consumer<MouseEvent> getClickConsumer() {
    return (MouseEvent t) -> {
        JBPopupFactory.ActionSelectionAid mnemonics = JBPopupFactory.ActionSelectionAid.MNEMONICS;
        Component component = t.getComponent();
        List<AnAction> actions = new ArrayList<>();
        if (wrapper.getStatus() == ServerStatus.INITIALIZED) {
            actions.add(new ShowConnectedFiles());
        }
        actions.add(new ShowTimeouts());
        if (wrapper.isRestartable()) {
            actions.add(new Restart());
        }

        String title = "Server actions";
        DataContext context = DataManager.getInstance().getDataContext(component);
        DefaultActionGroup group = new DefaultActionGroup(actions);
        ListPopup popup = JBPopupFactory.getInstance()
                .createActionGroupPopup(title, group, context, mnemonics, true);
        Dimension dimension = popup.getContent().getPreferredSize();
        Point at = new Point(0, -dimension.height);
        popup.show(new RelativePoint(t.getComponent(), at));
    };
}
 
Example 2
Source File: LookupImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void showElementActions(@Nullable InputEvent event) {
  if (!isVisible()) return;

  LookupElement element = getCurrentItem();
  if (element == null) {
    return;
  }

  Collection<LookupElementAction> actions = getActionsFor(element);
  if (actions.isEmpty()) {
    return;
  }

  //UIEventLogger.logUIEvent(UIEventId.LookupShowElementActions);

  Rectangle itemBounds = getCurrentItemBounds();
  Rectangle visibleRect = SwingUtilities.convertRectangle(myList, myList.getVisibleRect(), getComponent());
  ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(new LookupActionsStep(actions, this, element));
  Point p = (itemBounds.intersects(visibleRect) || event == null)
            ? new Point(itemBounds.x + itemBounds.width, itemBounds.y)
            : SwingUtilities.convertPoint(event.getComponent(), new Point(0, event.getComponent().getHeight() + JBUIScale.scale(2)), getComponent());

  listPopup.show(new RelativePoint(getComponent(), p));
}
 
Example 3
Source File: PickAction.java    From otto-intellij-plugin with Apache License 2.0 6 votes vote down vote up
public static void startPicker(Type[] displayedTypes, RelativePoint relativePoint,
                               final Callback callback) {

  ListPopup listPopup = JBPopupFactory.getInstance()
      .createListPopup(new BaseListPopupStep<Type>("Select Type", displayedTypes) {
        @NotNull @Override public String getTextFor(Type value) {
          return value.toString();
        }

        @Override public PopupStep onChosen(Type selectedValue, boolean finalChoice) {
          callback.onTypeChose(selectedValue);
          return super.onChosen(selectedValue, finalChoice);
        }
      });

  listPopup.show(relativePoint);
}
 
Example 4
Source File: GraphQLSchemaEndpointsListNode.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public void handleDoubleClickOrEnter(SimpleTree tree, InputEvent inputEvent) {

    final String introspect = "Get GraphQL Schema from Endpoint (introspection)";
    final String createScratch = "New GraphQL Scratch File (for query, mutation testing)";
    ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<String>("Choose Endpoint Action", introspect, createScratch) {

        @Override
        public PopupStep onChosen(String selectedValue, boolean finalChoice) {
            return doFinalStep(() -> {
                if (introspect.equals(selectedValue)) {
                    GraphQLIntrospectionHelper.getService(myProject).performIntrospectionQueryAndUpdateSchemaPathFile(myProject, endpoint);
                } else if (createScratch.equals(selectedValue)) {
                    final String configBaseDir = endpoint.configPackageSet.getConfigBaseDir().getPresentableUrl();
                    final String text = "# " + GRAPHQLCONFIG_COMMENT + configBaseDir + "!" + Optional.ofNullable(projectKey).orElse("") + "\n\nquery ScratchQuery {\n\n}";
                    final VirtualFile scratchFile = ScratchRootType.getInstance().createScratchFile(myProject, "scratch.graphql", GraphQLLanguage.INSTANCE, text);
                    if (scratchFile != null) {
                        FileEditor[] fileEditors = FileEditorManager.getInstance(myProject).openFile(scratchFile, true);
                        for (FileEditor editor : fileEditors) {
                            if (editor instanceof TextEditor) {
                                final JSGraphQLEndpointsModel endpointsModel = ((TextEditor) editor).getEditor().getUserData(JS_GRAPH_QL_ENDPOINTS_MODEL);
                                if (endpointsModel != null) {
                                    endpointsModel.setSelectedItem(endpoint);
                                }
                            }
                        }
                    }
                }
            });
        }
    });
    if (inputEvent instanceof KeyEvent) {
        listPopup.showInFocusCenter();
    } else if (inputEvent instanceof MouseEvent) {
        listPopup.show(new RelativePoint((MouseEvent) inputEvent));
    }
}
 
Example 5
Source File: DataSourceTypesListPopupGuiTest.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@Override
protected PanelTestingFrame getPanelTestingFrame() {
    executor = mock(XQueryDataSourceTypeBasedActionExecutor.class);
    popup = new DataSourceTypesListPopup(executor);
    final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(popup);

    mainPanel = (JPanel) listPopup.getContent();
    listPopup.show((Component) null);
    return new PanelTestingFrame(mainPanel);
}
 
Example 6
Source File: PickTypeAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
public void startPickTypes(RelativePoint relativePoint, PsiParameter[] psiParameters,
    final Callback callback) {
  if (psiParameters.length == 0) return;

  ListPopup listPopup = JBPopupFactory.getInstance()
      .createListPopup(new BaseListPopupStep<PsiParameter>("Select Type", psiParameters) {
        @NotNull @Override public String getTextFor(PsiParameter value) {
          StringBuilder builder = new StringBuilder();

          Set<String> annotations = PsiConsultantImpl.getQualifierAnnotations(value);
          for (String annotation : annotations) {
            String trimmed = annotation.substring(annotation.lastIndexOf(".") + 1);
            builder.append("@").append(trimmed).append(" ");
          }

          PsiClass notLazyOrProvider = PsiConsultantImpl.checkForLazyOrProvider(value);
          return builder.append(notLazyOrProvider.getName()).toString();
        }

        @Override public PopupStep onChosen(PsiParameter selectedValue, boolean finalChoice) {
          callback.onParameterChosen(selectedValue);
          return super.onChosen(selectedValue, finalChoice);
        }
      });

  listPopup.show(relativePoint);
}
 
Example 7
Source File: EditorBasedStatusBarPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showPopup(@Nonnull MouseEvent e) {
  if (!actionEnabled) {
    return;
  }
  DataContext dataContext = getContext();
  ListPopup popup = createPopup(dataContext);

  if (popup != null) {
    Dimension dimension = popup.getContent().getPreferredSize();
    Point at = new Point(0, -dimension.height);
    popup.show(new RelativePoint(e.getComponent(), at));
    Disposer.register(this, popup); // destroy popup on unexpected project close
  }
}
 
Example 8
Source File: ScopesAndSeveritiesTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void addRow() {
  final List<Descriptor> descriptors = ContainerUtil.map(myTableSettings.getNodes(), new Function<InspectionConfigTreeNode, Descriptor>() {
    @Override
    public Descriptor fun(InspectionConfigTreeNode inspectionConfigTreeNode) {
      return inspectionConfigTreeNode.getDefaultDescriptor();
    }
  });
  final ScopesChooser scopesChooser = new ScopesChooser(descriptors, myInspectionProfile, myProject, myScopeNames) {
    @Override
    protected void onScopeAdded() {
      myTableSettings.onScopeAdded();
      refreshAggregatedScopes();
    }

    @Override
    protected void onScopesOrderChanged() {
      myTableSettings.onScopesOrderChanged();
    }
  };
  DataContext dataContext = DataManager.getInstance().getDataContext(myTable);
  final ListPopup popup = JBPopupFactory.getInstance()
          .createActionGroupPopup(ScopesChooser.TITLE, scopesChooser.createPopupActionGroup(myTable), dataContext,
                                  JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);
  final RelativePoint point = new RelativePoint(myTable, new Point(myTable.getWidth() - popup.getContent().getPreferredSize().width, 0));
  popup.show(point);
}
 
Example 9
Source File: BeforeRunStepsPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
void doAddAction(AnActionButton button) {
  if (isUnknown()) {
    return;
  }

  final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
  final List<BeforeRunTaskProvider<BeforeRunTask>> providers = BeforeRunTaskProvider.EP_NAME.getExtensionList(myRunConfiguration.getProject());
  Set<Key> activeProviderKeys = getActiveProviderKeys();

  DefaultActionGroup actionGroup = new DefaultActionGroup(null, false);
  for (final BeforeRunTaskProvider<BeforeRunTask> provider : providers) {
    if (provider.createTask(myRunConfiguration) == null) continue;
    if (activeProviderKeys.contains(provider.getId()) && provider.isSingleton()) continue;
    AnAction providerAction = new AnAction(provider.getName(), null, provider.getIcon()) {
      @RequiredUIAccess
      @Override
      public void actionPerformed(@Nonnull AnActionEvent e) {
        BeforeRunTask task = provider.createTask(myRunConfiguration);
        if (task == null) {
          return;
        }

        provider.configureTask(myRunConfiguration, task).doWhenProcessed(() -> {
          if (!provider.canExecuteTask(myRunConfiguration, task)) return;
          task.setEnabled(true);

          Set<RunConfiguration> configurationSet = new HashSet<>();
          getAllRunBeforeRuns(task, configurationSet);
          if (configurationSet.contains(myRunConfiguration)) {
            JOptionPane.showMessageDialog(BeforeRunStepsPanel.this,
                                          ExecutionBundle.message("before.launch.panel.cyclic_dependency_warning", myRunConfiguration.getName(), provider.getDescription(task)),
                                          ExecutionBundle.message("warning.common.title"), JOptionPane.WARNING_MESSAGE);
            return;
          }
          addTask(task);
          myListener.fireStepsBeforeRunChanged();
        });
      }
    };
    actionGroup.add(providerAction);
  }
  final ListPopup popup = popupFactory
          .createActionGroupPopup(ExecutionBundle.message("add.new.run.configuration.acrtion.name"), actionGroup, SimpleDataContext.getProjectContext(myRunConfiguration.getProject()), false, false,
                                  false, null, -1, Condition.TRUE);
  popup.show(button.getPreferredPopupPoint());
}
 
Example 10
Source File: ComboContentLayout.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void showContentPopup(ListPopup listPopup) {
  final int width = myComboLabel.getSize().width;
  listPopup.setMinimumSize(new Dimension(width, 0));
  listPopup.show(new RelativePoint(myComboLabel, new Point(-2, myComboLabel.getHeight())));
}