Example usage for javax.swing DefaultComboBoxModel addElement

List of usage examples for javax.swing DefaultComboBoxModel addElement

Introduction

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

Prototype

public void addElement(E anObject) 

Source Link

Usage

From source file:op.tools.SYSTools.java

public static <T> DefaultComboBoxModel<T> list2cmb(List<T> list) {
    DefaultComboBoxModel cmb = new DefaultComboBoxModel<T>();
    if (list != null) {
        for (T t : list) {
            cmb.addElement(t);
        }/*  w  w  w. j  av a 2 s.  c o m*/
    }
    return cmb;
}

From source file:org.mbs3.juniuploader.gui.pnlSettings.java

private void initGUI() {
    try {//from   w ww  . j a  v a 2s  . co  m
        GridBagLayout thisLayout = new GridBagLayout();
        thisLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                0.0, 0.0, 0.0, 0.0 };
        thisLayout.rowHeights = new int[] { 11, 20, 18, 22, 22, 23, 23, 20, 18, 23, 22, 24, 6, 26, 4, 30, 8 };
        thisLayout.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 0.0, 0.1, 0.0 };
        thisLayout.columnWidths = new int[] { 10, 106, 90, 20, 20, 7, 100, 20, 7 };
        this.setLayout(thisLayout);
        this.setPreferredSize(new java.awt.Dimension(659, 349));
        {
            {
                grpMain = new ButtonGroup();
            }
            {
                grpGUI = new ButtonGroup();
            }
            {
                grpObjects = new ButtonGroup();
            }
            {
                grpHTTP = new ButtonGroup();
            }
            {
            }
            {
            }
            lblGUI = new JLabel();
            this.add(lblGUI, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            lblGUI.setText("Graphical Interface");
        }
        {
            lblMain = new JLabel();
            this.add(lblMain, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            lblMain.setText("Main Program");
        }
        {
            lblObj = new JLabel();
            this.add(lblObj, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            lblObj.setText("Object Messages");
        }
        {
            lblLObj = new JLabel();
            this.add(lblLObj, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            lblLObj.setText("HTTP Messages");
        }
        {
            lblFatal = new JLabel();
            this.add(lblFatal, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            lblFatal.setText("Fatal Messages");
        }
        {
            lblError = new JLabel();
            this.add(lblError, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            lblError.setText("Errors");
        }
        {
            lblWarn = new JLabel();
            this.add(lblWarn, new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            lblWarn.setText("Warnings");
        }
        {
            lblInfo = new JLabel();
            this.add(lblInfo, new GridBagConstraints(5, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            lblInfo.setText("Info Messages");
        }
        {
            lblDebug = new JLabel();
            this.add(lblDebug, new GridBagConstraints(6, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            lblDebug.setText("Debug Messages");
        }
        {
            lblTrace = new JLabel();
            this.add(lblTrace, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            lblTrace.setText("Trace Execution");
        }
        {
            btnMainFatal = new JRadioButton();
            this.add(btnMainFatal, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        }
        grpMain.add(btnMainFatal);
        btnMainFatal.setActionCommand("fatal");
        btnMainFatal.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                logLevelBtnAction(evt);
            }
        });
        {
            btnMainError = new JRadioButton();
            this.add(btnMainError, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpMain.add(btnMainError);
            btnMainError.setActionCommand("error");
            btnMainError.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnMainWarn = new JRadioButton();
            this.add(btnMainWarn, new GridBagConstraints(4, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpMain.add(btnMainWarn);
            btnMainWarn.setActionCommand("warn");
            btnMainWarn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnMainInfo = new JRadioButton();
            this.add(btnMainInfo, new GridBagConstraints(5, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpMain.add(btnMainInfo);
            btnMainInfo.setActionCommand("info");
            btnMainInfo.setSelected(true);
            btnMainInfo.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnMainDebug = new JRadioButton();
            this.add(btnMainDebug, new GridBagConstraints(6, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpMain.add(btnMainDebug);
            btnMainDebug.setActionCommand("debug");
            btnMainDebug.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnMainTrace = new JRadioButton();
            this.add(btnMainTrace, new GridBagConstraints(7, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpMain.add(btnMainTrace);
            btnMainTrace.setActionCommand("trace");
            btnMainTrace.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnGUIFatal = new JRadioButton();
            this.add(btnGUIFatal, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpGUI.add(btnGUIFatal);
            btnGUIFatal.setActionCommand("fatal");
            btnGUIFatal.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnGUIError = new JRadioButton();
            this.add(btnGUIError, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpGUI.add(btnGUIError);
            btnGUIError.setActionCommand("error");
            btnGUIError.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnGUIWarn = new JRadioButton();
            this.add(btnGUIWarn, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpGUI.add(btnGUIWarn);
            btnGUIWarn.setActionCommand("warn");
            btnGUIWarn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnGUIInfo = new JRadioButton();
            this.add(btnGUIInfo, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpGUI.add(btnGUIInfo);
            btnGUIInfo.setActionCommand("info");
            btnGUIInfo.setSelected(true);
            btnGUIInfo.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnGUIDebug = new JRadioButton();
            this.add(btnGUIDebug, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpGUI.add(btnGUIDebug);
            btnGUIDebug.setActionCommand("debug");
            btnGUIDebug.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnGUITrace = new JRadioButton();
            this.add(btnGUITrace, new GridBagConstraints(7, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpGUI.add(btnGUITrace);
            btnGUITrace.setActionCommand("trace");
            btnGUITrace.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnObjFatal = new JRadioButton();
            this.add(btnObjFatal, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpObjects.add(btnObjFatal);
            btnObjFatal.setActionCommand("fatal");
            btnObjFatal.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnObjError = new JRadioButton();
            this.add(btnObjError, new GridBagConstraints(3, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpObjects.add(btnObjError);
            btnObjError.setActionCommand("error");
            btnObjError.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnObjWarn = new JRadioButton();
            this.add(btnObjWarn, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpObjects.add(btnObjWarn);
            btnObjWarn.setActionCommand("warn");
            btnObjWarn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnObjInfo = new JRadioButton();
            this.add(btnObjInfo, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpObjects.add(btnObjInfo);
            btnObjInfo.setActionCommand("info");
            btnObjInfo.setSelected(true);
            btnObjInfo.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnObjDebug = new JRadioButton();
            this.add(btnObjDebug, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpObjects.add(btnObjDebug);
            btnObjDebug.setActionCommand("debug");
            btnObjDebug.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnObjTrace = new JRadioButton();
            this.add(btnObjTrace, new GridBagConstraints(7, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpObjects.add(btnObjTrace);
            btnObjTrace.setActionCommand("trace");
            btnObjTrace.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnHTTPFatal = new JRadioButton();
            this.add(btnHTTPFatal, new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpHTTP.add(btnHTTPFatal);
            btnHTTPFatal.setActionCommand("fatal");
            btnHTTPFatal.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnHTTPError = new JRadioButton();
            this.add(btnHTTPError, new GridBagConstraints(3, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpHTTP.add(btnHTTPError);
            btnHTTPError.setActionCommand("error");
            btnHTTPError.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnHTTPWarn = new JRadioButton();
            this.add(btnHTTPWarn, new GridBagConstraints(4, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpHTTP.add(btnHTTPWarn);
            btnHTTPWarn.setActionCommand("warn");
            btnHTTPWarn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnHTTPInfo = new JRadioButton();
            this.add(btnHTTPInfo, new GridBagConstraints(5, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpHTTP.add(btnHTTPInfo);
            btnHTTPInfo.setActionCommand("info");
            btnHTTPInfo.setSelected(true);
            btnHTTPInfo.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnHTTPDebug = new JRadioButton();
            this.add(btnHTTPDebug, new GridBagConstraints(6, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpHTTP.add(btnHTTPDebug);
            btnHTTPDebug.setActionCommand("debug");
            btnHTTPDebug.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            btnHTTPTrace = new JRadioButton();
            this.add(btnHTTPTrace, new GridBagConstraints(7, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            grpHTTP.add(btnHTTPTrace);
            btnHTTPTrace.setActionCommand("trace");
            btnHTTPTrace.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    logLevelBtnAction(evt);
                }
            });
        }
        {
            lblLogLevel = new JLabel();
            this.add(lblLogLevel, new GridBagConstraints(1, 1, 7, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            lblLogLevel.setText("Set the level of logging for different parts of this application:");
        }
        {
            lblDeLF = new JLabel();
            this.add(lblDeLF, new GridBagConstraints(1, 8, 6, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            lblDeLF.setText("Set the look and feel for the GUI of this application:");
        }
        {
            LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels();
            LookAndFeel lf = UIManager.getLookAndFeel();
            DefaultComboBoxModel cmbLFModel = new DefaultComboBoxModel();
            for (int i = 0; i < lfs.length; i++) {
                String n = lfs[i].getName();
                cmbLFModel.addElement(n);
                if (lf.getName().equals(lfs[i].getName()))
                    cmbLFModel.setSelectedItem(n);
            }
            cmbLF = new JComboBox();
            this.add(cmbLF, new GridBagConstraints(1, 9, 6, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            cmbLF.setModel(cmbLFModel);
            cmbLF.addItemListener(new ItemListener() {
                public void itemStateChanged(ItemEvent evt) {
                    cmbLFItemStateChanged(evt);
                }
            });
        }
        {
            tfUserAgent = new JTextField(Util.getUserAgent());
            this.add(tfUserAgent, new GridBagConstraints(1, 11, 6, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            tfUserAgent.addKeyListener(new KeyAdapter() {
                public void keyReleased(KeyEvent evt) {
                    tfUserAgentKeyReleased(evt);
                }
            });
        }
        {
            lblUserAgent = new JLabel();
            this.add(lblUserAgent, new GridBagConstraints(1, 10, 6, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            lblUserAgent.setText("User Agent");
        }
        {
            btnExport = new JToggleButton();
            this.add(btnExport, new GridBagConstraints(1, 15, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            btnExport.setText("Export All Settings and Data to File");
            btnExport.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    btnExportActionPerformed(evt);
                }
            });
        }
        {
            txtWarn = new JTextPane();
            this.add(txtWarn, new GridBagConstraints(4, 15, 4, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            txtWarn.setText(
                    "Note: This includes rules, form variables, sites, and ANYTHING else this program can remember from run to run.");
            txtWarn.setEditable(false);
            txtWarn.setBackground(new java.awt.Color(255, 255, 255));
            txtWarn.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0)));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.netbeans.jpa.modeler.properties.named.nativequery.NamedNativeQueryPanel.java

private void initResultClassesModel() {
    resultClass_jComboBox.removeAllItems();
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    model.addElement(null);
    for (org.netbeans.jpa.modeler.spec.Entity entity : entityMappings.getEntity()) {
        model.addElement(entity.getClazz());
    }//from w w  w .j  a  va 2 s  .  co  m
    resultClass_jComboBox.setModel(model);
}

From source file:org.netbeans.jpa.modeler.properties.named.nativequery.NamedNativeQueryPanel.java

private void initResultSetMappingModel() {
    resultSetMapping_jComboBox.removeAllItems();
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    model.addElement(null);
    for (SqlResultSetMapping mapping : entity.getSqlResultSetMapping()) {
        model.addElement(mapping.getName());
    }/*from  w  w  w.  ja  va2s .  c  o  m*/
    resultSetMapping_jComboBox.setModel(model);
}

From source file:org.netbeans.jpa.modeler.properties.named.nativequery.NamedNativeQueryPanel.java

private void addResultClass(String resultClass) {
    DefaultComboBoxModel model = (DefaultComboBoxModel) resultClass_jComboBox.getModel();
    String unqualifiedClassName = SourceGroupSupport.getClassName(resultClass);
    if (model.getIndexOf(unqualifiedClassName) != -1) { // check if it is Entity then select
        resultClass_jComboBox.setSelectedItem(unqualifiedClassName);
    } else { //if other class
        if (model.getIndexOf(resultClass) == -1) {
            model.addElement(resultClass);
        }/*from  w w w. j a va2s .c  om*/
        resultClass_jComboBox.setSelectedItem(resultClass);
    }
}

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

/**
 * Command: save filter/*from   w  ww  . j a  v a2s . c  om*/
 */
protected void cmdSaveFilter() {
    UIUtils.runCommand(this.getTab(), new CommonRunnable() {
        @Override
        public void run() throws CommonValidationException {
            if (!stopEditingInSearch()) {
                throw new CommonValidationException(
                        getSpringLocaleDelegate().getMessage("NuclosCollectController.4",
                                "Die eingegebene Suchbedingung ist ung\u00fcltig bzw. unvollst\u00e4ndig."));
            }
            try {
                final SearchFilter filterSelected = getSelectedSearchFilter();
                SearchFilter filterCurrent = getCurrentSearchFilterFromSearchPanel();
                final DefaultComboBoxModel model = (DefaultComboBoxModel) getSearchFilterComboBox().getModel();
                final SaveFilterController.Command cmd = new SaveFilterController(getTab(), getSearchFilters())
                        .runSave(filterSelected, filterCurrent);
                switch (cmd) {
                case None:
                    // do nothing
                    break;

                case Overwrite:
                    selectDefaultFilter();
                    getSearchFilterComboBox().removeItem(filterSelected);
                    // note that there is no "break" here!

                case New:
                    filterCurrent = SearchFilterCache.getInstance().getSearchFilter(filterCurrent.getName(),
                            filterCurrent.getOwner());
                    model.addElement(filterCurrent);
                    UIUtils.ensureMinimumSize(getTab());
                    getSearchFilterComboBox().setSelectedItem(filterCurrent);
                    break;

                default:
                    assert false;
                }
            } catch (CommonBusinessException ex) {
                Errors.getInstance().showExceptionDialog(getTab(), ex);
            }
        }
    });
}

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

/**
 * refreshes the combobox containing the filters
 *///w w w  . j  a v a  2s  .  com
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//from  w w  w  .j ava 2 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.openmicroscopy.shoola.agents.fsimporter.chooser.LocationDialog.java

/**
 * Populates the JComboBox with the user details provided, 
 * selecting the logged in user and attaching the item listener.
 * //w  w w.j a  v  a2s.  co  m
 * @param comboBox The JComboBox to populate
 * @param group The group being displayed
 * @param itemListener An item listener to add for the JComboBox
 * @param userID The id of the user.
 */
private void displayUsers(JComboBox comboBox, GroupData group, ItemListener itemListener, long userID) {

    if (comboBox == null || group == null)
        return;

    if (itemListener != null)
        comboBox.removeItemListener(itemListener);
    comboBox.removeAllItems();

    DefaultComboBoxModel model = new SelectableComboBoxModel();
    Selectable<ExperimenterDisplay> selected = null;

    List<ExperimenterData> members = sort(group.getExperimenters());
    boolean canImportAs;
    Selectable<ExperimenterDisplay> item;
    List<String> tooltips = new ArrayList<String>(members.size());
    List<String> lines;
    for (ExperimenterData user : members) {
        canImportAs = canImportForUserInGroup(user, group);
        item = new Selectable<ExperimenterDisplay>(new ExperimenterDisplay(user), canImportAs);
        if (user.getId() == userID)
            selected = item;
        lines = new ArrayList<String>();
        lines.addAll(UIUtilities.wrapStyleWord(EditorUtil.formatExperimenter(user)));
        tooltips.add(UIUtilities.formatToolTipText(lines));
        model.addElement(item);
    }
    ComboBoxToolTipRenderer renderer = createComboboxRenderer();
    renderer.setTooltips(tooltips);
    comboBox.setModel(model);
    comboBox.setRenderer(renderer);

    if (selected != null)
        comboBox.setSelectedItem(selected);

    if (itemListener != null)
        comboBox.addItemListener(itemListener);
}

From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java

private void initSettingsConfig() {
    Settings s = Settings.getInstance();

    settingsFolderTextField.setText(s.getConfDir());
    panboxFolderTextField.setText(s.getMountDir());
    languageComboBox.setSelectedItem(SupportedLanguage.fromShorthand(s.getLanguage()));
    expertModeCheckBox.setSelected(s.getExpertMode());
    uriHandlerCheckbox.setSelected(s.isUriHandlerSupported());
    if (uriHandlerCheckbox.isSelected()) {
        clipboardHandlerCheckbox.setEnabled(true);
        clipboardHandlerCheckbox.setSelected(s.isClipboardHandlerSupported());
    } else {//w  w w .ja va 2  s. c  o m
        clipboardHandlerCheckbox.setEnabled(false);
        clipboardHandlerCheckbox.setSelected(false);
    }
    mailtoSchemeCheckbox.setSelected(s.isMailtoSchemeSupported());
    if (cspSelectionComboBox.getModel().getSize() > 0) {
        // in case dropbox has been found select it by default
        selectedCSPContentPanel.removeAll();
        selectedCSPContentPanel.add(dropboxSettingsPanel);
    }

    NetworkInterface nic;
    try {
        if (s.getPairingAddress() == null) {
            // no network interface found!
            DefaultComboBoxModel<Object> noNicModel = new DefaultComboBoxModel<>();

            noNicModel.addElement(bundle.getString("client.networkinterface.notexisting"));

            networkInterfaceComboBox.setModel(noNicModel);
            networkAddressComboBox.setModel(noNicModel);
            return; // finish from here
        }
        DefaultComboBoxModel<Object> model = generateNetworkInterfacesModel();
        nic = NetworkInterface.getByInetAddress(s.getPairingAddress());
        if (nic == null) {
            // The configured IP address does not exist anymore! Will reset
            // to localhost
            s.setPairingAddress(InetAddress.getByName("localhost"));
            nic = NetworkInterface.getByInetAddress(s.getPairingAddress());
        }
        model.setSelectedItem(nic);
        networkInterfaceComboBox.setModel(model);
        networkAddressComboBox.setModel(generateNetworkAddressModel(nic));
    } catch (SocketException | UnknownHostException e) {
        logger.warn("Paiting settings Exception", e);
    }
}