Search in sources :

Example 1 with RadioButtonEnumModel

use of com.intellij.util.ui.RadioButtonEnumModel in project kotlin by JetBrains.

the class KotlinModuleSettingStep method isLibrarySelected.

private Boolean isLibrarySelected() {
    try {
        // TODO: Get rid of this hack
        LibraryOptionsPanel panel = getLibraryPanel();
        Class<LibraryOptionsPanel> panelClass = LibraryOptionsPanel.class;
        Field modelField = ArraysKt.singleOrNull(panelClass.getDeclaredFields(), new Function1<Field, Boolean>() {

            @Override
            public Boolean invoke(Field field) {
                return RadioButtonEnumModel.class.isAssignableFrom(field.getType());
            }
        });
        if (modelField == null) {
            LOG.error("There must be exactly one field of type RadioButtonEnumModel: " + Arrays.toString(panelClass.getDeclaredFields()));
            return false;
        }
        modelField.setAccessible(true);
        RadioButtonEnumModel enumModel = (RadioButtonEnumModel) modelField.get(panel);
        int ordinal = enumModel.getSelected().ordinal();
        if (ordinal == 0) {
            Field libComboboxField = ArraysKt.singleOrNull(panelClass.getDeclaredFields(), new Function1<Field, Boolean>() {

                @Override
                public Boolean invoke(Field field) {
                    return JComboBox.class.isAssignableFrom(field.getType());
                }
            });
            if (libComboboxField == null) {
                LOG.error("There must be exactly one field of type JComboBox: " + Arrays.toString(panelClass.getDeclaredFields()));
                return false;
            }
            libComboboxField.setAccessible(true);
            JComboBox combobox = (JComboBox) libComboboxField.get(panel);
            return combobox.getSelectedItem() != null;
        }
        return ordinal != 2;
    } catch (Exception e) {
        LOG.warn("Error in reflection", e);
    }
    return null;
}
Also used : Field(java.lang.reflect.Field) RadioButtonEnumModel(com.intellij.util.ui.RadioButtonEnumModel) LibraryOptionsPanel(com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel) ConfigurationException(com.intellij.openapi.options.ConfigurationException)

Aggregations

LibraryOptionsPanel (com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 RadioButtonEnumModel (com.intellij.util.ui.RadioButtonEnumModel)1 Field (java.lang.reflect.Field)1