Example usage for javax.swing DefaultComboBoxModel setSelectedItem

List of usage examples for javax.swing DefaultComboBoxModel setSelectedItem

Introduction

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

Prototype

public void setSelectedItem(Object anObject) 

Source Link

Document

Set the value of the selected item.

Usage

From source file:org.apache.cayenne.modeler.editor.SelectPropertiesPanel.java

/**
 * Updates the view from the current model state. Invoked when a currently displayed
 * query is changed.// ww  w. ja va 2 s  .  c  om
 */
public void initFromModel(QueryDescriptor query) {
    DefaultComboBoxModel cacheModel = new DefaultComboBoxModel(CACHE_POLICIES);

    String selectedStrategyString = query.getProperty(QueryMetadata.CACHE_STRATEGY_PROPERTY);

    QueryCacheStrategy selectedStrategy = selectedStrategyString != null
            ? QueryCacheStrategy.valueOf(selectedStrategyString)
            : null;

    cacheModel.setSelectedItem(
            selectedStrategy != null ? selectedStrategy : QueryCacheStrategy.getDefaultStrategy());

    cacheStrategy.setModel(cacheModel);

    cacheGroups.setText(query.getProperty(QueryMetadata.CACHE_GROUPS_PROPERTY));
    setCacheGroupsEnabled(selectedStrategy != null && selectedStrategy != QueryCacheStrategy.NO_CACHE);

    String fetchOffsetStr = query.getProperty(QueryMetadata.FETCH_OFFSET_PROPERTY);
    String fetchLimitStr = query.getProperty(QueryMetadata.FETCH_LIMIT_PROPERTY);
    String pageSizeStr = query.getProperty(QueryMetadata.PAGE_SIZE_PROPERTY);

    fetchOffset.setText(fetchOffsetStr != null ? fetchOffsetStr : ZERO.toString());
    fetchLimit.setText(fetchLimitStr != null ? fetchLimitStr : ZERO.toString());
    pageSize.setText(pageSizeStr != null ? pageSizeStr : ZERO.toString());
}

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

private void initGUI() {
    try {/*  ww w  .j  a va2 s .c  o  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.objectstyle.cayenne.modeler.editor.ObjEntityTab.java

/**
 * Updates the view from the current model state. Invoked when a currently displayed
 * ObjEntity is changed.//from  ww  w .j  a  v a  2 s.  c o  m
 */
private void initFromModel(final ObjEntity entity) {
    // TODO: this is a hack until we implement a real MVC
    qualifier.getComponent().setBackground(Color.WHITE);

    name.setText(entity.getName());
    superClassName.setText(entity.getSuperClassName() != null ? entity.getSuperClassName() : "");
    className.setText(entity.getClassName() != null ? entity.getClassName() : "");
    readOnly.setSelected(entity.isReadOnly());

    StringConvertor convertor = StringConvertors.forClass(Expression.class);
    qualifier.setText(convertor.valueAsString(entity.getDeclaredQualifier()));

    // TODO: fix inheritance - we should allow to select optimistic
    // lock if superclass is not already locked,
    // otherwise we must keep this checked in but not editable.
    optimisticLocking.setSelected(entity.getDeclaredLockType() == ObjEntity.LOCK_TYPE_OPTIMISTIC);

    // init DbEntities
    DataMap map = mediator.getCurrentDataMap();
    Object[] dbEntities = map.getNamespace().getDbEntities().toArray();
    Arrays.sort(dbEntities, Comparators.getDataMapChildrenComparator());

    DefaultComboBoxModel dbModel = new DefaultComboBoxModel(dbEntities);
    dbModel.setSelectedItem(entity.getDbEntity());
    dbEntityCombo.setRenderer(CellRenderers.entityListRendererWithIcons(map));
    dbEntityCombo.setModel(dbModel);

    // if a super-entity selected, disable table selection
    activateFields(entity.getSuperEntityName() == null);

    // init ObjEntities for inheritance
    Predicate inheritanceFilter = new Predicate() {

        public boolean evaluate(Object object) {
            // do not show this entity or any of the subentities
            if (entity == object) {
                return false;
            }

            if (object instanceof ObjEntity) {
                return !((ObjEntity) object).isSubentityOf(entity);
            }

            return false;
        }
    };

    Object[] objEntities = CollectionUtils.select(map.getNamespace().getObjEntities(), inheritanceFilter)
            .toArray();
    Arrays.sort(objEntities, Comparators.getDataMapChildrenComparator());
    Object[] finalObjEntities = new Object[objEntities.length + 1];
    finalObjEntities[0] = noInheritance;
    System.arraycopy(objEntities, 0, finalObjEntities, 1, objEntities.length);

    DefaultComboBoxModel superEntityModel = new DefaultComboBoxModel(finalObjEntities);
    superEntityModel.setSelectedItem(entity.getSuperEntity());
    superEntityCombo.setRenderer(CellRenderers.entityListRendererWithIcons(map));
    superEntityCombo.setModel(superEntityModel);
}

From source file:org.objectstyle.cayenne.modeler.editor.SelectPropertiesPanel.java

/**
 * Updates the view from the current model state. Invoked when a currently displayed
 * query is changed.//from   ww  w  . ja  v  a 2s  .c om
 */
public void initFromModel(GenericSelectQuery query) {
    DefaultComboBoxModel cacheModel = new DefaultComboBoxModel(CACHE_POLICIES);
    cacheModel.setSelectedItem(query.getCachePolicy());
    cachePolicy.setModel(cacheModel);

    fetchLimit.setText(String.valueOf(query.getFetchLimit()));
    pageSize.setText(String.valueOf(query.getPageSize()));
    refreshesResults.setSelected(query.isRefreshingObjects());
}

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 {/*from   ww w.j  a  v a 2  s .  c om*/
        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);
    }
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryOpenDialog.java

private ComboBoxModel createLocationModel(final FileObject selectedFolder) {
    if (fileSystemRoot == null) {
        return new DefaultComboBoxModel();
    }//from  ww w  .  ja v  a2  s .co m

    try {
        final ArrayList<FileObject> list = new ArrayList<FileObject>();
        FileObject folder = selectedFolder;
        while (folder != null) {
            if (fileSystemRoot.equals(folder)) {
                break;
            }

            if (folder.getType() != FileType.FILE) {
                list.add(folder);
            }

            final FileObject parent = folder.getParent();
            if (folder.equals(parent)) {
                // protect yourself against infinite loops ..
                break;
            }
            folder = parent;
        }
        list.add(fileSystemRoot);
        final DefaultComboBoxModel model = new DefaultComboBoxModel(list.toArray());
        model.setSelectedItem(list.get(0));
        return model;
    } catch (FileSystemException e) {
        return new DefaultComboBoxModel();
    }
}

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

public void layout() {
    inLayoutProcess = true;/*  ww w.j  a  v a 2s . co  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: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;
        }/* w w w.j av  a 2s.  c o m*/
    }
    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;/*from www  .j a v  a  2  s.  c o  m*/
    }
    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);
    }
}