@Override
 public Configurable[] getConfigurables() {
   if (!isInitialized) {
     ArrayList<Configurable> list = new ArrayList<Configurable>();
     if (super.myEp.dynamic) {
       Composite composite = cast(Composite.class, this);
       if (composite != null) {
         Collections.addAll(list, composite.getConfigurables());
       }
     }
     if (super.myEp.children != null) {
       for (ConfigurableEP ep : super.myEp.getChildren()) {
         if (ep.isAvailable()) {
           list.add((Configurable) wrapConfigurable(ep));
         }
       }
     }
     if (super.myEp.childrenEPName != null) {
       Object[] extensions =
           Extensions.getArea(super.myEp.getProject())
               .getExtensionPoint(super.myEp.childrenEPName)
               .getExtensions();
       if (extensions.length > 0) {
         if (extensions[0] instanceof ConfigurableEP) {
           for (Object object : extensions) {
             list.add((Configurable) wrapConfigurable((ConfigurableEP) object));
           }
         } else if (!super.myEp.dynamic) {
           Composite composite = cast(Composite.class, this);
           if (composite != null) {
             Collections.addAll(list, composite.getConfigurables());
           }
         }
       }
     }
     Collections.addAll(list, myKids);
     // sort configurables is needed
     for (Configurable configurable : list) {
       if (configurable instanceof Weighted) {
         if (((Weighted) configurable).getWeight() != 0) {
           myComparator = COMPARATOR;
           Collections.sort(list, myComparator);
           break;
         }
       }
     }
     myKids = ArrayUtil.toObjectArray(list, Configurable.class);
     isInitialized = true;
   }
   return myKids;
 }
 @Override
 public VirtualFile[] getAllVersionedRoots() {
   List<VirtualFile> vFiles = new ArrayList<VirtualFile>();
   final AbstractVcs[] vcses = myMappings.getActiveVcses();
   for (AbstractVcs vcs : vcses) {
     Collections.addAll(vFiles, getRootsUnderVcs(vcs));
   }
   return VfsUtilCore.toVirtualFileArray(vFiles);
 }
  private static void addGetterSetterElements(
      CompletionResultSet result, PsiClass parent, Set<MethodSignature> addedSignatures) {
    int count = 0;
    for (PsiField field : parent.getFields()) {
      if (field instanceof PsiEnumConstant) continue;

      List<PsiMethod> prototypes = ContainerUtil.newSmartList();
      Collections.addAll(
          prototypes, GetterSetterPrototypeProvider.generateGetterSetters(field, true));
      Collections.addAll(
          prototypes, GetterSetterPrototypeProvider.generateGetterSetters(field, false));
      for (final PsiMethod prototype : prototypes) {
        if (parent.findMethodBySignature(prototype, false) == null
            && addedSignatures.add(prototype.getSignature(PsiSubstitutor.EMPTY))) {
          Icon icon = prototype.getIcon(Iconable.ICON_FLAG_VISIBILITY);
          result.addElement(
              createGenerateMethodElement(
                  prototype,
                  PsiSubstitutor.EMPTY,
                  icon,
                  "",
                  new InsertHandler<LookupElement>() {
                    @Override
                    public void handleInsert(InsertionContext context, LookupElement item) {
                      removeLookupString(context);

                      insertGenerationInfos(
                          context,
                          Collections.singletonList(new PsiGenerationInfo<PsiMethod>(prototype)));
                    }
                  }));

          if (count++ > 100) return;
        }
      }
    }
  }
 @Override
 public void showStandardOptions(String... optionNames) {
   Collections.addAll(myAllowedOptions, optionNames);
   for (Option each : myOptions) {
     each.setEnabled(false);
     for (String optionName : optionNames) {
       if (each.field.getName().equals(optionName)) {
         each.setEnabled(true);
       }
     }
   }
   for (Option each : myCustomOptions) {
     each.setEnabled(false);
   }
 }
 public Collection<String> getAdditionalAnnotations() {
   List<String> annos = ADDITIONAL_ANNOS;
   if (annos == null) {
     annos = new ArrayList<String>();
     Collections.addAll(annos, STANDARD_ANNOS);
     final EntryPoint[] extensions =
         Extensions.getExtensions(ExtensionPoints.DEAD_CODE_TOOL, null);
     for (EntryPoint extension : extensions) {
       final String[] ignoredAnnotations = extension.getIgnoreAnnotations();
       if (ignoredAnnotations != null) {
         ContainerUtil.addAll(annos, ignoredAnnotations);
       }
     }
     ADDITIONAL_ANNOS = annos = Collections.unmodifiableList(annos);
   }
   return annos;
 }
