javax.swing.ComboBoxModel Java Examples

The following examples show how to use javax.swing.ComboBoxModel. 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: AllLocalProductsRepositoryPanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public void addLocalRepositoryFolderIfMissing(LocalRepositoryFolder localRepositoryFolder) {
    ComboBoxModel<LocalRepositoryFolder> foldersModel = this.foldersComboBox.getModel();
    boolean foundFolder = false;
    for (int i = 0; i < foldersModel.getSize() && !foundFolder; i++) {
        LocalRepositoryFolder existingFolder = foldersModel.getElementAt(i);
        if (existingFolder != null && existingFolder.getId() == localRepositoryFolder.getId()) {
            foundFolder = true;
        }
    }
    if (!foundFolder) {
        if (foldersModel.getSize() == 0) {
            this.foldersComboBox.addItem(null);
        }
        this.foldersComboBox.addItem(localRepositoryFolder);
    }
}
 
Example #2
Source File: AutoCompletionComboBox.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
public AutoCompletionComboBox(boolean caseSensitive, int preferredWidth, int preferredHeight, boolean wide,
		ComboBoxModel<E> model) {
	super(preferredWidth, preferredHeight, wide, model);

	this.caseSensitive = caseSensitive;

	setEditable(true);
	setEditor(getEditor());

	addFocusListener(new FocusAdapter() {

		@Override
		public void focusLost(FocusEvent e) {
			setSelectedItem(((JTextField) getEditor().getEditorComponent()).getText());
			actionPerformed(new ActionEvent(this, 0, "editingStopped"));
		}
	});
}
 
Example #3
Source File: MantTaskEvents.java    From openprodoc with GNU Affero General Public License v3.0 6 votes vote down vote up
private ComboBoxModel getListObjFold()
{
Vector VObjects=new Vector();
try {
DriverGeneric Session=MainWin.getSession();
PDObjDefs Obj = new PDObjDefs(Session);
Cursor CursorId = Obj.getListFold();
Record Res=Session.NextRec(CursorId);
while (Res!=null)
    {
    Attribute Attr=Res.getAttr(PDObjDefs.fNAME);
    VObjects.add(Attr.getValue());
    Res=Session.NextRec(CursorId);
    }
Session.CloseCursor(CursorId);
} catch (PDException ex)
    {
    MainWin.Message("Error"+ex.getLocalizedMessage());
    }
return(new DefaultComboBoxModel(VObjects));
}
 
Example #4
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 #5
Source File: FindUsagesDialogOperator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Select the scope
 *
 * @param projectName The name of project or null if find should be
 * performed on all projects
 */
public void setScope(String projectName) {
    JComboBoxOperator scopeOperator = getScope();
    String select_item;
    if (projectName == null) {
        select_item = Bundle.getStringTrimmed("org.netbeans.modules.refactoring.java.ui.scope.Bundle", "LBL_AllProjects");
    } else {
        select_item = projectName;
    }

    ComboBoxModel model = scopeOperator.getModel();
    int index = -1;
    String dn;
    for (int i = 0; i < model.getSize()-1; i++) { /// -1 ... it's custom and it fails
        dn = ((org.netbeans.modules.refactoring.spi.impl.DelegatingScopeProvider) model.getElementAt(i)).getDisplayName();
        if (dn.indexOf(select_item) != -1) {
            index = i;
        }
    }
    scopeOperator.selectItem(index);
}
 
Example #6
Source File: MantTaskEvents.java    From openprodoc with GNU Affero General Public License v3.0 6 votes vote down vote up
private ComboBoxModel getListObjDoc()
{
Vector VObjects=new Vector();
try {
DriverGeneric Session=MainWin.getSession();
PDObjDefs Obj = new PDObjDefs(Session);
Cursor CursorId = Obj.getListDocs();
Record Res=Session.NextRec(CursorId);
while (Res!=null)
    {
    Attribute Attr=Res.getAttr(PDObjDefs.fNAME);
    VObjects.add(Attr.getValue());
    Res=Session.NextRec(CursorId);
    }
Session.CloseCursor(CursorId);
} catch (PDException ex)
    {
    MainWin.Message("Error"+ex.getLocalizedMessage());
    }
return(new DefaultComboBoxModel(VObjects));
}
 
Example #7
Source File: AjaxSpiderExplorer.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
public void optionsLoaded(QuickStartParam quickStartParam) {
    getSelectCheckBox().setSelected(quickStartParam.isAjaxSpiderEnabled());
    String def = quickStartParam.getAjaxSpiderDefaultBrowser();
    if (def == null || def.length() == 0) {
        // no default
        return;
    }
    ComboBoxModel<ProvidedBrowserUI> model = this.getBrowserComboBox().getModel();
    for (int idx = 0; idx < model.getSize(); idx++) {
        ProvidedBrowserUI el = model.getElementAt(idx);
        if (el.getName().equals(def)) {
            model.setSelectedItem(el);
            break;
        }
    }
}
 
