List of usage examples for javax.swing.table DefaultTableModel getDataVector
@SuppressWarnings("rawtypes") public Vector<Vector> getDataVector()
Vector
of Vectors
that contains the table's data values. From source file:org.isatools.isacreator.gui.formelements.SubForm.java
protected void removeColumn(int curColDelete) { if ((curColDelete == -1) || (curColDelete == 0)) { return;/* w ww .j ava2 s. c o m*/ } if (defaultTableModel.getColumnCount() == 2 && curColDelete == (defaultTableModel.getColumnCount() - 1)) { clearColumn(curColDelete); return; } else { clearColumn(curColDelete); } if (fieldType == FieldTypes.ASSAY && (dataEntryForm != null) && !uneditableRecords.contains(curColDelete)) { clearColumn(curColDelete); return; } DefaultTableModel model = (DefaultTableModel) scrollTable.getModel(); // get the column. because 1 was added on previously to take account of the first column, we need to remove // it this time since the column indexes are now coming from the table. TableColumn col = scrollTable.getColumnModel().getColumn(curColDelete - 1); int columnModelIndex = col.getModelIndex(); Vector data = model.getDataVector(); Vector<String> colIds = new Vector<String>(); for (int i = 0; i < model.getColumnCount(); i++) { colIds.addElement(model.getColumnName(i)); } scrollTable.removeColumn(col); colIds.removeElementAt(columnModelIndex); // remove any data present in the column on deletion for (Object aData : data) { Vector row = (Vector) aData; row.removeElementAt(columnModelIndex); } model.setDataVector(data, colIds); // decrease each column index after deleted column by 1 so that indexes can be kept intact. Enumeration columnEnumeration = scrollTable.getColumnModel().getColumns(); while (columnEnumeration.hasMoreElements()) { TableColumn c = (TableColumn) columnEnumeration.nextElement(); if (c.getModelIndex() >= columnModelIndex) { c.setModelIndex(c.getModelIndex() - 1); } } if (fieldType == FieldTypes.ASSAY && uneditableRecords.contains(defaultTableModel.getColumnCount() - 1)) { uneditableRecords.remove(defaultTableModel.getColumnCount() - 1); } // update the model model.fireTableStructureChanged(); updateTables(); }
From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.FileSelectionTable.java
/** Removes the selected files from the queue. */ private void removeSelectedFiles() { table.removeKeyListener(keyListener); int[] rows = table.getSelectedRows(); if (rows == null || rows.length == 0) return;/* www . j a v a 2s.c o m*/ DefaultTableModel dtm = (DefaultTableModel) table.getModel(); Vector<?> v = dtm.getDataVector(); List<Object> indexes = new ArrayList<Object>(); for (int i = 0; i < table.getRowCount(); i++) { if (table.isRowSelected(i)) indexes.add(v.get(i)); } v.removeAll(indexes); dtm.setDataVector(v, this.columnHeadings); table.clearSelection(); formatTableModel(); table.repaint(); table.addKeyListener(keyListener); int n = table.getRowCount(); firePropertyChange(REMOVE_PROPERTY, n - 1, n); enabledControl(table.getRowCount() > 0); model.onSelectionChanged(); }
From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.FileSelectionTable.java
/** Removes all the files from the queue. */ void removeAllFiles() { int n = table.getRowCount(); if (n == 0)//w w w . j a v a 2 s . com return; DefaultTableModel dtm = (DefaultTableModel) table.getModel(); dtm.getDataVector().clear(); table.clearSelection(); formatTableModel(); table.repaint(); firePropertyChange(REMOVE_PROPERTY, -1, 0); enabledControl(false); model.onSelectionChanged(); }