private void initializeClientsList() { myClientsList.setModel(myClientsListModel); myClientsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myClientsList.setEmptyText("No debuggable applications"); myClientsList.setCellRenderer(new ClientCellRenderer()); new ListSpeedSearch(myClientsList) { @Override protected boolean isMatchingElement(Object element, String pattern) { if (element instanceof Client) { String pkg = ((Client) element).getClientData().getClientDescription(); return pkg != null && pkg.contains(pattern); } return false; } }; myClientsList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() || myIgnoreListeners) { return; } Object sel = myClientsList.getSelectedValue(); Client c = (sel instanceof Client) ? (Client) sel : null; myDeviceContext.fireClientSelected(c); } }); }
@NotNull private static JPanel createFilesViewPanel(@NotNull List<VirtualFile> files) { JPanel panel = new JPanel(new BorderLayout(0, 2)); panel.add(new JLabel("Files to add:"), BorderLayout.NORTH); final JBList fileList = new JBList(ArrayUtil.EMPTY_STRING_ARRAY); fileList.setBorder(BorderFactory.createLineBorder(Color.lightGray)); fileList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { fileList.clearSelection(); } }); fileList.setFocusable(false); fileList.setRequestFocusEnabled(false); fileList.setBackground(Gray._242); fileList.setCellRenderer( new ListCellRendererWrapper<VirtualFile>() { @Override public void customize( JList list, VirtualFile value, int index, boolean selected, boolean hasFocus) { setText(" " + value.getName()); } }); fileList.setListData(files.toArray()); panel.add(fileList, BorderLayout.CENTER); return panel; }
private void showRecentFilesPopup() { final JBList files = new JBList(getRecentFiles()) { @Override public Dimension getPreferredSize() { return new Dimension( myPathTextField.getField().getWidth(), super.getPreferredSize().height); } }; files.setCellRenderer( new ColoredListCellRenderer() { @Override protected void customizeCellRenderer( JList list, Object value, int index, boolean selected, boolean hasFocus) { final String path = value.toString(); append(path); final VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(path)); if (file != null) { setIcon(IconUtil.getIcon(file, Iconable.ICON_FLAG_READ_STATUS, null)); } } }); JBPopupFactory.getInstance() .createListPopupBuilder(files) .setItemChoosenCallback( new Runnable() { @Override public void run() { myPathTextField.getField().setText(files.getSelectedValue().toString()); } }) .createPopup() .showUnderneathOf(myPathTextField.getField()); }
public LookupImpl(Project project, Editor editor, @NotNull LookupArranger arranger) { super(new JPanel(new BorderLayout())); setForceShowAsPopup(true); setCancelOnClickOutside(false); setResizable(true); AbstractPopup.suppressMacCornerFor(getComponent()); myProject = project; myEditor = editor; myArranger = arranger; myPresentableArranger = arranger; myCellRenderer = new LookupCellRenderer(this); myList.setCellRenderer(myCellRenderer); myList.setFocusable(false); myList.setFixedCellWidth(50); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myList.setBackground(LookupCellRenderer.BACKGROUND_COLOR); myList.getExpandableItemsHandler(); myAdComponent = new Advertiser(); myOffsets = new LookupOffsets(editor); final CollectionListModel<LookupElement> model = getListModel(); addEmptyItem(model); updateListHeight(model); addListeners(); }
public JComponent createComponent() { myList = new JBList(getListModel()); myList.setCellRenderer(createListCellRenderer(myList)); ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(myList) .disableUpDownActions() .setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final VirtualFile[] added = doAdd(); if (added.length > 0) { setModified(true); } requestDefaultFocus(); setSelectedRoots(added); } }) .setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { int[] idxs = myList.getSelectedIndices(); doRemoveItems(idxs, myList); } }) .setAddActionUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { return myEnabled; } }) .setRemoveActionUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { Object[] values = getSelectedRoots(); return values.length > 0 && myEnabled; } }); addToolbarButtons(toolbarDecorator); myPanel = toolbarDecorator.createPanel(); myPanel.setBorder(null); return myPanel; }
public SSBasedInspectionOptions(final List<Configuration> configurations) { myConfigurations = configurations; myTemplatesList = new JBList(new MyListModel()); myTemplatesList.setCellRenderer( new DefaultListCellRenderer() { public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel component = (JLabel) super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); Configuration configuration = myConfigurations.get(index); component.setText(configuration.getName()); return component; } }); }
@Override public void invoke(@NotNull final Project project, @Nullable final Editor editor, PsiFile file) { if (myModules.size() == 1) { addDependencyOnModule(project, editor, myModules.get(0)); } else { final JBList list = new JBList(myModules); list.setCellRenderer( new ListCellRendererWrapper<Module>() { @Override public void customize( JList list, Module module, int index, boolean selected, boolean hasFocus) { if (module != null) { setIcon(ModuleType.get(module).getIcon()); setText(module.getName()); } } }); final JBPopup popup = JBPopupFactory.getInstance() .createListPopupBuilder(list) .setTitle("Choose Module to Add Dependency on") .setMovable(false) .setResizable(false) .setRequestFocus(true) .setItemChoosenCallback( new Runnable() { @Override public void run() { final Object value = list.getSelectedValue(); if (value instanceof Module) { addDependencyOnModule(project, editor, (Module) value); } } }) .createPopup(); if (editor != null) { popup.showInBestPositionFor(editor); } else { popup.showCenteredInCurrentWindow(project); } } }
@Override protected JComponent createCenterPanel() { myJBList = new JBList(mySettings); myJBList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myJBList .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { Object selectedValue = myJBList.getSelectedValue(); if (selectedValue instanceof RunnerAndConfigurationSettings) { mySelectedSettings = (RunnerAndConfigurationSettings) selectedValue; } else { mySelectedSettings = null; } setOKActionEnabled(mySelectedSettings != null); } }); myJBList.setCellRenderer( new ColoredListCellRenderer() { @Override protected void customizeCellRenderer( JList list, Object value, int index, boolean selected, boolean hasFocus) { if (value instanceof RunnerAndConfigurationSettings) { RunnerAndConfigurationSettings settings = (RunnerAndConfigurationSettings) value; RunManagerEx runManager = RunManagerEx.getInstanceEx(myProject); setIcon(runManager.getConfigurationIcon(settings)); RunConfiguration configuration = settings.getConfiguration(); append( configuration.getName(), settings.isTemporary() ? SimpleTextAttributes.GRAY_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES); } } }); return new JBScrollPane(myJBList); }
public RecentProjectPanel() { super(new BorderLayout()); final AnAction[] recentProjectActions = RecentProjectsManagerBase.getInstance().getRecentProjectsActions(false); myList = new MyList(recentProjectActions); myList.setCellRenderer(new RecentProjectItemRenderer()); new ClickListener() { @Override public boolean onClick(MouseEvent event, int clickCount) { int selectedIndex = myList.getSelectedIndex(); if (selectedIndex >= 0) { if (myList.getCellBounds(selectedIndex, selectedIndex).contains(event.getPoint())) { Object selection = myList.getSelectedValue(); if (selection != null) { ((AnAction) selection) .actionPerformed( AnActionEvent.createFromInputEvent( (AnAction) selection, event, ActionPlaces.WELCOME_SCREEN)); } } } return true; } }.installOn(myList); myList.registerKeyboardAction( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object selection = myList.getSelectedValue(); if (selection != null) { ((AnAction) selection) .actionPerformed( AnActionEvent.createFromInputEvent( (AnAction) selection, null, ActionPlaces.WELCOME_SCREEN)); } } }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionListener deleteAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReopenProjectAction selection = (ReopenProjectAction) myList.getSelectedValue(); final int rc = Messages.showOkCancelDialog( RecentProjectPanel.this, "Remove '" + selection.getTemplatePresentation().getText() + "' from recent projects list?", "Remove Recent Project", Messages.getQuestionIcon()); if (rc == 0) { final RecentProjectsManagerBase manager = RecentProjectsManagerBase.getInstance(); manager.removePath(selection.getProjectPath()); ListUtil.removeSelectedItems(myList); } } }; myList.registerKeyboardAction( deleteAction, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); myList.registerKeyboardAction( deleteAction, KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); myList.addMouseMotionListener( new MouseMotionAdapter() { boolean myIsEngaged = false; public void mouseMoved(MouseEvent e) { if (myIsEngaged && !UIUtil.isSelectionButtonDown(e)) { Point point = e.getPoint(); int index = myList.locationToIndex(point); myList.setSelectedIndex(index); final Rectangle bounds = myList.getCellBounds(index, index); if (bounds != null && bounds.contains(point)) { myList.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } else { myList.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } else { myIsEngaged = true; } } }); myList.setSelectedIndex(0); JBScrollPane scroll = new JBScrollPane(myList); scroll.setBorder(null); JComponent list = recentProjectActions.length == 0 ? myList : ListWithFilter.wrap( myList, scroll, new Function<Object, String>() { @Override public String fun(Object o) { ReopenProjectAction item = (ReopenProjectAction) o; String home = SystemProperties.getUserHome(); String path = item.getProjectPath(); if (FileUtil.startsWith(path, home)) { path = path.substring(home.length()); } return item.getProjectName() + " " + path; } }); add(list, BorderLayout.CENTER); JPanel title = new JPanel() { @Override public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, 28); } }; title.setBorder(new BottomLineBorder()); JLabel titleLabel = new JLabel("Recent Projects"); title.add(titleLabel); titleLabel.setHorizontalAlignment(SwingConstants.CENTER); titleLabel.setForeground(WelcomeScreenColors.CAPTION_FOREGROUND); title.setBackground(WelcomeScreenColors.CAPTION_BACKGROUND); add(title, BorderLayout.NORTH); setBorder(new LineBorder(WelcomeScreenColors.BORDER_COLOR)); }
void execute(@NotNull AnActionEvent e, @NotNull ExecutionEnvironment environment) { MyRunProfile profile = getRunProfile(environment); if (profile == null) { return; } final ExecutionEnvironmentBuilder environmentBuilder = new ExecutionEnvironmentBuilder(environment).runProfile(profile); final InputEvent event = e.getInputEvent(); if (!(event instanceof MouseEvent) || !event.isShiftDown()) { performAction(environmentBuilder); return; } final LinkedHashMap<Executor, ProgramRunner> availableRunners = new LinkedHashMap<>(); for (Executor ex : new Executor[] { DefaultRunExecutor.getRunExecutorInstance(), DefaultDebugExecutor.getDebugExecutorInstance() }) { final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(ex.getId(), profile); if (runner != null) { availableRunners.put(ex, runner); } } if (availableRunners.isEmpty()) { LOG.error(environment.getExecutor().getActionName() + " is not available now"); } else if (availableRunners.size() == 1) { //noinspection ConstantConditions performAction(environmentBuilder.runner(availableRunners.get(environment.getExecutor()))); } else { final JBList list = new JBList(availableRunners.keySet()); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedValue(environment.getExecutor(), true); list.setCellRenderer( new DefaultListCellRenderer() { @NotNull @Override public Component getListCellRendererComponent( @NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof Executor) { setText(UIUtil.removeMnemonic(((Executor) value).getStartActionText())); setIcon(((Executor) value).getIcon()); } return component; } }); //noinspection ConstantConditions JBPopupFactory.getInstance() .createListPopupBuilder(list) .setTitle("Restart Failed Tests") .setMovable(false) .setResizable(false) .setRequestFocus(true) .setItemChoosenCallback( () -> { final Object value = list.getSelectedValue(); if (value instanceof Executor) { //noinspection ConstantConditions performAction( environmentBuilder .runner(availableRunners.get(value)) .executor((Executor) value)); } }) .createPopup() .showUnderneathOf(event.getComponent()); } }
@Nullable @Override public JComponent createComponent() { final JBList dependenciesList = new JBList(); dependenciesList.setCellRenderer( new ColoredListCellRendererWrapper<DependencyOnPlugin>() { @Override protected void doCustomize( JList list, DependencyOnPlugin value, int index, boolean selected, boolean hasFocus) { if (value != null) { append( getPluginNameById(value.getPluginId()), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); String minVersion = value.getMinVersion(); String maxVersion = value.getMaxVersion(); if (minVersion != null || maxVersion != null) { append(", version "); } if (minVersion != null && minVersion.equals(maxVersion)) { append(minVersion, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); } else if (minVersion != null && maxVersion != null) { append("between "); append(minVersion, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); append(" and "); append(maxVersion, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); } else if (minVersion != null) { append("at least "); append(minVersion, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); } else if (maxVersion != null) { append("at most "); append(maxVersion, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); } } } }); dependenciesList.setModel(myListModel); JPanel dependenciesPanel = ToolbarDecorator.createDecorator(dependenciesList) .disableUpDownActions() .setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { replaceDependency( new DependencyOnPlugin("", null, null, null), dependenciesList); } }) .setEditAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { DependencyOnPlugin selected = (DependencyOnPlugin) dependenciesList.getSelectedValue(); if (selected != null) { replaceDependency(selected, dependenciesList); } } }) .createPanel(); return FormBuilder.createFormBuilder() .addLabeledComponentFillVertically( "Plugins which are required to work on this project.", dependenciesPanel) .getPanel(); }
public ProjectTypesList( JBList list, SearchTextField searchField, MultiMap<TemplatesGroup, ProjectTemplate> map, final WizardContext context) { myList = list; mySearchField = searchField; List<TemplateItem> items = buildItems(map); final RemoteTemplatesFactory factory = new RemoteTemplatesFactory(); final String groupName = factory.getGroups()[0]; final TemplatesGroup samplesGroup = new TemplatesGroup(groupName, "", null); myLoadingItem = new TemplateItem(new LoadingProjectTemplate(), samplesGroup) { @Override Icon getIcon() { return null; } @Override String getDescription() { return ""; } }; items.add(myLoadingItem); final CollectionListModel<TemplateItem> model = new CollectionListModel<TemplateItem>(items); myFilteringListModel = new FilteringListModel<TemplateItem>(model); ProgressManager.getInstance() .run( new Task.Backgroundable(context.getProject(), "Loading Samples") { @Override public void run(@NotNull ProgressIndicator indicator) { try { myList.setPaintBusy(true); final ProjectTemplate[] templates = factory.createTemplates(groupName, context); Runnable runnable = new Runnable() { public void run() { int index = myList.getSelectedIndex(); model.remove(myLoadingItem); for (ProjectTemplate template : templates) { model.add(new TemplateItem(template, samplesGroup)); } myList.setSelectedIndex(index); } }; SwingUtilities.invokeLater(runnable); } finally { myList.setPaintBusy(false); } } }); myList.setCellRenderer( new GroupedItemsListRenderer( new ListItemDescriptor() { @Nullable @Override public String getTextFor(Object value) { return ((TemplateItem) value).getName(); } @Nullable @Override public String getTooltipFor(Object value) { return null; } @Nullable @Override public Icon getIconFor(Object value) { return ((TemplateItem) value).getIcon(); } @Override public boolean hasSeparatorAboveOf(Object value) { TemplateItem item = (TemplateItem) value; int index = myFilteringListModel.getElementIndex(item); return index == 0 || !myFilteringListModel .getElementAt(index - 1) .getGroupName() .equals(item.getGroupName()); } @Nullable @Override public String getCaptionAboveOf(Object value) { return ((TemplateItem) value).getGroupName(); } })); myFilteringListModel.setFilter( new Condition<TemplateItem>() { @Override public boolean value(TemplateItem item) { return item.getMatchingDegree() > Integer.MIN_VALUE; } }); myList.setModel(myFilteringListModel); mySearchField.addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { String text = "*" + mySearchField.getText().trim(); myMatcher = NameUtil.buildMatcher(text, NameUtil.MatchingCaseSensitivity.NONE); TemplateItem value = (TemplateItem) myList.getSelectedValue(); int degree = value == null ? Integer.MIN_VALUE : value.getMatchingDegree(); myBestMatch = Pair.create(degree > Integer.MIN_VALUE ? value : null, degree); myFilteringListModel.refilter(); if (myBestMatch.first != null) { myList.setSelectedValue(myBestMatch.first, true); } } }); new AnAction() { @Override public void actionPerformed(AnActionEvent e) { InputEvent event = e.getInputEvent(); if (event instanceof KeyEvent) { int row = myList.getSelectedIndex(); int toSelect; switch (((KeyEvent) event).getKeyCode()) { case KeyEvent.VK_UP: toSelect = row == 0 ? myList.getItemsCount() - 1 : row - 1; myList.setSelectedIndex(toSelect); myList.ensureIndexIsVisible(toSelect); break; case KeyEvent.VK_DOWN: toSelect = row < myList.getItemsCount() - 1 ? row + 1 : 0; myList.setSelectedIndex(toSelect); myList.ensureIndexIsVisible(toSelect); break; } } } }.registerCustomShortcutSet( new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN), mySearchField); }
public EmbeditorCompletionLookup(Project project, final JBTerminal terminal) { super(new JPanel(new BorderLayout())); CollectionListModel<LookupElement> model = new CollectionListModel<LookupElement>(); myList = new JBList(model) { @Override protected void processKeyEvent(final KeyEvent e) { final char keyChar = e.getKeyChar(); if ((keyChar == KeyEvent.VK_ENTER || keyChar == KeyEvent.VK_TAB)) { LookupElement lookupElement = (LookupElement) myList.getSelectedValue(); try { terminal .getEmulator() .sendString(lookupElement.getLookupString().substring(myPrefixLength)); } catch (RuntimeException e1) { e1.printStackTrace(); // TODO } doHide(); } if (keyChar == KeyEvent.VK_ESCAPE) { doHide(); } super.processKeyEvent(e); } ExpandableItemsHandler<Integer> myExtender = new CompletionExtender(this); @NotNull @Override public ExpandableItemsHandler<Integer> getExpandableItemsHandler() { return myExtender; } }; myScrollBarIncreaseButton = new JButton(); myScrollBarIncreaseButton.setFocusable(false); myScrollBarIncreaseButton.setRequestFocusEnabled(false); myScrollPane = new JBScrollPane(myList); myScrollPane.setViewportBorder(new EmptyBorder(0, 0, 0, 0)); myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); myScrollPane.getVerticalScrollBar().setPreferredSize(new Dimension(13, -1)); myScrollPane .getVerticalScrollBar() .setUI( new ButtonlessScrollBarUI() { @Override protected JButton createIncreaseButton(int orientation) { return myScrollBarIncreaseButton; } }); getComponent().add(myLayeredPane, BorderLayout.CENTER); myLayeredPane.mainPanel.add(myScrollPane, BorderLayout.CENTER); myScrollPane.setBorder(null); myCellRenderer = new EmbeditorLookupCellRenderer(this, terminal.getColorScheme()); myList.setCellRenderer(myCellRenderer); }
@Override protected JComponent createCenterPanel() { final int selectionMode = myAllowMultipleSelections ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION; myList.setSelectionMode(selectionMode); if (myUseIdeaEditor) { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); myList.setFont(scheme.getFont(EditorFontType.PLAIN)); Color fg = ObjectUtils.chooseNotNull(scheme.getDefaultForeground(), UIUtil.getListForeground()); Color bg = ObjectUtils.chooseNotNull(scheme.getDefaultBackground(), UIUtil.getListBackground()); myList.setForeground(fg); myList.setBackground(bg); } new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { close(OK_EXIT_CODE); return true; } }.installOn(myList); myList.setCellRenderer(new MyListCellRenderer()); myList.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { int newSelectionIndex = -1; for (Object o : myList.getSelectedValues()) { int i = ((Item) o).index; removeContentAt(myAllContents.get(i)); if (newSelectionIndex < 0) { newSelectionIndex = i; } } rebuildListContent(); if (myAllContents.isEmpty()) { close(CANCEL_EXIT_CODE); return; } newSelectionIndex = Math.min(newSelectionIndex, myAllContents.size() - 1); myList.setSelectedIndex(newSelectionIndex); } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { doOKAction(); } else { final char aChar = e.getKeyChar(); if (aChar >= '0' && aChar <= '9') { int idx = aChar == '0' ? 9 : aChar - '1'; if (idx < myAllContents.size()) { myList.setSelectedIndex(idx); e.consume(); doOKAction(); } } } } }); mySplitter.setFirstComponent( ListWithFilter.wrap( myList, ScrollPaneFactory.createScrollPane(myList), new Function<Object, String>() { @Override public String fun(Object o) { return ((Item) o).longText; } })); mySplitter.setSecondComponent(new JPanel()); rebuildListContent(); ScrollingUtil.installActions(myList); ScrollingUtil.ensureSelectionExists(myList); updateViewerForSelection(); myList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { myUpdateAlarm.cancelAllRequests(); myUpdateAlarm.addRequest( new Runnable() { @Override public void run() { updateViewerForSelection(); } }, 100); } }); mySplitter.setPreferredSize(JBUI.size(500, 500)); SplitterProportionsData d = new SplitterProportionsDataImpl(); d.externalizeToDimensionService(getClass().getName()); d.restoreSplitterProportions(mySplitter); return mySplitter; }
@Override public void invoke( @NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) { if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return; try { final XmlTag contextTag = getContextTag(editor, file); if (contextTag == null) { throw new CommonRefactoringUtil.RefactoringErrorHintException( "Caret should be positioned inside a tag"); } XmlElementDescriptor currentTagDescriptor = contextTag.getDescriptor(); assert currentTagDescriptor != null; final XmlElementDescriptor[] descriptors = currentTagDescriptor.getElementsDescriptors(contextTag); Arrays.sort( descriptors, new Comparator<XmlElementDescriptor>() { @Override public int compare(XmlElementDescriptor o1, XmlElementDescriptor o2) { return o1.getName().compareTo(o2.getName()); } }); final JBList list = new JBList(descriptors); list.setCellRenderer(new MyListCellRenderer()); Runnable runnable = new Runnable() { @Override public void run() { final XmlElementDescriptor selected = (XmlElementDescriptor) list.getSelectedValue(); new WriteCommandAction.Simple(project, "Generate XML Tag", file) { @Override protected void run() { if (selected == null) return; XmlTag newTag = createTag(contextTag, selected); PsiElement anchor = getAnchor(contextTag, editor, selected); if (anchor == null) { // insert it in the cursor position int offset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); document.insertString(offset, newTag.getText()); PsiDocumentManager.getInstance(project).commitDocument(document); newTag = PsiTreeUtil.getParentOfType( file.findElementAt(offset + 1), XmlTag.class, false); } else { newTag = (XmlTag) contextTag.addAfter(newTag, anchor); } if (newTag != null) { generateTag(newTag, editor); } } }.execute(); } }; if (ApplicationManager.getApplication().isUnitTestMode()) { XmlElementDescriptor descriptor = ContainerUtil.find( descriptors, new Condition<XmlElementDescriptor>() { @Override public boolean value(XmlElementDescriptor xmlElementDescriptor) { return xmlElementDescriptor.getName().equals(TEST_THREAD_LOCAL.get()); } }); list.setSelectedValue(descriptor, false); runnable.run(); } else { JBPopupFactory.getInstance() .createListPopupBuilder(list) .setTitle("Choose Tag Name") .setItemChoosenCallback(runnable) .setFilteringEnabled( new Function<Object, String>() { @Override public String fun(Object o) { return ((XmlElementDescriptor) o).getName(); } }) .createPopup() .showInBestPositionFor(editor); } } catch (CommonRefactoringUtil.RefactoringErrorHintException e) { HintManager.getInstance().showErrorHint(editor, e.getMessage()); } }
public boolean runMethodInAbstractClass( final ConfigurationContext context, final Runnable performRunnable, final PsiMethod psiMethod, final PsiClass containingClass, final Condition<PsiClass> acceptAbstractCondition) { if (containingClass != null && containingClass.hasModifierProperty(PsiModifier.ABSTRACT) && acceptAbstractCondition.value(containingClass)) { final Location location = context.getLocation(); if (location instanceof MethodLocation) { final PsiClass aClass = ((MethodLocation) location).getContainingClass(); if (aClass != null && !aClass.hasModifierProperty(PsiModifier.ABSTRACT)) { return false; } } else if (location instanceof PsiMemberParameterizedLocation) { return false; } final List<PsiClass> classes = new ArrayList<PsiClass>(); if (!ProgressManager.getInstance() .runProcessWithProgressSynchronously( new Runnable() { @Override public void run() { ClassInheritorsSearch.search(containingClass) .forEach( new Processor<PsiClass>() { @Override public boolean process(PsiClass aClass) { if (PsiClassUtil.isRunnableClass(aClass, true, true)) { classes.add(aClass); } return true; } }); } }, "Search for " + containingClass.getQualifiedName() + " inheritors", true, containingClass.getProject())) { return true; } if (classes.size() == 1) { runForClass(classes.get(0), psiMethod, context, performRunnable); return true; } if (classes.isEmpty()) return false; final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(context.getDataContext()); if (fileEditor instanceof TextEditor) { final Document document = ((TextEditor) fileEditor).getEditor().getDocument(); final PsiFile containingFile = PsiDocumentManager.getInstance(context.getProject()).getPsiFile(document); if (containingFile instanceof PsiClassOwner) { final List<PsiClass> psiClasses = new ArrayList<PsiClass>(Arrays.asList(((PsiClassOwner) containingFile).getClasses())); psiClasses.retainAll(classes); if (psiClasses.size() == 1) { runForClass(psiClasses.get(0), psiMethod, context, performRunnable); return true; } } } final PsiClassListCellRenderer renderer = new PsiClassListCellRenderer() { @Override protected boolean customizeNonPsiElementLeftRenderer( ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) { if (value == null) { renderer.append("All"); return true; } return super.customizeNonPsiElementLeftRenderer( renderer, list, value, index, selected, hasFocus); } }; Collections.sort(classes, renderer.getComparator()); // suggest to run all inherited tests classes.add(0, null); final JBList list = new JBList(classes); list.setCellRenderer(renderer); JBPopupFactory.getInstance() .createListPopupBuilder(list) .setTitle( "Choose executable classes to run " + (psiMethod != null ? psiMethod.getName() : containingClass.getName())) .setMovable(false) .setResizable(false) .setRequestFocus(true) .setItemChoosenCallback( new Runnable() { public void run() { final Object[] values = list.getSelectedValues(); if (values == null) return; chooseAndPerform(values, psiMethod, context, performRunnable, classes); } }) .createPopup() .showInBestPositionFor(context.getDataContext()); return true; } return false; }
private void initLeftPanel() { myLeftPanel = new JPanel(new GridLayoutManager(2, 1, JBInsets.NONE, -1, -1)); mySearchField = new SearchTextField(false); mySearchField.addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { TemplateItem tmp = myCurrentTemplateItem; myFilteringListModel.refilter(); int idx = myFilteringListModel.getElementIndex(tmp); myList.setSelectedIndex(idx < 0 ? 0 : idx); } }); new AnAction() { @Override public void actionPerformed(AnActionEvent e) { InputEvent event = e.getInputEvent(); if (event instanceof KeyEvent) { int row = myList.getSelectedIndex(); int toSelect; switch (((KeyEvent) event).getKeyCode()) { case KeyEvent.VK_UP: toSelect = row == 0 ? myList.getItemsCount() - 1 : row - 1; myList.setSelectedIndex(toSelect); myList.ensureIndexIsVisible(toSelect); break; case KeyEvent.VK_DOWN: toSelect = row < myList.getItemsCount() - 1 ? row + 1 : 0; myList.setSelectedIndex(toSelect); myList.ensureIndexIsVisible(toSelect); break; } } } }.registerCustomShortcutSet( new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN), mySearchField); myLeftPanel.add( mySearchField, new GridConstraints( 0, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK, GridConstraints.SIZEPOLICY_FIXED, null, null, null)); myList = new JBList(); List<ProjectTemplatesGroup> templatesGroups = new SortedList<ProjectTemplatesGroup>( new Comparator<ProjectTemplatesGroup>() { @Override public int compare(ProjectTemplatesGroup o1, ProjectTemplatesGroup o2) { // Put DSL/Development groups on top & Other group to the last place if (o1.getName().equals("DSL")) return -1; if (o2.getName().equals("DSL")) return 1; if (o1.getName().equals("Development")) return -1; if (o2.getName().equals("Development")) return 1; if (o1.getName().equals("Other")) return 1; if (o2.getName().equals("Other")) return -1; return o1.getName().compareToIgnoreCase(o2.getName()); } }); List<TemplateItem> templateItems = new LinkedList<TemplateItem>(); templatesGroups.addAll(Arrays.asList(ProjectTemplatesGroup.EP_NAME.getExtensions())); for (ProjectTemplatesGroup templatesGroup : templatesGroups) { for (MPSProjectTemplate template : templatesGroup.getTemplates()) { templateItems.add(new TemplateItem(template, templatesGroup)); } } CollectionListModel<TemplateItem> model = new CollectionListModel<TemplateItem>(templateItems); myFilteringListModel = new FilteringListModel<TemplateItem>(model); myFilteringListModel.setFilter( new Condition<TemplateItem>() { @Override public boolean value(TemplateItem templateItem) { return templateItem .getName() .toLowerCase() .contains(mySearchField.getText().trim().toLowerCase()); } }); myList.setModel(myFilteringListModel); myList.setCellRenderer( new GroupedItemsListRenderer( new ListItemDescriptor() { @Nullable @Override public String getTextFor(Object value) { return ((TemplateItem) value).getName(); } @Nullable @Override public String getTooltipFor(Object value) { return null; } @Nullable @Override public Icon getIconFor(Object value) { return ((TemplateItem) value).getIcon(); } @Override public boolean hasSeparatorAboveOf(Object value) { TemplateItem item = (TemplateItem) value; int index = myFilteringListModel.getElementIndex(item); return index == 0 || !myFilteringListModel .getElementAt(index - 1) .getGroupName() .equals(item.getGroupName()); } @Nullable @Override public String getCaptionAboveOf(Object value) { return ((TemplateItem) value).getGroupName(); } })); myList .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { myCurrentTemplateItem = (TemplateItem) myList.getSelectedValue(); updateRightPanel(); } }); myLeftPanel.add( ScrollPaneFactory.createScrollPane(myList), new GridConstraints( 1, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null)); myLeftPanel.setPreferredSize(new Dimension(200, 400)); }
@SuppressWarnings("unchecked") private void createUIComponents() { final JBList projectExistLocalesList = new JBList(); final MyExistLocalesListModel existLocalesListModel = new MyExistLocalesListModel(); projectExistLocalesList.setModel(existLocalesListModel); projectExistLocalesList.setCellRenderer(getLocaleRenderer()); myProjectExistLocalesPanel = ToolbarDecorator.createDecorator(projectExistLocalesList) .disableRemoveAction() .disableUpDownActions() .createPanel(); myProjectExistLocalesPanel.setBorder( IdeBorderFactory.createTitledBorder("Project locales", false)); final JBList localesToAddList = new JBList(); final List<Locale> locales; final List<Locale> restrictedLocales; if (myResourceBundle == null) { locales = Collections.singletonList(PropertiesUtil.DEFAULT_LOCALE); restrictedLocales = Collections.emptyList(); } else { locales = Collections.emptyList(); restrictedLocales = ContainerUtil.map(myResourceBundle.getPropertiesFiles(), PropertiesFile::getLocale); } myLocalesModel = new CollectionListModel<Locale>(locales) { @Override public void add(@NotNull List<? extends Locale> elements) { final List<Locale> currentItems = getItems(); elements = ContainerUtil.filter( elements, locale -> !restrictedLocales.contains(locale) && !currentItems.contains(locale)); super.add(elements); } }; localesToAddList.setModel(myLocalesModel); localesToAddList.setCellRenderer(getLocaleRenderer()); localesToAddList.addFocusListener( new FocusAdapter() { @Override public void focusGained(FocusEvent e) { projectExistLocalesList.clearSelection(); } }); projectExistLocalesList.addFocusListener( new FocusAdapter() { @Override public void focusGained(FocusEvent e) { localesToAddList.clearSelection(); } }); myNewBundleLocalesPanel = ToolbarDecorator.createDecorator(localesToAddList) .setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final String rawAddedLocales = Messages.showInputDialog( myProject, PropertiesBundle.message( "create.resource.bundle.dialog.add.locales.validator.message"), PropertiesBundle.message( "create.resource.bundle.dialog.add.locales.validator.title"), null, null, new InputValidatorEx() { @Nullable @Override public String getErrorText(String inputString) { return checkInput(inputString) ? null : "Invalid locales"; } @Override public boolean checkInput(String inputString) { return extractLocalesFromString(inputString) != null; } @Override public boolean canClose(String inputString) { return checkInput(inputString); } }); if (rawAddedLocales != null) { final List<Locale> locales = extractLocalesFromString(rawAddedLocales); LOG.assertTrue(locales != null); myLocalesModel.add(locales); } } }) .setAddActionName("Add locales by suffix") .disableUpDownActions() .createPanel(); myNewBundleLocalesPanel.setBorder(IdeBorderFactory.createTitledBorder("Locales to add", false)); myAddLocaleFromExistButton = new JButton(AllIcons.Actions.Forward); new ClickListener() { @Override public boolean onClick(@NotNull MouseEvent event, int clickCount) { if (clickCount == 1) { myLocalesModel.add( ContainerUtil.map(projectExistLocalesList.getSelectedValues(), o -> (Locale) o)); return true; } return false; } }.installOn(myAddLocaleFromExistButton); projectExistLocalesList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { final List<Locale> currentItems = myLocalesModel.getItems(); for (Object o : projectExistLocalesList.getSelectedValues()) { Locale l = (Locale) o; if (!restrictedLocales.contains(l) && !currentItems.contains(l)) { myAddLocaleFromExistButton.setEnabled(true); return; } } myAddLocaleFromExistButton.setEnabled(false); } }); myAddLocaleFromExistButton.setEnabled(false); myAddAllButton = new JButton("Add All"); new ClickListener() { @Override public boolean onClick(@NotNull MouseEvent event, int clickCount) { if (clickCount == 1) { myLocalesModel.add(existLocalesListModel.getLocales()); } return false; } }.installOn(myAddAllButton); }
BeforeRunStepsPanel(StepsBeforeRunListener listener) { myListener = listener; myModel = new CollectionListModel<BeforeRunTask>(); myList = new JBList(myModel); myList.getEmptyText().setText(ExecutionBundle.message("before.launch.panel.empty")); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myList.setCellRenderer(new MyListCellRenderer()); myModel.addListDataListener( new ListDataListener() { @Override public void intervalAdded(ListDataEvent e) { adjustVisibleRowCount(); updateText(); } @Override public void intervalRemoved(ListDataEvent e) { adjustVisibleRowCount(); updateText(); } @Override public void contentsChanged(ListDataEvent e) {} private void adjustVisibleRowCount() { myList.setVisibleRowCount(Math.max(4, Math.min(8, myModel.getSize()))); } }); ToolbarDecorator myDecorator = ToolbarDecorator.createDecorator(myList); if (!SystemInfo.isMac) { myDecorator.setAsUsualTopToolbar(); } myDecorator.setEditAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { int index = myList.getSelectedIndex(); if (index == -1) return; Pair<BeforeRunTask, BeforeRunTaskProvider<BeforeRunTask>> selection = getSelection(); if (selection == null) return; BeforeRunTask task = selection.getFirst(); BeforeRunTaskProvider<BeforeRunTask> provider = selection.getSecond(); if (provider.configureTask(myRunConfiguration, task)) { myModel.setElementAt(task, index); } } }); myDecorator.setEditActionUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { Pair<BeforeRunTask, BeforeRunTaskProvider<BeforeRunTask>> selection = getSelection(); return selection != null && selection.getSecond().isConfigurable(); } }); myDecorator.setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { doAddAction(button); } }); myDecorator.setAddActionUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { return checkBeforeRunTasksAbility(true); } }); myShowSettingsBeforeRunCheckBox = new JCheckBox(ExecutionBundle.message("configuration.edit.before.run")); myShowSettingsBeforeRunCheckBox.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateText(); } }); myPanel = myDecorator.createPanel(); setLayout(new BorderLayout()); add(myPanel, BorderLayout.CENTER); add(myShowSettingsBeforeRunCheckBox, BorderLayout.SOUTH); }
public ProjectTypeStep( WizardContext context, NewProjectWizard wizard, ModulesProvider modulesProvider) { myContext = context; myWizard = wizard; myTemplatesMap = new ConcurrentMultiMap<TemplatesGroup, ProjectTemplate>(); final List<TemplatesGroup> groups = fillTemplatesMap(context); myProjectTypeList.setModel(new CollectionListModel<TemplatesGroup>(groups)); myProjectTypeList.setSelectionModel(new SingleSelectionModel()); myProjectTypeList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateSelection(); } }); myProjectTypeList.setCellRenderer( new GroupedItemsListRenderer( new ListItemDescriptorAdapter<TemplatesGroup>() { @Nullable @Override public String getTextFor(TemplatesGroup value) { return value.getName(); } @Nullable @Override public String getTooltipFor(TemplatesGroup value) { return value.getDescription(); } @Nullable @Override public Icon getIconFor(TemplatesGroup value) { return value.getIcon(); } @Override public boolean hasSeparatorAboveOf(TemplatesGroup value) { int index = groups.indexOf(value); if (index < 1) return false; TemplatesGroup upper = groups.get(index - 1); if (upper.getParentGroup() == null && value.getParentGroup() == null) return true; return !Comparing.equal(upper.getParentGroup(), value.getParentGroup()) && !Comparing.equal(upper.getName(), value.getParentGroup()); } }) { @Override protected JComponent createItemComponent() { JComponent component = super.createItemComponent(); myTextLabel.setBorder(IdeBorderFactory.createEmptyBorder(3)); return component; } }); new ListSpeedSearch(myProjectTypeList) { @Override protected String getElementText(Object element) { return ((TemplatesGroup) element).getName(); } }; myModulesProvider = modulesProvider; Project project = context.getProject(); final LibrariesContainer container = LibrariesContainerFactory.createContainer(context, modulesProvider); FrameworkSupportModelBase model = new FrameworkSupportModelBase(project, null, container) { @NotNull @Override public String getBaseDirectoryForLibrariesPath() { ModuleBuilder builder = getSelectedBuilder(); return StringUtil.notNullize(builder.getContentEntryPath()); } @Override public ModuleBuilder getModuleBuilder() { return getSelectedBuilder(); } }; myFrameworksPanel = new AddSupportForFrameworksPanel( Collections.<FrameworkSupportInModuleProvider>emptyList(), model, true, myHeaderPanel); Disposer.register(this, myFrameworksPanel); myFrameworksPanelPlaceholder.add(myFrameworksPanel.getMainPanel()); myConfigurationUpdater = new ModuleBuilder.ModuleConfigurationUpdater() { @Override public void update(@NotNull Module module, @NotNull ModifiableRootModel rootModel) { if (isFrameworksMode()) { myFrameworksPanel.addSupport(module, rootModel); } } }; myProjectTypeList .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { projectTypeChanged(); } }); myTemplatesList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateSelection(); } }); for (TemplatesGroup templatesGroup : myTemplatesMap.keySet()) { ModuleBuilder builder = templatesGroup.getModuleBuilder(); if (builder != null) { myWizard.getSequence().addStepsForBuilder(builder, context, modulesProvider); } for (ProjectTemplate template : myTemplatesMap.get(templatesGroup)) { myWizard .getSequence() .addStepsForBuilder(myBuilders.get(template), context, modulesProvider); } } final String groupId = PropertiesComponent.getInstance().getValue(PROJECT_WIZARD_GROUP); if (groupId != null) { TemplatesGroup group = ContainerUtil.find( groups, new Condition<TemplatesGroup>() { @Override public boolean value(TemplatesGroup group) { return groupId.equals(group.getId()); } }); if (group != null) { myProjectTypeList.setSelectedValue(group, true); } } if (myProjectTypeList.getSelectedValue() == null) { myProjectTypeList.setSelectedIndex(0); } myTemplatesList.restoreSelection(); }