Example #8
Source File: KnownSaneOptions.java    From swingsane with Apache License 2.0 6 votes vote down vote up
public static ComboBoxModel<String> getSourceModel(Scanner scanner) {
  DefaultComboBoxModel<String> sourceModel = new DefaultComboBoxModel<String>();

  HashMap<String, StringOption> stringOptions = scanner.getStringOptions();

  StringOption stringOption = stringOptions.get(SANE_NAME_SCAN_SOURCE);

  if (stringOption == null) {
    return null;
  }

  Constraints constraints = stringOption.getConstraints();
  List<String> values = constraints.getStringList();

  for (String value : values) {
    sourceModel.addElement(value);
  }

  if (values.size() > 0) {
    return sourceModel;
  } else {
    return null;
  }
}
 
Example #9
Source File: FieldPanel.java    From quickfix-messenger with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setValue(String value)
{
	if (fieldComboBox != null)
	{
		ComboBoxModel<FieldValue> comboBoxModel = fieldComboBox.getModel();
		for (int i = 0; i < comboBoxModel.getSize(); i++)
		{
			FieldValue fieldValue = comboBoxModel.getElementAt(i);
			if (fieldValue.getEnumValue().equals(value))
			{
				fieldComboBox.setSelectedIndex(i);
			}
		}
	}

	else
	{
		fieldTextField.setText(value);
	}
}
 
Example #10
Source File: ConfigureFXMLControllerPanelVisual.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void updatePackages() {
    final Object item = createdLocationComboBox.getSelectedItem();
    if (!(item instanceof SourceGroupSupport.SourceGroupProxy)) {
        return;
    }
    WAIT_MODEL.setSelectedItem(createdPackageComboBox.getEditor().getItem());
    createdPackageComboBox.setModel(WAIT_MODEL);

    if (updatePackagesTask != null) {
        updatePackagesTask.cancel();
    }

    updatePackagesTask = new RequestProcessor("ComboUpdatePackages").post(new Runnable() { // NOI18N
        @Override
        public void run() {
            final ComboBoxModel model = ((SourceGroupSupport.SourceGroupProxy) item).getPackagesComboBoxModel();
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    model.setSelectedItem(createdPackageComboBox.getEditor().getItem());
                    createdPackageComboBox.setModel(model);
                }
            });
        }
    });
}
 
Example #11
Source File: ColorPaletteChooser.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public Range getRangeFromFile() {
    final ComboBoxModel<ColorPaletteWrapper> model = getModel();
    final int selectedIndex = getSelectedIndex();
    final ColorPaletteWrapper paletteWrapper = model.getElementAt(selectedIndex);
    String name = paletteWrapper.name;
    final ColorPaletteDef cpd;
    if (name.startsWith(DERIVED_FROM)) {
        name = name.substring(DERIVED_FROM.length()).trim();
        if (name.toLowerCase().endsWith(".cpd")) {
            name = FileUtils.getFilenameWithoutExtension(name);
        }
        cpd = findColorPalette(name);
    } else {
        cpd = paletteWrapper.cpd;
    }
    return new Range(cpd.getMinDisplaySample(), cpd.getMaxDisplaySample());
}
 
Example #12
Source File: SettingsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Selects a given template.
 *
 * @param  templatePath  path of the template which should be selected;
 *                       may be <code>null</code> - then no item is selected
 */
void selectTemplate(String templatePath) {
    if (templatePath == null) {
        return;
    }
    
    ComboBoxModel model = cboTemplate.getModel();
    int itemsCount = model.getSize();
    
    if (itemsCount == 0) {
        return;
    }
    
    for (int i = 0; i < itemsCount; i++) {
        NamedObject namedObj = (NamedObject) model.getElementAt(i);
        FileObject template = (FileObject) namedObj.object;
        if (template.getPath().equals(templatePath)) {
            cboTemplate.setSelectedIndex(i);
            return;
        }
    }
}
 
Example #13
Source File: TCImportFold.java    From openprodoc with GNU Affero General Public License v3.0 6 votes vote down vote up
private ComboBoxModel getListObjDoc()
{
Vector VObjects=new Vector();
try {
DriverGeneric Session=MainWin.getSession();
PDObjDefs Obj = new PDObjDefs(Session);
Cursor CursorId = Obj.getListDocs();
Record Res=Session.NextRec(CursorId);
while (Res!=null)
    {
    Attribute Attr=Res.getAttr(PDObjDefs.fNAME);
    VObjects.add(Attr.getValue());
    Res=Session.NextRec(CursorId);
    }
Session.CloseCursor(CursorId);
} catch (PDException ex)
    {
    MainWin.Message("Error"+ex.getLocalizedMessage());
    }
return(new DefaultComboBoxModel(VObjects));
}
 
