com.intellij.ui.SortedComboBoxModel Java Examples

The following examples show how to use com.intellij.ui.SortedComboBoxModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModuleDescriptionsComboBox.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ModuleDescriptionsComboBox() {
  myModel = new SortedComboBoxModel<>(Comparator.comparing(description -> description != null ? description.getName() : "", String.CASE_INSENSITIVE_ORDER));
  setModel(myModel);
  new ComboboxSpeedSearch(this) {
    @Override
    protected String getElementText(Object element) {
      if (element instanceof ModuleDescription) {
        return ((ModuleDescription)element).getName();
      }
      else {
        return "";
      }
    }
  };
  setRenderer(new ModuleDescriptionListCellRenderer());
}
 
Example #2
Source File: ModulesComboBox.java    From consulo with Apache License 2.0 6 votes vote down vote up
private ModulesComboBox(final SortedComboBoxModel<Module> model) {
  super(model);
  myModel = model;
  new ComboboxSpeedSearch(this){
    @Override
    protected String getElementText(Object element) {
      if (element instanceof Module) {
        return ((Module)element).getName();
      } else if (element == null) {
        return "";
      }
      return super.getElementText(element);
    }
  };
  setRenderer(new ModuleListCellRenderer());
}
 
Example #3
Source File: ConfigurationModuleSelector.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
public ConfigurationModuleSelector(final Project project, final JComboBox<Module> modulesList, final String noModule) {
    myProject = project;
    myModulesList = modulesList;
    new ComboboxSpeedSearch(modulesList) {
        protected String getElementText(Object element) {
            if (element instanceof Module) {
                return ((Module) element).getName();
            } else if (element == null) {
                return noModule;
            }
            return super.getElementText(element);
        }
    };
    myModulesList.setModel(new SortedComboBoxModel<>(ModulesAlphaComparator.INSTANCE));
    myModulesList.setRenderer(new ModuleListCellRenderer(noModule));
}
 
Example #4
Source File: ProjectSettingsForm.java    From EclipseCodeFormatter with Apache License 2.0 6 votes vote down vote up
private SortedComboBoxModel createProfilesModel() {
	// noinspection unchecked
	SortedComboBoxModel settingsSortedComboBoxModel = new SortedComboBoxModel(new Comparator<Settings>() {
		@Override
		public int compare(Settings o1, Settings o2) {
			if (o1.isProjectSpecific()) {
				return -1;
			}
			if (o2.isProjectSpecific()) {
				return 1;
			}
			return o1.getName().compareTo(o2.getName());
		}
	});
	refreshProfilesModel(settingsSortedComboBoxModel);
	return settingsSortedComboBoxModel;
}
 
Example #5
Source File: ConfigFileLocator.java    From EclipseCodeFormatter with Apache License 2.0 6 votes vote down vote up
private void processWorkspaceConfig(SortedComboBoxModel profilesModel, JComboBox comboBox, File uiPrefs) throws IOException {
	Properties properties = FileUtils.readPropertiesFile(uiPrefs);
	String xml = properties.getProperty("org.eclipse.jdt.ui.formatterprofiles");
	List<String> profileNamesFromConfigXML = FileUtils.getProfileNamesFromConfigXML(IOUtils.toInputStream(xml));


	if (profileNamesFromConfigXML.isEmpty()) {
		invalid("Workspace does not contain custom formatter profiles!", profilesModel, comboBox);
	} else {
		profilesModel.addAll(profileNamesFromConfigXML);

		String formatter_profile1 = properties.getProperty("formatter_profile");
		String substring = formatter_profile1.substring(1);
		if (new HashSet<>(profileNamesFromConfigXML).contains(substring)) {
			profilesModel.setSelectedItem(substring);
		}
	}
}
 
Example #6
Source File: CreatePullRequestModel.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
private ComboBoxModel createRemoteBranchDropdownModel() {
    final SortedComboBoxModel<GitRemoteBranch> sortedRemoteBranches
            = new SortedComboBoxModel<GitRemoteBranch>(new TfGitHelper.BranchComparator());
    final GitRemoteBranch remoteTrackingBranch = this.getRemoteTrackingBranch();

    // only show valid remote branches
    sortedRemoteBranches.addAll(Collections2.filter(getInfo().getRemoteBranches(),
            remoteBranch -> {
                /* two conditions:
                 *   1. remote must be a vso/tfs remote
                 *   2. this isn't the remote tracking branch of current local branch
                 */
                return tfGitRemotes.contains(remoteBranch.getRemote())
                        && !remoteBranch.equals(remoteTrackingBranch);
            })
    );
    sortedRemoteBranches.setSelectedItem(TfGitHelper.getDefaultBranch(sortedRemoteBranches.getItems(), tfGitRemotes));

    return sortedRemoteBranches;
}
 
