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);
         }
       });
 }
 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());
 }
Beispiel #3
0
 public List<String> getPluginsHosts() {
   final List<String> result = new ArrayList<String>();
   for (int i = 0; i < myUrlsList.getModel().getSize(); i++) {
     result.add((String) myUrlsList.getModel().getElementAt(i));
   }
   return result;
 }
  public void ensureSelectionVisible(boolean forceTopSelection) {
    if (isSelectionVisible() && !forceTopSelection) {
      return;
    }

    if (!forceTopSelection) {
      ListScrollingUtil.ensureIndexIsVisible(myList, myList.getSelectedIndex(), 1);
      return;
    }

    // selected item should be at the top of the visible list
    int top = myList.getSelectedIndex();
    if (top > 0) {
      top--; // show one element above the selected one to give the hint that there are more
             // available via scrolling
    }

    int firstVisibleIndex = myList.getFirstVisibleIndex();
    if (firstVisibleIndex == top) {
      return;
    }

    ListScrollingUtil.ensureRangeIsVisible(
        myList, top, top + myList.getLastVisibleIndex() - firstVisibleIndex);
  }
 void resetSelection() {
   if (myList.getSelectedIndex() != -1) return;
   SelectTemplateSettings settings = SelectTemplateSettings.getInstance();
   if (settings.getLastGroup() == null
       || !setSelectedTemplate(settings.getLastGroup(), settings.getLastTemplate())) {
     myList.setSelectedIndex(0);
   }
 }
 private JBList preparePathList(DefaultListModel pathListModel) {
   final JBList pathList = new JBList(pathListModel);
   pathList.getEmptyText().setText("No classpath entries defined");
   pathList.setDragEnabled(false);
   pathList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   pathList.setName(PATH_LIST_NAME);
   return pathList;
 }
  @Override
  public void setPopupVisible(boolean visible) {
    if (!isSwingPopup()) {
      if (visible && (myJBPopup == null || myJBPopup.isDisposed())) {
        final JBList list = createJBList(getModel());
        myJBPopup =
            JBPopupFactory.getInstance()
                .createListPopupBuilder(list)
                .setItemChoosenCallback(
                    new Runnable() {
                      @Override
                      public void run() {
                        final Object value = list.getSelectedValue();
                        if (value != null) {
                          configureEditor(getEditor(), value);
                          IdeFocusManager.getGlobalInstance().requestFocus(ComboBox.this, true);
                          assert myJBPopup != null;
                          ComboBox.this.getUI().setPopupVisible(ComboBox.this, false);
                          myJBPopup.cancel();
                        }
                      }
                    })
                .setFocusOwners(new Component[] {this})
                .setMinSize(new Dimension(getWidth(), -1))
                .createPopup();
        list.setBorder(IdeBorderFactory.createEmptyBorder());
        myJBPopup.showUnderneathOf(this);
        list.addFocusListener(
            new FocusAdapter() {
              @Override
              public void focusLost(FocusEvent e) {
                ComboBox.this.getUI().setPopupVisible(ComboBox.this, false);
                myJBPopup.cancel();
              }
            });
      }
      return;
    }

    if (getModel().getSize() == 0 && visible) return;
    if (visible && JBPopupFactory.getInstance().getChildFocusedPopup(this) != null) return;

    final boolean wasShown = isPopupVisible();
    super.setPopupVisible(visible);
    if (!wasShown
        && visible
        && isEditable()
        && !UIManager.getBoolean("ComboBox.isEnterSelectablePopup")) {

      final ComboBoxEditor editor = getEditor();
      final Object item = editor.getItem();
      final Object selectedItem = getSelectedItem();
      if (isSwingPopup() && (item == null || item != selectedItem)) {
        configureEditor(editor, selectedItem);
      }
    }
  }
  private void updateListHeight(ListModel model) {
    myList.setFixedCellHeight(
        myCellRenderer
            .getListCellRendererComponent(myList, model.getElementAt(0), 0, false, false)
            .getPreferredSize()
            .height);

    myList.setVisibleRowCount(
        Math.min(model.getSize(), UISettings.getInstance().MAX_LOOKUP_LIST_HEIGHT));
  }
  public boolean setSelectedTemplate(@Nullable String group, @Nullable String name) {
    for (int i = 0; i < myList.getModel().getSize(); i++) {
      Object o = myList.getModel().getElementAt(i);
      if (o instanceof TemplateItem
          && ((TemplateItem) o).myGroup.getName().equals(group)
          && ((TemplateItem) o).getName().equals(name)) {
        myList.setSelectedIndex(i);
        return true;
      }
    }

    return false;
  }
Beispiel #10
0
  private static void assertMerge(
      String[] items, int startSelection, int expectedSelection, String... newItems) {
    CollectionListModel<String> model = new CollectionListModel<String>();
    model.add(Arrays.asList(items));
    JBList list = new JBList(model);
    list.setSelectedIndex(startSelection);

    FinderRecursivePanel.mergeListItems(model, Arrays.asList(newItems));
    assertEquals(newItems.length, model.getSize());
    for (int i = 0; i < newItems.length; i++) {
      assertEquals(newItems[i], model.getElementAt(i));
    }
    assertEquals(expectedSelection, list.getSelectedIndex());
  }
  @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;
  }
