Search in sources :

Example 1 with HideableDecorator

use of com.intellij.ui.HideableDecorator in project android by JetBrains.

the class TreeGrid method setModel.

private void setModel(@NotNull AbstractTreeStructure model, boolean showSectionHeaders) {
    // using the AbstractTreeStructure instead of the model as the actual TreeModel when used with IJ components
    // works in a very strange way, each time you expand or contract a node it will add or remove all its children.
    Object root = model.getRootElement();
    Object[] sections = model.getChildElements(root);
    mySectionToComponent.clear();
    myLists.clear();
    myHideables.clear();
    removeAll();
    setAutoscrolls(false);
    ListSelectionListener listSelectionListener = e -> {
        if (e.getValueIsAdjusting()) {
            return;
        }
        ListSelectionModel sourceSelectionModel = (ListSelectionModel) e.getSource();
        if (!sourceSelectionModel.isSelectionEmpty()) {
            for (JList<T> aList : myLists) {
                if (sourceSelectionModel != aList.getSelectionModel()) {
                    aList.clearSelection();
                }
            }
        }
    };
    for (Object section : sections) {
        String name = section.toString();
        FilteringListModel<T> listModel = new FilteringListModel<>(new AbstractListModel() {

            @Override
            public int getSize() {
                return model.getChildElements(section).length;
            }

            @Override
            public Object getElementAt(int index) {
                return model.getChildElements(section)[index];
            }
        });
        // Needed as otherwise the filtered list does not show any content.
        listModel.refilter();
        // JBList does not work with HORIZONTAL_WRAP
        //noinspection UndesirableClassUsage,unchecked
        JList<T> list = new JList<>(listModel);
        list.setAutoscrolls(false);
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list.setVisibleRowCount(-1);
        list.getSelectionModel().addListSelectionListener(listSelectionListener);
        // for tests to find the right list
        list.setName(name);
        list.addKeyListener(myKeyListener);
        new ListSpeedSearch(list);
        myLists.add(list);
        if (showSectionHeaders) {
            JPanel panel = new // must be BorderLayout for HideableDecorator to work
            JPanel(// must be BorderLayout for HideableDecorator to work
            new BorderLayout()) {

                @Override
                public Dimension getMaximumSize() {
                    return new Dimension(super.getMaximumSize().width, super.getPreferredSize().height);
                }
            };
            HideableDecorator hidyPanel = new HideableDecorator(panel, name, false);
            myHideables.add(hidyPanel);
            hidyPanel.setContentComponent(list);
            add(panel);
            mySectionToComponent.put(section, panel);
        } else {
            if (getComponentCount() > 0) {
                add(new JSeparator());
            }
            list.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
            add(list);
            mySectionToComponent.put(section, list);
        }
    }
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) KeyListener(java.awt.event.KeyListener) IdentityHashMap(java.util.IdentityHashMap) ModalityState(com.intellij.openapi.application.ModalityState) ContainerUtil(com.intellij.util.containers.ContainerUtil) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) ArrayList(java.util.ArrayList) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Map(java.util.Map) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure) ApplicationManager(com.intellij.openapi.application.ApplicationManager) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) NotNull(org.jetbrains.annotations.NotNull) ListSelectionListener(javax.swing.event.ListSelectionListener) MouseListener(java.awt.event.MouseListener) Condition(com.intellij.openapi.util.Condition) HideableDecorator(com.intellij.ui.HideableDecorator) ListSpeedSearch(com.intellij.ui.ListSpeedSearch) javax.swing(javax.swing) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) HideableDecorator(com.intellij.ui.HideableDecorator) ListSelectionListener(javax.swing.event.ListSelectionListener) ListSpeedSearch(com.intellij.ui.ListSpeedSearch)

Example 2 with HideableDecorator

use of com.intellij.ui.HideableDecorator in project azure-tools-for-java by Microsoft.

the class IntellijErrorDialog method init.

