@Nullable
 private InjInfo getSelectedInjection() {
   final int row = myInjectionsTable.getSelectedRow();
   return row < 0
       ? null
       : myInjectionsTable.getItems().get(myInjectionsTable.convertRowIndexToModel(row));
 }
 private List<InjInfo> getSelectedInjections() {
   final ArrayList<InjInfo> toRemove = new ArrayList<InjInfo>();
   for (int row : myInjectionsTable.getSelectedRows()) {
     toRemove.add(myInjectionsTable.getItems().get(myInjectionsTable.convertRowIndexToModel(row)));
   }
   return toRemove;
 }
 private void addInjection(final BaseInjection injection) {
   final InjInfo info = getDefaultCfgInfo().addInjection(injection);
   myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
   final int index =
       myInjectionsTable.convertRowIndexToView(
           myInjectionsTable.getListTableModel().getItems().indexOf(info));
   myInjectionsTable.getSelectionModel().setSelectionInterval(index, index);
   TableUtil.scrollSelectionToVisible(myInjectionsTable);
 }
 private void performRemove() {
   final int selectedRow = myInjectionsTable.getSelectedRow();
   if (selectedRow < 0) return;
   final List<InjInfo> selected = getSelectedInjections();
   for (InjInfo info : selected) {
     if (info.bundled) continue;
     info.cfgInfo.injectionInfos.remove(info);
   }
   myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
   final int index =
       Math.min(myInjectionsTable.getListTableModel().getRowCount() - 1, selectedRow);
   myInjectionsTable.getSelectionModel().setSelectionInterval(index, index);
   TableUtil.scrollSelectionToVisible(myInjectionsTable);
   updateCountLabel();
 }
  public InjectionsSettingsUI(final Project project, final Configuration configuration) {
    myProject = project;
    myConfiguration = configuration;

    final CfgInfo currentInfo = new CfgInfo(configuration, "Project");
    myInfos =
        configuration instanceof Configuration.Prj
            ? new CfgInfo[] {
              new CfgInfo(((Configuration.Prj) configuration).getParentConfiguration(), "IDE"),
              currentInfo
            }
            : new CfgInfo[] {currentInfo};

    myRoot = new JPanel(new BorderLayout());

    myInjectionsTable = new InjectionsTable(getInjInfoList(myInfos));
    myInjectionsTable.getEmptyText().setText("No injections configured");

    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myInjectionsTable);
    createActions(decorator);

    // myRoot.add(new TitledSeparator("Languages injection places"), BorderLayout.NORTH);
    myRoot.add(decorator.createPanel(), BorderLayout.CENTER);
    myCountLabel = new JLabel();
    myCountLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    myCountLabel.setForeground(SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES.getFgColor());
    myRoot.add(myCountLabel, BorderLayout.SOUTH);
    updateCountLabel();
  }
 private void performSelectedInjectionsEnabled(final boolean enabled) {
   for (InjInfo info : getSelectedInjections()) {
     info.injection.setPlaceEnabled(null, enabled);
   }
   myInjectionsTable.updateUI();
   updateCountLabel();
 }
 public void reset() {
   for (CfgInfo info : myInfos) {
     info.reset();
   }
   myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
   updateCountLabel();
 }
 private void updateCountLabel() {
   int placesCount = 0;
   int enablePlacesCount = 0;
   final List<InjInfo> items = myInjectionsTable.getListTableModel().getItems();
   if (!items.isEmpty()) {
     for (InjInfo injection : items) {
       for (InjectionPlace place : injection.injection.getInjectionPlaces()) {
         placesCount++;
         if (place.isEnabled()) enablePlacesCount++;
       }
     }
     myCountLabel.setText(
         items.size()
             + " injection"
             + (items.size() > 1 ? "s" : "")
             + " ("
             + enablePlacesCount
             + " of "
             + placesCount
             + " place"
             + (placesCount > 1 ? "s" : "")
             + " enabled) ");
   } else {
     myCountLabel.setText("no injections configured ");
   }
 }
 private void performEditAction() {
   final AnAction action = getEditAction();
   if (action != null) {
     final int row = myInjectionsTable.getSelectedRow();
     action.actionPerformed(
         new AnActionEvent(
             null,
             DataManager.getInstance().getDataContext(myInjectionsTable),
             ActionPlaces.UNKNOWN,
             new Presentation(""),
             ActionManager.getInstance(),
             0));
     myInjectionsTable.getListTableModel().fireTableDataChanged();
     myInjectionsTable.getSelectionModel().setSelectionInterval(row, row);
     updateCountLabel();
   }
 }
  private void doImportAction(final DataContext dataContext) {
    final FileChooserDescriptor descriptor =
        new FileChooserDescriptor(true, false, true, false, true, false) {
          @Override
          public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, showHiddenFiles)
                && (file.isDirectory()
                    || "xml".equals(file.getExtension())
                    || file.getFileType() == FileTypes.ARCHIVE);
          }

          @Override
          public boolean isFileSelectable(VirtualFile file) {
            return file.getFileType() == StdFileTypes.XML;
          }
        };
    descriptor.setDescription(
        "Please select the configuration file (usually named IntelliLang.xml) to import.");
    descriptor.setTitle("Import Configuration");

    descriptor.putUserData(LangDataKeys.MODULE_CONTEXT, LangDataKeys.MODULE.getData(dataContext));

    final SplitterProportionsData splitterData = new SplitterProportionsDataImpl();
    splitterData.externalizeFromDimensionService(
        "IntelliLang.ImportSettingsKey.SplitterProportions");

    final VirtualFile file = FileChooser.chooseFile(descriptor, myProject, null);
    if (file == null) return;
    try {
      final Configuration cfg = Configuration.load(file.getInputStream());
      if (cfg == null) {
        Messages.showWarningDialog(
            myProject,
            "The selected file does not contain any importable configuration.",
            "Nothing to Import");
        return;
      }
      final CfgInfo info = getDefaultCfgInfo();
      final Map<String, Set<InjInfo>> currentMap =
          ContainerUtil.classify(
              info.injectionInfos.iterator(),
              new Convertor<InjInfo, String>() {
                public String convert(final InjInfo o) {
                  return o.injection.getSupportId();
                }
              });
      final List<BaseInjection> originalInjections = new ArrayList<BaseInjection>();
      final List<BaseInjection> newInjections = new ArrayList<BaseInjection>();
      //// remove duplicates
      // for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
      //  final Set<BaseInjection> currentInjections = currentMap.get(supportId);
      //  if (currentInjections == null) continue;
      //  for (BaseInjection injection : currentInjections) {
      //    Configuration.importInjections(newInjections, Collections.singleton(injection),
      // originalInjections, newInjections);
      //  }
      // }
      // myInjections.clear();
      // myInjections.addAll(newInjections);

      for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
        ArrayList<InjInfo> list =
            new ArrayList<InjInfo>(
                ObjectUtils.notNull(currentMap.get(supportId), Collections.<InjInfo>emptyList()));
        final List<BaseInjection> currentInjections = getInjectionList(list);
        final List<BaseInjection> importingInjections = cfg.getInjections(supportId);
        if (currentInjections == null) {
          newInjections.addAll(importingInjections);
        } else {
          Configuration.importInjections(
              currentInjections, importingInjections, originalInjections, newInjections);
        }
      }
      info.replace(originalInjections, newInjections);
      myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
      final int n = newInjections.size();
      if (n > 1) {
        Messages.showInfoMessage(
            myProject, n + " entries have been successfully imported", "Import Successful");
      } else if (n == 1) {
        Messages.showInfoMessage(
            myProject, "One entry has been successfully imported", "Import Successful");
      } else {
        Messages.showInfoMessage(myProject, "No new entries have been imported", "Import");
      }
    } catch (Exception ex) {
      Configuration.LOG.error(ex);

      final String msg = ex.getLocalizedMessage();
      Messages.showErrorDialog(
          myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), "Import Failed");
    }
  }