Example #7
Source File: ConfigFileLocator.java    From EclipseCodeFormatter with Apache License 2.0 5 votes vote down vote up
public void validate(ProjectSettingsForm projectSettingsForm,
					 SortedComboBoxModel profilesModel, String path) {
	String text = path;
	File file = new File(text);
	String lowerCaseName = file.getName().toLowerCase();
	JComboBox comboBox = projectSettingsForm.javaFormatterProfile;
	comboBox.setEnabled(true);
	comboBox.setBorder(projectSettingsForm.normalBorder);

	try {
		if (!file.exists()) {
			invalid(ProjectSettingsForm.NOT_EXISTS, profilesModel, comboBox);
		}
		if (file.isDirectory()) {
			file = resolve(file);
			if (file == null) {
				invalid("invalid location", profilesModel, comboBox);
			}
		}

		if (lowerCaseName.equals(".org.eclipse.jdt.ui.prefs")) {
			processWorkspaceConfig(profilesModel, comboBox, file);
		} else if (lowerCaseName.endsWith(".prefs")) {
			processPrefs(projectSettingsForm, profilesModel, comboBox, file);
		} else if (lowerCaseName.endsWith(".epf")) {
			processEPF(projectSettingsForm, profilesModel, file, comboBox);
		} else if (lowerCaseName.endsWith(".xml")) {
			processXml(profilesModel, file, comboBox);
		} else {
			//lets assume it is properties
			processPrefs(projectSettingsForm, profilesModel, comboBox, file);
		}
	} catch (IOException e) {
		invalid("Plugin error:" + e.toString(), profilesModel, comboBox);
		throw new RuntimeException(e);
	}

}
 
Example #8
Source File: LocalToServerSettingsEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public LocalToServerSettingsEditor(final ServerType<S> type, DeploymentConfigurator<D> deploymentConfigurator, Project project) {
  myServerType = type;
  myDeploymentConfigurator = deploymentConfigurator;
  myProject = project;

   mySourceListModel = new SortedComboBoxModel<DeploymentSource>(new Comparator<DeploymentSource>() {
    @Override
    public int compare(DeploymentSource o1, DeploymentSource o2) {
      return o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName());
    }
  });
  mySourceListModel.addAll(deploymentConfigurator.getAvailableDeploymentSources());
  mySourceComboBox = new ComboBox(mySourceListModel);
  mySourceComboBox.setRenderer(new ColoredListCellRenderer<DeploymentSource>() {
    @Override
    protected void customizeCellRenderer(@Nonnull JList list, DeploymentSource value, int index, boolean selected, boolean hasFocus) {
      if (value == null) return;
      setIcon(value.getIcon());
      append(value.getPresentableName());
    }
  });

  myDeploymentSettingsComponent = new JPanel(new BorderLayout());
  mySourceComboBox.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      onDeploymentSourceChanged(null);
    }
  });
}
 
Example #9
Source File: ConfigFileLocator.java    From EclipseCodeFormatter with Apache License 2.0 5 votes vote down vote up
private void processPrefs(ProjectSettingsForm projectSettingsForm, SortedComboBoxModel profilesModel, JComboBox comboBox, File file) {
	if (isValidCorePrefs(file)) {
		valid("valid config", projectSettingsForm, profilesModel, comboBox);
	} else {
		invalid("Enable 'Project Specific Settings' in Eclipse!", profilesModel, comboBox);
	}
}
 
Example #10
Source File: ConfigFileLocator.java    From EclipseCodeFormatter with Apache License 2.0 5 votes vote down vote up
private void processXml(SortedComboBoxModel profilesModel, File file, JComboBox comboBox) {
	try {
		profilesModel.addAll(FileUtils.getProfileNamesFromConfigXML(file));
		if (profilesModel.getSize() == 0) {
			invalid(ProjectSettingsForm.CONTAINS_NO_PROFILES, profilesModel, comboBox);
		}
	} catch (ParsingFailedException e) {
		invalid(ProjectSettingsForm.PARSING_FAILED, profilesModel, comboBox);
	}
}
 
Example #11
Source File: ConfigFileLocator.java    From EclipseCodeFormatter with Apache License 2.0 5 votes vote down vote up
private void processEPF(ProjectSettingsForm projectSettingsForm, SortedComboBoxModel profilesModel, File file, JComboBox comboBox) {
	if (isValidEPF(file)) {
		valid("valid config", projectSettingsForm, profilesModel, comboBox);
	} else {
		invalid("Invalid config, should contain 100+ org.eclipse.jdt.core properties", profilesModel, comboBox);
	}
}
 
