Example usage for javax.swing.table DefaultTableModel getValueAt

List of usage examples for javax.swing.table DefaultTableModel getValueAt

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableModel getValueAt.

Prototype

public Object getValueAt(int row, int column) 

Source Link

Document

Returns an attribute value for the cell at row and column.

Usage

From source file:org.apache.jmeter.save.CSVSaveService.java

/**
 * Method saves aggregate statistics as CSV from a table model. Same as
 * {@link #saveCSVStats(List, FileWriter, String[])} except that there is no
 * need to create a List containing the data.
 * //from  ww  w  .j  a v a 2 s .  co m
 * @param model
 *            table model containing the data
 * @param writer
 *            output file
 * @param saveHeaders
 *            whether or not to save headers
 * @throws IOException
 *             when writing to <code>writer</code> fails
 */
public static void saveCSVStats(DefaultTableModel model, FileWriter writer, boolean saveHeaders)
        throws IOException {
    final char DELIM = ',';
    final char[] SPECIALS = new char[] { DELIM, QUOTING_CHAR };
    final int columns = model.getColumnCount();
    final int rows = model.getRowCount();
    if (saveHeaders) {
        for (int i = 0; i < columns; i++) {
            if (i > 0) {
                writer.write(DELIM);
            }
            writer.write(quoteDelimiters(model.getColumnName(i), SPECIALS));
        }
        writer.write(LINE_SEP);
    }
    for (int row = 0; row < rows; row++) {
        for (int column = 0; column < columns; column++) {
            if (column > 0) {
                writer.write(DELIM);
            }
            Object item = model.getValueAt(row, column);
            writer.write(quoteDelimiters(String.valueOf(item), SPECIALS));
        }
        writer.write(LINE_SEP);
    }
}

From source file:org.fhaes.gui.AnalysisResultsPanel.java

/**
 * Write the specified DefaultTableModel to the provided Excel spreadsheet
 * /*from  ww w. j  ava 2  s.  c om*/
 * @param dataSheet
 * @param model
 */
private void writeModelToXLSXSheet(Sheet dataSheet, DefaultTableModel model) {

    if (model == null) {
        Row headerrow = dataSheet.createRow(0);
        Cell cell = headerrow.createCell(0);
        cell.setCellValue("No results available");
        return;
    }

    if (model.getColumnCount() > excelRowColLimit || model.getRowCount() > excelRowColLimit) {
        Row headerrow = dataSheet.createRow(0);
        Cell cell = headerrow.createCell(0);
        cell.setCellValue("Number of rows and/or columns too large to write to Excel");
        return;
    }

    Row headerrow = dataSheet.createRow(0);

    // Write column headers
    for (int i = 0; i < model.getColumnCount(); i++) {
        Cell cell = headerrow.createCell(i);
        cell.setCellValue(model.getColumnName(i));
    }

    // Write data values
    for (int r = 0; r < model.getRowCount(); r++) {
        Row row = dataSheet.createRow(r + 1);

        for (int c = 0; c < model.getColumnCount(); c++) {
            Cell cell = row.createCell(c);

            String value;

            if (model.getValueAt(r, c) == null) {
                value = "";
            } else

            {
                value = model.getValueAt(r, c).toString();
            }

            try {
                Double d = Double.valueOf(value);
                cell.setCellValue(d);
                cell.setCellStyle(doubleStyle);

            } catch (NumberFormatException ex) {
                cell.setCellValue(value);
            }
        }
    }
}

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

/** 
 * Returns the collection of files to import. 
 * /*from  w ww.j ava2s  .  co m*/
 * @return See above.
 */
List<ImportableFile> getFilesToImport() {
    List<ImportableFile> files = new ArrayList<ImportableFile>();
    int n = table.getRowCount();
    DefaultTableModel dtm = (DefaultTableModel) table.getModel();
    FileElement element;
    FileObject file;
    ImportableFile importable;
    boolean isFolderDataset;
    DataNodeElement dne;
    DatasetData dataset;
    for (int i = 0; i < n; i++) {
        element = (FileElement) dtm.getValueAt(i, this.fileIndex);
        file = element.getFile();

        dne = (DataNodeElement) dtm.getValueAt(i, this.containerIndex);
        isFolderDataset = (Boolean) dtm.getValueAt(i, this.folderAsDatasetIndex);
        importable = new ImportableFile(file, isFolderDataset);

        dataset = dne.getLocation();

        if (isFolderDataset)
            dataset = null;
        importable.setLocation(dne.getParent(), dataset);
        importable.setRefNode(dne.getRefNode());
        importable.setGroup(element.getGroup());
        importable.setUser(element.getUser());
        files.add(importable);
    }
    return files;
}

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

/**
 * Adds the collection of files to the queue.
 * //from   ww w  .ja v a2  s  .c  om
 * @param files The files to add.
 * @param settings The import settings.
 */
