Search in sources :

Example 1 with Extensions

use of com.intellij.openapi.extensions.Extensions in project intellij-community by JetBrains.

the class GutterIconsConfigurable method createComponent.

@Nullable
@Override
public JComponent createComponent() {
    ExtensionPoint<LineMarkerProvider> point = Extensions.getRootArea().getExtensionPoint(LineMarkerProviders.EP_NAME);
    @SuppressWarnings("unchecked") LanguageExtensionPoint<LineMarkerProvider>[] extensions = (LanguageExtensionPoint<LineMarkerProvider>[]) point.getExtensions();
    NullableFunction<LanguageExtensionPoint<LineMarkerProvider>, PluginDescriptor> function = point1 -> {
        LineMarkerProvider instance = point1.getInstance();
        return instance instanceof LineMarkerProviderDescriptor && ((LineMarkerProviderDescriptor) instance).getName() != null ? point1.getPluginDescriptor() : null;
    };
    MultiMap<PluginDescriptor, LanguageExtensionPoint<LineMarkerProvider>> map = ContainerUtil.groupBy(Arrays.asList(extensions), function);
    Map<GutterIconDescriptor, PluginDescriptor> pluginDescriptorMap = ContainerUtil.newHashMap();
    Set<String> ids = new HashSet<>();
    myDescriptors = new ArrayList<>();
    for (final PluginDescriptor descriptor : map.keySet()) {
        Collection<LanguageExtensionPoint<LineMarkerProvider>> points = map.get(descriptor);
        for (LanguageExtensionPoint<LineMarkerProvider> extensionPoint : points) {
            GutterIconDescriptor instance = (GutterIconDescriptor) extensionPoint.getInstance();
            if (instance.getOptions().length > 0) {
                for (GutterIconDescriptor option : instance.getOptions()) {
                    if (ids.add(option.getId())) {
                        myDescriptors.add(option);
                    }
                    pluginDescriptorMap.put(option, descriptor);
                }
            } else {
                if (ids.add(instance.getId())) {
                    myDescriptors.add(instance);
                }
                pluginDescriptorMap.put(instance, descriptor);
            }
        }
    }
    /*
    List<GutterIconDescriptor> options = new ArrayList<GutterIconDescriptor>();
    for (Iterator<GutterIconDescriptor> iterator = myDescriptors.iterator(); iterator.hasNext(); ) {
      GutterIconDescriptor descriptor = iterator.next();
      if (descriptor.getOptions().length > 0) {
        options.addAll(Arrays.asList(descriptor.getOptions()));
        iterator.remove();
      }
    }
    myDescriptors.addAll(options);
    */
    myDescriptors.sort((o1, o2) -> {
        if (pluginDescriptorMap.get(o1) != pluginDescriptorMap.get(o2))
            return 0;
        return Comparing.compare(o1.getName(), o2.getName());
    });
    PluginDescriptor current = null;
    for (GutterIconDescriptor descriptor : myDescriptors) {
        PluginDescriptor pluginDescriptor = pluginDescriptorMap.get(descriptor);
        if (pluginDescriptor != current) {
            myFirstDescriptors.put(descriptor, pluginDescriptor);
            current = pluginDescriptor;
        }
    }
    myList.setItems(myDescriptors, GutterIconDescriptor::getName);
    myShowGutterIconsJBCheckBox.addChangeListener(e -> myList.setEnabled(myShowGutterIconsJBCheckBox.isSelected()));
    return myPanel;
}
Also used : java.util(java.util) ContainerUtil(com.intellij.util.containers.ContainerUtil) Nls(org.jetbrains.annotations.Nls) ProjectManager(com.intellij.openapi.project.ProjectManager) Comparing(com.intellij.openapi.util.Comparing) CheckBoxList(com.intellij.ui.CheckBoxList) EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable) Project(com.intellij.openapi.project.Project) HashSet(com.intellij.util.containers.hash.HashSet) ChangeListener(javax.swing.event.ChangeListener) MultiMap(com.intellij.util.containers.MultiMap) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) Extensions(com.intellij.openapi.extensions.Extensions) EmptyIcon(com.intellij.util.ui.EmptyIcon) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) JBCheckBox(com.intellij.ui.components.JBCheckBox) NullableFunction(com.intellij.util.NullableFunction) Configurable(com.intellij.openapi.options.Configurable) SeparatorWithText(com.intellij.ui.SeparatorWithText) com.intellij.codeInsight.daemon(com.intellij.codeInsight.daemon) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) LanguageExtensionPoint(com.intellij.lang.LanguageExtensionPoint) PluginDescriptor(com.intellij.openapi.extensions.PluginDescriptor) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) LanguageExtensionPoint(com.intellij.lang.LanguageExtensionPoint) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginDescriptor(com.intellij.openapi.extensions.PluginDescriptor) HashSet(com.intellij.util.containers.hash.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Extensions

use of com.intellij.openapi.extensions.Extensions in project intellij-community by JetBrains.

the class UsageViewImpl method setupCentralPanel.

private void setupCentralPanel() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    myCentralPanel.removeAll();
    disposeUsageContextPanels();
    JScrollPane treePane = ScrollPaneFactory.createScrollPane(myTree);
    // add reaction to scrolling:
    // since the UsageViewTreeCellRenderer ignores invisible nodes (outside the viewport), their preferred size is incorrect
    // and we need to recalculate them when the node scrolled into the visible rectangle
    treePane.getViewport().addChangeListener(__ -> clearRendererCache());
    myPreviewSplitter = new Splitter(false, 0.5f, 0.1f, 0.9f);
    myPreviewSplitter.setFirstComponent(treePane);
    myCentralPanel.add(myPreviewSplitter, BorderLayout.CENTER);
    if (UsageViewSettings.getInstance().IS_PREVIEW_USAGES) {
        myPreviewSplitter.setProportion(UsageViewSettings.getInstance().PREVIEW_USAGES_SPLITTER_PROPORTIONS);
        treePane.putClientProperty(UIUtil.KEEP_BORDER_SIDES, SideBorder.RIGHT);
        final JBTabbedPane tabbedPane = new JBTabbedPane(SwingConstants.BOTTOM) {

            @NotNull
            @Override
            protected Insets getInsetsForTabComponent() {
                return new Insets(0, 0, 0, 0);
            }
        };
        UsageContextPanel.Provider[] extensions = Extensions.getExtensions(UsageContextPanel.Provider.EP_NAME, myProject);
        myUsageContextPanelProviders = ContainerUtil.filter(extensions, provider -> provider.isAvailableFor(this));
        for (UsageContextPanel.Provider provider : myUsageContextPanelProviders) {
            JComponent component;
            if (myCurrentUsageContextProvider == null || myCurrentUsageContextProvider == provider) {
                myCurrentUsageContextProvider = provider;
                myCurrentUsageContextPanel = provider.create(this);
                component = myCurrentUsageContextPanel.createComponent();
            } else {
                component = new JLabel();
            }
            tabbedPane.addTab(provider.getTabTitle(), component);
        }
        int index = myUsageContextPanelProviders.indexOf(myCurrentUsageContextProvider);
        tabbedPane.setSelectedIndex(index);
        tabbedPane.addChangeListener(e -> {
            int currentIndex = tabbedPane.getSelectedIndex();
            UsageContextPanel.Provider selectedProvider = myUsageContextPanelProviders.get(currentIndex);
            if (selectedProvider != myCurrentUsageContextProvider) {
                tabSelected(selectedProvider);
            }
        });
        tabbedPane.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
        myPreviewSplitter.setSecondComponent(tabbedPane);
    } else {
        myPreviewSplitter.setProportion(1);
    }
    myCentralPanel.add(myAdditionalComponent, BorderLayout.SOUTH);
    myAdditionalComponent.add(myButtonPanel, BorderLayout.SOUTH);
    myRootPanel.revalidate();
    myRootPanel.repaint();
}
Also used : EdtExecutorService(com.intellij.util.concurrency.EdtExecutorService) UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) ScheduledFuture(java.util.concurrent.ScheduledFuture) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) Disposer(com.intellij.openapi.util.Disposer) Messages(com.intellij.openapi.ui.Messages) MultiMap(com.intellij.util.containers.MultiMap) TIntArrayList(gnu.trove.TIntArrayList) UsageViewManager(com.intellij.usageView.UsageViewManager) Extensions(com.intellij.openapi.extensions.Extensions) DumbService(com.intellij.openapi.project.DumbService) ReflectionUtil(com.intellij.util.ReflectionUtil) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) com.intellij.ide(com.intellij.ide) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Content(com.intellij.ui.content.Content) ExclusionHandler(com.intellij.ide.actions.exclusion.ExclusionHandler) com.intellij.ui(com.intellij.ui) FindManager(com.intellij.find.FindManager) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) List(java.util.List) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) PsiDocumentManagerBase(com.intellij.psi.impl.PsiDocumentManagerBase) java.awt.event(java.awt.event) ApplicationManager(com.intellij.openapi.application.ApplicationManager) javax.swing.tree(javax.swing.tree) NotNull(org.jetbrains.annotations.NotNull) Factory(com.intellij.openapi.util.Factory) TreeExpansionListener(javax.swing.event.TreeExpansionListener) Consumer(com.intellij.util.Consumer) JBTabbedPane(com.intellij.ui.components.JBTabbedPane) com.intellij.usages.rules(com.intellij.usages.rules) NavigationItem(com.intellij.navigation.NavigationItem) java.util(java.util) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) ReadonlyStatusHandler(com.intellij.openapi.vfs.ReadonlyStatusHandler) NonNls(org.jetbrains.annotations.NonNls) UsageInfo(com.intellij.usageView.UsageInfo) ContainerUtil(com.intellij.util.containers.ContainerUtil) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) EditSourceOnDoubleClickHandler(com.intellij.util.EditSourceOnDoubleClickHandler) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) TreeSelectionListener(javax.swing.event.TreeSelectionListener) Comparing(com.intellij.openapi.util.Comparing) ProgressWrapper(com.intellij.openapi.progress.util.ProgressWrapper) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) Splitter(com.intellij.openapi.ui.Splitter) PsiInvalidElementAccessException(com.intellij.psi.PsiInvalidElementAccessException) TreeUtil(com.intellij.util.ui.tree.TreeUtil) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) BasicTreeUI(javax.swing.plaf.basic.BasicTreeUI) EmptyEnumeration(com.intellij.util.enumeration.EmptyEnumeration) CloseTabToolbarAction(com.intellij.ide.actions.CloseTabToolbarAction) com.intellij.usages(com.intellij.usages) Disposable(com.intellij.openapi.Disposable) SystemInfo(com.intellij.openapi.util.SystemInfo) DialogUtil(com.intellij.util.ui.DialogUtil) SmartPointerManager(com.intellij.psi.SmartPointerManager) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) CommandProcessor(com.intellij.openapi.command.CommandProcessor) TreeUI(javax.swing.plaf.TreeUI) LinkedMultiMap(com.intellij.util.containers.LinkedMultiMap) UsageViewBundle(com.intellij.usageView.UsageViewBundle) Navigatable(com.intellij.pom.Navigatable) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) JBTabbedPane(com.intellij.ui.components.JBTabbedPane) Splitter(com.intellij.openapi.ui.Splitter)

Aggregations

Extensions (com.intellij.openapi.extensions.Extensions)2 Project (com.intellij.openapi.project.Project)2 Comparing (com.intellij.openapi.util.Comparing)2 ContainerUtil (com.intellij.util.containers.ContainerUtil)2 MultiMap (com.intellij.util.containers.MultiMap)2 java.awt (java.awt)2 java.util (java.util)2 List (java.util.List)2 javax.swing (javax.swing)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 com.intellij.codeInsight.daemon (com.intellij.codeInsight.daemon)1 FindManager (com.intellij.find.FindManager)1 AllIcons (com.intellij.icons.AllIcons)1 com.intellij.ide (com.intellij.ide)1 CloseTabToolbarAction (com.intellij.ide.actions.CloseTabToolbarAction)1 ExclusionHandler (com.intellij.ide.actions.exclusion.ExclusionHandler)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 LanguageExtensionPoint (com.intellij.lang.LanguageExtensionPoint)1 NavigationItem (com.intellij.navigation.NavigationItem)1