Exemplo n.º 6
0
  private void resetSelection(@NotNull String[] selectedSerials) {
    MyDeviceTableModel model = (MyDeviceTableModel) myDeviceTable.getModel();
    Set<String> selectedSerialsSet = new HashSet<String>();
    Collections.addAll(selectedSerialsSet, selectedSerials);
    IDevice[] myDevices = model.myDevices;
    ListSelectionModel selectionModel = myDeviceTable.getSelectionModel();
    boolean cleared = false;

    for (int i = 0, n = myDevices.length; i < n; i++) {
      String serialNumber = myDevices[i].getSerialNumber();
      if (selectedSerialsSet.contains(serialNumber)) {
        if (!cleared) {
          selectionModel.clearSelection();
          cleared = true;
        }
        selectionModel.addSelectionInterval(i, i);
      }
    }
  }
  private void warnAboutMissedDependencies(
      final Boolean newVal, final IdeaPluginDescriptor... ideaPluginDescriptors) {
    final Set<PluginId> deps = new HashSet<PluginId>();
    final List<IdeaPluginDescriptor> descriptorsToCheckDependencies =
        new ArrayList<IdeaPluginDescriptor>();
    if (newVal) {
      Collections.addAll(descriptorsToCheckDependencies, ideaPluginDescriptors);
    } else {
      descriptorsToCheckDependencies.addAll(view);
      descriptorsToCheckDependencies.addAll(filtered);
      descriptorsToCheckDependencies.removeAll(Arrays.asList(ideaPluginDescriptors));

      for (Iterator<IdeaPluginDescriptor> iterator = descriptorsToCheckDependencies.iterator();
          iterator.hasNext(); ) {
        IdeaPluginDescriptor descriptor = iterator.next();
        final Boolean enabled = myEnabled.get(descriptor.getPluginId());
        if (enabled == null || !enabled.booleanValue()) {
          iterator.remove();
        }
      }
    }

    for (final IdeaPluginDescriptor ideaPluginDescriptor : descriptorsToCheckDependencies) {
      PluginManager.checkDependants(
          ideaPluginDescriptor,
          new Function<PluginId, IdeaPluginDescriptor>() {
            @Nullable
            public IdeaPluginDescriptor fun(final PluginId pluginId) {
              return PluginManager.getPlugin(pluginId);
            }
          },
          new Condition<PluginId>() {
            public boolean value(final PluginId pluginId) {
              Boolean enabled = myEnabled.get(pluginId);
              if (enabled == null) {
                return false;
              }
              if (newVal && !enabled.booleanValue()) {
                deps.add(pluginId);
              }

              if (!newVal) {
                final PluginId pluginDescriptorId = ideaPluginDescriptor.getPluginId();
                for (IdeaPluginDescriptor descriptor : ideaPluginDescriptors) {
                  if (pluginId.equals(descriptor.getPluginId())) {
                    deps.add(pluginDescriptorId);
                    break;
                  }
                }
              }
              return true;
            }
          });
    }
    if (!deps.isEmpty()) {
      final String listOfSelectedPlugins =
          StringUtil.join(
              ideaPluginDescriptors,
              new Function<IdeaPluginDescriptor, String>() {
                @Override
                public String fun(IdeaPluginDescriptor pluginDescriptor) {
                  return pluginDescriptor.getName();
                }
              },
              ", ");
      final Set<IdeaPluginDescriptor> pluginDependencies = new HashSet<IdeaPluginDescriptor>();
      final String listOfDependencies =
          StringUtil.join(
              deps,
              new Function<PluginId, String>() {
                public String fun(final PluginId pluginId) {
                  final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(pluginId);
                  assert pluginDescriptor != null;
                  pluginDependencies.add(pluginDescriptor);
                  return pluginDescriptor.getName();
                }
              },
              "<br>");
      final String message =
          !newVal
              ? "<html>The following plugins <br>"
                  + listOfDependencies
                  + "<br>are enabled and depend"
                  + (deps.size() == 1 ? "s" : "")
                  + " on selected plugins. "
                  + "<br>Would you like to disable them too?</html>"
              : "<html>The following plugins on which "
                  + listOfSelectedPlugins
                  + " depend"
                  + (ideaPluginDescriptors.length == 1 ? "s" : "")
                  + " are disabled:<br>"
                  + listOfDependencies
                  + "<br>Would you like to enable them?</html>";
      if (Messages.showOkCancelDialog(
              message,
              newVal ? "Enable Dependant Plugins" : "Disable Plugins with Dependency on this",
              Messages.getQuestionIcon())
          == DialogWrapper.OK_EXIT_CODE) {
        for (PluginId pluginId : deps) {
          myEnabled.put(pluginId, newVal);
        }

        updatePluginDependencies();
        hideNotApplicablePlugins(
            newVal,
            pluginDependencies.toArray(new IdeaPluginDescriptor[pluginDependencies.size()]));
      }
    }
  }
  protected List<ColorAndFontPanelFactory> createPanelFactories() {
    List<ColorAndFontPanelFactory> result = new ArrayList<ColorAndFontPanelFactory>();
    result.add(new FontConfigurableFactory());

    List<ColorAndFontPanelFactory> extensions = new ArrayList<ColorAndFontPanelFactory>();
    extensions.add(new ConsoleFontConfigurableFactory());
    ColorSettingsPage[] pages = ColorSettingsPages.getInstance().getRegisteredPages();
    for (final ColorSettingsPage page : pages) {
      extensions.add(
          new ColorAndFontPanelFactoryEx() {
            @Override
            @NotNull
            public NewColorAndFontPanel createPanel(@NotNull ColorAndFontOptions options) {
              final SimpleEditorPreview preview = new SimpleEditorPreview(options, page);
              return NewColorAndFontPanel.create(
                  preview, page.getDisplayName(), options, null, page);
            }

            @Override
            @NotNull
            public String getPanelDisplayName() {
              return page.getDisplayName();
            }

            @Override
            public DisplayPriority getPriority() {
              if (page instanceof DisplayPrioritySortable) {
                return ((DisplayPrioritySortable) page).getPriority();
              }
              return DisplayPriority.LANGUAGE_SETTINGS;
            }
          });
    }
    Collections.addAll(extensions, Extensions.getExtensions(ColorAndFontPanelFactory.EP_NAME));
    Collections.sort(
        extensions,
        new Comparator<ColorAndFontPanelFactory>() {
          @Override
          public int compare(ColorAndFontPanelFactory f1, ColorAndFontPanelFactory f2) {
            if (f1 instanceof DisplayPrioritySortable) {
              if (f2 instanceof DisplayPrioritySortable) {
                int result =
                    ((DisplayPrioritySortable) f1)
                        .getPriority()
                        .compareTo(((DisplayPrioritySortable) f2).getPriority());
                if (result != 0) return result;
              } else {
                return 1;
              }
            } else if (f2 instanceof DisplayPrioritySortable) {
              return -1;
            }
            return f1.getPanelDisplayName().compareToIgnoreCase(f2.getPanelDisplayName());
          }
        });
    result.addAll(extensions);

    result.add(new DiffColorsPageFactory());
    result.add(new FileStatusColorsPageFactory());
    result.add(new ScopeColorsPageFactory());

    return result;
  }
  private void show(
      @NotNull final Project project,
      @NotNull Editor editor,
      @NotNull PsiFile file,
      @NotNull final GotoData gotoData) {
    final PsiElement[] targets = gotoData.targets;
    final List<AdditionalAction> additionalActions = gotoData.additionalActions;

    if (targets.length == 0 && additionalActions.isEmpty()) {
      HintManager.getInstance().showErrorHint(editor, getNotFoundMessage(project, editor, file));
      return;
    }

    if (targets.length == 1 && additionalActions.isEmpty()) {
      Navigatable descriptor =
          targets[0] instanceof Navigatable
              ? (Navigatable) targets[0]
              : EditSourceUtil.getDescriptor(targets[0]);
      if (descriptor != null && descriptor.canNavigate()) {
        navigateToElement(descriptor);
      }
      return;
    }

    for (PsiElement eachTarget : targets) {
      gotoData.renderers.put(eachTarget, createRenderer(gotoData, eachTarget));
    }

    final String name = ((PsiNamedElement) gotoData.source).getName();
    boolean finished = gotoData.listUpdaterTask == null || gotoData.listUpdaterTask.isFinished();
    final String title = getChooserTitle(gotoData.source, name, targets.length, finished);

    if (shouldSortTargets()) {
      Arrays.sort(targets, createComparator(gotoData.renderers, gotoData));
    }

    List<Object> allElements = new ArrayList<Object>(targets.length + additionalActions.size());
    Collections.addAll(allElements, targets);
    allElements.addAll(additionalActions);

    final JBListWithHintProvider list =
        new JBListWithHintProvider(new CollectionListModel<Object>(allElements)) {
          @Override
          protected PsiElement getPsiElementForHint(final Object selectedValue) {
            return selectedValue instanceof PsiElement ? (PsiElement) selectedValue : null;
          }
        };

    list.setFont(EditorUtil.getEditorFont());

    list.setCellRenderer(
        new DefaultListCellRenderer() {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if (value == null)
              return super.getListCellRendererComponent(
                  list, value, index, isSelected, cellHasFocus);
            if (value instanceof AdditionalAction) {
              return myActionElementRenderer.getListCellRendererComponent(
                  list, value, index, isSelected, cellHasFocus);
            }
            PsiElementListCellRenderer renderer = getRenderer(value, gotoData.renderers, gotoData);
            return renderer.getListCellRendererComponent(
                list, value, index, isSelected, cellHasFocus);
          }
        });

    final Runnable runnable =
        () -> {
          int[] ids = list.getSelectedIndices();
          if (ids == null || ids.length == 0) return;
          Object[] selectedElements = list.getSelectedValues();
          for (Object element : selectedElements) {
            if (element instanceof AdditionalAction) {
              ((AdditionalAction) element).execute();
            } else {
              Navigatable nav =
                  element instanceof Navigatable
                      ? (Navigatable) element
                      : EditSourceUtil.getDescriptor((PsiElement) element);
              try {
                if (nav != null && nav.canNavigate()) {
                  navigateToElement(nav);
                }
              } catch (IndexNotReadyException e) {
                DumbService.getInstance(project)
                    .showDumbModeNotification("Navigation is not available while indexing");
              }
            }
          }
        };

    final PopupChooserBuilder builder = new PopupChooserBuilder(list);
    builder.setFilteringEnabled(
        o -> {
          if (o instanceof AdditionalAction) {
            return ((AdditionalAction) o).getText();
          }
          return getRenderer(o, gotoData.renderers, gotoData).getElementText((PsiElement) o);
        });

    final Ref<UsageView> usageView = new Ref<UsageView>();
    final JBPopup popup =
        builder
            .setTitle(title)
            .setItemChoosenCallback(runnable)
            .setMovable(true)
            .setCancelCallback(
                () -> {
                  HintUpdateSupply.hideHint(list);
                  final ListBackgroundUpdaterTask task = gotoData.listUpdaterTask;
                  if (task != null) {
                    task.cancelTask();
                  }
                  return true;
                })
            .setCouldPin(
                popup1 -> {
                  usageView.set(
                      FindUtil.showInUsageView(
                          gotoData.source,
                          gotoData.targets,
                          getFindUsagesTitle(gotoData.source, name, gotoData.targets.length),
                          project));
                  popup1.cancel();
                  return false;
                })
            .setAdText(getAdText(gotoData.source, targets.length))
            .createPopup();

    builder.getScrollPane().setBorder(null);
    builder.getScrollPane().setViewportBorder(null);

    if (gotoData.listUpdaterTask != null) {
      gotoData.listUpdaterTask.init((AbstractPopup) popup, list, usageView);
      ProgressManager.getInstance().run(gotoData.listUpdaterTask);
    }
    popup.showInBestPositionFor(editor);
  }
  private void show(Project project, Editor editor, PsiFile file, final GotoData gotoData) {
    final PsiElement[] targets = gotoData.targets;
    final List<AdditionalAction> additionalActions = gotoData.additionalActions;

    if (targets.length == 0 && additionalActions.isEmpty()) {
      HintManager.getInstance().showErrorHint(editor, getNotFoundMessage(project, editor, file));
      return;
    }

    if (targets.length == 1 && additionalActions.isEmpty()) {
      Navigatable descriptor =
          targets[0] instanceof Navigatable
              ? (Navigatable) targets[0]
              : EditSourceUtil.getDescriptor(targets[0]);
      if (descriptor != null && descriptor.canNavigate()) {
        navigateToElement(descriptor);
      }
      return;
    }

    for (PsiElement eachTarget : targets) {
      gotoData.renderers.put(eachTarget, createRenderer(gotoData, eachTarget));
    }

    String name = ((PsiNamedElement) gotoData.source).getName();
    String title = getChooserTitle(gotoData.source, name, targets.length);

    if (shouldSortTargets()) {
      Arrays.sort(targets, createComparator(gotoData.renderers, gotoData));
    }

    List<Object> allElements = new ArrayList<Object>(targets.length + additionalActions.size());
    Collections.addAll(allElements, targets);
    allElements.addAll(additionalActions);

    final JBListWithHintProvider list =
        new JBListWithHintProvider(new CollectionListModel<Object>(allElements)) {
          @Override
          protected PsiElement getPsiElementForHint(final Object selectedValue) {
            return selectedValue instanceof PsiElement ? (PsiElement) selectedValue : null;
          }
        };

    list.setCellRenderer(
        new DefaultListCellRenderer() {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if (value == null)
              return super.getListCellRendererComponent(
                  list, value, index, isSelected, cellHasFocus);
            if (value instanceof AdditionalAction) {
              return myActionElementRenderer.getListCellRendererComponent(
                  list, value, index, isSelected, cellHasFocus);
            }
            PsiElementListCellRenderer renderer = getRenderer(value, gotoData.renderers, gotoData);
            return renderer.getListCellRendererComponent(
                list, value, index, isSelected, cellHasFocus);
          }
        });

    final Runnable runnable =
        new Runnable() {
          @Override
          public void run() {
            int[] ids = list.getSelectedIndices();
            if (ids == null || ids.length == 0) return;
            Object[] selectedElements = list.getSelectedValues();
            for (Object element : selectedElements) {
              if (element instanceof AdditionalAction) {
                ((AdditionalAction) element).execute();
              } else {
                Navigatable nav =
                    element instanceof Navigatable
                        ? (Navigatable) element
                        : EditSourceUtil.getDescriptor((PsiElement) element);
                if (nav != null && nav.canNavigate()) {
                  navigateToElement(nav);
                }
              }
            }
          }
        };

    final PopupChooserBuilder builder = new PopupChooserBuilder(list);
    builder.setFilteringEnabled(
        new Function<Object, String>() {
          @Override
          public String fun(Object o) {
            if (o instanceof AdditionalAction) {
              return ((AdditionalAction) o).getText();
            }
            return getRenderer(o, gotoData.renderers, gotoData).getElementText((PsiElement) o);
          }
        });

    final JBPopup popup =
        builder
            .setTitle(title)
            .setItemChoosenCallback(runnable)
            .setMovable(true)
            .setCancelCallback(
                new Computable<Boolean>() {
                  @Override
                  public Boolean compute() {
                    list.hideHint();
                    return true;
                  }
                })
            .setAdText(getAdText(gotoData.source, targets.length))
            .createPopup();
    if (gotoData.listUpdaterTask != null) {
      gotoData.listUpdaterTask.init((AbstractPopup) popup, list);
      ProgressManager.getInstance().run(gotoData.listUpdaterTask);
    }
    popup.showInBestPositionFor(editor);
  }