Example usage for javax.swing.table TableColumn getCellEditor

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

Introduction

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

Prototype

public TableCellEditor getCellEditor() 

Source Link

Document

Returns the TableCellEditor used by the JTable to edit values for this column.

Usage

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

/**
 * Refresh the list of ObjEntity targets. Also refresh the table in case some
 * ObjRelationships were deleted.//from   w  ww  .  j a v a 2s. c  o m
 */
private void reloadEntityList(EntityEvent e) {
    if (e.getSource() != this) {
        return;
    }

    // If current model added/removed, do nothing.
    ObjEntity entity = mediator.getCurrentObjEntity();
    if (entity == e.getEntity() || entity == null) {
        return;
    }

    TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET);
    DefaultCellEditor editor = (DefaultCellEditor) col.getCellEditor();

    JComboBox combo = (JComboBox) editor.getComponent();
    combo.setRenderer(CellRenderers.entityListRendererWithIcons(entity.getDataMap()));

    ObjRelationshipTableModel model = (ObjRelationshipTableModel) table.getModel();
    model.fireTableDataChanged();
}

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

/**
 * Refresh the list of ObjEntity targets. Also refresh the table in case some
 * ObjRelationships were deleted.//from   ww  w. j  av a  2 s.c o m
 */
private void reloadEntityList(EntityEvent e) {
    if (e.getSource() != this) {
        return;
    }

    // If current model added/removed, do nothing.
    ObjEntity entity = mediator.getCurrentObjEntity();
    if (entity == e.getEntity() || entity == null) {
        return;
    }

    TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET);
    DefaultCellEditor editor = (DefaultCellEditor) col.getCellEditor();

    JComboBox combo = (JComboBox) editor.getComponent();
    combo.setRenderer(CellRenderers.entityListRendererWithIcons(entity.getDataMap()));
    combo.setModel(new DefaultComboBoxModel(createObjEntityComboModel()));

    ObjRelationshipTableModel model = (ObjRelationshipTableModel) table.getModel();
    model.fireTableDataChanged();
}

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

/**
 * Exports current Table into a CSV or TAB file depending on separator chosen.
 *
 * @param f                  File to be written to
 * @param separator          -> "\t" for tab separation or "," for CSV
 * @param removeEmptyColumns - should empty columns be removed from the submission?
 * @throws java.io.FileNotFoundException - never thrown since the file is created if it doesn't exist, and over written if
 *                                       it already exists
 *                                       <p/>
 *                                       todo Move this code into a utils class
 *///w  ww. j av a2s . c o  m
public boolean exportTable(File f, String separator, boolean removeEmptyColumns) throws FileNotFoundException {
    PrintStream ps = new PrintStream(f);

    Set<TableColumn> emptyColumns = new HashSet<TableColumn>();

    for (int col = 1; col < spreadsheet.getTable().getColumnCount(); col++) {
        TableColumn tc = spreadsheet.getTable().getColumnModel().getColumn(col);
        // only hide columns which are empty and that are not necessarily required!
        if (removeEmptyColumns && checkIsEmpty(tc)
                && !spreadsheet.getTableReferenceObject().isRequired(tc.getHeaderValue().toString())) {
            emptyColumns.add(tc);
        } else {

            String toPrint = null;

            String header = tc.getHeaderValue().toString();

            OntologyTerm oo = OntologyManager.getOntologyTerm(IOUtils.getHeaderValue(header));

            if (oo != null)
                toPrint = "\"" + IOUtils.getHeaderName(header) + "["
                        + OntologyTermUtils.ontologyTermToString(oo) + "]" + "\"";
            else
                toPrint = "\"" + header + "\"";

            if (col == 1) {
                ps.print(toPrint);
            } else {
                ps.print(separator + toPrint);
            }
            if (tc.getCellEditor() instanceof OntologyCellEditor
                    || tc.getHeaderValue().toString().equalsIgnoreCase("unit")) {
                ps.print(separator + "\"Term Source REF\"");
                ps.print(separator + "\"Term Accession Number\"");
            }
        }
    }

    ps.print("\n");

    // write out each column
    for (int rows = 0; rows < spreadsheet.getTable().getRowCount(); rows++) {
        String rowInfo = "";

        for (int cols = 1; cols < spreadsheet.getTable().getColumnCount(); cols++) {
            // the value to be output to the field
            TableColumn tc = spreadsheet.getTable().getColumnModel().getColumn(cols);

            if (!emptyColumns.contains(tc)) {
                String val;

                // where the term came from if there is an ontology term.
                String source = "";
                String toAdd;

                if (spreadsheet.getTable().getValueAt(rows, cols) != null) {
                    val = spreadsheet.getTable().getValueAt(rows, cols).toString();

                    if (tc.getCellEditor() instanceof OntologyCellEditor
                            || tc.getHeaderValue().toString().equalsIgnoreCase("unit")) {

                        String termAccession = "";

                        if (!GeneralUtils.isValueURL(val)) {

                            OntologyTerm oo = OntologyManager.getOntologyTerm(val);

                            if (oo != null) {
                                if (ISAcreatorProperties.getProperty("ontologyTermURI").equals("true"))
                                    termAccession = oo.getOntologyTermURI();
                                else
                                    termAccession = oo.getOntologyTermAccession();
                            }

                            if (val.contains(":")) {
                                source = val.substring(0, val.indexOf(":"));
                                val = val.substring(val.indexOf(":") + 1);
                            }
                        }

                        toAdd = "\"" + val + "\"" + separator + "\"" + source + "\"" + separator + "\""
                                + termAccession + "\"";
                    } else {
                        toAdd = "\"" + val + "\"";
                    }
                } else {
                    if (tc.getCellEditor() instanceof OntologyCellEditor
                            || tc.getHeaderValue().toString().equalsIgnoreCase("unit")) {
                        // add triple separated value for term : source : accession triple
                        toAdd = "\"\"" + separator + "\"\"" + separator + "\"\"";
                    } else {
                        toAdd = "\"\"";
                    }
                }

                // only add the row separator if we are not adding the last column!
                if (cols == spreadsheet.getTable().getColumnCount() - 1) {
                    rowInfo += toAdd;
                } else {
                    rowInfo += (toAdd + separator);
                }
            }
        }

        if (rowInfo.length() > 0) {
            ps.println(rowInfo);
        }
    }

    ps.close();

    return spreadsheet.checkTableColumnOrderBad(f.getName());
}