Example #14
Source File: MantTaskCron.java    From openprodoc with GNU Affero General Public License v3.0 6 votes vote down vote up
private ComboBoxModel getListObjDoc()
{
Vector VObjects=new Vector();
try {
DriverGeneric Session=MainWin.getSession();
PDObjDefs Obj = new PDObjDefs(Session);
Cursor CursorId = Obj.getListDocs();
Record Res=Session.NextRec(CursorId);
while (Res!=null)
    {
    Attribute Attr=Res.getAttr(PDObjDefs.fNAME);
    VObjects.add(Attr.getValue());
    Res=Session.NextRec(CursorId);
    }
Session.CloseCursor(CursorId);
} catch (PDException ex)
    {
    MainWin.Message("Error"+ex.getLocalizedMessage());
    }
return(new DefaultComboBoxModel(VObjects));
}
 
Example #15
Source File: RepositoryOpenDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void setSelectedView( final FileObject selectedView ) {
  this.selectedView = selectedView;
  if ( selectedView != null ) {
    logger.debug( "Setting selected view to " + selectedView );
    try {
      if ( selectedView.getType() == FileType.FILE ) {
        logger.debug( "Setting filename in selected view to " + selectedView.getName().getBaseName() );
        this.fileNameTextField.setText( URLDecoder.decode( selectedView.getName().getBaseName(), "UTF-8" ) );
      }
    } catch ( Exception e ) {
      // can be ignored ..
      logger.debug( "Unable to determine file type. This is not fatal.", e );
    }
    final ComboBoxModel comboBoxModel = createLocationModel( selectedView );
    this.locationCombo.setModel( comboBoxModel );
    this.table.setSelectedPath( (FileObject) comboBoxModel.getSelectedItem() );
  } else {
    this.fileNameTextField.setText( null );
    this.table.setSelectedPath( null );
    this.locationCombo.setModel( new DefaultComboBoxModel() );
  }
}
 
Example #16
Source File: JExtendedComboBox.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void setModel(ComboBoxModel aModel) {
    if (!(aModel instanceof DefaultComboBoxModel)) {
        throw new RuntimeException("Only DefaultComboBoxModel is supported for this component"); //NOI18N
    }

    model = (DefaultComboBoxModel) aModel;
    super.setModel(model);
}
 
Example #17
Source File: CreatePullRequestControllerTest.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Test
public void whenSourceOfUpdateIsNotSetUpdateAll() throws Exception {
    underTest.update(null, null);
    verify(dialogMock).setSourceBranch(any(GitBranch.class));
    verify(dialogMock).setTargetBranchDropdownModel(any(ComboBoxModel.class));
    verify(dialogMock).setSelectedTargetBranch(any(GitRemoteBranch.class));
    verify(dialogMock).setTitle(anyString());
    verify(dialogMock).setDescription(anyString());
    verify(dialogMock).setIsLoading(anyBoolean());
    verify(dialogMock).populateDiff(any(Project.class), any(GitChangesContainer.class));
}
 
Example #18
Source File: SerialPortSimpleBean.java    From IrScrutinizer with GNU General Public License v3.0 5 votes vote down vote up
public void setup(String desiredPort) throws IOException {
    ComboBoxModel<String> model = portComboBox.getModel();
    if (model == null || model.getSize() == 0 || ((model.getSize() == 1) && ((String)portComboBox.getSelectedItem()).equals(notInitialized)))
        setupPortComboBox(true);

    portComboBox.setSelectedItem(desiredPort != null ? desiredPort : portName);
}
 
Example #19
Source File: PersistenceClientSetupPanelVisual.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void updateSourceGroupPackages() {
    SourceGroup sourceGroup = (SourceGroup)locationComboBox.getSelectedItem();
    JComboBox[] combos = {jpaPackageComboBox, jsfPackageComboBox};
    for (JComboBox combo : combos) {
        ComboBoxModel model = PackageView.createListView(sourceGroup);
        if (model.getSelectedItem()!= null && model.getSelectedItem().toString().startsWith("META-INF")
                && model.getSize() > 1) { // NOI18N
            model.setSelectedItem(model.getElementAt(1));
        }
        combo.setModel(model);
    }
}
 
Example #20
Source File: MultiTargetChooserPanelGUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void updatePackages( final boolean clean ) {
    WAIT_MODEL.setSelectedItem( packageComboBox.getEditor().getItem() );
    packageComboBox.setModel( WAIT_MODEL );
    
    if ( updatePackagesTask != null ) {
        updatePackagesTask.cancel();
    }
    
    updatePackagesTask = new RequestProcessor( "ComboUpdatePackages" ).post(
        new Runnable() {
        
            private ComboBoxModel model;
        
            public void run() {
                if ( !SwingUtilities.isEventDispatchThread() ) {
                    SourceGroup sourceGroup = (SourceGroup) rootComboBox.getSelectedItem();
                    if (sourceGroup != null) {
                        model = PackageView.createListView(sourceGroup);
                        SwingUtilities.invokeLater( this );
                    }
                }
                else {
                    if ( !clean ) {
                        model.setSelectedItem( packageComboBox.getEditor().getItem() );
                    }
                    packageComboBox.setModel( model );
                }
            }
        }
    );
            
}
 
