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;
}
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();
}
Aggregations