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:user.NewJPanel2.java

private void setCheckBox(String[] items) {
    DefaultComboBoxModel model = (DefaultComboBoxModel) choiceBox2.getModel();
    model.removeAllElements();

    for (String item : items) {
        model.addElement(item);/*from  w  w w.  j a v  a  2 s. c  o m*/
    }
    choiceBox2.setModel(model);

}

From source file:user.Screen.java

private void setCheckBox(String[] items) {
    DefaultComboBoxModel model = (DefaultComboBoxModel) choiceBox2.getModel();
    model.removeAllElements();

    for (String item : items) {
        model.addElement(item);//from w  ww  .ja  v  a2 s . com
    }
    choiceBox2.setModel(model);
}

From source file:com.github.alexfalappa.nbspringboot.projects.initializr.InitializrProjectPanelVisual1.java

private void fillCombo(JsonNode attrNode, DefaultComboBoxModel<NamedItem> comboModel, JComboBox combo) {
    JsonNode valArray = attrNode.path("values");
    comboModel.removeAllElements();
    for (JsonNode val : valArray) {
        comboModel.addElement(new NamedItem(val.get("id").asText(), val.get("name").asText()));
    }/* w ww  .j av a  2 s  .c  o m*/
    combo.setModel(comboModel);
    combo.setSelectedItem(new NamedItem(attrNode.path("default").asText(), ""));
}

From source file:org.pentaho.reporting.designer.extensions.legacycharts.LegacyChartEditModel.java

private void populateExpressionSelectorModel(final DefaultComboBoxModel model, final Class resultType) {
    model.removeAllElements();
    if (resultType == null) {
        model.setSelectedItem(null);/*  w w  w  .j a v a 2s  .  c o m*/
        return;
    }

    final ExpressionMetaData[] allExpressionMetaDatas = ExpressionRegistry.getInstance()
            .getAllExpressionMetaDatas();
    Arrays.sort(allExpressionMetaDatas, new GroupedMetaDataComparator());
    for (int i = 0; i < allExpressionMetaDatas.length; i++) {
        final ExpressionMetaData data = allExpressionMetaDatas[i];
        if (data.isHidden()) {
            continue;
        }
        if (!WorkspaceSettings.getInstance().isVisible(data)) {
            continue;
        }
        if (StructureFunction.class.isAssignableFrom(data.getExpressionType())) {
            continue;
        }

        if (resultType.isAssignableFrom(data.getResultType())) {
            model.addElement(data);
        }
    }

    model.setSelectedItem(null);
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatDlg.java

/**
 * Populates the field value combo with fields and leaves the right one
 * selected (for multiple formats)/*  w  w  w  .jav a 2s. c om*/
 */
protected void addValueFieldsToCombo(DataObjSwitchFormatter switchFormatter) {
    // clear combo box list
    DefaultComboBoxModel cboModel = (DefaultComboBoxModel) valueFieldCbo.getModel();
    cboModel.removeAllElements();

    // add fields to combo box
    List<DBFieldInfo> fields = tableInfo.getFields();
    int selectedFieldIndex = -1;
    for (int i = 0; i < fields.size(); ++i) {
        DBFieldInfo currentField = fields.get(i);
        cboModel.addElement(currentField);
        if (switchFormatter != null && currentField.getName().equals(switchFormatter.getFieldName())) {
            // found the selected field
            selectedFieldIndex = i;
        }
    }

    // set selected field
    if (selectedFieldIndex != -1) {
        valueFieldCbo.setSelectedIndex(selectedFieldIndex);
    }
}

From source file:edu.ku.brc.specify.datamodel.busrules.PickListBusRules.java

@Override
public void adjustForm(final FormViewObj fvo) {
    final ValComboBox formatterCBX = (ValComboBox) fvo.getControlByName("formatterCBX");
    final ValComboBox tablesCBX = (ValComboBox) fvo.getControlByName("tablesCBX");
    final ValComboBox fieldsCBX = (ValComboBox) fvo.getControlByName("fieldsCBX");
    final ValComboBox typesCBX = (ValComboBox) fvo.getControlByName("typesCBX");
    final ValCheckBox readOnlyChk = (ValCheckBox) fvo.getControlByName("readOnly");

    tablesCBX.getComboBox().addActionListener(new ActionListener() {
        @Override//from   www  .ja  v  a2s . c o  m
        public void actionPerformed(ActionEvent e) {
            tableSelected(fvo);
        }
    });

    typesCBX.getComboBox().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            typeSelected(fvo);
        }
    });

    readOnlyChk.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (!readOnlyChk.isSelected() && formViewObj.getDataObj() != null) {
                adjustSizeSpinner();
            }
        }
    });

    fieldsCBX.setEnabled(false);
    formatterCBX.setEnabled(false);

    fillTableNameCBX(tablesCBX);

    DefaultComboBoxModel model = (DefaultComboBoxModel) typesCBX.getComboBox().getModel();
    model.removeAllElements();
    String[] types = { getResourceString("PL_ITEMS"), getResourceString("PL_TABLE"),
            getResourceString("PLTABLEFIELD") };
    for (String title : types) {
        model.addElement(title);
    }
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjAggregatorDlg.java

