Java源码示例:com.intellij.ui.SortedComboBoxModel
示例1
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;
}
示例2
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));
}
示例3
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;
}
示例4
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);
}
}
}
示例5
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());
}
示例6
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());
}
示例7
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;
}
示例8
static SortedComboBoxModel<String> comboBoxModel() {
return new SortedComboBoxModel<String>(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
});
}
示例9
private SortedComboBoxModel<XQueryFlavour> comboBoxModel() {
return new SortedComboBoxModel<>(new Comparator<XQueryFlavour>() {
@Override
public int compare(XQueryFlavour o1, XQueryFlavour o2) {
return o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName());
}
});
}
示例10
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);
}
}
示例11
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;
}
示例12
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);
}
}
示例13
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);
}
}
示例14
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);
}
}
示例15
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);
}
}
示例16
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);
}
});
}
示例17
private void populateExtensionsList(SortedComboBoxModel<String> model, Object defaultItem, List<String> allItems) {
for (String type : allItems) {
model.add(type);
}
model.setSelectedItem(defaultItem);
}
示例18
private void refreshProfilesModel(SortedComboBoxModel profilesModel) {
profilesModel.setAll(GlobalSettings.getInstance().getSettingsList());
Settings projectSpecificProfile = ProjectSettings.getInstance(project).getState().getProjectSpecificProfile();
profilesModel.add(projectSpecificProfile);
}
示例19
private void valid(String valid_config, ProjectSettingsForm projectSettingsForm, SortedComboBoxModel profilesModel, JComboBox comboBox) {
profilesModel.add(valid_config);
comboBox.setEnabled(false);
comboBox.setBorder(projectSettingsForm.normalBorder);
}
示例20
private void invalid(String text, SortedComboBoxModel profilesModel, JComboBox comboBox) {
profilesModel.add(text);
comboBox.setEnabled(false);
comboBox.setBorder(ProjectSettingsForm.ERROR_BORDER);
}
示例21
public ModulesComboBox() {
this(new SortedComboBoxModel<>(ModulesAlphaComparator.INSTANCE));
}