private void createPopup(Project project) { final JPanel panel = new JPanel(new BorderLayout()); final EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class); myEditorField = service.getEditorField( FileTypes.PLAIN_TEXT.getLanguage(), project, Collections.singletonList(EditorCustomization.Feature.SOFT_WRAP), Collections.singletonList(EditorCustomization.Feature.SPELL_CHECK)); myEditorField.setBorder( new CompoundBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), myEditorField.getBorder())); myEditorField.setText("s"); myEditorField.setText(myCurrentText); myEditorField.setOneLineMode(false); panel.add(myEditorField, BorderLayout.CENTER); myTextFieldCompletionProvider = new TextFieldCompletionProviderDumbAware(true) { @NotNull @Override protected String getPrefix(@NotNull String currentTextPrefix) { final int text = currentTextPrefix.lastIndexOf(','); return text == -1 ? currentTextPrefix : currentTextPrefix.substring(text + 1).trim(); } @Override protected void addCompletionVariants( @NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result) { final List<String> list = myUsers.get(); if (list != null) { for (String completionVariant : list) { final LookupElementBuilder element = LookupElementBuilder.create(completionVariant); result.addElement(element.withLookupString(completionVariant.toLowerCase())); } } } }; myComponentPopupBuilder = JBPopupFactory.getInstance() .createComponentPopupBuilder(panel, myEditorField) .setCancelOnClickOutside(true) .setAdText( KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish") .setTitle("Specify user names, comma separated") .setMovable(true) .setRequestFocus(true) .setResizable(true); mySelectOkAction = new AnAction() { @Override public void actionPerformed(AnActionEvent e) { myPopup.closeOk(e.getInputEvent()); final String newText = myEditorField.getText(); if (Comparing.equal(newText.trim(), myCurrentText.trim())) return; myCurrentText = newText; setText(myCurrentText.trim()); myPanel.setToolTipText(USER + " " + myCurrentText); myUserFilterI.filter(myCurrentText); } }; }
private InjectionsTable(final List<InjInfo> injections) { super(new ListTableModel<InjInfo>(createInjectionColumnInfos(), injections, 1)); setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN); getColumnModel().getColumn(2).setCellRenderer(createLanguageCellRenderer()); getColumnModel().getColumn(1).setCellRenderer(createDisplayNameCellRenderer()); getColumnModel().getColumn(0).setResizable(false); setShowGrid(false); setShowVerticalLines(false); setGridColor(getForeground()); TableUtil.setupCheckboxColumn(getColumnModel().getColumn(0)); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { final int row = rowAtPoint(e.getPoint()); if (row < 0) return false; if (columnAtPoint(e.getPoint()) <= 0) return false; myInjectionsTable.getSelectionModel().setSelectionInterval(row, row); performEditAction(); return true; } }.installOn(this); final String[] maxName = new String[] {""}; ContainerUtil.process( injections, new Processor<InjInfo>() { public boolean process(final InjInfo injection) { String languageId = injection.injection.getInjectedLanguageId(); Language language = InjectedLanguage.findLanguageById(languageId); String displayName = language == null ? languageId : language.getDisplayName(); if (maxName[0].length() < displayName.length()) maxName[0] = displayName; return true; } }); ContainerUtil.process( InjectedLanguage.getAvailableLanguages(), new Processor<Language>() { public boolean process(final Language language) { String displayName = language.getDisplayName(); if (maxName[0].length() < displayName.length()) maxName[0] = displayName; return true; } }); Icon icon = FileTypes.PLAIN_TEXT.getIcon(); int preferred = (int) (new JLabel(maxName[0], icon, SwingConstants.LEFT).getPreferredSize().width * 1.1); getColumnModel().getColumn(2).setMinWidth(preferred); getColumnModel().getColumn(2).setPreferredWidth(preferred); getColumnModel().getColumn(2).setMaxWidth(preferred); new TableViewSpeedSearch<InjInfo>(this) { @Override protected String getItemText(@NotNull InjInfo element) { final BaseInjection injection = element.injection; return injection.getSupportId() + " " + injection.getInjectedLanguageId() + " " + injection.getDisplayName(); } }; }