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