protected void updateFieldValueCombo() {
    // clear combo box list
    DefaultComboBoxModel cboModel = (DefaultComboBoxModel) fieldOrderCbo.getModel();
    cboModel.removeAllElements();

    // add an empty entry at the beginning so the user can clear the selection if he wants to
    cboModel.addElement(getResourceString("NONE"));

    // add fields to combo box
    List<DBFieldInfo> fields = tableInfo.getFields();
    int selectedFieldIndex = 0;
    for (int i = 0; i < fields.size(); ++i) {
        DBFieldInfo currentField = fields.get(i);
        cboModel.addElement(currentField);
        if (selectedAggregator != null
                && currentField.getName().equals(selectedAggregator.getOrderFieldName())) {
            // found the selected field
            // current combo index is (i+1) because of empty entry at the beginning
            selectedFieldIndex = i + 1;//from w w  w .  j a  v  a2  s  .  c  om
        }
    }

    // set selected field
    fieldOrderCbo.setSelectedIndex(selectedFieldIndex);
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjAggregatorDlg.java

protected void updateDisplayCombo() {
    // save selected aggregator because that one will be reset when elements are removed from combo box model
    DataObjAggregator tempAgg = selectedAggregator;

    // clear combo box list
    DefaultComboBoxModel cboModel = (DefaultComboBoxModel) displayCbo.getModel();
    cboModel.removeAllElements();

    // add formatters to display combo box
    List<DataObjSwitchFormatter> fmts = dataObjFieldFormatMgrCache.getFormatterList(tableInfo.getClassObj());

    // add an empty entry at the beginning so the user can clear the selection if he wants to
    cboModel.addElement(getResourceString("NONE"));

    if (fmts.size() == 0) {
        return;/*from  w  ww .  j a  v  a 2  s. com*/
    }

    int selectedFieldIndex = 0;
    for (int i = 0; i < fmts.size(); ++i) {
        DataObjSwitchFormatter currentFormat = fmts.get(i);
        cboModel.addElement(currentFormat);
        if (tempAgg != null && currentFormat.getName().equals(tempAgg.getFormatName())) {
            // found the selected field
            // current combo index is (i+1) because of empty entry at the beginning
            selectedFieldIndex = i + 1;
        }
    }

    // set selected field
    displayCbo.setSelectedIndex(selectedFieldIndex);
}

From source file:com.qspin.qtaste.ui.ConfigInfoPanel.java

public void init() {

    setLayout(new GridBagLayout());
    GridBagLineAdder adder = new GridBagLineAdder(this);
    adder.setWeight(1.0f, 0.0f);//from   w  w w. jav a2 s  .co  m
    adder.setLength(6);

    //1st column - 1st row
    adder.setWeight(0.0, 0.0);
    adder.add(new JLabel("Test suite:"));
    adder.setWeight(1.0, 0.0);
    adder.add(mTestSuiteLabel);
    adder.setWeight(0.0, 0.0);

    //2d column - 1st row
    adder.add(new JLabel("Testbed config:"));
    // set the combobox as read only (not possible to modify the testbed from GUI at this time
    UIManager.put("ComboBox.disabledForeground", Color.BLACK);
    mTestbedList.setEnabled(true);
    adder.add(mTestbedList);

    // add testbed mouse listener, for the "Edit File" action
    TestbedMouseListener testbedMouseListener = new TestbedMouseListener();
    java.awt.Component[] mTestbedListComponents = mTestbedList.getComponents();
    for (int i = 0; i < mTestbedListComponents.length; i++) {
        mTestbedListComponents[i].addMouseListener(testbedMouseListener);
    }

    // go to second row
    adder.addSeparator();

    //1st column - 2d row
    adder.add(new JLabel("Test results directory:"));
    adder.add(mTestResultsLabel);

    //2d column - 2d row
    m_ignoreControlScript.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            TestEngine.setIgnoreControlScript(ignoreControlScript());
            setControlTestbedButtonsEnabled();

            GUIConfiguration guiConfiguration = GUIConfiguration.getInstance();
            guiConfiguration.setProperty(StaticConfiguration.IGNORE_CONTROL_SCRIPT_PROPERTY,
                    m_ignoreControlScript.isSelected());
            try {
                guiConfiguration.save();
            } catch (ConfigurationException ex) {
                logger.error("Error while saving GUI configuration: " + ex.getMessage());
            }
        }
    });
    adder.add(m_ignoreControlScript);
    JPanel sutPanel = new JPanel();
    JLabel sutVersion = new JLabel("SUT version: ");
    sutPanel.add(sutVersion);
    m_SUTVersion.setHorizontalAlignment(JTextField.RIGHT);
    m_SUTVersion.setPreferredSize(new Dimension(150, m_SUTVersion.getPreferredSize().height));
    sutPanel.add(m_SUTVersion);
    adder.add(sutPanel);
    m_SUTVersion.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            TestBedConfiguration.setSUTVersion(m_SUTVersion.getText());
        }
    });
    //create a 3d row
    adder.addSeparator();

    //1st column - 3d row
    adder.add(new JLabel("Reporting Format:"));
    adder.add(mTestReportingFormat);

    //2d column - 3d row
    // add a button to manually start the testbed
    m_startTestbed.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            isStartingOrStoppingTestbed = true;
            setControlTestbedButtonsEnabled();
            parent.getTestCasePanel().setStopButtonEnabled(true, true);
            parent.getTestCasePanel().showTestcaseResultsTab();
            TestBedConfiguration.setSUTVersion(getSUTVersion());
            new SUTStartStopThread("start").start();
        }
    });
    m_startTestbed.setEnabled(false);
    adder.add(m_startTestbed);

    // add a button to manually stop the testbed
    m_stopTestbed.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            isStartingOrStoppingTestbed = true;
            setControlTestbedButtonsEnabled();
            parent.getTestCasePanel().showTestcaseResultsTab();
            TestBedConfiguration.setSUTVersion(getSUTVersion());
            new SUTStartStopThread("stop").start();
        }
    });
    m_stopTestbed.setEnabled(false);
    adder.add(m_stopTestbed);

    DefaultComboBoxModel model = (DefaultComboBoxModel) mTestbedList.getModel();
    model.removeAllElements();
    String testbedDir = testbedConfig.getFile().getParent();
    File fTestbedDir = new File(testbedDir);
    FileMask fileMask = new FileMask();
    fileMask.addExtension("xml");
    File[] fTestbedList = FileUtilities.listSortedFiles(fTestbedDir, fileMask);
    for (int i = 0; i < fTestbedList.length; i++) {
        // remove the extension
        String testbedName = fTestbedList[i].getName().substring(0, fTestbedList[i].getName().lastIndexOf('.'));
        model.addElement(testbedName);
    }

    mTestbedList.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (mTestbedList.getSelectedItem() != null) {
                String selectedTestbed = (String) mTestbedList.getSelectedItem();
                String configFile = StaticConfiguration.TESTBED_CONFIG_DIRECTORY + "/" + selectedTestbed + "."
                        + StaticConfiguration.TESTBED_CONFIG_FILE_EXTENSION;
                TestBedConfiguration.setConfigFile(configFile);

                GUIConfiguration guiConfiguration = GUIConfiguration.getInstance();
                guiConfiguration.setProperty(StaticConfiguration.LAST_SELECTED_TESTBED_PROPERTY,
                        selectedTestbed);
                try {
                    guiConfiguration.save();
                } catch (ConfigurationException ex) {
                    logger.error("Error while saving GUI configuration: " + ex.getMessage());
                }
            }
            refreshData();
        }
    });

    refreshTestBed();
    refreshData();
    if (GUIConfiguration.getInstance().getBoolean(StaticConfiguration.IGNORE_CONTROL_SCRIPT_PROPERTY, false))
        m_ignoreControlScript.doClick();

    TestBedConfiguration
            .registerConfigurationChangeHandler(new TestBedConfiguration.ConfigurationChangeHandler() {

                public void onConfigurationChange() {
                    testbedConfig = TestBedConfiguration.getInstance();
                    String configFileName = testbedConfig.getFile().getName();
                    mTestbedList.getModel()
                            .setSelectedItem(configFileName.substring(0, configFileName.lastIndexOf('.')));
                }
            });
}

