Example usage for javax.swing.table TableColumn getHeaderValue

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

Introduction

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

Prototype

public Object getHeaderValue() 

Source Link

Document

Returns the Object used as the value for the header renderer.

Usage

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

/**
 * Method will replace any absolute file paths to relative ones to match with their new location inside the ISArchive
 *
 * @param toSwitch -> to switch to relative, use Spreadsheet.SWITCH_RELATIVE, to switch back to absolute, use Spreadsheet.SWITCH_ABSOLUTE
 *///from  ww w . j  av a2s.  c o  m
public void changeFilesToRelativeOrAbsolute(int toSwitch) {
    Enumeration<TableColumn> columns = table.getColumnModel().getColumns();

    if (absRelFileMappings == null) {
        absRelFileMappings = new HashMap<String, String>();
    }

    while (columns.hasMoreElements()) {
        TableColumn tc = columns.nextElement();

        if (tableReferenceObject.acceptsFileLocations(tc.getHeaderValue().toString())) {
            int colIndex = tc.getModelIndex();

            for (int row = 0; row < spreadsheetModel.getRowCount(); row++) {
                String s = (spreadsheetModel.getValueAt(row, colIndex) == null) ? ""
                        : spreadsheetModel.getValueAt(row, colIndex).toString();

                if (s != null && !s.trim().equals("")) {
                    switch (toSwitch) {
                    case SWITCH_RELATIVE:

                        if (!s.startsWith("ftp") && !s.startsWith("http")) {
                            String newFileName = s.substring(s.lastIndexOf(File.separator) + 1);
                            absRelFileMappings.put(newFileName, s);
                            spreadsheetModel.doSetValueAt(newFileName, row, colIndex);
                        }

                        break;

                    case SWITCH_ABSOLUTE:

                        if (!s.startsWith("ftp") && !s.startsWith("ftps")) {
                            String absFileName = absRelFileMappings.get(s);

                            if (absFileName != null) {
                                spreadsheetModel.doSetValueAt(absFileName, row, colIndex);
                            }
                        }

                        break;
                    }
                }
            }
        }
    }

    if (toSwitch == SWITCH_ABSOLUTE) {
        absRelFileMappings = null;
    }
}

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

protected Map<String, Set<String>> getColumnGroups() {

    Map<String, Set<String>> groupInfo = new HashMap<String, Set<String>>();

    Enumeration<TableColumn> enumer = table.getColumnModel().getColumns();

    while (enumer.hasMoreElements()) {
        TableColumn tc = enumer.nextElement();

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

        if (columnHeaderValue.contains("Characteristics")) {
            if (!groupInfo.containsKey("Characteristics")) {
                groupInfo.put("Characteristics", new HashSet<String>());
            }/* ww w  . j  av a2s.co m*/
            groupInfo.get("Characteristics").add(columnHeaderValue);

        } else if (columnHeaderValue.contains("Factor")) {
            if (!groupInfo.containsKey("Factor")) {
                groupInfo.put("Factor", new HashSet<String>());
            }
            groupInfo.get("Factor").add(columnHeaderValue);
        } else {
            if (!groupInfo.containsKey("Normal")) {
                groupInfo.put("Normal", new HashSet<String>());
            }
            groupInfo.get("Normal").add(columnHeaderValue);
        }
    }

    return groupInfo;
}

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

private String getFieldDescription(TableColumn tc) {
    return tableReferenceObject.getFieldByName(tc.getHeaderValue().toString()).getDescription();
}

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

protected void showRenameColumnsGUI(final TableColumn column) {

    EventQueue.invokeLater(new Runnable() {
        public void run() {
            RenameColumnGUI goingToDisplay = null;
            String toShow = column.getHeaderValue().toString().substring(0,
                    column.getHeaderValue().toString().indexOf("["));
            if (toShow.contains("Characteristics")) {
                goingToDisplay = new RenameColumnGUI(Spreadsheet.this, AddColumnGUI.ADD_CHARACTERISTIC_COLUMN,
                        column);/*from ww w .ja v a  2s . c o m*/

            } else if (toShow.contains("Parameter Value")) {
                goingToDisplay = new RenameColumnGUI(Spreadsheet.this, AddColumnGUI.ADD_PARAMETER_COLUMN,
                        column);

            } else if (toShow.contains("Comment")) {
                goingToDisplay = new RenameColumnGUI(Spreadsheet.this, AddColumnGUI.ADD_COMMENT_COLUMN, column);
            }

            if (goingToDisplay != null) {
                goingToDisplay.createGUI();
                // do this to ensure that the gui is fully created before displaying it.
                parentFrame.showJDialogAsSheet(goingToDisplay);
            }
        }
    });
}

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