From source file:org.pentaho.reporting.designer.core.util.table.ElementMetaDataTable.java

public TableCellEditor getCellEditor(final int row, final int viewColumn) {
    final int column = convertColumnIndexToModel(viewColumn);
    final Object value = getModel().getValueAt(row, column);
    if (value instanceof GroupingHeader) {
        return getDefaultEditor(GroupingHeader.class);
    }/*from ww w. j av  a2  s. c om*/

    final ElementMetaDataTableModel model = (ElementMetaDataTableModel) getModel();
    final PropertyEditor propertyEditor = model.getEditorForCell(row, column);
    final Class columnClass = model.getClassForCell(row, column);

    if (propertyEditor != null) {
        final String[] tags = propertyEditor.getTags();
        if (columnClass.isArray()) {
            arrayCellEditor.setPropertyEditorType(propertyEditor.getClass());
        } else if (tags == null || tags.length == 0) {
            propertyEditorCellEditor.setPropertyEditor(propertyEditor);
            return propertyEditorCellEditor;
        } else {
            taggedPropertyEditorCellEditor.setPropertyEditor(propertyEditor);
            return taggedPropertyEditorCellEditor;
        }
    }

    final TableColumn tableColumn = getColumnModel().getColumn(column);
    final TableCellEditor renderer = tableColumn.getCellEditor();
    if (renderer != null) {
        return renderer;
    }

    if (columnClass.isArray()) {
        return arrayCellEditor;
    }

    final TableCellEditor editor = getDefaultEditor(columnClass);
    if (editor != null && logger.isTraceEnabled()) {
        logger.trace("Using preconfigured default editor for column class " + columnClass + ": " + editor); // NON-NLS
    }
    return editor;
}

From source file:org.pentaho.reporting.libraries.designtime.swing.table.PropertyTable.java

public TableCellEditor getCellEditor(final int row, final int viewColumn) {
    final TableModel tableModel = getModel();
    if (tableModel instanceof PropertyTableModel) {
        final PropertyTableModel model = (PropertyTableModel) getModel();
        final int column = convertColumnIndexToModel(viewColumn);

        final PropertyEditor propertyEditor = model.getEditorForCell(row, column);
        final Class columnClass = model.getClassForCell(row, column);

        if (propertyEditor != null) {
            final String[] tags = propertyEditor.getTags();

            if (columnClass.isArray()) {
                arrayCellEditor.setPropertyEditorType(propertyEditor.getClass());
            } else if (tags == null || tags.length == 0) {
                propertyEditorCellEditor.setPropertyEditor(propertyEditor);
                return propertyEditorCellEditor;
            } else {
                taggedPropertyEditorCellEditor.setPropertyEditor(propertyEditor);
                return taggedPropertyEditorCellEditor;
            }//www . j a va  2s.c  om
        }

        final TableColumn tableColumn = getColumnModel().getColumn(column);
        final TableCellEditor renderer = tableColumn.getCellEditor();
        if (renderer != null) {
            return renderer;
        }

        if (columnClass.isArray()) {
            return arrayCellEditor;
        }

        final TableCellEditor editor = getDefaultEditor(columnClass);
        if (editor != null && logger.isTraceEnabled()) {
            logger.trace("Using preconfigured default editor for column class " + columnClass + ": " + editor); // NON-NLS
        }
        return editor;
    }
    return super.getCellEditor(row, viewColumn);
}