From source file:edu.ku.brc.specify.datamodel.busrules.PickListBusRules.java

/**
 * /*from   w ww  .  j a v a  2  s .  c  om*/
 */
private void tableSelected(final FormViewObj fvo) {
    ValComboBox formatterCBX = (ValComboBox) fvo.getControlByName("formatterCBX");
    ValComboBox tablesCBX = (ValComboBox) fvo.getControlByName("tablesCBX");
    ValComboBox fieldsCBX = (ValComboBox) fvo.getControlByName("fieldsCBX");

    fvo.getValidator().setHasChanged(true);
    tablesCBX.setChanged(true);

    //int typeIndex = typesCBX.getComboBox().getSelectedIndex();

    String noneStr = getResourceString("NONE");

    PickList pickList = (PickList) fvo.getDataObj();
    if (pickList == null) {
        return;
    }

    JComboBox tableCbx = tablesCBX.getComboBox();
    DBTableInfo tblInfo = (DBTableInfo) tableCbx.getSelectedItem();
    if (tblInfo != null) {
        if (tblInfo.getName().equals(noneStr)) {
            pickList.setTableName(null);
            pickList.setFieldName(null);
            pickList.setFormatter(null);

        } else {
            pickList.setTableName(tblInfo.getName());

            DefaultComboBoxModel fldModel = (DefaultComboBoxModel) fieldsCBX.getComboBox().getModel();
            fldModel.removeAllElements();

            for (DBFieldInfo fi : tblInfo.getFields()) {
                if (fi.getDataClass() == String.class) {
                    fldModel.addElement(fi);
                }
            }

            Vector<DataObjSwitchFormatter> list = new Vector<DataObjSwitchFormatter>();
            for (DataObjSwitchFormatter fmt : DataObjFieldFormatMgr.getInstance().getFormatters()) {
                if (fmt.getDataClass() == tblInfo.getClassObj()) {
                    list.add(fmt);
                }
            }

            DefaultComboBoxModel fmtModel = (DefaultComboBoxModel) formatterCBX.getComboBox().getModel();
            fmtModel.removeAllElements();

            if (list.size() > 0) {
                Collections.sort(list);

                for (DataObjSwitchFormatter fmt : list) {
                    fmtModel.addElement(fmt);
                }
                formatterCBX.setEnabled(true);
            } else {
                formatterCBX.setEnabled(false);
            }
        }

    } else {
        fieldsCBX.setEnabled(false);
    }
}