List of usage examples for javax.swing DefaultComboBoxModel getElementAt
public E getElementAt(int index)
From source file:edu.ku.brc.specify.datamodel.busrules.BaseTreeBusRules.java
/** * @param parentField/*w w w. j av a2s.com*/ * @param rankComboBox * @param nodeInForm */ @SuppressWarnings("unchecked") protected void adjustRankComboBoxModel(final GetSetValueIFace parentField, final ValComboBox rankComboBox, final T nodeInForm) { log.debug("Adjusting the model for the 'rank' combo box in a tree node form"); if (nodeInForm == null) { return; } log.debug("nodeInForm = " + nodeInForm.getName()); DefaultComboBoxModel<I> model = (DefaultComboBoxModel<I>) rankComboBox.getModel(); model.removeAllElements(); // this is the highest rank the edited item can possibly be I topItem = null; // this is the lowest rank the edited item can possibly be I bottomItem = null; Object value = parentField.getValue(); T parent = null; if (value instanceof String) { // this happens when the combobox is in view mode, which means it's really a textfield // in that case, the parent of the node in the form will do, since the user can't change the parents parent = nodeInForm.getParent(); } else { parent = (T) parentField.getValue(); } if (parent == null) { return; } // grab all the def items from just below the parent's item all the way to the next enforced level // or to the level of the highest ranked child topItem = parent.getDefinitionItem().getChild(); log.debug("highest valid tree level: " + topItem); if (topItem == null) { // this only happens if a parent was chosen that cannot have children b/c it is at the // lowest defined level in the tree log.warn("Chosen node cannot be a parent node. It is at the lowest defined level of the tree."); return; } // find the child with the highest rank and set that child's def item as the bottom of the range if (!nodeInForm.getChildren().isEmpty()) { for (T child : nodeInForm.getChildren()) { if (bottomItem == null || child.getRankId() > bottomItem.getRankId()) { bottomItem = child.getDefinitionItem().getParent(); } } } log.debug("lowest valid tree level: " + bottomItem); I item = topItem; boolean done = false; while (!done) { model.addElement(item); if (item.getChild() == null || item.getIsEnforced() == Boolean.TRUE || (bottomItem != null && item.getRankId().intValue() == bottomItem.getRankId().intValue())) { done = true; } item = item.getChild(); } if (nodeInForm.getDefinitionItem() != null) { I defItem = nodeInForm.getDefinitionItem(); for (int i = 0; i < model.getSize(); ++i) { I modelItem = (I) model.getElementAt(i); if (modelItem.getRankId().equals(defItem.getRankId())) { log.debug("setting rank selected value to " + modelItem); model.setSelectedItem(modelItem); } } // if (model.getIndexOf(defItem) != -1) // { // model.setSelectedItem(defItem); // } } else if (model.getSize() == 1) { Object defItem = model.getElementAt(0); log.debug("setting rank selected value to the only available option: " + defItem); model.setSelectedItem(defItem); } }
From source file:op.tools.SYSTools.java
public static DefaultListModel cmb2lst(DefaultComboBoxModel dcbm) { DefaultListModel dlm = new DefaultListModel(); for (int i = 0; i < dcbm.getSize(); i++) { dlm.addElement(dcbm.getElementAt(i)); }/*from w w w.j ava 2 s . c o m*/ return dlm; }
From source file:org.nuclos.client.ui.collect.component.CollectableComboBox.java
/** * @return the list of (possible) values (dropdown list) *//* w w w .j av a 2 s .c o m*/ public List<CollectableField> getValueList() { final List<CollectableField> result = new ArrayList<CollectableField>(); final DefaultComboBoxModel model = getDefaultComboBoxModel(); for (int i = 0; i < model.getSize(); i++) { result.add((CollectableField) model.getElementAt(i)); } return result; }
From source file:org.nuclos.client.ui.collect.component.CollectableComboBox.java
@Override protected void updateView(CollectableField clctfValue) { if (hasAdditionalEntry()) { removeAdditionalEntry();// w w w .ja va2s . 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/* w w w . ja v a 2 s .co m*/ 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: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 . java 2 s.c om } comboBoxModel.addElement(fieldName); comboBoxModel.setSelectedItem(fieldName); }
From source file:pl.otros.logview.gui.LogViewPanel.java
protected void initMessageDetailsToolbar() { final JButton buttonFormatters = new JButton("Message formatters", Icons.MESSAGE_FORMATTER); buttonFormatters.addMouseListener(new MouseAdapter() { @Override/*from w w w .j ava2s.com*/ public void mouseClicked(MouseEvent e) { showMessageFormatterOrColorizerPopupMenu(e, "Message formatters", selectedMessageFormattersContainer, messageFormattersContainer); } }); buttonFormatters.setToolTipText("Select used message formatters"); messageDetailToolbar.add(buttonFormatters); final JButton buttonColorizers = new JButton("Message colorizers", Icons.MESSAGE_COLORIZER); buttonColorizers.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { showMessageFormatterOrColorizerPopupMenu(e, "Message colorizers", selectedMessageColorizersContainer, messageColorizersContainer); } }); buttonColorizers.setToolTipText("Select used message colorizers"); messageDetailToolbar.add(buttonColorizers); messageDetailToolbar.add(new CopyStyledMessageDetailAction(otrosApplication, dateFormat, selectedMessageColorizersContainer, selectedMessageFormattersContainer)); messageDetailToolbar.add(new JLabel("Maximum message size for format")); final DefaultComboBoxModel defaultComboBoxModel = new DefaultComboBoxModel(new String[] {}); String[] values = new String[] { "10kB", "100kB", "200kB", "300kB", "400kB", "500kB", "600kB", "700kB", "800kB", "900kB", "1MB", "2MB", "3MB", "4MB", "5MB" }; for (String value : values) { defaultComboBoxModel.addElement(value); } final JXComboBox messageMaximumSize = new JXComboBox(defaultComboBoxModel); messageMaximumSize.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String max = (String) defaultComboBoxModel.getElementAt(messageMaximumSize.getSelectedIndex()); configuration.setProperty(ConfKeys.MESSAGE_FORMATTER_MAX_SIZE, max); messageDetailListener.setMaximumMessageSize((int) new FileSize(max).getBytes()); } }); messageMaximumSize.setEditable(false); AutoCompleteDecorator.decorate(messageMaximumSize); messageMaximumSize.setMaximumSize(new Dimension(100, 50)); messageDetailToolbar.add(messageMaximumSize); String messageMaxSize = configuration.getString(ConfKeys.MESSAGE_FORMATTER_MAX_SIZE, (String) defaultComboBoxModel.getElementAt(messageMaximumSize.getSelectedIndex())); if (defaultComboBoxModel.getIndexOf(messageMaxSize) >= 0) { messageMaximumSize.setSelectedItem(messageMaxSize); } }
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);// w w w. ja v a 2s.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 {/* w w w . j av a 2 s.c o m*/ 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); } }