Java Code Examples for com.intellij.openapi.ui.popup.JBPopup#showInBestPositionFor()

The following examples show how to use com.intellij.openapi.ui.popup.JBPopup#showInBestPositionFor() . 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: ShowBaseRevisionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void onSuccess() {
  if (myProject.isDisposed() || ! myProject.isOpen()) return;

  if (myDescription != null) {
    NotificationPanel panel = new NotificationPanel();
    panel.setText(createMessage(myDescription, selectedFile));
    final JBPopup message = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, panel.getLabel()).createPopup();
    if (vcsContext.getEditor() != null) {
      message.showInBestPositionFor(vcsContext.getEditor());
    } else {
      message.showCenteredInCurrentWindow(vcsContext.getProject());
    }
  }
}
 
Example 2
Source File: DocumentIntention.java    From weex-language-support with MIT License 5 votes vote down vote up
private void openSample(Project project, Editor editor) {

        EditorTextField field = new EditorTextField(editor.getDocument(), project, WeexFileType.INSTANCE, true, false) {
            @Override
            protected EditorEx createEditor() {
                EditorEx editor1 = super.createEditor();
                editor1.setVerticalScrollbarVisible(true);
                editor1.setHorizontalScrollbarVisible(true);
                return editor1;

            }
        };

        field.setFont(editor.getContentComponent().getFont());

        JBPopup jbPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(field, null)
                .createPopup();

        jbPopup.setSize(new Dimension(500, 500));
        jbPopup.showInBestPositionFor(editor);
    }
 
Example 3
Source File: CamelAddEndpointIntention.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
     // filter libraries to only be Camel libraries
    Set<String> artifacts = ServiceManager.getService(project, CamelService.class).getLibraries();

    // find the camel component from those libraries
    boolean consumerOnly = getCamelIdeaUtils().isConsumerEndpoint(element);
    List<String> names = findCamelComponentNamesInArtifact(artifacts, consumerOnly, project);

    // no camel endpoints then exit
    if (names.isEmpty()) {
        return;
    }

    // show popup to chose the component
    JBList list = new JBList(names.toArray(new Object[names.size()]));
    PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
    builder.setAdText(names.size() + " components");
    builder.setTitle("Add Camel Endpoint");
    builder.setItemChoosenCallback(() -> {
        String line = (String) list.getSelectedValue();
        int pos = editor.getCaretModel().getCurrentCaret().getOffset();
        if (pos > 0) {
            // must run this as write action because we change the source code
            new WriteCommandAction(project, element.getContainingFile()) {
                @Override
                protected void run(@NotNull Result result) throws Throwable {
                    String text = line + ":";
                    editor.getDocument().insertString(pos, text);
                    editor.getCaretModel().moveToOffset(pos + text.length());
                }
            }.execute();
        }
    });

    JBPopup popup = builder.createPopup();
    popup.showInBestPositionFor(editor);
}
 
Example 4
Source File: TranslateQueryAction.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
@Override
protected void actionPerformed(AnActionEvent e, Project project, Editor editor, String query, Map<String, Object> parameters) {
    String gremlin = new OpenCypherGremlinSimpleTranslator().translate(query, parameters);

    JTextArea translation = new JTextArea(gremlin);
    translation.setEditable(false);
    translation.setLineWrap(true);

    JButton configure = new JButton("Configure/optimize translation");
    configure.addActionListener(v -> LandingPageAction.open());

    JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(translation, null)
            .setAdText("Query translated using Cypher for Gremlin")
            .setSettingButtons(configure)
            .setCancelButton(new IconButton("Cancel", AllIcons.Actions.Cancel))
            .setRequestFocus(true)
            .setResizable(true)
            .setMovable(true)
            .setMinSize(new Dimension(200, 150))
            .createPopup();

    if (editor == null) {
        popup.showCenteredInCurrentWindow(project);
    } else {
        popup.showInBestPositionFor(editor);
    }
}
 
Example 5
Source File: TemplateCreateByNameLocalQuickFix.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void applyFix(@NotNull Project project) {
    Collection<String> templatePaths = TwigUtil.getCreateAbleTemplatePaths(project, templateName);

    if(templatePaths.size() == 0) {
        Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();

        // notify error if editor is focused
        if(editor != null) {
            HintManager.getInstance().showErrorHint(editor, "Can not find a target dir");
        }

        return;
    }

    JBList<String> list = new JBList<>(templatePaths);

    JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list)
        .setTitle("Twig: Template Path")
        .setItemChoosenCallback(() -> {
            final String selectedValue = list.getSelectedValue();
            String commandName = "Create Template: " + (selectedValue.length() > 15 ? selectedValue.substring(selectedValue.length() - 15) : selectedValue);

            new WriteCommandAction.Simple(project, commandName) {
                @Override
                protected void run() {
                    createFile(project, selectedValue);
                }
            }.execute();
        })
        .createPopup();

    // show popup in scope
    Editor selectedTextEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    if(selectedTextEditor != null) {
        popup.showInBestPositionFor(selectedTextEditor);
    } else {
        popup.showCenteredInCurrentWindow(project);
    }
}
 
