private void updateText() {
    StringBuilder sb = new StringBuilder();

    if (myShowSettingsBeforeRunCheckBox.isSelected()) {
      sb.append(ExecutionBundle.message("configuration.edit.before.run")).append(", ");
    }

    List<BeforeRunTask> tasks = myModel.getItems();
    if (!tasks.isEmpty()) {
      LinkedHashMap<BeforeRunTaskProvider, Integer> counter =
          new LinkedHashMap<BeforeRunTaskProvider, Integer>();
      for (BeforeRunTask task : tasks) {
        BeforeRunTaskProvider<BeforeRunTask> provider =
            BeforeRunTaskProvider.getProvider(
                myRunConfiguration.getProject(), task.getProviderId());
        if (provider != null) {
          Integer count = counter.get(provider);
          if (count == null) {
            count = task.getItemsCount();
          } else {
            count += task.getItemsCount();
          }
          counter.put(provider, count);
        }
      }
      for (Iterator<Map.Entry<BeforeRunTaskProvider, Integer>> iterator =
              counter.entrySet().iterator();
          iterator.hasNext(); ) {
        Map.Entry<BeforeRunTaskProvider, Integer> entry = iterator.next();
        BeforeRunTaskProvider provider = entry.getKey();
        String name = provider.getName();
        if (name.startsWith("Run ")) {
          name = name.substring(4);
        }
        sb.append(name);
        if (entry.getValue() > 1) {
          sb.append(" (").append(entry.getValue().intValue()).append(")");
        }
        if (iterator.hasNext()) sb.append(", ");
      }
    }
    if (sb.length() > 0) {
      sb.insert(0, ": ");
    }
    sb.insert(0, ExecutionBundle.message("before.launch.panel.title"));
    myListener.titleChanged(sb.toString());
  }
 private void updateCurrentRule() {
   if (myLastSelected >= 0 && myLastSelected < myRulesModel.getSize()) {
     LibraryBundlificationRule newRule = new LibraryBundlificationRule();
     newRule.setRuleRegex(myLibraryRegex.getText().trim());
     newRule.setAdditionalProperties(myManifestEditor.getText().trim());
     newRule.setDoNotBundle(myNeverBundle.isSelected());
     newRule.setStopAfterThisRule(myStopAfterThisRule.isSelected());
     if (!newRule.equals(myRulesModel.getElementAt(myLastSelected))) {
       myRulesModel.setElementAt(newRule, myLastSelected);
     }
   }
 }
 public boolean isModified(ApplicationSettings settings) {
   updateCurrentRule();
   List<LibraryBundlificationRule> rules = settings.getLibraryBundlificationRules();
   if (myRulesModel.getSize() != rules.size()) {
     return true;
   }
   for (int i = 0; i < rules.size(); i++) {
     if (!rules.get(i).equals(myRulesModel.getElementAt(i))) {
       return true;
     }
   }
   return false;
 }
  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()));
  }
 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);
   }
 }
 private Set<Key> getActiveProviderKeys() {
   Set<Key> result = new HashSet<Key>();
   for (BeforeRunTask task : myModel.getItems()) {
     result.add(task.getProviderId());
   }
   return result;
 }
 public List<BeforeRunTask> getTasks(boolean applyCurrentState) {
   if (applyCurrentState) {
     originalTasks.clear();
     originalTasks.addAll(myModel.getItems());
   }
   return Collections.unmodifiableList(originalTasks);
 }
 @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;
 }
Пример #9
0
  private void addEmptyItem(CollectionListModel<LookupElement> model) {
    LookupItem<String> item =
        new EmptyLookupItem(
            myCalculating ? " " : LangBundle.message("completion.no.suggestions"), false);
    myMatchers.put(item, new CamelHumpMatcher(""));
    model.add(item);

    updateLookupWidth(item);
    requestResize();
  }
 @NotNull
 private Set<String> getFileNamesToCreate() {
   final String name = getBaseName();
   final String suffix = getPropertiesFileSuffix();
   return ContainerUtil.map2Set(
       myLocalesModel.getItems(),
       locale ->
           name
               + (locale == PropertiesUtil.DEFAULT_LOCALE ? "" : ("_" + locale.toString()))
               + suffix);
 }
