Search in sources :

Example 1 with MasterDetails

use of com.intellij.openapi.options.MasterDetails in project intellij-community by JetBrains.

the class ConfigurableCardPanel method createConfigurableComponent.

/**
   * Creates UI component for the specified configurable.
   * If a component is created successfully the configurable will be reset.
   * If the configurable implements {@link MasterDetails},
   * created component will not have the following modifications.
   * If the configurable does not implement {@link Configurable.NoMargin},
   * this method sets an empty border with default margins for created component.
   * If the configurable does not implement {@link Configurable.NoScroll},
   * this method adds a scroll bars for created component.
   */
public static JComponent createConfigurableComponent(Configurable configurable) {
    return configurable == null ? null : ApplicationManager.getApplication().runReadAction(new Computable<JComponent>() {

        @Override
        public JComponent compute() {
            JComponent component = null;
            long time = System.currentTimeMillis();
            try {
                component = configurable.createComponent();
            } catch (Exception unexpected) {
                LOG.error("cannot create configurable component", unexpected);
            } finally {
                warn(configurable, "create", time);
            }
            if (component != null) {
                reset(configurable);
                if (ConfigurableWrapper.cast(MasterDetails.class, configurable) == null) {
                    if (ConfigurableWrapper.cast(Configurable.NoMargin.class, configurable) == null) {
                        if (!component.getClass().equals(JPanel.class)) {
                            // some custom components do not support borders
                            JPanel panel = new JPanel(new BorderLayout());
                            panel.add(BorderLayout.CENTER, component);
                            component = panel;
                        }
                        component.setBorder(JBUI.Borders.empty(5, 10, 10, 10));
                    }
                    if (ConfigurableWrapper.cast(Configurable.NoScroll.class, configurable) == null) {
                        JScrollPane scroll = ScrollPaneFactory.createScrollPane(null, true);
                        scroll.setViewport(new GradientViewport(component, JBUI.insetsTop(5), true));
                        component = scroll;
                    }
                }
            }
            return component;
        }
    });
}
Also used : MasterDetails(com.intellij.openapi.options.MasterDetails) BorderLayout(java.awt.BorderLayout) Computable(com.intellij.openapi.util.Computable) GradientViewport(com.intellij.ui.components.GradientViewport)

Example 2 with MasterDetails

use of com.intellij.openapi.options.MasterDetails in project intellij-community by JetBrains.

the class SearchUtil method processConfigurables.

private static void processConfigurables(Configurable[] configurables, Map<SearchableConfigurable, Set<OptionDescription>> options) {
    for (Configurable configurable : configurables) {
        if (configurable instanceof SearchableConfigurable) {
            //ignore invisible root nodes
            if (configurable instanceof SearchableConfigurable.Parent && !((SearchableConfigurable.Parent) configurable).isVisible()) {
                continue;
            }
            Set<OptionDescription> configurableOptions = new TreeSet<>();
            options.put((SearchableConfigurable) configurable, configurableOptions);
            if (configurable instanceof MasterDetails) {
                final MasterDetails md = (MasterDetails) configurable;
                md.initUi();
                processComponent(configurable, configurableOptions, md.getMaster());
                processComponent(configurable, configurableOptions, md.getDetails().getComponent());
            } else {
                processComponent(configurable, configurableOptions, configurable.createComponent());
            }
        }
    }
}
Also used : MasterDetails(com.intellij.openapi.options.MasterDetails) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) Configurable(com.intellij.openapi.options.Configurable) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable)

Aggregations

MasterDetails (com.intellij.openapi.options.MasterDetails)2 Configurable (com.intellij.openapi.options.Configurable)1 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)1 Computable (com.intellij.openapi.util.Computable)1 GradientViewport (com.intellij.ui.components.GradientViewport)1 BorderLayout (java.awt.BorderLayout)1