Example 6
Source File: AddCommentAction.java    From Crucible4IDEA with MIT License 5 votes vote down vote up
private void addGeneralComment(@NotNull final Project project, DataContext dataContext) {
  final CommentForm commentForm = new CommentForm(project, true, myIsReply, null);
  commentForm.setReview(myReview);

  if (myIsReply) {
    final JBTable contextComponent = (JBTable)getContextComponent();
    final int selectedRow = contextComponent.getSelectedRow();
    if (selectedRow >= 0) {
      final Object parentComment = contextComponent.getValueAt(selectedRow, 0);
      if (parentComment instanceof Comment) {
        commentForm.setParentComment(((Comment)parentComment));
      }
    }
    else return;
  }

  final JBPopup balloon = CommentBalloonBuilder.getNewCommentBalloon(commentForm, myIsReply ? CrucibleBundle
    .message("crucible.new.reply.$0", commentForm.getParentComment().getPermId()) :
                                                                                  CrucibleBundle
                                                                                    .message("crucible.new.comment.$0",
                                                                                             myReview.getPermaId()));
  balloon.addListener(new JBPopupListener() {
    @Override
    public void onClosed(LightweightWindowEvent event) {
      if(!commentForm.getText().isEmpty()) { // do not try to save draft if text is empty
        commentForm.postComment();
      }
      final JComponent component = getContextComponent();
      if (component instanceof GeneralCommentsTree) {
        ((GeneralCommentsTree)component).refresh();
      }
    }
  });

  commentForm.setBalloon(balloon);
  balloon.showInBestPositionFor(dataContext);
  commentForm.requestFocus();
}
 
Example 7
Source File: GoToChangePopupBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  JBPopup popup = createPopup(e);

  InputEvent event = e.getInputEvent();
  if (event instanceof MouseEvent) {
    popup.show(new RelativePoint((MouseEvent)event));
  }
  else {
    popup.showInBestPositionFor(e.getDataContext());
  }
}
 
Example 8
Source File: InspectionResultsView.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void showPopup(AnActionEvent e, JBPopup popup) {
  final InputEvent event = e.getInputEvent();
  if (event instanceof MouseEvent) {
    popup.showUnderneathOf(event.getComponent());
  }
  else {
    popup.showInBestPositionFor(e.getDataContext());
  }
}
 
Example 9
Source File: PsiElementListNavigator.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void openTargets(Editor e, NavigatablePsiElement[] targets, String title, final String findUsagesTitle,
                               ListCellRenderer listRenderer, @Nullable BackgroundUpdaterTask listUpdaterTask) {
  final JBPopup popup = navigateOrCreatePopup(targets, title, findUsagesTitle, listRenderer, listUpdaterTask);
  if (popup != null) {
    if (listUpdaterTask != null) {
      runActionAndListUpdaterTask(() -> popup.showInBestPositionFor(e), listUpdaterTask);
    }
    else {
      popup.showInBestPositionFor(e);
    }
  }
}
 
Example 10
Source File: PopupPositionManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void positionPopupInBestPosition(final JBPopup hint, @Nullable final Editor editor, @Nullable DataContext dataContext, @Nonnull Position... relationToExistingPopup) {
  final LookupEx lookup = LookupManager.getActiveLookup(editor);
  if (lookup != null && lookup.getCurrentItem() != null && lookup.getComponent().isShowing()) {
    new PositionAdjuster(lookup.getComponent()).adjust(hint, relationToExistingPopup);
    lookup.addLookupListener(new LookupListener() {
      @Override
      public void lookupCanceled(@Nonnull LookupEvent event) {
        if (hint.isVisible()) {
          hint.cancel();
        }
      }
    });
    return;
  }

  final PositionAdjuster positionAdjuster = createPositionAdjuster(hint);
  if (positionAdjuster != null) {
    positionAdjuster.adjust(hint, relationToExistingPopup);
    return;
  }

  if (editor != null && editor.getComponent().isShowing() && editor instanceof EditorEx) {
    dataContext = ((EditorEx)editor).getDataContext();
  }

  if (dataContext != null) {
    if (hint.canShow()) {
      hint.showInBestPositionFor(dataContext);
    }
    else {
      hint.setLocation(hint.getBestPositionFor(dataContext));
    }
  }
}
 
