Example usage for javax.swing.table TableColumn setCellEditor

List of usage examples for javax.swing.table TableColumn setCellEditor

Introduction

In this page you can find the example usage for javax.swing.table TableColumn setCellEditor.

Prototype

@BeanProperty(description = "The editor to use for cell values.")
public void setCellEditor(TableCellEditor cellEditor) 

Source Link

Document

Sets the editor to used by when a cell in this column is edited.

Usage

From source file:org.executequery.gui.browser.ConnectionPanel.java

private void init() {

    // ---------------------------------
    // create the basic props panel

    // initialise the fields
    nameField = createTextField();//from   w  w  w  .j av  a  2s  .  c  om
    passwordField = createPasswordField();
    hostField = createTextField();
    portField = createNumberTextField();
    sourceField = createMatchedWidthTextField();
    userField = createTextField();
    urlField = createMatchedWidthTextField();

    nameField.addFocusListener(new ConnectionNameFieldListener(this));

    savePwdCheck = ActionUtilities.createCheckBox("Store Password", "setStorePassword");
    encryptPwdCheck = ActionUtilities.createCheckBox("Encrypt Password", "setEncryptPassword");

    savePwdCheck.addActionListener(this);
    encryptPwdCheck.addActionListener(this);

    // retrieve the drivers
    buildDriversList();

    // ---------------------------------
    // add the basic connection fields

    TextFieldPanel mainPanel = new TextFieldPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.insets = new Insets(10, 10, 10, 10);
    gbc.gridy = 0;
    gbc.gridx = 0;

    statusLabel = new DefaultFieldLabel();
    addLabelFieldPair(mainPanel, "Status:", statusLabel, "Current connection status", gbc);

    gbc.insets.bottom = 5;
    addLabelFieldPair(mainPanel, "Connection Name:", nameField, "A friendly name for this connection", gbc);

    addLabelFieldPair(mainPanel, "User Name:", userField, "Login user name", gbc);

    addLabelFieldPair(mainPanel, "Password:", passwordField, "Login password", gbc);

    JButton showPassword = new LinkButton("Show Password");
    showPassword.setActionCommand("showPassword");
    showPassword.addActionListener(this);

    JPanel passwordOptionsPanel = new JPanel(new GridBagLayout());
    addComponents(passwordOptionsPanel,
            new ComponentToolTipPair[] {
                    new ComponentToolTipPair(savePwdCheck,
                            "Store the password with the connection information"),
                    new ComponentToolTipPair(encryptPwdCheck, "Encrypt the password when saving"),
                    new ComponentToolTipPair(showPassword, "Show the password in plain text") });

    gbc.gridy++;
    gbc.gridx = 1;
    gbc.weightx = 1.0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    mainPanel.add(passwordOptionsPanel, gbc);

    addLabelFieldPair(mainPanel, "Host Name:", hostField, "Server host name or IP address", gbc);

    addLabelFieldPair(mainPanel, "Port:", portField, "Database port number", gbc);

    addLabelFieldPair(mainPanel, "Data Source:", sourceField, "Data source name", gbc);

    addLabelFieldPair(mainPanel, "JDBC URL:", urlField, "The full JDBC URL for this connection (optional)",
            gbc);

    addDriverFields(mainPanel, gbc);

    connectButton = createButton("Connect", CONNECT_ACTION_COMMAND, 'T');
    disconnectButton = createButton("Disconnect", "disconnect", 'D');

    JPanel buttons = new JPanel(new GridBagLayout());
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.insets.top = 5;
    gbc.insets.left = 0;
    gbc.insets.right = 10;
    gbc.gridwidth = 1;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.NORTHEAST;
    gbc.fill = GridBagConstraints.NONE;
    buttons.add(connectButton, gbc);
    gbc.gridx++;
    gbc.weightx = 0;
    buttons.add(disconnectButton, gbc);

    gbc.insets.right = 0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    mainPanel.add(buttons, gbc);

    // ---------------------------------
    // create the advanced panel

    model = new JdbcPropertiesTableModel();
    JTable table = new DefaultTable(model);
    table.getTableHeader().setReorderingAllowed(false);

    TableColumnModel tcm = table.getColumnModel();

    TableColumn column = tcm.getColumn(2);
    column.setCellRenderer(new DeleteButtonRenderer());
    column.setCellEditor(new DeleteButtonEditor(table, new JCheckBox()));
    column.setMaxWidth(24);
    column.setMinWidth(24);

    JScrollPane scroller = new JScrollPane(table);

    // advanced jdbc properties
    JPanel advPropsPanel = new JPanel(new GridBagLayout());
    advPropsPanel.setBorder(BorderFactory.createTitledBorder("JDBC Properties"));
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.insets.top = 0;
    gbc.insets.left = 10;
    gbc.insets.right = 10;
    gbc.weighty = 0;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    advPropsPanel.add(new DefaultFieldLabel("Enter any key/value pair properties for this connection"), gbc);
    gbc.gridy++;
    advPropsPanel.add(
            new DefaultFieldLabel("Refer to the relevant JDBC driver documentation for possible entries"), gbc);
    gbc.gridy++;
    gbc.insets.bottom = 10;
    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.BOTH;
    advPropsPanel.add(scroller, gbc);

    // transaction isolation
    txApplyButton = WidgetFactory.createInlineFieldButton("Apply", "transactionLevelChanged");
    txApplyButton.setToolTipText("Apply this level to all open connections of this type");
    txApplyButton.setEnabled(false);
    txApplyButton.addActionListener(this);

    // add a dummy select value to the tx levels
    String[] txLevels = new String[Constants.TRANSACTION_LEVELS.length + 1];
    txLevels[0] = "Database Default";
    for (int i = 1; i < txLevels.length; i++) {
        txLevels[i] = Constants.TRANSACTION_LEVELS[i - 1];
    }
    txCombo = WidgetFactory.createComboBox(txLevels);

    JPanel advTxPanel = new JPanel(new GridBagLayout());
    advTxPanel.setBorder(BorderFactory.createTitledBorder("Transaction Isolation"));
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.insets.top = 0;
    gbc.insets.left = 10;
    gbc.insets.right = 10;
    gbc.insets.bottom = 5;
    gbc.weighty = 0;
    gbc.weightx = 1.0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    advTxPanel.add(new DefaultFieldLabel("Default transaction isolation level for this connection"), gbc);
    gbc.gridy++;
    gbc.insets.bottom = 10;
    advTxPanel.add(
            new DefaultFieldLabel(
                    "Note: the selected isolation level " + "will apply to ALL open connections of this type."),
            gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.gridwidth = 1;
    gbc.insets.top = 0;
    gbc.insets.left = 10;
    gbc.weightx = 0;
    advTxPanel.add(new DefaultFieldLabel("Isolation Level:"), gbc);
    gbc.gridx = 1;
    gbc.insets.left = 5;
    gbc.weightx = 1.0;
    gbc.insets.right = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    advTxPanel.add(txCombo, gbc);
    gbc.gridx = 2;
    gbc.weightx = 0;
    gbc.insets.left = 0;
    gbc.insets.right = 10;
    advTxPanel.add(txApplyButton, gbc);

    JPanel advancedPanel = new JPanel(new BorderLayout());
    advancedPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    advancedPanel.add(advPropsPanel, BorderLayout.CENTER);
    advancedPanel.add(advTxPanel, BorderLayout.SOUTH);

    JScrollPane scrollPane = new JScrollPane(mainPanel);
    scrollPane.setBorder(null);

    sshTunnelConnectionPanel = new SSHTunnelConnectionPanel();

    tabPane = new JTabbedPane(JTabbedPane.BOTTOM);
    tabPane.addTab("Basic", scrollPane);
    tabPane.addTab("Advanced", advancedPanel);
    tabPane.addTab("SSH Tunnel", sshTunnelConnectionPanel);

    tabPane.addChangeListener(this);

    add(tabPane, BorderLayout.CENTER);

    EventMediator.registerListener(this);
}

From source file:org.executequery.gui.importexport.ImportExportPanelThree.java

private void prepareTable() {
    TableColumnModel tcm = table.getColumnModel();
    TableColumn col = tcm.getColumn(0);
    col.setPreferredWidth(140);/*www . ja va2 s . c  om*/

    col = tcm.getColumn(1);
    col.setPreferredWidth(255);

    if (browseButtonCellRenderer == null) {

        browseButtonCellRenderer = new BrowseButtonRenderer();
    }

    if (browseButtonCellEditor == null) {

        browseButtonCellEditor = new BrowseButtonEditor(new JCheckBox());
    }

    col = tcm.getColumn(2);
    col.setCellRenderer(browseButtonCellRenderer);
    col.setCellEditor(browseButtonCellEditor);
    col.setPreferredWidth(80);
}

From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java

/**
 * Recovers cell editor for a field for attachment to a column
 *
 * @param col - Column to attach a custom cell editor to
 *//* w ww.j a v  a2  s .  c  om*/
@SuppressWarnings({ "ConstantConditions" })
protected void addCellEditor(TableColumn col, String previousColumnName) {
    ValidationObject vo = spreadsheet.getTableReferenceObject()
            .getValidationConstraints(col.getHeaderValue().toString());
    DataTypes classType = spreadsheet.getTableReferenceObject().getColumnType(col.getHeaderValue().toString());

    String columnName = col.getHeaderValue().toString();

    PluginSpreadsheetWidget widget;

    if ((widget = SpreadsheetPluginRegistry.findPluginForColumn(columnName)) != null) {
        TableCellEditor editor = (TableCellEditor) widget;
        col.setCellEditor(editor);
        return;
    }

    if (vo != null && classType == DataTypes.STRING) {
        StringValidation sv = ((StringValidation) vo);
        col.setCellEditor(new StringEditor(sv));
        return;
    }

    if (columnName.equals("Sample Name") && !spreadsheet.getSpreadsheetTitle().contains("Sample Definitions")
            && spreadsheet.getStudyDataEntryEnvironment() != null) {

        if (sampleSelectorCellEditor == null) {
            sampleSelectorCellEditor = new SampleSelectorCellEditor(spreadsheet);
        }

        col.setCellEditor(sampleSelectorCellEditor);

        return;
    }

    if (columnName.equals("Protocol REF") && spreadsheet.getStudyDataEntryEnvironment() != null) {
        if (protocolSelectorCellEditor == null) {
            protocolSelectorCellEditor = new ProtocolSelectorCellEditor(spreadsheet);
        }
        col.setCellEditor(protocolSelectorCellEditor);
        return;
    }

    if (spreadsheet.getTableReferenceObject().getClassType(columnName) == DataTypes.ONTOLOGY_TERM) {

        Map<String, RecommendedOntology> recommendedOntologyMap = null;
        if (columnName.equalsIgnoreCase("unit")) {
            // we should be keeping note of the previous value, and automatically link this up with the unit.
            // If no link, is found, the fall back is to use no recommended ontology for that field.
            if (previousColumnName != null) {
                FieldObject unitField = spreadsheet.getTableReferenceObject()
                        .getNextUnitField(previousColumnName);
                if (unitField != null) {
                    recommendedOntologyMap = unitField.getRecommmendedOntologySource();
                }
            }
        } else {
            recommendedOntologyMap = spreadsheet.getTableReferenceObject().getRecommendedSource(columnName);
        }

        col.setCellEditor(new OntologyCellEditor(
                spreadsheet.getTableReferenceObject().acceptsMultipleValues(columnName),
                spreadsheet.getTableReferenceObject().forceOntology(columnName), recommendedOntologyMap));
        return;
    }

    if (spreadsheet.getTableReferenceObject().getClassType(columnName) == DataTypes.LIST) {
        if (columnName.equalsIgnoreCase("unit")) {
            FieldObject unitField = spreadsheet.getTableReferenceObject().getNextUnitField(previousColumnName);
            if (unitField != null) {
                System.out.println(Arrays.toString(unitField.getFieldList()));

                col.setCellEditor(
                        new AutoFilterComboCellEditor(new AutoFilterCombo(unitField.getFieldList(), false)));
            }
        } else {
            col.setCellEditor(new AutoFilterComboCellEditor(new AutoFilterCombo(
                    spreadsheet.getTableReferenceObject().getListItems(columnName), false)));

        }
        return;
    }

    if (spreadsheet.getTableReferenceObject().getClassType(columnName) == DataTypes.DATE) {
        col.setCellEditor(Spreadsheet.dateEditor);

        return;
    }

    if (spreadsheet.getTableReferenceObject().getClassType(columnName) == DataTypes.BOOLEAN) {
        col.setCellEditor(new StringEditor(
                new StringValidation("true|yes|TRUE|YES|NO|FALSE|no|false", "not a valid boolean!"), true));
        return;
    }

    if ((classType == DataTypes.STRING)
            && spreadsheet.getTableReferenceObject().acceptsFileLocations(columnName)) {
        col.setCellEditor(Spreadsheet.fileSelectEditor);
        return;
    }

    if (classType == DataTypes.INTEGER) {
        col.setCellEditor(
                new StringEditor(new StringValidation("[0-9]+", "Please enter an integer value!"), true));
        return;
    }

    if (classType == DataTypes.DOUBLE) {
        col.setCellEditor(new StringEditor(
                new StringValidation("[0-9]+[.]{0,1}[0-9]*", "Please enter a double value!"), true));
        return;
    }

    col.setCellEditor(new StringEditor(new StringValidation(".*", "")));
}

From source file:org.kootox.episodesmanager.content.EpisodesListTableModel.java

public void update() {

    initValues();//from  w ww  . j a  va  2 s  . c om
    fireTableDataChanged();
    if (ui != null) {
        JTable table = ui.getEpisodeslistTable();
        TableColumn column = table.getColumn(_("episodesmanager.episode.actions"));
        column.setCellRenderer(new ButtonRenderer());
        column.setCellEditor(new ButtonEditor(new JCheckBox()));
    }
}

From source file:org.openconcerto.task.TodoListPanel.java

private void initUserCellEditor(final TableColumn userColumn) {
    SwingWorker2<List<UserTaskRight>, Object> worker = new SwingWorker2<List<UserTaskRight>, Object>() {
        @Override/*w  ww .j a  va2s . c  om*/
        protected List<UserTaskRight> doInBackground() throws Exception {
            return UserTaskRight.getUserTaskRight(UserManager.getInstance().getCurrentUser());
        }

        @Override
        protected void done() {
            // only display allowed recipients
            try {
                final List<UserTaskRight> rights = get();
                final List<User> canAddUsers = new ArrayList<User>();
                for (final UserTaskRight right : rights) {
                    assert right.getIdUser() == UserManager.getUserID();
                    if (right.canAdd()) {
                        canAddUsers.add(UserManager.getInstance().getUser(right.getIdToUser()));
                    }
                }
                userColumn.setCellEditor(new UserTableCellEditor(new UserComboBox(canAddUsers)));
                t.setEnabled(true);
            } catch (Exception e) {
                ExceptionHandler.handle("Unable to get user task rights", e);
            }

            super.done();
        }
    };
    worker.execute();

}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.FileSelectionTable.java

/**
 * Helper method to setup the column as a boolean column
 * @param column the column to set/*from w  w  w . j  av a2s  .co m*/
 */
private void setColumnAsBoolean(TableColumn column) {
    column.setCellEditor(table.getDefaultEditor(Boolean.class));
    column.setCellRenderer(table.getDefaultRenderer(Boolean.class));
    column.setResizable(false);
}

From source file:org.openstreetmap.josm.gui.preferences.imagery.CacheContentsPanel.java

private static JTable getTableForCache(final CacheAccess<String, BufferedImageCacheEntry> cache,
        final TableModel tableModel) {
    final JTable ret = new JTable(tableModel);

    ButtonColumn buttonColumn = new ButtonColumn(new AbstractAction() {
        @Override/*  w w w. j  a va  2  s .c o  m*/
        public void actionPerformed(ActionEvent e) {
            int row = ret.convertRowIndexToModel(ret.getEditingRow());
            tableModel.setValueAt("0", row, 1);
            cache.remove(ret.getValueAt(row, 0).toString() + ':');
        }
    });
    TableColumn tableColumn = ret.getColumnModel().getColumn(2);
    tableColumn.setCellRenderer(buttonColumn);
    tableColumn.setCellEditor(buttonColumn);
    return ret;
}

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

private void updateColumnModel() {
    TableColumnModel columnModel = table.getColumnModel();
    totalFlex = 0;/*from  w  w  w  .j a va  2  s .com*/

    for (int i = 0; i < columns.getChildNodes().size(); i++) {
        if (i >= columnModel.getColumnCount()) {
            break;
        }

        SwingTreeCol child = (SwingTreeCol) columns.getChildNodes().get(i);
        TableColumn col = columnModel.getColumn(i);

        totalFlex += child.getFlex();

        col.setHeaderValue(child.getLabel());

        col.setCellEditor(getCellEditor(child));

        col.setCellRenderer(getCellRenderer(child));

        // List<XulComponent> cells = child.getChildNodes();
        // for(int z=0; z<cells.size(); z++){
        // XulComponent cell = cells.get(z);
        // }
    }
}

From source file:org.piraso.ui.api.StackTraceFilterDialog.java

private void initTable() {
    TableColumn regexColumn = jtable.getColumnModel().getColumn(0);
    TableColumn boldColumn = jtable.getColumnModel().getColumn(1);

    regexColumn.setHeaderValue("Regex");
    regexColumn.setPreferredWidth(210);/*from ww w .  j a  v  a 2s.c om*/

    boldColumn.setHeaderValue("Bold");
    boldColumn.setPreferredWidth(30);
    boldColumn.setMaxWidth(30);
    boldColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class));
    boldColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class));

    jtable.setShowHorizontalLines(false);
    jtable.setAutoscrolls(true);
    jtable.setColumnSelectionAllowed(false);
    jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jtable.getTableHeader().setReorderingAllowed(false);
}

From source file:org.piraso.ui.base.ExportDialog.java

private void initTable() {
    TableColumn selectionColumn = jtable.getColumnModel().getColumn(0);
    TableColumn boldOption = jtable.getColumnModel().getColumn(1);

    selectionColumn.setHeaderValue("");
    selectionColumn.setPreferredWidth(30);
    selectionColumn.setMaxWidth(30);/*  w  w  w. j a v a2s .c o  m*/
    selectionColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class));
    selectionColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class));

    boldOption.setHeaderValue("Option");
    boldOption.setPreferredWidth(200);

    jtable.setShowHorizontalLines(false);
    jtable.setAutoscrolls(true);
    jtable.setColumnSelectionAllowed(false);
    jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jtable.getTableHeader().setReorderingAllowed(false);
}