Beispiel #12
0
 @TestOnly
 public boolean setSelectedTemplate(String group, String name) {
   ListModel model = myProjectTypeList.getModel();
   for (int i = 0; i < model.getSize(); i++) {
     TemplatesGroup templatesGroup = (TemplatesGroup) model.getElementAt(i);
     if (group.equals(templatesGroup.getName())) {
       myProjectTypeList.setSelectedIndex(i);
       if (name == null) return getSelectedGroup().getName().equals(group);
       Collection<ProjectTemplate> templates = myTemplatesMap.get(templatesGroup);
       setTemplatesList(templatesGroup, templates, false);
       return myTemplatesList.setSelectedTemplate(name);
     }
   }
   return false;
 }
 public void markSelectionTouched() {
   if (!ApplicationManager.getApplication().isUnitTestMode()) {
     ApplicationManager.getApplication().assertIsDispatchThread();
   }
   mySelectionTouched = true;
   myList.repaint();
 }
  @Nullable
  @Override
  protected JComponent createCenterPanel() {
    if (myPanel == null) {
      myPanel = new JPanel(new GridLayoutManager(1, 1, JBInsets.NONE, -1, -1));

      initLeftPanel();

      initRightPanel();

      mySplitter = new JBSplitter(false, 0.3f, 0.3f, 0.6f);
      mySplitter.setSplitterProportionKey("select.template.proportion");
      mySplitter.setFirstComponent(myLeftPanel);
      mySplitter.setSecondComponent(myRightPanel);
      myPanel.add(
          mySplitter,
          new GridConstraints(
              0,
              0,
              1,
              1,
              GridConstraints.ANCHOR_CENTER,
              GridConstraints.FILL_BOTH,
              GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK,
              GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK,
              null,
              null,
              null));

      myPanel.setPreferredSize(new Dimension(600, 400));
      myList.setSelectedIndex(0);
    }

    return myPanel;
  }
 @Override
 protected void processMouseEvent(MouseEvent e) {
   if (UIUtil.isActionClick(e, MouseEvent.MOUSE_PRESSED) && isOnNextStepButton(e)) {
     e.consume();
   }
   super.processMouseEvent(e);
 }
  private void performEditAction() {
    final Configuration configuration = (Configuration) myTemplatesList.getSelectedValue();
    if (configuration == null) return;

    SearchDialog dialog =
        createDialog(
            new SearchDialogFactory() {
              public SearchDialog createDialog(SearchContext searchContext) {
                if (configuration instanceof SearchConfiguration) {
                  return new SearchDialog(searchContext, false, false) {
                    public Configuration createConfiguration() {
                      SearchConfiguration newConfiguration = new SearchConfiguration();
                      copyConfiguration(configuration, newConfiguration);
                      return newConfiguration;
                    }
                  };
                } else {
                  return new ReplaceDialog(searchContext, false, false) {
                    public Configuration createConfiguration() {
                      ReplaceConfiguration newConfiguration = new ReplaceConfiguration();
                      copyConfiguration(configuration, newConfiguration);
                      return newConfiguration;
                    }
                  };
                }
              }
            });
    dialog.setValuesFromConfig(configuration);
    dialog.setUseLastConfiguration(true);
    dialog.show();
    if (!dialog.isOK()) return;
    Configuration newConfiguration = dialog.getConfiguration();
    copyConfiguration(newConfiguration, configuration);
    configurationsChanged(dialog.getSearchContext());
  }
