List of usage examples for javax.swing DefaultComboBoxModel getSize
public int getSize()
From source file:org.nuclos.client.ui.collect.component.CollectableComboBox.java
@Override protected void updateView(CollectableField clctfValue) { if (hasAdditionalEntry()) { removeAdditionalEntry();//from www.j a v a 2s .c om } final JComboBox cb = getJComboBox(); final DefaultComboBoxModel cbm = getDefaultComboBoxModel(); int iIndex = cbm.getIndexOf(clctfValue); // If the value could not be found, it might be the mnemonic, so look for the value id if (iIndex < 0 && clctfValue.isIdField() && clctfValue.getValueId() != null) { for (int i = 0; i < cbm.getSize(); i++) { final CollectableField cf = (CollectableField) cbm.getElementAt(i); if (!cf.isIdField()) continue; final Long valueId = IdUtils.toLongId(cf.getValueId()); final Long vid = IdUtils.toLongId(clctfValue.getValueId()); if (LangUtils.equals(vid, valueId)) { iIndex = i; break; } } } if (iIndex >= 0) { cb.setSelectedIndex(iIndex); // Note that setSelectedItem doesn't work here, as clctf might have no label. } else { assert iIndex == -1; final Long vid = !clctfValue.isIdField() ? null : IdUtils.toLongId(clctfValue.getValueId()); Long oValueId = null; if (clctfValue.isIdField()) { oValueId = vid; // sbWarning.append(" (Id: ").append(oValueId).append(")"); } if (isInsertable() && (oValueId == null) && (vid != null)) { final String sText = clctfValue.toString(); cb.setSelectedItem(sText); } else { addAdditionalEntry(clctfValue); cb.setSelectedIndex(cbm.getIndexOf(clctfValue)); } } }
From source file:org.nuclos.client.ui.collect.component.CollectableComboBox.java
@Override public TableCellRenderer getTableCellRenderer(boolean subform) { if (!isSearchComponent() && getValueListProvider() != null) { return new CollectableComponentDetailTableCellRenderer() { @Override/*from w w w . j a va 2s . c om*/ public Component getTableCellRendererComponent(JTable tbl, Object oValue, boolean bSelected, boolean bHasFocus, int iRow, int iColumn) { CollectableField cf = (CollectableField) oValue; boolean valid = true; // NUCLEUSINT-885 Object valueId = (cf != null && cf.isIdField()) ? cf.getValueId() : null; if (valueId != null) { valid = false; DefaultComboBoxModel cbModel = getDefaultComboBoxModel(); for (int i = 0, n = cbModel.getSize(); i < n; i++) { CollectableField cf2 = (CollectableField) cbModel.getElementAt(i); if (cf2 != null && cf2.isIdField() && IdUtils.equals(valueId, cf2.getValueId())) { cf = cf2; valid = true; break; } } } else if (!cf.isIdField()) { valid = insertable; Object value = cf.getValue(); DefaultComboBoxModel cbModel = getDefaultComboBoxModel(); for (int i = 0, n = cbModel.getSize(); i < n; i++) { CollectableField cf2 = (CollectableField) cbModel.getElementAt(i); if (cf2 != null && ObjectUtils.equals(value, cf2.getValue())) { cf = cf2; valid = true; break; } } } Component renderer = super.getTableCellRendererComponent(tbl, cf, bSelected, bHasFocus, iRow, iColumn); // NUCLEUSINT-525 if (!valid) { // NUCLOS-82 setForeground(Color.RED); if (StringUtils.looksEmpty((getText()))) { setText("<ung\u00fcltiger Eintrag>"); } } return renderer; } }; } else if (isSearchComponent()) { //NOAINT-215 return new My2CollectableComponentDetailTableCellRenderer(); } else { return new CollectableComponentDetailTableCellRenderer(); } }
From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java
private DefaultComboBoxModel<String> generateCSPSelectionModel() { DefaultComboBoxModel<String> ret = new DefaultComboBoxModel<String>(); for (StorageBackendType t : StorageBackendType.values()) { if (t != StorageBackendType.FOLDER) { if (t == StorageBackendType.DROPBOX) { // Check if Dropbox is installed. If yes -> Add to list DropboxAdapterFactory dropboxAdapterFactory = (DropboxAdapterFactory) CSPAdapterFactory .getInstance(StorageBackendType.DROPBOX); DropboxClientIntegration dropboxClientIntegration = (DropboxClientIntegration) dropboxAdapterFactory .getClientAdapter(); try { if (dropboxClientIntegration.isClientInstalled()) { ret.addElement(t.getDisplayName()); }//ww w.j a v a 2 s . com } catch (IOException e) { // an error occurred, but it could be possible that // Dropbox is installed ret.addElement(t.getDisplayName()); } } else { ret.addElement(t.getDisplayName()); } } } if (ret.getSize() == 0) { cspSelectionComboBox.setEnabled(false); } return ret; }
From source file:org.yccheok.jstock.gui.NewBuyTransactionJDialog.java
private void initBrokerCostsComboBox() { if (jComboBox2 == null) { return;// ww w.j av a2s .co m } DefaultComboBoxModel model = new DefaultComboBoxModel(); final JStockOptions jStockOptions = JStock.instance().getJStockOptions(); final java.util.List<BrokingFirm> brokerFirms = jStockOptions.getBrokingFirms(); for (BrokingFirm brokingFirm : brokerFirms) { model.addElement(brokingFirm.getName()); } model.addElement(GUIBundle.getString("NewBuyTransactionJDialog_None")); jComboBox2.setModel(model); jComboBox2.addItemListener((java.awt.event.ItemEvent e) -> { int index = jComboBox2.getSelectedIndex(); jStockOptions.setSelectedBrokingFirmIndex(index); update(); }); // Ensure valid selection. int index = jStockOptions.getSelectedBrokingFirmIndex(); if (index < 0 || index >= model.getSize()) { index = model.getSize() - 1; jStockOptions.setSelectedBrokingFirmIndex(index); } jComboBox2.setSelectedIndex(index); jComboBox2.setPrototypeDisplayValue("a"); BoundsPopupMenuListener listener = new BoundsPopupMenuListener(true, false); jComboBox2.addPopupMenuListener(listener); }
From source file:org.yccheok.jstock.gui.NewSellTransactionJDialog.java
private void initBrokerCostsComboBox() { if (jComboBox1 == null) { return;/* w w w. j ava2 s.c o m*/ } DefaultComboBoxModel model = new DefaultComboBoxModel(); final JStockOptions jStockOptions = JStock.instance().getJStockOptions(); final java.util.List<BrokingFirm> brokerFirms = jStockOptions.getBrokingFirms(); for (BrokingFirm brokingFirm : brokerFirms) { model.addElement(brokingFirm.getName()); } model.addElement(GUIBundle.getString("NewSellTransactionJDialog_None")); jComboBox1.setModel(model); jComboBox1.addItemListener((java.awt.event.ItemEvent e) -> { int index = jComboBox1.getSelectedIndex(); jStockOptions.setSelectedBrokingFirmIndex(index); update(); }); // Ensure valid selection. int index = jStockOptions.getSelectedBrokingFirmIndex(); if (index < 0 || index >= model.getSize()) { index = model.getSize() - 1; jStockOptions.setSelectedBrokingFirmIndex(index); } jComboBox1.setSelectedIndex(index); jComboBox1.setPrototypeDisplayValue("a"); BoundsPopupMenuListener listener = new BoundsPopupMenuListener(true, false); jComboBox1.addPopupMenuListener(listener); }
From source file:pipeline.GUI_utils.ListOfPointsView.java
@SuppressWarnings("unchecked") public void setFieldForColoring(@NonNull String fieldName) { @SuppressWarnings("rawtypes") DefaultComboBoxModel comboBoxModel = (DefaultComboBoxModel) coloringComboBox.getModel(); for (int i = 0; i < comboBoxModel.getSize(); i++) { if (fieldName.equals(comboBoxModel.getElementAt(i))) { comboBoxModel.setSelectedItem(fieldName); return; }//from w w w .ja v a 2 s. c om } comboBoxModel.addElement(fieldName); comboBoxModel.setSelectedItem(fieldName); }
From source file:pl.otros.logview.gui.actions.search.SearchAction.java
public void performSearch(String text, SearchDirection direction) { StatusObserver statusObserver = getOtrosApplication().getStatusObserver(); JTabbedPane jTabbedPane = getOtrosApplication().getJTabbedPane(); LogViewPanelWrapper lvPanel = (LogViewPanelWrapper) jTabbedPane.getSelectedComponent(); if (lvPanel == null) { return;// w w w .j a va 2 s. c om } JTable table = lvPanel.getLogViewPanel().getTable(); NextRowProvider nextRowProvider = NextRowProviderFactory.getFilteredTableRow(table, direction); SearchContext context = new SearchContext(); context.setDataTableModel(lvPanel.getDataTableModel()); SearchMatcher searchMatcher = null; String confKey = null; if (SearchMode.STRING_CONTAINS.equals(searchMode)) { searchMatcher = new StringContainsSearchMatcher(text); confKey = ConfKeys.SEARCH_LAST_STRING; } else if (SearchMode.REGEX.equals(searchMode)) { try { searchMatcher = new RegexMatcher(text); confKey = ConfKeys.SEARCH_LAST_REGEX; } catch (Exception e) { statusObserver.updateStatus("Error in regular expression: " + e.getMessage(), StatusObserver.LEVEL_ERROR); return; } } else if (SearchMode.QUERY.equals(searchMode)) { QueryAcceptCondition acceptCondition; try { acceptCondition = new QueryAcceptCondition(text); searchMatcher = new AcceptConditionSearchMatcher(acceptCondition); confKey = ConfKeys.SEARCH_LAST_QUERY; } catch (RuleException e) { statusObserver.updateStatus("Wrong query rule: " + e.getMessage(), StatusObserver.LEVEL_ERROR); return; } } updateList(confKey, getOtrosApplication().getConfiguration(), text); DefaultComboBoxModel model = (DefaultComboBoxModel) getOtrosApplication().getSearchField().getModel(); model.removeElement(text); model.insertElementAt(text, 0); model.setSelectedItem(text); int maxCount = getOtrosApplication().getConfiguration().getInt(ConfKeys.SEARCH_LAST_COUNT, 30); while (model.getSize() > maxCount) { model.removeElementAt(model.getSize() - 1); } context.setSearchMatcher(searchMatcher); SearchResult searchNext = searchEngine.searchNext(context, nextRowProvider); if (searchNext.isFound()) { int row = table.convertRowIndexToView(searchNext.getRow()); Rectangle rect = table.getCellRect(row, 0, true); table.scrollRectToVisible(rect); table.clearSelection(); table.setRowSelectionInterval(row, row); statusObserver.updateStatus(String.format("Found at row %d", row), StatusObserver.LEVEL_NORMAL); if (markFound) { lvPanel.getDataTableModel().markRows(markerColors, table.convertRowIndexToModel(row)); } scrollToSearchResult( searchMatcher.getFoundTextFragments( lvPanel.getDataTableModel().getLogData(table.convertRowIndexToModel(row))), lvPanel.getLogViewPanel().getLogDetailTextArea()); } else { statusObserver.updateStatus(String.format("\"%s\" not found", text), StatusObserver.LEVEL_WARNING); } }
From source file:se.trixon.toolbox.rsync.RsyncTopComponent.java
@Override public void onJobSave() { DefaultComboBoxModel model = JobManager.INSTANCE .populateModel((DefaultComboBoxModel) jobsComboBox.getModel()); boolean hasJob = model.getSize() > 0; jobsComboBox.setModel(model);//from ww w .j a va 2 s .c o m jobsComboBox.setVisible(hasJob); stateButton.setVisible(hasJob); mSpeedDialPanel.setButtonsVisibility(hasJob); if (mSelectedJob != null) { jobsComboBox.setSelectedItem(mSelectedJob); for (int i = 0; i < model.getSize(); i++) { Job job = (Job) model.getElementAt(i); if (job.getId() == mSelectedJob.getId()) { jobsComboBox.setSelectedIndex(i); break; } } } }
From source file:ve.zoonosis.controller.funcionales.CrearEspecieController.java
@Override public void guardar() { try {//ww w .j a v a 2s . com DefaultComboBoxModel model = (DefaultComboBoxModel) especies.getModel(); Object[] o = new Object[model.getSize()]; for (int i = 0; i < o.length; i++) { o[i] = model.getElementAt(i); } rb = new RequestBuilder("services/funcionales/EspecieWs/CrearEspecies.php") .setMetodo(MetodosDeEnvio.POST).crearJson(o); List<Especie> especiess = rb.ejecutarJson(List.class, Especie.class); if (especiess != null) { especies.setModel(new DefaultComboBoxModel(especiess.toArray())); especies.setSelectedIndex(-1); MGrowl.showGrowl(MGrowlState.SUCCESS, "Datos guardados con exito"); } else { MGrowl.showGrowl(MGrowlState.ERROR, "Los Datos no han sido guardados"); } } catch (URISyntaxException | RuntimeException ex) { LOG.LOGGER.log(Level.SEVERE, null, ex); } }