public void init( final Project project, final boolean suggestSearchInLibs, final boolean prevSearchWholeFiles, final String preselect) { mySuggestSearchInLibs = suggestSearchInLibs; myPrevSearchFiles = prevSearchWholeFiles; myProject = project; myScopeListener = new NamedScopesHolder.ScopeListener() { @Override public void scopesChanged() { final SearchScope selectedScope = getSelectedScope(); rebuildModel(); if (selectedScope != null) { selectScope(selectedScope.getDisplayName()); } } }; myNamedScopeManager = NamedScopeManager.getInstance(project); myNamedScopeManager.addScopeListener(myScopeListener); myValidationManager = DependencyValidationManager.getInstance(project); myValidationManager.addScopeListener(myScopeListener); addActionListener(createScopeChooserListener()); final JComboBox combo = getComboBox(); combo.setRenderer(new ScopeDescriptionWithDelimiterRenderer(combo.getRenderer())); rebuildModel(); selectScope(preselect); }
private void selectScope(String preselect) { if (preselect != null) { final JComboBox combo = getComboBox(); DefaultComboBoxModel model = (DefaultComboBoxModel) combo.getModel(); for (int i = 0; i < model.getSize(); i++) { ScopeDescriptor descriptor = (ScopeDescriptor) model.getElementAt(i); if (preselect.equals(descriptor.getDisplay())) { combo.setSelectedIndex(i); break; } } } }
@Nullable public String getSelectedScopeName() { final JComboBox combo = getComboBox(); int idx = combo.getSelectedIndex(); return idx < 0 ? null : ((ScopeDescriptor) combo.getSelectedItem()).getDisplay(); }
@Nullable public SearchScope getSelectedScope() { final JComboBox combo = getComboBox(); int idx = combo.getSelectedIndex(); return idx < 0 ? null : ((ScopeDescriptor) combo.getSelectedItem()).getScope(); }