Ejemplo n.º 1
0
  @NotNull
  public Object[] getVariants() {
    final String[] ids = InjectedLanguage.getAvailableLanguageIDs();
    return ContainerUtil.map2Array(
        ids,
        LookupElement.class,
        new Function<String, LookupElement>() {
          public LookupElement fun(String s) {
            final Language l = InjectedLanguage.findLanguageById(s);
            assert l != null;

            final FileType ft = l.getAssociatedFileType();
            if (ft != null) {
              return LookupElementBuilder.create(s)
                  .setIcon(ft.getIcon())
                  .setTypeText(ft.getDescription());
              //                } else if (l == StdLanguages.EL) {
              //                    // IDEA-10012
              //                    return new LanguageLookupValue(s, StdFileTypes.JSP.getIcon(),
              // "Expression Language");
            }
            return LookupElementBuilder.create(s).setIcon(EmptyIcon.ICON_16);
          }
        });
  }
    private InjectionsTable(final List<InjInfo> injections) {
      super(new ListTableModel<InjInfo>(createInjectionColumnInfos(), injections, 1));
      setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN);
      getColumnModel().getColumn(2).setCellRenderer(createLanguageCellRenderer());
      getColumnModel().getColumn(1).setCellRenderer(createDisplayNameCellRenderer());
      getColumnModel().getColumn(0).setResizable(false);
      setShowGrid(false);
      setShowVerticalLines(false);
      setGridColor(getForeground());
      TableUtil.setupCheckboxColumn(getColumnModel().getColumn(0));

      new DoubleClickListener() {
        @Override
        protected boolean onDoubleClick(MouseEvent e) {
          final int row = rowAtPoint(e.getPoint());
          if (row < 0) return false;
          if (columnAtPoint(e.getPoint()) <= 0) return false;
          myInjectionsTable.getSelectionModel().setSelectionInterval(row, row);
          performEditAction();
          return true;
        }
      }.installOn(this);

      final String[] maxName = new String[] {""};
      ContainerUtil.process(
          injections,
          new Processor<InjInfo>() {
            public boolean process(final InjInfo injection) {
              String languageId = injection.injection.getInjectedLanguageId();
              Language language = InjectedLanguage.findLanguageById(languageId);
              String displayName = language == null ? languageId : language.getDisplayName();
              if (maxName[0].length() < displayName.length()) maxName[0] = displayName;
              return true;
            }
          });
      ContainerUtil.process(
          InjectedLanguage.getAvailableLanguages(),
          new Processor<Language>() {
            public boolean process(final Language language) {
              String displayName = language.getDisplayName();
              if (maxName[0].length() < displayName.length()) maxName[0] = displayName;
              return true;
            }
          });
      Icon icon = FileTypes.PLAIN_TEXT.getIcon();
      int preferred =
          (int) (new JLabel(maxName[0], icon, SwingConstants.LEFT).getPreferredSize().width * 1.1);
      getColumnModel().getColumn(2).setMinWidth(preferred);
      getColumnModel().getColumn(2).setPreferredWidth(preferred);
      getColumnModel().getColumn(2).setMaxWidth(preferred);
      new TableViewSpeedSearch<InjInfo>(this) {
        @Override
        protected String getItemText(@NotNull InjInfo element) {
          final BaseInjection injection = element.injection;
          return injection.getSupportId()
              + " "
              + injection.getInjectedLanguageId()
              + " "
              + injection.getDisplayName();
        }
      };
    }
Ejemplo n.º 3
0
 @Nullable
 public PsiElement resolve() {
   return InjectedLanguage.findLanguageById(getValue()) != null ? myValue : null;
 }