void addFiles(List<FileObject> files, ImportLocationSettings settings) {
    if (CollectionUtils.isEmpty(files))
        return;
    boolean fad = settings.isParentFolderAsDataset();
    GroupData group = settings.getImportGroup();
    ExperimenterData user = settings.getImportUser();
    enabledControl(true);

    DefaultTableModel dtm = (DefaultTableModel) table.getModel();
    //Check if the file has already 
    List<FileElement> inQueue = new ArrayList<FileElement>();
    FileElement element;
    for (int i = 0; i < table.getRowCount(); i++) {
        element = (FileElement) dtm.getValueAt(i, this.fileIndex);
        inQueue.add(element);
    }
    Iterator<FileObject> i = files.iterator();
    DataNode node = settings.getImportLocation();
    if (model.getType() != Importer.SCREEN_TYPE)
        node.setParent(settings.getParentImportLocation());
    String value = null;
    boolean v;
    long gID = group.getId();
    FileObject f;
    while (i.hasNext()) {
        f = i.next();
        if (allowAddToQueue(inQueue, f, gID, user.getId())) {
            element = new FileElement(f, model.getType(), group, user);
            element.setName(f.getName());
            inQueue.add(element);
            value = null;
            v = false;
            value = f.getFolderAsContainerName();
            if (f.isDirectory()) {
                v = fad;
                if (model.getType() == Importer.SCREEN_TYPE) {
                    value = null;
                }
            } else {
                if (fad) {
                    v = true;
                    element.setToggleContainer(v);
                }
            }

            final Vector<Object> row = new Vector<Object>();
            row.setSize(this.columnHeadings.size());

            if (this.fileIndex != null) {
                row.set(this.fileIndex, element);
            }
            if (this.groupIndex != null) {
                row.set(this.groupIndex, group.getName());
            }
            if (this.ownerIndex != null) {
                row.set(this.ownerIndex, user.getUserName());
            }
            if (this.containerIndex != null) {
                row.set(this.containerIndex, new DataNodeElement(node, value));
            }
            if (this.folderAsDatasetIndex != null) {
                row.set(this.folderAsDatasetIndex, v);
            }
            if (this.sizeIndex != null) {
                row.set(this.sizeIndex, element.getFileLengthAsString());
            }
            dtm.addRow(row);
        }
    }
    model.onSelectionChanged();
}

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

/**
 * Returns the size of the files to import.
 * //from  www  .j av  a2 s. com
 * @return See above.
 */
long getSizeFilesInQueue() {
    DefaultTableModel dtm = (DefaultTableModel) table.getModel();
    FileElement element;
    long size = 0;
    for (int i = 0; i < table.getRowCount(); i++) {
        element = (FileElement) dtm.getValueAt(i, this.fileIndex);
        size += element.getFileLength();
    }
    return size;
}

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

/**
 * Marks the folder as a dataset./*from  ww w. j  a v  a  2  s  .c om*/
 * 
 * @param fad Pass <code>true</code> to mark the folder as a dataset,
 *            <code>false</code> otherwise.
 */
void markFolderAsDataset(boolean fad) {
    int n = table.getRowCount();
    if (n == 0)
        return;
    DefaultTableModel dtm = (DefaultTableModel) table.getModel();
    FileElement element;

    for (int i = 0; i < n; i++) {
        element = (FileElement) dtm.getValueAt(i, this.fileIndex);
        if (element.isDirectory())
            dtm.setValueAt(fad, i, this.folderAsDatasetIndex);
    }
}

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

/** Resets the names of all selected files. */
void resetFilesName() {
    int n = table.getRowCount();
    if (n == 0)//from www .j ava  2  s .  co m
        return;
    DefaultTableModel model = (DefaultTableModel) table.getModel();
    FileElement element;
    for (int i = 0; i < n; i++) {
        element = (FileElement) model.getValueAt(i, this.fileIndex);
        element.setName(element.getFile().getAbsolutePath());
    }
    table.repaint();
}

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

/** Applies the partial names to all the files. */
void applyToAll() {
    int n = table.getRowCount();
    DefaultTableModel dtm = (DefaultTableModel) table.getModel();
    FileElement element;//from  w ww.ja va  2 s  . c om
    for (int i = 0; i < n; i++) {
        element = (FileElement) dtm.getValueAt(i, this.fileIndex);
        if (!element.isDirectory()) {
            element.setName(model.getDisplayedFileName(element.getFile().getAbsolutePath()));
        }
    }
    table.repaint();
}

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

private void saveContactChanges() {
    DefaultTableModel model = (DefaultTableModel) cspInfoTable.getModel();
    for (CloudProviderInfo csp : removedCSPs) {
        contact.removeCloudProvider(csp.getProviderName());
    }//from   w w  w .j  a v  a2s  . co  m
    ArrayList<CloudProviderInfo> addedCSPs = new ArrayList<>();
    for (int i = 0; i < addedCSPCount; i++) {
        String providerName = (String) model.getValueAt(model.getRowCount() - addedCSPCount + i, 0);
        String username = (String) model.getValueAt(model.getRowCount() - addedCSPCount + i, 1);
        CloudProviderInfo cpi = new CloudProviderInfo(providerName, username);
        addedCSPs.add(cpi);
        contact.addCloudProvider(cpi);
    }
    if (contact instanceof PanboxMyContact) {
        client.saveMyContact(removedCSPs, addedCSPs);
    } else {
        String newFirstName = firstNameTextField.getText();
        String newName = lastNameTextField.getText();
        // contact.setFirstName(newFirstName);
        // contact.setName(newName);
        client.saveContact(contact, newFirstName, newName, removedCSPs, addedCSPs,
                contactVerificationStatusCheckBox.isSelected());
    }
}

From source file:org.signserver.admin.gui.AddWorkerDialog.java

private void addOrEditProperty(final String key, final String value) {
    if (PropertiesConstants.NAME.equals(key)) {
        JOptionPane.showMessageDialog(this, "Use the Name text field to edit the worker name",
                "Set worker name", JOptionPane.ERROR_MESSAGE);
    } else {//from w w  w  . j a  v  a 2s .  co  m
        final DefaultTableModel model = (DefaultTableModel) propertiesTable.getModel();
        boolean existing = false;

        for (int i = 0; i < model.getRowCount(); i++) {
            final String foundKey = (String) model.getValueAt(i, 0);

            if (key.equals(foundKey)) {
                // update existing row
                model.setValueAt(key, i, 0);
                model.setValueAt(value, i, 1);
                existing = true;
                break;
            }
        }

        if (!existing) {
            model.addRow(new Object[] { key, value });
        }
    }
}