@Override
protected void init() {
    super.init();
    this.iconLabel.setIcon(Messages.getErrorIcon());
    this.contentPane.setText(message.getContent());
    this.contentPane.setBackground(JBColor.WHITE);
    this.contentPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
    this.contentPane.addHyperlinkListener(e -> {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            BrowserUtil.browse(e.getURL());
        }
    });
    final String details = message.getDetails();
    if (StringUtils.isNotBlank(details)) {
        final HideableDecorator slotDecorator = new HideableDecorator(detailsContainer, "&Call Stack", false);
        slotDecorator.setContentComponent(detailsScrollPane);
        slotDecorator.setOn(false);
        this.detailsPane.setText(details);
        this.detailsPane.setBackground(JBColor.WHITE);
        this.detailsPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
    } else {
        this.detailsContainer.setVisible(false);
    }
}
Also used : HideableDecorator(com.intellij.ui.HideableDecorator)

Example 3 with HideableDecorator

use of com.intellij.ui.HideableDecorator in project intellij-community by JetBrains.

the class ProjectSpecificSettingsStep method createAdvancedSettings.

@Override
@Nullable
protected JPanel createAdvancedSettings() {
    JComponent advancedSettings = null;
    if (myProjectGenerator instanceof PythonProjectGenerator) {
        advancedSettings = ((PythonProjectGenerator) myProjectGenerator).getSettingsPanel(myProjectDirectory);
    } else if (myProjectGenerator instanceof WebProjectTemplate) {
        advancedSettings = ((WebProjectTemplate) myProjectGenerator).getPeer().getComponent();
    }
    if (advancedSettings != null) {
        final JPanel jPanel = new JPanel(new VerticalFlowLayout());
        final HideableDecorator deco = new HideableDecorator(jPanel, "Mor&e Settings", false);
        boolean isValid = checkValid();
        deco.setOn(!isValid);
        if (myProjectGenerator instanceof PythonProjectGenerator && !deco.isExpanded()) {
            final ValidationResult result = ((PythonProjectGenerator) myProjectGenerator).warningValidation(getSdk());
            deco.setOn(!result.isOk());
        }
        deco.setContentComponent(advancedSettings);
        return jPanel;
    }
    return null;
}
Also used : PythonProjectGenerator(com.jetbrains.python.newProject.PythonProjectGenerator) WebProjectTemplate(com.intellij.ide.util.projectWizard.WebProjectTemplate) HideableDecorator(com.intellij.ui.HideableDecorator) ValidationResult(com.intellij.facet.ui.ValidationResult) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with HideableDecorator

use of com.intellij.ui.HideableDecorator in project ballerina by ballerina-lang.

the class BallerinaLibrariesConfigurableProvider method createConfigurable.

