Example usage for javax.swing DefaultComboBoxModel removeAllElements

List of usage examples for javax.swing DefaultComboBoxModel removeAllElements

Introduction

In this page you can find the example usage for javax.swing DefaultComboBoxModel removeAllElements.

Prototype

public void removeAllElements() 

Source Link

Document

Empties the list.

Usage

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private void editSubmodelInfo(final SubmodelInfo sInfo) {
    constDef.setSelected(true);// w ww  .ja v  a2  s  .  c  om
    incrDef.setEnabled(false);
    listDef.setEnabled(false);
    cancelButton.setEnabled(true);
    final DefaultComboBoxModel model = (DefaultComboBoxModel) submodelTypeBox.getModel();
    model.removeAllElements();
    model.addElement("Loading class information...");
    final CardLayout cl = (CardLayout) rightMiddle.getLayout();
    cl.show(rightMiddle, "SUBMODEL");

    try {
        final ClassElement[] elements = fetchPossibleTypes(sInfo);
        model.removeAllElements();
        for (final ClassElement classElement : elements)
            model.addElement(classElement);

        if (sInfo.getActualType() != null)
            submodelTypeBox.setSelectedItem(new ClassElement(sInfo.getActualType(), sInfo.getInstance()));
        submodelTypeBox.setEnabled(true);
        modifyButton.setEnabled(true);
    } catch (final ComboBoxIsTooFullException e) {
        String errorMsg = "Too much possibilities for " + sInfo.getName()
                + ". Please narrow down the domain by "
                + "defining the possible classes in the @Submodel annotation.";
        JOptionPane.showMessageDialog(wizard, new JLabel(errorMsg), "Error while analyizing model",
                JOptionPane.ERROR_MESSAGE);
        cancelButton.doClick();
    }
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

/** Edits the information object <code>info</code> so this method fills the appropriate
 *  components with the informations of <code>info</code>.
 *//*from w  w w  . j a va 2 s . c om*/
private void edit(final ParameterInfo info) {
    changeText(info.getName(), info.getType());
    if (info instanceof SubmodelInfo) {
        final SubmodelInfo sInfo = (SubmodelInfo) info;
        editSubmodelInfo(sInfo);
    } else {
        String view = null;
        switch (info.getDefinitionType()) {
        case ParameterInfo.CONST_DEF: {
            if (info.isEnum() || info instanceof MasonChooserParameterInfo) {
                view = "ENUM";
                constDef.setSelected(true);
                incrDef.setEnabled(false);
                listDef.setEnabled(false);
                Object[] elements = null;
                if (info.isEnum()) {
                    @SuppressWarnings("unchecked")
                    final Class<Enum<?>> type = (Class<Enum<?>>) info.getJavaType();
                    elements = type.getEnumConstants();
                } else {
                    final MasonChooserParameterInfo chooserInfo = (MasonChooserParameterInfo) info;
                    elements = chooserInfo.getValidStrings();
                }
                final DefaultComboBoxModel model = (DefaultComboBoxModel) enumDefBox.getModel();
                model.removeAllElements();
                for (final Object object : elements) {
                    model.addElement(object);
                }
                if (info.isEnum())
                    enumDefBox.setSelectedItem(info.getValue());
                else
                    enumDefBox.setSelectedIndex((Integer) info.getValue());
            } else if (info.isFile()) {
                view = "FILE";
                constDef.setSelected(true);
                final File file = (File) info.getValue();
                if (file != null) {
                    fileTextField.setText(file.getName());
                    fileTextField.setToolTipText(file.getAbsolutePath());
                }
            } else {
                view = "CONST";
                constDef.setSelected(true);
                constDefField.setText(info.valuesToString());
            }
            break;
        }
        case ParameterInfo.LIST_DEF:
            view = "LIST";
            listDef.setSelected(true);
            listDefArea.setText(info.valuesToString());
            break;
        case ParameterInfo.INCR_DEF:
            view = "INCREMENT";
            incrDef.setSelected(true);
            incrStartValueField.setText(info.startToString());
            incrEndValueField.setText(info.endToString());
            incrStepField.setText(info.stepToString());
        }

        final CardLayout cl = (CardLayout) rightMiddle.getLayout();
        cl.show(rightMiddle, view);
        enableDisableSettings(true);
        if (!info.isNumeric())
            incrDef.setEnabled(false);
        if (info.isEnum() || info instanceof MasonChooserParameterInfo || info.isFile()) {
            incrDef.setEnabled(false);
            listDef.setEnabled(false);
        }
        modifyButton.setEnabled(true);
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java

public void updateAvailableConcepts() {
    if (!isUpdatingAvailableConcepts.get() && this.isExportMapping) {
        isUpdatingAvailableConcepts.set(true);
        try {/*  w ww .  j  a va2s.co  m*/
            List<SpExportSchemaItem> available = this.getAvailableConcepts();
            for (QueryFieldPanel qfp : queryFieldItems) {
                JComboBox bx = qfp.getSchemaItemCBX();
                if (bx != null) {
                    DefaultComboBoxModel bxm = (DefaultComboBoxModel) bx.getModel();
                    bxm.removeAllElements();
                    for (SpExportSchemaItem i : available) {
                        bxm.addElement(i);
                    }
                    SpExportSchemaItem qi = qfp.getSchemaItem();
                    if (qi != null && qi.getSpExportSchemaItemId() != null) {
                        SpExportSchemaItem unMappedItem = new SpExportSchemaItem();
                        unMappedItem.setFieldName(getResourceString("QueryBldrPane.UnmappedSchemaItemName"));
                        bxm.insertElementAt(unMappedItem, 0);
                        bxm.insertElementAt(qi, 1);
                        bx.setSelectedIndex(1);
                    } else {
                        //System.out.println("Setting unmapped concept field name to " + qfp.getExportedFieldName());
                        SpExportSchemaItem unMappedItem = new SpExportSchemaItem();
                        String expFldName = qfp.getExportedFieldName();
                        if (StringUtils.isBlank(expFldName)) {
                            if (available.size() > 0) {
                                unMappedItem.setFieldName(
                                        getResourceString("QueryBldrPane.UnmappedSchemaItemName"));
                            } else {
                                unMappedItem.setFieldName(qfp.getFieldTitle());
                            }
                        } else {
                            unMappedItem.setFieldName(expFldName);
                        }
                        bxm.insertElementAt(unMappedItem, 0);
                        bx.setSelectedIndex(0);
                    }
                    bx.setEditable(qi == null || qi.getSpExportSchemaItemId() == null);
                }
            }
        } finally {
            isUpdatingAvailableConcepts.set(false);
        }
    }
}

From source file:org.nuclos.client.common.NuclosCollectController.java

/**
 * refreshes the combobox containing the filters
 *//*from w ww . j  a v  a 2s.c  om*/
protected void refreshFilterView() {
    // remember selected filter, if any:
    final SearchFilter filterSelected = getSelectedSearchFilter();

    final List<? extends SearchFilter> lstFilters;
    try {
        lstFilters = getSearchFilters().getAll();
    } catch (PreferencesException ex) {
        throw new NuclosFatalException(ex);
    }
    final DefaultComboBoxModel model = (DefaultComboBoxModel) this.getSearchFilterComboBox().getModel();

    // don't fire changed events here:
    this.getSearchFilterComboBox().removeActionListener(this.alSearchFilter);
    try {
        model.removeAllElements();
        model.addElement(newDefaultFilter());
        for (SearchFilter filter : lstFilters) {
            model.addElement(filter);
        }

        // try to restore the previously selected filter, if any:
        if (filterSelected != null) {
            setSelectedSearchFilter(filterSelected);
        }
    } finally {
        getSearchFilterComboBox().addActionListener(this.alSearchFilter);
    }

    // perform alSearchFilter's action manually:
    this.alSearchFilter.actionPerformed(null);
}

From source file:org.nuclos.client.ui.collect.component.CollectableComboBox.java

/**
 * uses a copy of the given Collection as model for this combobox. The selected value is not changed,
 * thus no CollectableFieldEvents are fired.
 * @param collEnumeratedFields Collection<CollectableField>
 * @param bSort Sort the fields before adding them to the model?
 * @todo make private/*  w w w.ja v a2 s  . c  o m*/
 */
public synchronized void setComboBoxModel(Collection<? extends CollectableField> collEnumeratedFields,
        boolean bSort) {
    final List<CollectableField> lst = new ArrayList<CollectableField>();
    if (collEnumeratedFields != null) {
        lst.addAll(collEnumeratedFields);
    }

    if (bSort) {
        Collections.sort(lst, CollectableFieldComparatorFactory.getInstance()
                .newCollectableFieldComparator(getEntityField()));
        //Collections.sort(lst, CollectableComparator.getFieldComparator(getEntityField()));
    }

    runLocked(new Runnable() {
        @Override
        public void run() {
            // re-fill the model:
            final DefaultComboBoxModel model = getDefaultComboBoxModel();

            model.removeAllElements();

            // forget the previous additional entry, if any. If an additional entry is needed after setting the model,
            // it will be set later:
            if (hasAdditionalEntry()) {
                removeAdditionalEntry();
            }

            // always add a null value as the first entry:
            model.addElement(getEntityField().getNullField());

            for (CollectableField clctf : lst) {
                Object value = clctf.getValue();
                if (value instanceof String) {
                    value = value.toString().replaceAll("\\p{Cntrl}", "");
                    if (clctf instanceof LocalizedCollectableValueField)
                        clctf = new LocalizedCollectableValueField(value,
                                ((LocalizedCollectableValueField) clctf).toLocalizedString());
                    else if (clctf instanceof CollectableValueField)
                        clctf = new CollectableValueField(value);
                    if (clctf instanceof LocalizedCollectableValueIdField)
                        clctf = new LocalizedCollectableValueIdField(
                                IdUtils.unsafeToId(((CollectableValueIdField) clctf).getValueId()), value,
                                ((LocalizedCollectableValueIdField) clctf).toLocalizedString());
                    else if (clctf instanceof CollectableValueIdField)
                        clctf = new CollectableValueIdField(((CollectableValueIdField) clctf).getValueId(),
                                value);
                }
                model.addElement(clctf);
            }

            // set the view according to the model:
            modelToView();
        }
    });

}

From source file:org.pentaho.ui.xul.swing.tags.SwingMenuList.java

public void layout() {
    inLayoutProcess = true;/*from   www  .j ava  2  s  . c  o  m*/
    if (suppressLayout) {
        inLayoutProcess = false;
        return;
    }
    SwingMenupopup popup = getPopupElement();
    DefaultComboBoxModel model = (DefaultComboBoxModel) this.combobox.getModel();
    model.removeAllElements();

    SwingMenuitem selectedItem = null;

    // capture first child as default selection
    boolean firstChild = true;
    for (XulComponent item : popup.getChildNodes()) {
        JMenuItem jmenuItem = (JMenuItem) ((SwingMenuitem) item).getManagedObject();
        SwingMenuitem tempItem = (SwingMenuitem) item;
        model.addElement(tempItem);

        if (tempItem.isSelected() || firstChild) {
            selectedItem = tempItem;
            firstChild = false;
        }
    }

    inLayoutProcess = false;

    if (selectedItem != null) {
        // if first setting it to the currently selected one will not fire event.
        // manually firing here
        if (model.getSelectedItem() == selectedItem) {
            fireSelectedEvents();
        }
        model.setSelectedItem(selectedItem);
    }
    initialized = true;
    loaded = true;
}

From source file:org.zaproxy.zap.extension.quickstart.AttackPanel.java

private void setRecentUrls() {
    if (urlField != null) {
        QuickStartParam quickStartParam = this.getExtensionQuickStart().getQuickStartParam();
        Object currentUrl = urlField.getSelectedItem();
        DefaultComboBoxModel<String> model = getUrlModel();
        model.removeAllElements();
        List<Object> recentUrls = quickStartParam.getRecentUrls();
        for (Object url : recentUrls) {
            if (url != null) {
                model.addElement(url.toString());
            }/*from www.ja  va  2 s  .c  om*/
        }
        if (currentUrl != null && currentUrl.toString().length() > 0) {
            urlField.setSelectedItem(currentUrl);
        } else {
            urlField.setSelectedItem(DEFAULT_VALUE_URL_FIELD);
        }
    }
}

From source file:paquete.HollywoodUI.java

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
    try {//from  w w  w . j  ava 2s.c  o m
        Peliculas.remove(cb_delete_movie.getSelectedIndex());
        if (Peliculas.isEmpty()) {
            DefaultComboBoxModel model = (DefaultComboBoxModel) cb_delete_movie.getModel();
            model.removeAllElements();
            model.addElement("No hay mas peliculas");
        } else {
            DefaultComboBoxModel model = (DefaultComboBoxModel) cb_delete_movie.getModel();
            model.removeElementAt(Peliculas.size() - 1);
            model.addElement(Peliculas.get(Peliculas.size() - 1));
        }
        JOptionPane.showMessageDialog(delete_movie, "Pelicula eliminada por completo", "INFO",
                JOptionPane.INFORMATION_MESSAGE);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(delete_movie, "Error al tratar de eliminar la pelicula", "Error",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:se.trixon.toolbox.rsync.job.JobManager.java

public DefaultComboBoxModel populateModel(DefaultComboBoxModel model) {

    model.removeAllElements();

    for (Job job : mJobs) {
        model.addElement(job);/*from  w w w  .  ja v  a 2 s. c o m*/
    }

    return model;
}

From source file:vn.hieptn.interesttopic.InterestTopicMain.java

private void tabTwitterCollectionStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabTwitterCollectionStateChanged
    // TODO add your handling code here:
    System.out.println("Mo:" + tabTwitterCollection.getSelectedIndex());
    DefaultComboBoxModel modelTopic = (DefaultComboBoxModel) cmboxTopic.getModel();
    modelTopic.removeAllElements();

    if (tabTwitterCollection.getSelectedIndex() == 2) {
        List<ClassifiedTopicEnt> lstTopic = DataBaseService.GetListDataClassifiedTopic();
        if (lstTopic != null && lstTopic.size() > 0) {
            for (ClassifiedTopicEnt tmpTopic : lstTopic) {
                if (tmpTopic != null) {
                    modelTopic.addElement(tmpTopic.TopicName);
                    ConfigInfo.MAP_TOPIC_REPORT.put(tmpTopic.TopicName, tmpTopic);
                }/*from   www  .  j a v a 2  s .  c  om*/
            }

            cmboxTopic.setModel(modelTopic);
        }
    }
}