Beispiel #17
0
 public void setPluginHosts(final List<String> pluginHosts) {
   final DefaultListModel model = (DefaultListModel) myUrlsList.getModel();
   model.clear();
   for (String host : pluginHosts) {
     //noinspection unchecked
     model.addElement(host);
   }
 }
 @Override
 public Rectangle getCurrentItemBounds() {
   int index = myList.getSelectedIndex();
   if (index < 0) {
     LOG.error("No selected element, size=" + getListModel().getSize() + "; items" + getItems());
   }
   Rectangle itmBounds = myList.getCellBounds(index, index);
   if (itmBounds == null) {
     LOG.error("No bounds for " + index + "; size=" + getListModel().getSize());
     return null;
   }
   Point layeredPanePoint =
       SwingUtilities.convertPoint(myList, itmBounds.x, itmBounds.y, getComponent());
   itmBounds.x = layeredPanePoint.x;
   itmBounds.y = layeredPanePoint.y;
   return itmBounds;
 }
 protected void setSelectedRoots(Object[] roots) {
   ArrayList<Object> rootsList = new ArrayList<Object>(roots.length);
   for (Object root : roots) {
     if (root != null) {
       rootsList.add(root);
     }
   }
   myList.getSelectionModel().clearSelection();
   int rowCount = getRowCount();
   for (int i = 0; i < rowCount; i++) {
     Object currObject = getValueAt(i);
     LOG.assertTrue(currObject != null);
     if (rootsList.contains(currObject)) {
       myList.getSelectionModel().addSelectionInterval(i, i);
     }
   }
 }
 @NotNull
 public int[] getSelectedIndices() {
   Object[] values = myList.getSelectedValues();
   int[] result = new int[values.length];
   for (int i = 0, length = values.length; i < length; i++) {
     result[i] = ((Item) values[i]).index;
   }
   return result;
 }
 @Nullable
 private Pair<BeforeRunTask, BeforeRunTaskProvider<BeforeRunTask>> getSelection() {
   final int index = myList.getSelectedIndex();
   if (index == -1) return null;
   BeforeRunTask task = myModel.getElementAt(index);
   Key providerId = task.getProviderId();
   BeforeRunTaskProvider<BeforeRunTask> provider =
       BeforeRunTaskProvider.getProvider(myRunConfiguration.getProject(), providerId);
   return provider != null ? Pair.create(task, provider) : null;
 }
 @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
 public void run() {
   String branchToCompare = myList.getSelectedValue().toString();
   try {
     showDiffWithBranch(myProject, myFile, myHead, branchToCompare);
   } catch (VcsException e) {
     if (e.getMessage().contains("exists on disk, but not in")) {
       fileDoesntExistInBranchError(myProject, myFile, branchToCompare);
     } else {
       GitUIUtil.notifyError(
           myProject,
           "Couldn't compare with branch",
           String.format(
               "Couldn't compare file [%s] with selected branch [%s]",
               myFile, myList.getSelectedValue()),
           false,
           e);
     }
   }
 }
  @Test
  public void shouldCreateJBListWithActionCellRenderer() {
    // when
    JList popupList = popupListFactory.getPopupList();

    // then
    assertThat(popupList).isInstanceOf(JBList.class);
    assertThat(popupList.getCellRenderer()).isInstanceOf(ExpandedItemListCellRendererWrapper.class);
    assertThat(((ExpandedItemListCellRendererWrapper) popupList.getCellRenderer()).getWrappee())
        .isInstanceOf(ActionCellRenderer.class);
    assertThat(((JBList) popupList).getItemsCount()).isEqualTo(1);
  }
 @NotNull
 public String getSelectedText() {
   StringBuilder sb = new StringBuilder();
   boolean first = true;
   for (Object o : myList.getSelectedValues()) {
     if (first) first = false;
     else sb.append("\n");
     String s = ((Item) o).longText;
     sb.append(StringUtil.convertLineSeparators(s));
   }
   return sb.toString();
 }
  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();
  }
Beispiel #27
0
 private SelectionDialog(
     RunnerAndConfigurationSettings selectedSettings,
     @NotNull List<RunnerAndConfigurationSettings> settings) {
   super(myProject);
   setTitle(ExecutionBundle.message("before.launch.run.another.configuration.choose"));
   mySelectedSettings = selectedSettings;
   mySettings = settings;
   init();
   myJBList.setSelectedValue(mySelectedSettings, true);
   myJBList.addMouseListener(
       new MouseAdapter() {
         @Override
         public void mouseClicked(MouseEvent e) {
           if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
             doOKAction();
           }
         }
       });
   FontMetrics fontMetrics = myJBList.getFontMetrics(myJBList.getFont());
   int maxWidth = fontMetrics.stringWidth("m") * 30;
   for (RunnerAndConfigurationSettings setting : settings) {
     maxWidth =
         Math.max(fontMetrics.stringWidth(setting.getConfiguration().getName()), maxWidth);
   }
   maxWidth += 24; // icon and gap
   myJBList.setMinimumSize(new Dimension(maxWidth, myJBList.getPreferredSize().height));
 }
Beispiel #28
0
 @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);
 }
 private void replaceDependency(DependencyOnPlugin original, JBList dependenciesList) {
   DependencyOnPlugin dependency = editPluginDependency(dependenciesList, original);
   if (dependency != null) {
     for (ProjectExternalDependency dependency1 :
         new ArrayList<ProjectExternalDependency>(myListModel.getItems())) {
       if (dependency1 instanceof DependencyOnPlugin
           && ((DependencyOnPlugin) dependency1).getPluginId().equals(dependency.getPluginId())) {
         myListModel.remove(dependency1);
       }
     }
     myListModel.add(dependency);
     dependenciesList.setSelectedValue(dependency, true);
   }
 }
  public void applyTo(ApplicationSettings settings) throws ConfigurationException {
    updateCurrentRule();

    for (int i = 0; i < myRulesModel.getSize(); i++) {
      try {
        myRulesModel.getElementAt(i).validate();
      } catch (IllegalArgumentException e) {
        myRulesList.setSelectedIndex(i);
        throw new ConfigurationException(e.getMessage());
      }
    }

    settings.setLibraryBundlificationRules(ContainerUtil.newArrayList(myRulesModel.getItems()));
  }