Example #21
Source File: TestbedSidePanel.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void updateTests(ComboBoxModel<ListItem> model) {
  ObservableList<ListItem> list = tests.itemsProperty().get();
  list.clear();
  for (int i = 0; i < model.getSize(); i++) {
    list.add((ListItem) model.getElementAt(i));
  }
}
 
Example #22
Source File: EjbFacadeVisualPanel2.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void updateSourceGroupPackages() {
    SourceGroup sourceGroup = (SourceGroup)locationComboBox.getSelectedItem();
    if (sourceGroup != null) {
        ComboBoxModel model = PackageView.createListView(sourceGroup);
        if (model.getSelectedItem()!= null && model.getSelectedItem().toString().startsWith("META-INF") //NOI18N
                && model.getSize() > 1) { // NOI18N
            model.setSelectedItem(model.getElementAt(1));
        }
        packageComboBox.setModel(model);
    }
}
 
Example #23
Source File: JFileChooserOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private int findDirIndex(String dir, StringComparator comparator) {
    ComboBoxModel<?> cbModel = getPathCombo().getModel();
    for (int i = cbModel.getSize() - 1; i >= 0; i--) {
        if (comparator.equals(((File) cbModel.getElementAt(i)).getName(),
                dir)) {
            return i;
        }
    }
    return -1;
}
 
Example #24
Source File: ColorPaletteChooser.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private ColorPaletteDef findColorPalette(String name) {
    final ComboBoxModel<ColorPaletteWrapper> model = getModel();
    for (int i = 0; i < model.getSize(); i++) {
        final ColorPaletteWrapper paletteWrapper = model.getElementAt(i);
        if (paletteWrapper.name.equals(name)) {
            return paletteWrapper.cpd;
        }
    }
    return null;
}
 
Example #25
Source File: ActionTypePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ComboBoxModel createCookieClassModel() {
    DefaultComboBoxModel cookieClassModel = new DefaultComboBoxModel();
    for (String fqcn : DataModel.PREDEFINED_COOKIE_CLASSES) {
        String name = DataModel.parseClassName(fqcn);
        cookieClassModel.addElement(name);
    }
    return cookieClassModel;
}
 
Example #26
Source File: PanelOcrInput.java    From java-ocr-api with GNU Affero General Public License v3.0 5 votes vote down vote up
static void selectCombo(JComboBox comboBox, String value) {
    if(value == null || value.trim().length() == 0) {
        return;
    }
    ComboBoxModel model = comboBox.getModel();
    for(int i = 0; i < model.getSize(); i++) {
        if(value.equals(model.getElementAt(i).toString())) {
            comboBox.setSelectedIndex(i);
            return;
        }
    }
}
 
Example #27
Source File: AutoSuggest.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private ComboBoxModel<String> getSuggestedModel() {
    DefaultComboBoxModel<String> m = new DefaultComboBoxModel<>();
    for (String s : searchList) {
        if (s.toLowerCase().contains(getSearchString().toLowerCase())) {
            m.addElement(s);
        }
    }
    if (m.getSize() == 0) {
        m = new DefaultComboBoxModel<>(searchList.toArray(new String[searchList.size()]));
    }
    return m;
}
 
Example #28
Source File: FmtOptions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ComboItem whichItem(String value, ComboBoxModel model) {

            for (int i = 0; i < model.getSize(); i++) {
                ComboItem item = (ComboItem)model.getElementAt(i);
                if ( value.equals(item.value)) {
                    return item;
                }
            }
            return null;
        }
 
Example #29
Source File: TestCategory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ComboBoxModel<RunBuild> runBuildModel() {
    DefaultComboBoxModel<RunBuild> model = new DefaultComboBoxModel<>();

    for (RunBuild rb : RunBuild.values()) {
        model.addElement(rb);
    }

    return model;
}
 
Example #30
Source File: ModifyElementRulesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ComboBoxModel createClassesModel() {
    Collection<String> classes = new ArrayList<>();
    classes.add(null);
    FileObject selectedStyleSheet = (FileObject) styleSheetCB.getSelectedItem();
    if (selectedStyleSheet != null) {
        Collection<String> foundInFile = files2classes.get(selectedStyleSheet);
        if (foundInFile != null) {
            classes.addAll(foundInFile);
        }
    }
    return new DefaultComboBoxModel(classes.toArray());
}