private Set<Integer> getRequiredFieldIndices() {
    Set<Integer> indices = new HashSet<Integer>();
    Enumeration<TableColumn> columns = table.getColumnModel().getColumns();
    boolean lastTermRequired = false;
    while (columns.hasMoreElements()) {
        TableColumn tc = columns.nextElement();
        if (!tc.getHeaderValue().toString().equalsIgnoreCase(TableReferenceObject.ROW_NO_TEXT)) {
            int columnViewIndex = Utils.convertModelIndexToView(table, tc.getModelIndex());
            if (tableReferenceObject.isRequired(tc.getHeaderValue().toString())) {
                if (tc.getHeaderValue().toString().equals("Unit") && lastTermRequired) {
                    indices.add(columnViewIndex);
                } else {
                    indices.add(columnViewIndex);
                    lastTermRequired = SpreadsheetUtils
                            .isFactorParameterOrCharacteristic(tc.getHeaderValue().toString());
                }/* w ww . j a v  a2 s  .co  m*/
            }
        }
    }
    return indices;
}

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

/**
 * Substitutes headers - replaces a column name with another one
 *
 * @param prevHeaderName - Previous column header
 * @param newHeaderName  - New column header
 *///w w  w. j  av  a 2 s .c  o m
public void substituteHeaderNames(String prevHeaderName, String newHeaderName) {
    Enumeration<TableColumn> columns = spreadsheet.getTable().getColumnModel().getColumns();

    while (columns.hasMoreElements()) {
        TableColumn col = columns.nextElement();

        if (col.getHeaderValue().toString().equals(prevHeaderName)) {
            col.setHeaderValue(newHeaderName);
        }
    }

    spreadsheet.getTable().addNotify();
}

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

/**
 * Substitutes a given value prevTerm with a new value newTerm in a column whose header
 * is colName/*from   w  ww. java2s  .  c  o m*/
 *
 * @param colName  - Column to be searched in.
 * @param prevTerm - the term to replace
 * @param newTerm  - the new term to be used instead.
 */
public void substituteTermsInColumn(String colName, String prevTerm, String newTerm) {

    Enumeration<TableColumn> columns = spreadsheet.getTable().getColumnModel().getColumns();

    while (columns.hasMoreElements()) {
        TableColumn col = columns.nextElement();

        if (col.getHeaderValue().toString().equals(colName)) {
            int colIndex = col.getModelIndex();

            for (int i = 0; i < spreadsheet.spreadsheetModel.getRowCount(); i++) {
                // safety precaution to finalise any cells. otherwise their value would be missed!
                if (spreadsheet.getTable().getCellEditor(i, colIndex) != null) {
                    spreadsheet.getTable().getCellEditor(i, colIndex).stopCellEditing();
                }

                if (spreadsheet.spreadsheetModel.getValueAt(i, colIndex) != null
                        && spreadsheet.spreadsheetModel.getValueAt(i, colIndex).toString().equals(prevTerm)) {
                    spreadsheet.spreadsheetModel.setValueAt(newTerm, i, colIndex);
                }
            }
        }
    }
}

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

/**
 * Method returns a Set of all the files defined in a spreadsheet. These locations are used to zip up the data files
 * in the ISArchive for submission to the index.
 *
 * @return Set of files defined in the spreadsheet
 *//*ww w  .ja va2 s .  c  o m*/
public Set<String> getFilesDefinedInTable() {
    Enumeration<TableColumn> columns = spreadsheet.getTable().getColumnModel().getColumns();
    Set<String> files = new HashSet<String>();

    while (columns.hasMoreElements()) {
        TableColumn tc = columns.nextElement();
        if (spreadsheet.getTableReferenceObject().acceptsFileLocations(tc.getHeaderValue().toString())) {
            int colIndex = Utils.convertModelIndexToView(spreadsheet.getTable(), tc.getModelIndex());

            for (int row = 0; row < spreadsheet.getTable().getRowCount(); row++) {
                String s = (spreadsheet.getTable().getValueAt(row, colIndex) == null) ? ""
                        : spreadsheet.getTable().getValueAt(row, colIndex).toString();
                if (s != null && !s.trim().equals("")) {
                    files.add(s);
                }
            }
        }
    }

    return files;
}

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  . ja va2 s . 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.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java

protected void removeColumn() {
    try {/*from  w ww  .ja  v  a  2  s.c o m*/
        if (spreadsheet.curColDelete != -1) {
            SpreadsheetModel model = (SpreadsheetModel) spreadsheet.getTable().getModel();
            TableColumn col = spreadsheet.getTable().getColumnModel().getColumn(spreadsheet.curColDelete);

            spreadsheet.hiddenColumns.add(col.getHeaderValue().toString());
            deleteColumn(model, col);

            removeDependentColumns(col);
            removeColumnFromDependencies(col);
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        log.error("Problem encountered when removing a column " + e.getMessage());
    }
}