private static int lastIndexOfProperItemIn(LibraryDescriptor[] descriptors) {
   int result = -1;
   for (LibraryDescriptor descriptor : descriptors) {
     if (descriptor.data().get().problem().isDefined()) break;
     result++;
   }
   return result;
 }
 public LibraryDescriptor findLibraryDescriptorFor(LibraryId id) {
   DefaultComboBoxModel model = (DefaultComboBoxModel) myCompilerLibrary.getModel();
   for (int i = 0; i < model.getSize(); i++) {
     LibraryDescriptor entry = (LibraryDescriptor) model.getElementAt(i);
     if (entry != null && entry.id().equals(id)) {
       return entry;
     }
   }
   return null;
 }
  private static ValidationResult checkCompilerLibrary(LibraryDescriptor descriptor) {
    if (descriptor == null || descriptor.data().isEmpty()) return ValidationResult.OK;

    String libraryName = "Compiler library";

    CompilerLibraryData compilerLibraryData = (CompilerLibraryData) descriptor.data().get();

    Option<String> compilerLibraryProblem = compilerLibraryData.problem();

    if (compilerLibraryProblem.isDefined())
      return new ValidationResult(libraryName + ": " + compilerLibraryProblem.get());

    return ValidationResult.OK;
  }
  private void updateLibrariesList() {
    LibraryId id = getCompilerLibraryId();

    LibraryDescriptor[] items =
        (LibraryDescriptor[]) LibraryDescriptor.compilersFor(myEditorContext.getProject());
    DefaultComboBoxModel model = new DefaultComboBoxModel(items);
    model.insertElementAt(null, 0);
    myCompilerLibrary.setModel(model);
    myLibraryRenderer.setPrefixLength(lastIndexOfProperItemIn(items) + 1);

    setCompilerLibraryById(id);
  }
 public void setCompilerLibraryById(LibraryId id) {
   if (id.isEmpty()) {
     //      myCompilerLibrary.addItem(null);
     myCompilerLibrary.setSelectedItem(null);
   } else {
     LibraryDescriptor descriptor = findLibraryDescriptorFor(id);
     if (descriptor == null) {
       LibraryDescriptor newId = LibraryDescriptor.createFor(id);
       myCompilerLibrary.addItem(newId);
       myCompilerLibrary.setSelectedItem(newId);
     } else {
       myCompilerLibrary.setSelectedItem(descriptor);
     }
   }
 }
 private LibraryId getCompilerLibraryId() {
   LibraryDescriptor descriptor = (LibraryDescriptor) myCompilerLibrary.getSelectedItem();
   return descriptor == null ? LibraryId.empty() : descriptor.id();
 }