@Nullable
private Configurable createConfigurable(boolean dialogMode) {
    return new CompositeConfigurable<UnnamedConfigurable>() {

        @Nullable
        @Override
        public JComponent createComponent() {
            List<UnnamedConfigurable> configurables = getConfigurables();
            Collection<HideableDecorator> hideableDecorators = ContainerUtil.newHashSet();
            GridLayoutManager layoutManager = new GridLayoutManager(configurables.size() + 1, 1, new Insets(0, 0, 0, 0), -1, -1);
            JPanel rootPanel = new JPanel(layoutManager);
            Spacer spacer = new Spacer();
            rootPanel.add(spacer, new GridConstraints(configurables.size(), 0, 1, 1, GridConstraints.ANCHOR_SOUTH, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
            for (int i = 0; i < configurables.size(); i++) {
                UnnamedConfigurable configurable = configurables.get(i);
                JComponent configurableComponent = configurable.createComponent();
                assert configurableComponent != null;
                JPanel hideablePanel = new JPanel(new BorderLayout());
                rootPanel.add(hideablePanel, configurableConstrains(i));
                if (configurable instanceof Configurable) {
                    String displayName = ((Configurable) configurable).getDisplayName();
                    ListenableHideableDecorator decorator = new ListenableHideableDecorator(hideablePanel, displayName, configurableComponent);
                    decorator.addListener(new MyHideableDecoratorListener(layoutManager, hideablePanel, spacer, hideableDecorators, configurableExpandedPropertyKey((Configurable) configurable)));
                    hideableDecorators.add(decorator);
                    decorator.setOn(isConfigurableExpanded(i, (Configurable) configurable));
                }
            }
            if (dialogMode) {
                rootPanel.setPreferredSize(new Dimension(400, 600));
            }
            rootPanel.revalidate();
            return rootPanel;
        }

        @NotNull
        @Override
        protected List<UnnamedConfigurable> createConfigurables() {
            List<UnnamedConfigurable> result = ContainerUtil.newArrayList();
            String[] urlsFromEnv = ContainerUtil.map2Array(BallerinaSdkUtil.getBallerinaPathsRootsFromEnvironment(), String.class, VirtualFile::getUrl);
            result.add(new BallerinaLibrariesConfigurable("Global libraries", BallerinaApplicationLibrariesService.getInstance(), urlsFromEnv));
            if (!myProject.isDefault()) {
                result.add(new BallerinaLibrariesConfigurable("Project libraries", BallerinaProjectLibrariesService.getInstance(myProject)));
            }
            return result;
        }

        @NotNull
        @Nls
        @Override
        public String getDisplayName() {
            return "Ballerina Libraries";
        }

        @Nullable
        @Override
        public String getHelpTopic() {
            return null;
        }

        @NotNull
        private GridConstraints configurableConstrains(int i) {
            return new GridConstraints(i, 0, 1, 1, GridConstraints.ANCHOR_NORTHEAST, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null);
        }

        private boolean isConfigurableExpanded(int index, @NotNull Configurable configurable) {
            return PropertiesComponent.getInstance(myProject).getBoolean(configurableExpandedPropertyKey(configurable), index < 2);
        }

        private void storeConfigurableExpandedProperty(@NotNull String storeKey, @NotNull Boolean value) {
            PropertiesComponent.getInstance(myProject).setValue(storeKey, value.toString());
        }

        private String configurableExpandedPropertyKey(@NotNull Configurable configurable) {
            String keyName = "configurable " + configurable.getDisplayName() + " is expanded".toLowerCase(Locale.US);
            return StringUtil.replaceChar(keyName, ' ', '.');
        }

        class MyHideableDecoratorListener extends ListenableHideableDecorator.MyListener {

            private final GridLayoutManager myLayoutManager;

            private final JPanel myHideablePanel;

            @NotNull
            private final String myStoreKey;

            private final Spacer mySpacer;

            private final Collection<HideableDecorator> myHideableDecorators;

            public MyHideableDecoratorListener(@NotNull GridLayoutManager layoutManager, @NotNull JPanel hideablePanel, @NotNull Spacer spacer, @NotNull Collection<HideableDecorator> hideableDecorators, @NotNull String storeKey) {
                myLayoutManager = layoutManager;
                myHideablePanel = hideablePanel;
                myStoreKey = storeKey;
                mySpacer = spacer;
                myHideableDecorators = hideableDecorators;
            }

            @Override
            public void on() {
                GridConstraints c = myLayoutManager.getConstraintsForComponent(myHideablePanel);
                c.setVSizePolicy(c.getVSizePolicy() | GridConstraints.SIZEPOLICY_WANT_GROW);
                GridConstraints spacerConstraints = myLayoutManager.getConstraintsForComponent(mySpacer);
                spacerConstraints.setVSizePolicy(spacerConstraints.getVSizePolicy() & ~GridConstraints.SIZEPOLICY_WANT_GROW);
                storeConfigurableExpandedProperty(myStoreKey, Boolean.TRUE);
            }

            @Override
            public void beforeOff() {
                GridConstraints c = myLayoutManager.getConstraintsForComponent(myHideablePanel);
                c.setVSizePolicy(c.getVSizePolicy() & ~GridConstraints.SIZEPOLICY_WANT_GROW);
            }

            @Override
            public void afterOff() {
                if (isAllDecoratorsCollapsed()) {
                    GridConstraints c = myLayoutManager.getConstraintsForComponent(mySpacer);
                    c.setVSizePolicy(c.getVSizePolicy() | GridConstraints.SIZEPOLICY_WANT_GROW);
                }
                storeConfigurableExpandedProperty(myStoreKey, Boolean.FALSE);
            }

            private boolean isAllDecoratorsCollapsed() {
                for (HideableDecorator hideableDecorator : myHideableDecorators) {
                    if (hideableDecorator.isExpanded()) {
                        return false;
                    }
                }
                return true;
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JPanel(javax.swing.JPanel) CompositeConfigurable(com.intellij.openapi.options.CompositeConfigurable) Insets(java.awt.Insets) HideableDecorator(com.intellij.ui.HideableDecorator) JComponent(javax.swing.JComponent) UnnamedConfigurable(com.intellij.openapi.options.UnnamedConfigurable) CompositeConfigurable(com.intellij.openapi.options.CompositeConfigurable) UnnamedConfigurable(com.intellij.openapi.options.UnnamedConfigurable) Configurable(com.intellij.openapi.options.Configurable) Dimension(java.awt.Dimension) NotNull(org.jetbrains.annotations.NotNull) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) BorderLayout(java.awt.BorderLayout) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) Spacer(com.intellij.uiDesigner.core.Spacer) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with HideableDecorator

use of com.intellij.ui.HideableDecorator in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoLibrariesConfigurableProvider method createConfigurable.

@Nullable
private Configurable createConfigurable(boolean dialogMode) {
    return new CompositeConfigurable<UnnamedConfigurable>() {

        @Nullable
        @Override
        public JComponent createComponent() {
            List<UnnamedConfigurable> configurables = getConfigurables();
            Collection<HideableDecorator> hideableDecorators = ContainerUtil.newHashSet();
            GridLayoutManager layoutManager = new GridLayoutManager(configurables.size() + 1, 1, new Insets(0, 0, 0, 0), -1, -1);
            JPanel rootPanel = new JPanel(layoutManager);
            Spacer spacer = new Spacer();
            rootPanel.add(spacer, new GridConstraints(configurables.size(), 0, 1, 1, GridConstraints.ANCHOR_SOUTH, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
            for (int i = 0; i < configurables.size(); i++) {
                UnnamedConfigurable configurable = configurables.get(i);
                JComponent configurableComponent = configurable.createComponent();
                assert configurableComponent != null;
                JPanel hideablePanel = new JPanel(new BorderLayout());
                rootPanel.add(hideablePanel, configurableConstrains(i));
                if (configurable instanceof Configurable) {
                    String displayName = ((Configurable) configurable).getDisplayName();
                    ListenableHideableDecorator decorator = new ListenableHideableDecorator(hideablePanel, displayName, configurableComponent);
                    decorator.addListener(new MyHideableDecoratorListener(layoutManager, hideablePanel, spacer, hideableDecorators, configurableExpandedPropertyKey((Configurable) configurable)));
                    hideableDecorators.add(decorator);
                    decorator.setOn(isConfigurableExpanded(i, (Configurable) configurable));
                }
            }
            if (dialogMode) {
                rootPanel.setPreferredSize(new Dimension(400, 600));
            }
            rootPanel.revalidate();
            return rootPanel;
        }

        @NotNull
        @Override
        protected List<UnnamedConfigurable> createConfigurables() {
            List<UnnamedConfigurable> result = ContainerUtil.newArrayList();
            String[] urlsFromEnv = ContainerUtil.map2Array(GoSdkUtil.getGoPathsRootsFromEnvironment(), String.class, VirtualFile::getUrl);
            result.add(new GoLibrariesConfigurable("Global libraries", GoApplicationLibrariesService.getInstance(), urlsFromEnv));
            if (!myProject.isDefault()) {
                result.add(new GoLibrariesConfigurable("Project libraries", GoProjectLibrariesService.getInstance(myProject)));
                result.add(new GoModuleAwareConfigurable(myProject, "Module libraries", null) {

                    @NotNull
                    @Override
                    protected UnnamedConfigurable createModuleConfigurable(@NotNull Module module) {
                        return new GoLibrariesConfigurable("Module libraries", GoModuleLibrariesService.getInstance(module));
                    }
                });
            }
            return result;
        }

        @NotNull
        @Nls
        @Override
        public String getDisplayName() {
            return "Go Libraries";
        }

        @Nullable
        @Override
        public String getHelpTopic() {
            return null;
        }

        @NotNull
        private GridConstraints configurableConstrains(int i) {
            return new GridConstraints(i, 0, 1, 1, GridConstraints.ANCHOR_NORTHEAST, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null);
        }

        private boolean isConfigurableExpanded(int index, @NotNull Configurable configurable) {
            return PropertiesComponent.getInstance(myProject).getBoolean(configurableExpandedPropertyKey(configurable), index < 2);
        }

        private void storeConfigurableExpandedProperty(@NotNull String storeKey, @NotNull Boolean value) {
            PropertiesComponent.getInstance(myProject).setValue(storeKey, value.toString());
        }

        private String configurableExpandedPropertyKey(@NotNull Configurable configurable) {
            String keyName = "configurable " + configurable.getDisplayName() + " is expanded".toLowerCase(Locale.US);
            return StringUtil.replaceChar(keyName, ' ', '.');
        }

        class MyHideableDecoratorListener extends ListenableHideableDecorator.MyListener {

            private final GridLayoutManager myLayoutManager;

            private final JPanel myHideablePanel;

            @NotNull
            private final String myStoreKey;

            private final Spacer mySpacer;

            private final Collection<HideableDecorator> myHideableDecorators;

            public MyHideableDecoratorListener(@NotNull GridLayoutManager layoutManager, @NotNull JPanel hideablePanel, @NotNull Spacer spacer, @NotNull Collection<HideableDecorator> hideableDecorators, @NotNull String storeKey) {
                myLayoutManager = layoutManager;
                myHideablePanel = hideablePanel;
                myStoreKey = storeKey;
                mySpacer = spacer;
                myHideableDecorators = hideableDecorators;
            }

            @Override
            public void on() {
                GridConstraints c = myLayoutManager.getConstraintsForComponent(myHideablePanel);
                c.setVSizePolicy(c.getVSizePolicy() | GridConstraints.SIZEPOLICY_WANT_GROW);
                GridConstraints spacerConstraints = myLayoutManager.getConstraintsForComponent(mySpacer);
                spacerConstraints.setVSizePolicy(spacerConstraints.getVSizePolicy() & ~GridConstraints.SIZEPOLICY_WANT_GROW);
                storeConfigurableExpandedProperty(myStoreKey, Boolean.TRUE);
            }

            @Override
            public void beforeOff() {
                GridConstraints c = myLayoutManager.getConstraintsForComponent(myHideablePanel);
                c.setVSizePolicy(c.getVSizePolicy() & ~GridConstraints.SIZEPOLICY_WANT_GROW);
            }

            @Override
            public void afterOff() {
                if (isAllDecoratorsCollapsed()) {
                    GridConstraints c = myLayoutManager.getConstraintsForComponent(mySpacer);
                    c.setVSizePolicy(c.getVSizePolicy() | GridConstraints.SIZEPOLICY_WANT_GROW);
                }
                storeConfigurableExpandedProperty(myStoreKey, Boolean.FALSE);
            }

            private boolean isAllDecoratorsCollapsed() {
                for (HideableDecorator hideableDecorator : myHideableDecorators) {
                    if (hideableDecorator.isExpanded()) {
                        return false;
                    }
                }
                return true;
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HideableDecorator(com.intellij.ui.HideableDecorator) NotNull(org.jetbrains.annotations.NotNull) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) Spacer(com.intellij.uiDesigner.core.Spacer) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

HideableDecorator (com.intellij.ui.HideableDecorator)5 Nullable (org.jetbrains.annotations.Nullable)4 NotNull (org.jetbrains.annotations.NotNull)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)2 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)2 Spacer (com.intellij.uiDesigner.core.Spacer)2 ValidationResult (com.intellij.facet.ui.ValidationResult)1 WebProjectTemplate (com.intellij.ide.util.projectWizard.WebProjectTemplate)1 AbstractTreeStructure (com.intellij.ide.util.treeView.AbstractTreeStructure)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModalityState (com.intellij.openapi.application.ModalityState)1 Module (com.intellij.openapi.module.Module)1 CompositeConfigurable (com.intellij.openapi.options.CompositeConfigurable)1 Configurable (com.intellij.openapi.options.Configurable)1 UnnamedConfigurable (com.intellij.openapi.options.UnnamedConfigurable)1 Condition (com.intellij.openapi.util.Condition)1 ListSpeedSearch (com.intellij.ui.ListSpeedSearch)1 FilteringListModel (com.intellij.ui.speedSearch.FilteringListModel)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1