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();
  }
 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 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;
 }
Beispiel #4
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);
 }
  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());
    }
  }
  @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;
  }
Beispiel #7
0
    public CustomPluginRepositoriesPanel() {
      myUrlsList = new JBList(new DefaultListModel());
      myUrlsList.getEmptyText().setText(IdeBundle.message("update.no.update.hosts"));
      myUrlsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      myPanel =
          ToolbarDecorator.createDecorator(myUrlsList)
              .setAddAction(
                  new AnActionButtonRunnable() {
                    @Override
                    public void run(AnActionButton button) {
                      final HostMessages.InputHostDialog dlg =
                          new HostMessages.InputHostDialog(
                              myPanel,
                              IdeBundle.message("update.plugin.host.url.message"),
                              IdeBundle.message("update.add.new.plugin.host.title"),
                              Messages.getQuestionIcon(),
                              "",
                              new NonEmptyInputValidator());
                      dlg.show();
                      String input = dlg.getInputString();
                      if (input != null) {
                        //noinspection unchecked
                        ((DefaultListModel) myUrlsList.getModel())
                            .addElement(correctRepositoryRule(input));
                      }
                    }
                  })
              .setEditAction(
                  new AnActionButtonRunnable() {
                    @Override
                    public void run(AnActionButton button) {
                      final HostMessages.InputHostDialog dlg =
                          new HostMessages.InputHostDialog(
                              myPanel,
                              IdeBundle.message("update.plugin.host.url.message"),
                              IdeBundle.message("update.edit.plugin.host.title"),
                              Messages.getQuestionIcon(),
                              (String) myUrlsList.getSelectedValue(),
                              new InputValidator() {
                                @Override
                                public boolean checkInput(final String inputString) {
                                  return inputString.length() > 0;
                                }

                                @Override
                                public boolean canClose(final String inputString) {
                                  return checkInput(inputString);
                                }
                              });
                      dlg.show();
                      final String input = dlg.getInputString();
                      if (input != null) {
                        //noinspection unchecked
                        ((DefaultListModel) myUrlsList.getModel())
                            .set(myUrlsList.getSelectedIndex(), input);
                      }
                    }
                  })
              .disableUpDownActions()
              .createPanel();
    }
  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);
  }
  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) return;

    if (myPopup != null && myPopup.isVisible()) return;

    final JBList list = new JBList(buildModel(project));

    EditBookmarkDescriptionAction editDescriptionAction =
        new EditBookmarkDescriptionAction(project, list);
    DefaultActionGroup actions = new DefaultActionGroup();
    actions.add(editDescriptionAction);
    actions.add(new DeleteBookmarkAction(project, list));
    actions.add(new ToggleSortBookmarksAction());
    actions.add(new MoveBookmarkUpAction(project, list));
    actions.add(new MoveBookmarkDownAction(project, list));

    myPopup =
        new MasterDetailPopupBuilder(project)
            .setList(list)
            .setDelegate(this)
            .setDetailView(new DetailViewImpl(project))
            .setDimensionServiceKey("bookmarks")
            .setAddDetailViewToEast(true)
            .setActionsGroup(actions)
            .setPopupTuner(
                new Consumer<PopupChooserBuilder>() {
                  @Override
                  public void consume(PopupChooserBuilder builder) {
                    builder.setCloseOnEnter(false).setCancelOnClickOutside(false);
                  }
                })
            .setDoneRunnable(
                new Runnable() {
                  @Override
                  public void run() {
                    myPopup.cancel();
                  }
                })
            .createMasterDetailPopup();

    new AnAction() {
      @Override
      public void actionPerformed(AnActionEvent e) {
        @SuppressWarnings("deprecation")
        Object[] values = list.getSelectedValues();
        for (Object item : values) {
          if (item instanceof BookmarkItem) {
            itemChosen((BookmarkItem) item, project, myPopup, true);
          }
        }
      }
    }.registerCustomShortcutSet(CommonShortcuts.getEditSource(), list);

    editDescriptionAction.setPopup(myPopup);
    myPopup.showCenteredInCurrentWindow(project);

    list.getEmptyText().setText("No Bookmarks");
    list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    project
        .getMessageBus()
        .connect(myPopup)
        .subscribe(
            BookmarksListener.TOPIC,
            new BookmarksListener() {
              @Override
              public void bookmarkAdded(@NotNull Bookmark b) {}

              @Override
              public void bookmarkRemoved(@NotNull Bookmark b) {}

              @Override
              public void bookmarkChanged(@NotNull Bookmark b) {}

              @Override
              public void bookmarksOrderChanged() {
                doUpdate();
              }

              private void doUpdate() {
                TreeSet selectedValues = new TreeSet(Arrays.asList(list.getSelectedValues()));
                DefaultListModel listModel = buildModel(project);
                list.setModel(listModel);
                ListSelectionModel selectionModel = list.getSelectionModel();
                for (int i = 0; i < listModel.getSize(); i++) {
                  if (selectedValues.contains(listModel.get(i))) {
                    selectionModel.addSelectionInterval(i, i);
                  }
                }
              }
            });
  }