Search in sources :

Example 1 with ColoredListCellRendererWrapper

use of com.intellij.ui.ColoredListCellRendererWrapper in project intellij-plugins by JetBrains.

the class BCCombo method initCombo.

private void initCombo() {
    setMinimumSize(new Dimension(150, getMinimumSize().height));
    final Collection<FlexBuildConfiguration> allConfigs = new ArrayList<>();
    final Module[] modules = ModuleManager.getInstance(myProject).getModules();
    mySingleModuleProject = modules.length == 1;
    for (final Module module : modules) {
        if (ModuleType.get(module) instanceof FlexModuleType) {
            for (final FlexBuildConfiguration config : FlexBuildConfigurationManager.getInstance(module).getBuildConfigurations()) {
                allConfigs.add(config);
                myBCToModuleMap.put(config, module);
            }
        }
    }
    myAllConfigs = allConfigs.toArray(new FlexBuildConfiguration[allConfigs.size()]);
    setRenderer(new ColoredListCellRendererWrapper() {

        @Override
        protected void doCustomize(final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) {
            if (value instanceof Pair) {
                final String moduleName = (String) ((Pair) value).first;
                final String configName = (String) ((Pair) value).second;
                //setIcon(PlatformIcons.ERROR_INTRODUCTION_ICON);
                if (moduleName.isEmpty() || configName.isEmpty()) {
                    append(new SimpleColoredText("[none]", SimpleTextAttributes.ERROR_ATTRIBUTES));
                } else {
                    append(BCUtils.renderMissingBuildConfiguration(configName, moduleName));
                }
            } else {
                assert value instanceof FlexBuildConfiguration : value;
                final FlexBuildConfiguration bc = (FlexBuildConfiguration) value;
                setIcon(bc.getIcon());
                append(BCUtils.renderBuildConfiguration(bc, mySingleModuleProject ? null : myBCToModuleMap.get(bc).getName()));
            }
        }
    });
    addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            // remove invalid entry
            final Object selectedItem = getSelectedItem();
            final Object firstItem = getItemAt(0);
            if (selectedItem instanceof FlexBuildConfiguration && !(firstItem instanceof FlexBuildConfiguration)) {
                setModel(new DefaultComboBoxModel(myAllConfigs));
                setSelectedItem(selectedItem);
            }
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) SimpleColoredText(com.intellij.ui.SimpleColoredText) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) ActionListener(java.awt.event.ActionListener) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) Module(com.intellij.openapi.module.Module) ColoredListCellRendererWrapper(com.intellij.ui.ColoredListCellRendererWrapper) Pair(com.intellij.openapi.util.Pair)

Aggregations

FlexModuleType (com.intellij.lang.javascript.flex.FlexModuleType)1 FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)1 Module (com.intellij.openapi.module.Module)1 Pair (com.intellij.openapi.util.Pair)1 ColoredListCellRendererWrapper (com.intellij.ui.ColoredListCellRendererWrapper)1 SimpleColoredText (com.intellij.ui.SimpleColoredText)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1