Example 11
Source File: VectorComponentsIntention.java    From glsl4idea with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void processIntention(PsiElement psiElement) {
    GLSLIdentifier elementTemp = null;
    if(psiElement instanceof GLSLIdentifier){
        elementTemp = (GLSLIdentifier) psiElement;
    }else{
        PsiElement parent = psiElement.getParent();
        if(parent instanceof GLSLIdentifier){
            elementTemp = (GLSLIdentifier) parent;
        }
    }
    if(elementTemp == null){
        Logger.getInstance(VectorComponentsIntention.class).warn("Could not find GLSLIdentifier for psiElement: "+psiElement);
        return;
    }
    final GLSLIdentifier element = elementTemp;

    String components = element.getText();

    final String[] results = createComponentVariants(components);

    String[] variants = new String[]{components + " -> " + results[0], components + " -> " + results[1]};
    //http://www.jetbrains.net/devnet/message/5208622#5208622
    final JBList<String> list = new JBList<>(variants);
    PopupChooserBuilder builder = new PopupChooserBuilder(list);
    builder.setTitle("Select Variant");
    builder.setItemChoosenCallback(new Runnable() {
        public void run() {
            try {
                WriteCommandAction.writeCommandAction(element.getProject(), element.getContainingFile()).run(new ThrowableRunnable<Throwable>() {
                    @Override
                    public void run() {
                        replaceIdentifierElement(element, results[list.getSelectedIndex()]);
                    }
                });
            } catch (Throwable t) {
                LOG.error("replaceIdentifierElement failed", t);
            }
        }
    });
    JBPopup popup = builder.createPopup();
    popup.showInBestPositionFor(getEditor());
}
 
Example 12
Source File: ChangeListDetailsAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void showDetailsPopup(final Project project, final CommittedChangeList changeList) {
  StringBuilder detailsBuilder = new StringBuilder("<html><head>");
  detailsBuilder.append(UIUtil.getCssFontDeclaration(UIUtil.getLabelFont())).append("</head><body>");
  final AbstractVcs vcs = changeList.getVcs();
  CachingCommittedChangesProvider provider = null;
  if (vcs != null) {
    provider = vcs.getCachingCommittedChangesProvider();
    if (provider != null && provider.getChangelistTitle() != null) {
      detailsBuilder.append(provider.getChangelistTitle()).append(" #").append(changeList.getNumber()).append("<br>");
    }
  }
  @NonNls String committer = "<b>" + changeList.getCommitterName() + "</b>";
  detailsBuilder.append(VcsBundle.message("changelist.details.committed.format", committer,
                                          DateFormatUtil.formatPrettyDateTime(changeList.getCommitDate())));
  detailsBuilder.append("<br>");

  if (provider != null) {
    final CommittedChangeList originalChangeList;
    if (changeList instanceof ReceivedChangeList) {
      originalChangeList = ((ReceivedChangeList) changeList).getBaseList();
    }
    else {
      originalChangeList = changeList;
    }
    for(ChangeListColumn column: provider.getColumns()) {
      if (ChangeListColumn.isCustom(column)) {
        String value = column.getValue(originalChangeList).toString();
        if (value.length() == 0) {
          value = "<none>";
        }
        detailsBuilder.append(column.getTitle()).append(": ").append(XmlStringUtil.escapeString(value)).append("<br>");
      }
    }
  }

  detailsBuilder.append(IssueLinkHtmlRenderer.formatTextWithLinks(project, changeList.getComment()));
  detailsBuilder.append("</body></html>");

  JEditorPane editorPane = new JEditorPane(UIUtil.HTML_MIME, detailsBuilder.toString());
  editorPane.setEditable(false);
  editorPane.setBackground(HintUtil.INFORMATION_COLOR);
  editorPane.select(0, 0);
  editorPane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
  JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(editorPane);
  final JBPopup hint =
    JBPopupFactory.getInstance().createComponentPopupBuilder(scrollPane, editorPane)
      .setDimensionServiceKey(project, "changelist.details.popup", false)
      .setResizable(true)
      .setMovable(true)
      .setRequestFocus(true)
      .setTitle(VcsBundle.message("changelist.details.title"))
      .createPopup();
  hint.showInBestPositionFor(DataManager.getInstance().getDataContext());
}