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(
             @NotNull 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(
           () -> myPathTextField.getField().setText(files.getSelectedValue().toString()))
       .createPopup()
       .showUnderneathOf(myPathTextField.getField());
 }
  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());
  }
Exemple #3
0
  @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(
                    () -> {
                      final Object value = list.getSelectedValue();
                      if (value != null) {
                        configureEditor(getEditor(), value);
                        IdeFocusManager.getGlobalInstance().requestFocus(this, true);
                        assert myJBPopup != null;
                        this.getUI().setPopupVisible(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);
      }
    }
  }
 @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);
     }
   }
 }
  private void updateClientsForDevice(@Nullable IDevice device) {
    if (device == null) {
      // Note: we do want listeners triggered when the device itself disappears.
      // so we don't set myIgnoreListeners
      myClientsListModel.clear();
      return;
    }

    Object selectedObject = myClientsList.getSelectedValue();
    Client[] clients = device.getClients();

    try {
      // we want to refresh the list of clients, however we don't want the listeners to
      // think that this is a user driven change to the list selection.
      // the only time this update should trigger the selection listener is if the currently
      // selected client isn't there anymore
      myIgnoreListeners = ArrayUtil.contains(selectedObject, clients);
      myClientsListModel.clear();
      myClientsListModel.addAll(clients);
      myClientsList.setSelectedValue(selectedObject, true);
    } finally {
      myIgnoreListeners = false;
    }
  }
  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());
    }
  }
 public int getSelectedIndex() {
   Object o = myList.getSelectedValue();
   return o == null ? -1 : ((Item) o).index;
 }
 @Override
 @Nullable
 public LookupElement getCurrentItem() {
   LookupElement item = (LookupElement) myList.getSelectedValue();
   return item instanceof EmptyLookupItem ? null : item;
 }
 public void finishLookup(final char completionChar) {
   finishLookup(completionChar, (LookupElement) myList.getSelectedValue());
 }
Exemple #10
0
 private TemplatesGroup getSelectedGroup() {
   return (TemplatesGroup) myProjectTypeList.getSelectedValue();
 }
Exemple #11
0
  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();
  }
 @Nullable
 public ProjectTemplate getSelectedTemplate() {
   Object value = myList.getSelectedValue();
   return value instanceof TemplateItem ? ((TemplateItem) value).myTemplate : null;
 }
 void saveSelection() {
   TemplateItem item = (TemplateItem) myList.getSelectedValue();
   if (item != null) {
     SelectTemplateSettings.getInstance().setLastTemplate(item.getGroupName(), item.getName());
   }
 }