public ContentChooser(Project project, String title, boolean useIdeaEditor, boolean allowMultipleSelections) { super(project, true); myProject = project; myUseIdeaEditor = useIdeaEditor; myAllowMultipleSelections = allowMultipleSelections; myUpdateAlarm = new Alarm(getDisposable()); mySplitter = new JBSplitter(true, 0.3f); mySplitter.setSplitterProportionKey(getDimensionServiceKey() + ".splitter"); myList = new JBList(new CollectionListModel<Item>()); myList.setExpandableItemsEnabled(false); setOKButtonText(CommonBundle.getOkButtonText()); setTitle(title); init(); }
public void refreshCourse(String course) { logger.info("Refreshing course {}. @ProjectListManager", course); List<JBList> list = currentListElements.get(course); if (list == null) { return; } for (JBList jbList : list) { if (jbList == null || !jbList.getName().equals(course)) { continue; } DefaultListModel model = (DefaultListModel) jbList.getModel(); model.removeAllElements(); addExercisesToList(new ObjectFinder(), course, model, new CourseAndExerciseManager()); jbList.setModel(model); } refreshAllCourses(); }
private void addRightMouseButtonFunctionality(MouseEvent mouseEvent, final JBList list, JBScrollPane panel) { logger.info("Adding functionality for right mouse button. @CourseTabFactory"); if (!SwingUtilities.isRightMouseButton(mouseEvent)) { return; } int index = list.locationToIndex(mouseEvent.getPoint()); list.setSelectedIndex(index); PopUpMenu menu = new PopUpMenu(); JBMenuItem openInExplorer = new JBMenuItem("Open path"); final Object selectedItem = list.getSelectedValue(); JBMenuItem deleteFolder = new JBMenuItem("Delete folder"); openInExplorer.addActionListener(createOpenInExploreListener(list, selectedItem)); deleteFolder.addActionListener(createDeleteButtonActionListener(list, selectedItem)); menu.add(openInExplorer); menu.add(deleteFolder); menu.show(panel, mouseEvent.getX(), mouseEvent.getY()); menu.setLocation(mouseEvent.getXOnScreen(), mouseEvent.getYOnScreen()); }
private void chooseAnnotation(String title, JBList list) { final TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject) .createNoInnerClassesScopeChooser("Choose " + title + " annotation", GlobalSearchScope.allScope(myProject), new ClassFilter() { @Override public boolean isAccepted(PsiClass aClass) { return aClass.isAnnotationType(); } }, null); chooser.showDialog(); final PsiClass selected = chooser.getSelected(); if (selected == null) { return; } final String qualifiedName = selected.getQualifiedName(); final DefaultListModel model = (DefaultListModel)list.getModel(); final int index = model.indexOf(qualifiedName); if (index < 0) { model.addElement(qualifiedName); } else { myList.setSelectedIndex(index); } }
@Override protected JComponent createCenterPanel() { final DefaultListModel model = new DefaultListModel (); for (PsiField member : myFields) { model.addElement(member); } myList = new JBList(model); myList.setCellRenderer(new MyListCellRenderer()); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { if (myList.getSelectedValues().length > 0) { doOKAction(); return true; } return false; } }.installOn(myList); myList.setPreferredSize(JBUI.size(300, 400)); return myList; }
@Override protected JComponent createCenterPanel() { final JPanel panel = new JPanel(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP)); myList = new JBList(myNamedElements); myList.setCellRenderer(new FQNameCellRenderer()); panel.add(ScrollPaneFactory.createScrollPane(myList), BorderLayout.CENTER); panel.add(new JBLabel(myContainsClassesOnly ? CodeInsightBundle.message("dialog.paste.on.import.text") : CodeInsightBundle.message("dialog.paste.on.import.text2"), SMALL, BRIGHTER), BorderLayout.NORTH); final JPanel buttonPanel = new JPanel(new VerticalFlowLayout()); final JButton okButton = new JButton(CommonBundle.getOkButtonText()); getRootPane().setDefaultButton(okButton); buttonPanel.add(okButton); final JButton cancelButton = new JButton(CommonBundle.getCancelButtonText()); buttonPanel.add(cancelButton); panel.setPreferredSize(JBUI.size(500, 400)); return panel; }
@Override public void invoke(@NotNull Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException { final List<String> fqns = getPossibleFqns(myRef); myEditorComponent = editor.getComponent(); if (fqns.size() > 1) { final JBList listOfFqns = new JBList(fqns); JBPopupFactory.getInstance() .createListPopupBuilder(listOfFqns) .setTitle("Select Qualified Name") .setItemChoosenCallback(new Runnable() { @Override public void run() { final Object value = listOfFqns.getSelectedValue(); if (value instanceof String) { findJarsForFqn(((String)value), editor); } } }).createPopup().showInBestPositionFor(editor); } else if (fqns.size() == 1) { findJarsForFqn(fqns.get(0), editor); } }
AddSourceToProjectDialog(Project project, List<TargetInfo> targets) { super(project, /* canBeParent */ true, IdeModalityType.MODELESS); this.project = project; mainPanel = new JPanel(new VerticalLayout(12)); @SuppressWarnings({"rawtypes", "unchecked"}) // #api171: generify JBList usage JList<TargetInfo> targetsComponent = new JBList(targets); if (targets.size() == 1) { targetsComponent.setSelectedIndex(0); } this.targetsComponent = targetsComponent; setTitle("Add Source File to Project"); setupUi(); init(); }
public void show() { List<RecentChange> cc = myVcs.getRecentChanges(myGateway.createTransientRootEntry()); if (cc.isEmpty()) { Messages.showInfoMessage(myProject, LocalHistoryBundle.message("recent.changes.to.changes"), getTitle()); return; } final JList list = new JBList(createModel(cc)); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setCellRenderer(new RecentChangesListCellRenderer()); Runnable selectAction = new Runnable() { public void run() { RecentChange c = (RecentChange)list.getSelectedValue(); showRecentChangeDialog(c); } }; showList(list, selectAction); }
public void show(Collection<T> schemes) { if (schemes.isEmpty()) { Messages.showMessageDialog("There are no available schemes to import", "Import", Messages.getWarningIcon()); return; } final JList list = new JBList(new CollectionListModel<T>(schemes)); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setCellRenderer(new SchemesToImportListCellRenderer()); Runnable selectAction = new Runnable() { @Override public void run() { onSchemeSelected((T)list.getSelectedValue()); } }; showList(list, selectAction); }
protected JBList createList() { final JBList list = new JBList(myListModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setEmptyText(getListEmptyText()); list.setCellRenderer(createListCellRenderer()); installListActions(list); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent event) { if (event.getValueIsAdjusting()) return; if (isMergeListItemsRunning()) return; if (myUpdateSelectedPathModeActive.get()) return; updateRightComponent(true); } }); ScrollingUtil.installActions(list); // installSpeedSearch(list); // TODO installEditOnDoubleClick(list); return list; }
public GroupList(PsiClass[] classes) { super(new BorderLayout()); SortedListModel<String> model = new SortedListModel<String>(new Comparator<String>() { public int compare(String s1, String s2) { return s1.compareTo(s2); } }); list = new JBList(model); Set<String> groups = TestNGUtil.getAnnotationValues("groups", classes); String[] array = ArrayUtil.toStringArray(groups); Arrays.sort(array); model.addAll(array); add(ScrollPaneFactory.createScrollPane(list)); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ScrollingUtil.ensureSelectionExists(list); }
public void go(boolean forward) { JBList selected = getSelectedList(); JList list = selected; int index = list.getSelectedIndex(); if (forward) index++; else index--; if ((forward && index >= list.getModel().getSize()) || (!forward && index < 0)) { if (isFilesVisible()) { list = isFilesSelected() ? toolWindows : files; } index = forward ? 0 : list.getModel().getSize() - 1; } list.setSelectedIndex(index); list.ensureIndexIsVisible(index); if (selected != list) { IdeFocusManager.findInstanceByComponent(list).requestFocus(list, true); } }
@Nullable private static PositionAdjuster createPositionAdjuster() { final Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (focusOwner == null) return null; if (focusOwner instanceof JBList) { return new PositionAdjuster(SwingUtilities.getWindowAncestor(focusOwner)); } final Component existing = discoverPopup(LangDataKeys.POSITION_ADJUSTER_POPUP, focusOwner); if (existing != null) { return new PositionAdjuster2(existing, discoverPopup(LangDataKeys.PARENT_POPUP, focusOwner)); } //final Window window = SwingUtilities.getWindowAncestor(focusOwner); //return window == null ? null : new PositionAdjuster(window); return null; }
private void chooseAndImport(Editor editor) { final JList list = new JBList(getCandidates().toArray(new PsiMethod[getCandidates().size()])); list.setCellRenderer(new MethodCellRenderer(true)); new PopupChooserBuilder(list). setTitle(QuickFixBundle.message("static.import.method.choose.method.to.import")). setMovable(true). setItemChoosenCallback(new Runnable() { @Override public void run() { PsiMethod selectedValue = (PsiMethod)list.getSelectedValue(); if (selectedValue == null) return; LOG.assertTrue(selectedValue.isValid()); doImport(selectedValue); } }).createPopup(). showInBestPositionFor(editor); }
CustomFoldingRegionsPopup(@NotNull Collection<FoldingDescriptor> descriptors, @NotNull final Editor editor, @NotNull final Project project) { myEditor = editor; myRegionsList = new JBList(); //noinspection unchecked myRegionsList.setModel(new MyListModel(orderByPosition(descriptors))); myRegionsList.setSelectedIndex(0); final PopupChooserBuilder popupBuilder = JBPopupFactory.getInstance().createListPopupBuilder(myRegionsList); myPopup = popupBuilder .setTitle(IdeBundle.message("goto.custom.region.command")) .setResizable(false) .setMovable(false) .setItemChoosenCallback(new Runnable() { @Override public void run() { PsiElement navigationElement = getNavigationElement(); if (navigationElement != null) { navigateTo(editor, navigationElement); IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation(); } } }).createPopup(); }
GroovyDocGenerationPanel() { myInputDir.addBrowseFolderListener(GroovyDocBundle.message("groovydoc.generate.directory.browse"), null, null, FileChooserDescriptorFactory.createSingleFolderDescriptor()); myOutputDir.addBrowseFolderListener(GroovyDocBundle.message("groovydoc.generate.directory.browse"), null, null, FileChooserDescriptorFactory.createSingleFolderDescriptor()); myDataModel = new DefaultListModel(); myPackagesList = new JBList(myDataModel); myPackagesList.setMinimumSize(JBUI.size(100, 150)); JScrollPane packagesScrollPane = ScrollPaneFactory.createScrollPane(myPackagesList); myPackagesPanel.setLayout(new BorderLayout()); myPackagesPanel.setBorder(IdeBorderFactory.createTitledBorder("Source packages", false)); ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar("GroovyDoc", getActionGroup(), true); myPackagesPanel.add(actionToolbar.getComponent(), BorderLayout.NORTH); myPackagesPanel.add(packagesScrollPane, BorderLayout.SOUTH); actionToolbar.updateActionsImmediately(); myPanel.setMinimumSize(JBUI.size(275, 350)); }
public ProGuardConfigFilesPanel() { super(new BorderLayout()); myModel = new CollectionListModel<String>(); myList = new JBList(myModel); final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myList). setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final String path = chooseFile(); if (path != null) { myModel.add(path); } } }); JPanel tablePanel = decorator.setPreferredSize(new Dimension(-1, 120)).createPanel(); tablePanel.setMinimumSize(new Dimension(-1, 120)); add(tablePanel, BorderLayout.CENTER); final JBLabel label = new JBLabel("Config file paths:"); label.setBorder(IdeBorderFactory.createEmptyBorder(0, 0, 5, 0)); add(label, BorderLayout.NORTH); }
private void createUIComponents() { VirtualFile[] data = event.getData(DataKeys.VIRTUAL_FILE_ARRAY); fieldList = new JBList(data); fieldList.setEmptyText("No File Selected!"); ToolbarDecorator decorator = ToolbarDecorator.createDecorator(fieldList); filePanel = decorator.createPanel(); }
public AppEngineFacetEditor(AppEngineFacetConfiguration facetConfiguration, FacetEditorContext context, FacetValidatorsManager validatorsManager) { myFacetConfiguration = facetConfiguration; myContext = context; mySdkEditor = new AppEngineSdkEditor(myContext.getProject()); validatorsManager.registerValidator(new FacetEditorValidator() { @NotNull @Override public ValidationResult check() { return AppEngineSdkUtil.checkPath(mySdkEditor.getPath()); } }, mySdkEditor.getComboBox()); myRunEnhancerOnMakeCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { GuiUtils.enableChildren(myRunEnhancerOnMakeCheckBox.isSelected(), myFilesToEnhancePanel); if (myRunEnhancerOnMakeCheckBox.isSelected() && myFilesListModel.isEmpty()) { fillFilesList(AppEngineUtil.getDefaultSourceRootsToEnhance(myContext.getRootModel())); } } }); myFilesListModel = new DefaultListModel(); myFilesList = new JBList(myFilesListModel); myFilesList.setCellRenderer(new FilesListCellRenderer()); myFilesPanel.add(ToolbarDecorator.createDecorator(myFilesList) .setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { doAdd(); } }).disableUpDownActions().createPanel(), BorderLayout.CENTER); PersistenceApiComboboxUtil.setComboboxModel(myPersistenceApiComboBox, false); }
public void createCourseSpecificTab( ObjectFinder finder, ProjectOpener opener, String course, JTabbedPane tabbedPaneBase, CourseAndExerciseManager courseAndExerciseManager) { logger.info("Creating course specific tab. @CourseTabFactory"); final JBScrollPane panel = new JBScrollPane(); final JBList list = new JBList(); list.setCellRenderer(new ProjectListRenderer()); DefaultListModel defaultListModel = new DefaultListModel(); panel.setBorder(BorderFactory.createTitledBorder("")); ProjectListManagerHolder.get() .addExercisesToList(finder, course, defaultListModel, courseAndExerciseManager); if (defaultListModel.getSize() <= 0) { return; } list.setName(course); list.setModel(defaultListModel); MouseListener mouseListener = createMouseListenerForWindow(opener, panel, list); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.addMouseListener(mouseListener); panel.setName(course); panel.setViewportView(list); ProjectListManagerHolder.get().addList(list); tabbedPaneBase.addTab(course, panel); tabbedPaneBase.addMouseListener(tabMouseListener(tabbedPaneBase)); setScrollBarToBottom(course, tabbedPaneBase, panel); }
@NotNull private ActionListener createOpenInExploreListener(final JBList list, final Object selectedItem) { return actionEvent -> { logger.info("Right mouse button action performed. @CourseTabFactory"); try { if (selectedItem.getClass() != Exercise.class) { Desktop.getDesktop().open(new File(TmcSettingsManager .get().getProjectBasePath() + File.separator + list.getParent() .getParent().getName() + File.separator + list.getSelectedValue())); } else { logger.info("Getting TMC project directory " + "from settingsTmc. @CourseTabFactory"); Desktop.getDesktop().open(new File(((Exercise)selectedItem) .getExerciseDirectory(TmcSettingsManager .get().getTmcProjectDirectory()).toString())); } } catch (IOException e1) { logger.warn("IOException occurred. Something interrupted " + "the mouse action. @CourseTabFactory", e1, e1.getStackTrace()); new ErrorMessageService().showErrorMessage(e1, "IOException occurred. Something interrupted the mouse action.", true); } }; }
@NotNull private ActionListener createDeleteButtonActionListener(final JBList list, final Object selectedItem) { return actionEvent -> { logger.info("Trying to delete folder. @CourseTabFactory"); if (Messages .showYesNoDialog("Are you sure you wish to permanently delete this folder?", "Delete Exercise", Messages.getWarningIcon()) != 0) { return; } try { if (selectedItem.getClass() != Exercise.class) { FileUtils.deleteDirectory(new File(TmcSettingsManager .get().getProjectBasePath() + File.separator + list.getParent() .getParent().getName() + File.separator + list.getSelectedValue())); } else { logger.info("Getting TMC project directory " + "from settingsTmc. @CourseTabFactory"); FileUtils.deleteDirectory(new File(((Exercise) selectedItem) .getExerciseDirectory(TmcSettingsManager .get().getTmcProjectDirectory()).toString())); } new ProjectListWindow().refreshProjectList(); } catch (IOException e1) { logger.warn("IOException occurred. Something interrupted " + "the mouse action. @CourseTabFactory", e1, e1.getStackTrace()); new ErrorMessageService().showErrorMessage(e1, "IOException occurred. Something interrupted the mouse action.", true); } }; }
public CourseListWindow(List<Course> courses) { CourseCard[] courseCards = new CourseCard[courses.size()]; for (int i = 0; i < courses.size(); i++) { courseCards[i] = new CourseCard(courses.get(i)); } this.courses = new JBList<>(courseCards); this.courses.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.button = new JButton("Select"); button.addActionListener(new SelectCourseListener(this)); this.courses.setCellRenderer(new CourseCellRenderer()); this.courses.setVisibleRowCount(4); JScrollPane pane = new JBScrollPane(this.courses); Dimension d = pane.getPreferredSize(); d.width = 400; pane.setPreferredSize(d); pane.setBorder(new EmptyBorder(5, 0, 5, 0)); this.courses.setBackground(new Color(242, 241, 240)); this.courses.setSelectedIndex(setDefaultSelectedIndex()); this.courses.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent event) { if (event.getClickCount() >= 2) { button.doClick(); } } }); add(pane); add(button); }
public OrganizationListWindow(List<Organization> organizations) { OrganizationCard[] organizationCards = new OrganizationCard[organizations.size()]; for (int i = 0; i < organizations.size(); i++) { organizationCards[i] = new OrganizationCard(organizations.get(i)); } this.organizations = new JBList<>(organizationCards); this.organizations.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.button = new JButton("Select"); button.addActionListener(new SelectOrganizationListener(this)); this.organizations.setCellRenderer(new OrganizationCellRenderer()); this.organizations.setVisibleRowCount(4); JScrollPane pane = new JBScrollPane(this.organizations); Dimension d = pane.getPreferredSize(); d.width = 400; pane.setPreferredSize(d); pane.setBorder(new EmptyBorder(5, 0, 5, 0)); this.organizations.setBackground(new Color(242, 241, 240)); this.organizations.setSelectedIndex(setDefaultSelectedIndex()); this.organizations.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent event) { if (event.getClickCount() >= 2) { button.doClick(); } } }); add(pane); add(button); }
@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); }
/** * Override this if you haven't PsiMethod, like in Kotlin. * @param position * @param session * @param fileEditor * @return false to continue for another handler or for default action (step into) */ public boolean doSmartStep(SourcePosition position, final DebuggerSession session, TextEditor fileEditor) { final List<SmartStepTarget> targets = findSmartStepTargets(position); if (!targets.isEmpty()) { final SmartStepTarget firstTarget = targets.get(0); if (targets.size() == 1) { session.sessionResumed(); session.stepInto(true, createMethodFilter(firstTarget)); } else { final Editor editor = fileEditor.getEditor(); final PsiMethodListPopupStep popupStep = new PsiMethodListPopupStep(editor, targets, new PsiMethodListPopupStep.OnChooseRunnable() { public void execute(SmartStepTarget chosenTarget) { session.sessionResumed(); session.stepInto(true, createMethodFilter(chosenTarget)); } }); ListPopupImpl popup = new ListPopupImpl(popupStep); DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.STEP_INTO); DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.SMART_STEP_INTO); popup.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { popupStep.getScopeHighlighter().dropHighlight(); if (!e.getValueIsAdjusting()) { final SmartStepTarget selectedTarget = (SmartStepTarget)((JBList)e.getSource()).getSelectedValue(); if (selectedTarget != null) { highlightTarget(popupStep, selectedTarget); } } } }); highlightTarget(popupStep, firstTarget); DebuggerUIUtil.showPopupForEditorLine(popup, editor, position.getLine()); } return true; } return false; }
public void navigate(final Project project) { DefaultPsiElementListCellRenderer renderer = new DefaultPsiElementListCellRenderer(); final JList list = new JBList(myPsiFiles); list.setCellRenderer(renderer); final PopupChooserBuilder builder = new PopupChooserBuilder(list); renderer.installSpeedSearch(builder); final Runnable runnable = new Runnable() { public void run() { int[] ids = list.getSelectedIndices(); if (ids == null || ids.length == 0) return; Object[] selectedElements = list.getSelectedValues(); for (Object element : selectedElements) { Navigatable descriptor = EditSourceUtil.getDescriptor((PsiElement)element); if (descriptor != null && descriptor.canNavigate()) { descriptor.navigate(true); } } } }; final Editor editor = CommonDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext()); builder. setTitle("Choose file"). setItemChoosenCallback(runnable). createPopup().showInBestPositionFor(editor); }
@Override public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final PsiElement element = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiJavaCodeReferenceElement.class); if (element instanceof PsiJavaCodeReferenceElement) { final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)element; Collections.sort(originalClasses, new PsiProximityComparator(referenceElement.getElement())); final JList list = new JBList(originalClasses.toArray(new PsiClass[originalClasses.size()])); list.setCellRenderer(new FQNameCellRenderer()); final Runnable runnable = new Runnable() { @Override public void run() { if (!element.isValid()) return; final int index = list.getSelectedIndex(); if (index < 0) return; new WriteCommandAction(project, element.getContainingFile()){ @Override protected void run(@NotNull final Result result) throws Throwable { final PsiClass psiClass = originalClasses.get(index); if (psiClass.isValid()) { PsiDocumentManager.getInstance(project).commitAllDocuments(); referenceElement.bindToElement(psiClass); } } }.execute(); } }; final AsyncResult<DataContext> asyncResult = DataManager.getInstance().getDataContextFromFocus(); asyncResult.doWhenDone(new Consumer<DataContext>() { @Override public void consume(DataContext dataContext) { new PopupChooserBuilder(list). setTitle(QuickFixBundle.message("add.qualifier.original.class.chooser.title")). setItemChoosenCallback(runnable). createPopup(). showInBestPositionFor(dataContext); } }); } }
private void chooseTargetClass(List<PsiClass> classes, final Editor editor) { final PsiClass firstClass = classes.get(0); final Project project = firstClass.getProject(); final JList list = new JBList(classes); PsiElementListCellRenderer renderer = new PsiClassListCellRenderer(); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setCellRenderer(renderer); final PopupChooserBuilder builder = new PopupChooserBuilder(list); renderer.installSpeedSearch(builder); final PsiClass preselection = AnonymousTargetClassPreselectionUtil.getPreselection(classes, firstClass); if (preselection != null) { list.setSelectedValue(preselection, true); } Runnable runnable = new Runnable() { @Override public void run() { int index = list.getSelectedIndex(); if (index < 0) return; final PsiClass aClass = (PsiClass) list.getSelectedValue(); AnonymousTargetClassPreselectionUtil.rememberSelection(aClass, firstClass); CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { doInvoke(project, aClass); } }, getText(), null); } }; builder. setTitle(QuickFixBundle.message("target.class.chooser.title")). setItemChoosenCallback(runnable). createPopup(). showInBestPositionFor(editor); }
@Override protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception { String extensionsJar = PathUtil.getJarPathForClass(ExtensionPointName.class); moduleBuilder.addLibrary("extensions", extensionsJar); String platformApiJar = PathUtil.getJarPathForClass(JBList.class); moduleBuilder.addLibrary("platform-api", platformApiJar); }
@Override protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception { String pathForClass = PathUtil.getJarPathForClass(LocalInspectionEP.class); moduleBuilder.addLibrary("lang-api", pathForClass); String platformApiJar = PathUtil.getJarPathForClass(JBList.class); moduleBuilder.addLibrary("platform-api", platformApiJar); }
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiDirectory[] dirs = getDirectories(); final List<VirtualFile> virtualFiles = getPotentialRoots(myModule, dirs); final VirtualFile[] roots = prepare(VfsUtilCore.toVirtualFileArray(virtualFiles)); if (roots.length == 1) { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { createDescription(roots[0]); } }); } else { List<String> options = new ArrayList<String>(); for (VirtualFile file : roots) { String path = getPath(file); options.add(path); } final JBList files = new JBList(ArrayUtil.toStringArray(options)); files.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); final JBPopup popup = JBPopupFactory.getInstance() .createListPopupBuilder(files) .setTitle(DevKitBundle.message("select.target.location.of.description", myFilename)) .setItemChoosenCallback(new Runnable() { public void run() { final int index = files.getSelectedIndex(); if (0 <= index && index < roots.length) { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { createDescription(roots[index]); } }); } } }).createPopup(); final Editor editor = FileEditorManager.getInstance(myModule.getProject()).getSelectedTextEditor(); if (editor == null) return; popup.showInBestPositionFor(editor); } }
protected JComponent createCenterPanel() { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP)); final JLabel classListLabel = new JLabel(); panel.add(classListLabel, BorderLayout.NORTH); mySuperClassesList = new JBList(mySuperClasses.toArray()); mySuperClassesList.setCellRenderer(new ClassCellRenderer(mySuperClassesList.getCellRenderer())); mySuperClassesList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); classListLabel.setText(RefactoringBundle.message("turnRefsToSuper.change.usages.to", mySubClass.getQualifiedName())); PsiClass nearestBase = RefactoringHierarchyUtil.getNearestBaseClass(mySubClass, true); int indexToSelect = 0; if(nearestBase != null) { indexToSelect = mySuperClasses.indexOf(nearestBase); } mySuperClassesList.setSelectedIndex(indexToSelect); panel.add(ScrollPaneFactory.createScrollPane(mySuperClassesList), BorderLayout.CENTER); myCbReplaceInstanceOf.setText(RefactoringBundle.message("turnRefsToSuper.use.superclass.in.instanceof")); myCbReplaceInstanceOf.setSelected(false); myCbReplaceInstanceOf.setFocusable(false); panel.add(myCbReplaceInstanceOf, BorderLayout.SOUTH); return panel; }
protected JList createTargetVariableChooser() { final JList list = new JBList(new MyListModel()); list.setCellRenderer(new MyListCellRenderer()); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { updateOnChanged(list); } }); return list; }
protected JComponent createNorthPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints gbConstraints = new GridBagConstraints(); gbConstraints.insets = new Insets(4, 8, 4, 8); gbConstraints.weighty = 0; gbConstraints.weightx = 1; gbConstraints.gridy = 0; gbConstraints.gridwidth = GridBagConstraints.REMAINDER; gbConstraints.gridheight = 1; gbConstraints.fill = GridBagConstraints.BOTH; gbConstraints.anchor = GridBagConstraints.WEST; panel.add(new JLabel(RefactoringBundle.message("introduce.parameter.to.method")), gbConstraints); gbConstraints.weighty = 1; myEnclosingMethodsList = new JBList(myEnclosingMethods.toArray()); myEnclosingMethodsList.setCellRenderer(new MethodCellRenderer()); myEnclosingMethodsList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); int indexToSelect = 0; myEnclosingMethodsList.setSelectedIndex(indexToSelect); gbConstraints.gridy++; panel.add(ScrollPaneFactory.createScrollPane(myEnclosingMethodsList), gbConstraints); return panel; }
protected void showPopup() { if (myPopup == null || !myPopup.isVisible()) { final JList list = new JBList(myModel); final Runnable chooseRunnable = createItemChosenCallback(list); myPopup = JBPopupFactory.getInstance().createListPopupBuilder(list) .setMovable(false) .setRequestFocus(true) .setItemChoosenCallback(chooseRunnable).createPopup(); if (isShowing()) { myPopup.showUnderneathOf(getPopupLocationComponent()); } } }
private JBList createList(RefGroup group) { JBList list = new JBList(createListModel(group)); list.setCellRenderer(myCellRenderer); ListUtil.installAutoSelectOnMouseMove(list); list.setSelectedIndex(0); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jumpOnMouseClick(list); jumpOnEnter(list); return list; }
private void jumpOnMouseClick(JBList list) { list.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { jumpToSelectedRef(); } }); }
private void jumpOnEnter(JBList list) { list.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { jumpToSelectedRef(); } } }); }