Example #12
Source File: ProjectSettingsForm.java    From EclipseCodeFormatter with Apache License 2.0 5 votes vote down vote up
private ComboBoxModel createProfilesModel(JTextField pathToEclipsePreferenceFile, String selectedProfile) {
	@SuppressWarnings("unchecked")
	SortedComboBoxModel profilesModel = new SortedComboBoxModel(new Comparator<String>() {
		@Override
		public int compare(String o1, String o2) {
			return o1.compareTo(o2);
		}
	});
	String text = pathToEclipsePreferenceFile.getText();
	if (normalBorder == null) {
		this.normalBorder = javaFormatterProfile.getBorder();
	}
	if (!text.isEmpty() && schemeEclipseFile.isSelected()) {
		ConfigFileLocator configFileLocator = new ConfigFileLocator();

		configFileLocator.validate(this, profilesModel, text);

	} else {
		javaFormatterProfile.setEnabled(false);
		javaFormatterProfile.setBorder(this.normalBorder);
	}

	List<String> items = profilesModel.getItems();
	if (items.size() > 0) {
		for (String item : items) {
			if (item.equals(selectedProfile)) {
				profilesModel.setSelectedItem(item);
			}
		}
		if (profilesModel.getSelectedItem() == null) {
			profilesModel.setSelectedItem(items.get(0));
		}
	}

	return profilesModel;
}
 
Example #13
Source File: ConfigurationModuleSelector.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private void setModules(final Collection<Module> modules) {
    if (myModulesList instanceof ModulesComboBox) {
        ((ModulesComboBox) myModulesList).setModules(modules);
    } else {
        SortedComboBoxModel<Module> model = (SortedComboBoxModel<Module>) myModulesList.getModel();
        model.setAll(modules);
        model.add(null);
    }
}
 
Example #14
Source File: OtherOptionsPanel.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private SortedComboBoxModel<XQueryFlavour> comboBoxModel() {
    return new SortedComboBoxModel<>(new Comparator<XQueryFlavour>() {
        @Override
        public int compare(XQueryFlavour o1, XQueryFlavour o2) {
            return o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName());
        }
    });
}
 
Example #15
Source File: UIUtils.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
static SortedComboBoxModel<String> comboBoxModel() {
    return new SortedComboBoxModel<String>(new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            return o1.compareToIgnoreCase(o2);
        }
    });
}
 
Example #16
Source File: CreateBranchModel.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
private SortedComboBoxModel<GitRemoteBranch> createRemoteBranchDropdownModel() {
    logger.info("CreateBranchModel.createRemoteBranchDropdownModel");
    final SortedComboBoxModel<GitRemoteBranch> sortedRemoteBranches
            = new SortedComboBoxModel<GitRemoteBranch>(new TfGitHelper.BranchComparator());

    // TODO: add option to retrieve more branches in case the branch they are looking for is missing local
    // only show valid remote branches
    sortedRemoteBranches.addAll(Collections2.filter(gitRepository.getInfo().getRemoteBranches(), remoteBranch -> {
        //  condition: remote must be a vso/tfs remote
        return tfGitRemotes.contains(remoteBranch.getRemote());
    }));
    sortedRemoteBranches.setSelectedItem(TfGitHelper.getDefaultBranch(sortedRemoteBranches.getItems(), tfGitRemotes));
    return sortedRemoteBranches;
}
 
Example #17
Source File: ProjectSettingsForm.java    From EclipseCodeFormatter with Apache License 2.0 4 votes vote down vote up
private void refreshProfilesModel(SortedComboBoxModel profilesModel) {
	profilesModel.setAll(GlobalSettings.getInstance().getSettingsList());
	Settings projectSpecificProfile = ProjectSettings.getInstance(project).getState().getProjectSpecificProfile();
	profilesModel.add(projectSpecificProfile);
}
 
Example #18
Source File: ConfigFileLocator.java    From EclipseCodeFormatter with Apache License 2.0 4 votes vote down vote up
private void valid(String valid_config, ProjectSettingsForm projectSettingsForm, SortedComboBoxModel profilesModel, JComboBox comboBox) {
	profilesModel.add(valid_config);
	comboBox.setEnabled(false);
	comboBox.setBorder(projectSettingsForm.normalBorder);
}
 
Example #19
Source File: ConfigFileLocator.java    From EclipseCodeFormatter with Apache License 2.0 4 votes vote down vote up
private void invalid(String text, SortedComboBoxModel profilesModel, JComboBox comboBox) {
	profilesModel.add(text);
	comboBox.setEnabled(false);
	comboBox.setBorder(ProjectSettingsForm.ERROR_BORDER);
}
 
Example #20
Source File: ModulesComboBox.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ModulesComboBox() {
  this(new SortedComboBoxModel<>(ModulesAlphaComparator.INSTANCE));
}
 
Example #21
Source File: DefaultFileExtensionsPanel.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
private void populateExtensionsList(SortedComboBoxModel<String> model, Object defaultItem, List<String> allItems) {
    for (String type : allItems) {
        model.add(type);
    }
    model.setSelectedItem(defaultItem);
}