Пример #11
0
  private boolean updateList(boolean onExplicitAction, boolean reused) {
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
      ApplicationManager.getApplication().assertIsDispatchThread();
    }
    checkValid();

    CollectionListModel<LookupElement> listModel = getListModel();

    Pair<List<LookupElement>, Integer> pair;
    synchronized (myList) {
      pair = myPresentableArranger.arrangeItems(this, onExplicitAction || reused);
    }

    List<LookupElement> items = pair.first;
    Integer toSelect = pair.second;
    if (toSelect == null || toSelect < 0 || items.size() > 0 && toSelect >= items.size()) {
      LOG.error(
          "Arranger "
              + myPresentableArranger
              + " returned invalid selection index="
              + toSelect
              + "; items="
              + items);
      toSelect = 0;
    }

    myOffsets.checkMinPrefixLengthChanges(items, this);
    List<LookupElement> oldModel = listModel.toList();

    listModel.removeAll();
    if (!items.isEmpty()) {
      listModel.add(items);
    } else {
      addEmptyItem(listModel);
    }

    updateListHeight(listModel);

    myList.setSelectedIndex(toSelect);
    return !ContainerUtil.equalsIdentity(oldModel, items);
  }
  void doReset(RunnerAndConfigurationSettings settings) {
    myRunConfiguration = settings.getConfiguration();

    originalTasks.clear();
    RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(myRunConfiguration.getProject());
    originalTasks.addAll(runManager.getBeforeRunTasks(myRunConfiguration));
    myModel.replaceAll(originalTasks);
    myShowSettingsBeforeRunCheckBox.setSelected(settings.isEditBeforeRun());
    myShowSettingsBeforeRunCheckBox.setEnabled(!(isUnknown()));
    myPanel.setVisible(checkBeforeRunTasksAbility(false));
    updateText();
  }
 private void updateFields() {
   int index = myRulesList.getSelectedIndex();
   if (index >= 0 && index != myLastSelected) {
     final LibraryBundlificationRule rule = myRulesModel.getElementAt(index);
     myLibraryRegex.setText(rule.getRuleRegex());
     UIUtil.invokeLaterIfNeeded(() -> myManifestEditor.setText(rule.getAdditionalProperties()));
     myNeverBundle.setSelected(rule.isDoNotBundle());
     myStopAfterThisRule.setSelected(rule.isStopAfterThisRule());
     myLastSelected = index;
   }
   myLibraryRegex.setEnabled(index >= 0);
   myManifestEditor.setEnabled(index >= 0);
   myNeverBundle.setEnabled(index >= 0);
   myStopAfterThisRule.setEnabled(index >= 0);
 }
 @Override
 public void apply() throws ConfigurationException {
   myDependenciesManager.setAllDependencies(myListModel.getItems());
 }
 @Override
 public boolean isModified() {
   return !new HashSet<ProjectExternalDependency>(myDependenciesManager.getAllDependencies())
       .equals(new HashSet<ProjectExternalDependency>(myListModel.getItems()));
 }
 @Override
 public void reset() {
   List<ProjectExternalDependency> dependencies = myDependenciesManager.getAllDependencies();
   myListModel.replaceAll(dependencies);
 }
 public void addTask(BeforeRunTask task) {
   myModel.add(task);
 }
 public void resetTo(ApplicationSettings settings) {
   myLastSelected = -1;
   myRulesModel.replaceAll(settings.getLibraryBundlificationRules());
   myRulesList.setSelectedIndex(0);
   updateFields();
 }
  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);
  }