List of usage examples for javax.swing.table TableColumn getModelIndex
public int getModelIndex()
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 .ja v a 2 s. co 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 .j a v a2 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
private boolean checkIsEmpty(TableColumn tc) { int colIndex = tc.getModelIndex(); int viewIndex = Utils.convertModelIndexToView(spreadsheet.getTable(), colIndex); for (int rowNo = 0; rowNo < spreadsheet.getTable().getRowCount(); rowNo++) { if (spreadsheet.getTable().getValueAt(rowNo, viewIndex) != null && !spreadsheet.getTable().getValueAt(rowNo, viewIndex).equals("")) { return false; }/*from ww w. j a v a 2s . c o m*/ } return true; }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * if a given column has dependent columns, e.g. does a factor column have an associated unit column. if it does, * then remove the factor and the unit. this method does that. * * @param col - column to remove...//from www.j a v a2 s . c o m */ private void removeDependentColumns(TableColumn col) { try { if (spreadsheet.columnDependencies.containsKey(col)) { for (TableColumn tc : spreadsheet.columnDependencies.get(col)) { spreadsheet.curColDelete = Utils.convertModelIndexToView(spreadsheet.getTable(), tc.getModelIndex()); removeColumn(); } removeColumnFromDependencies(col); } } catch (ConcurrentModificationException cme) { // ignore this error } }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * Remove a column from the spreadsheet.getTable(), delete all the data associated with the column in the model, and keep indices * intact by decreasing the index of every column after the one deleted by one to stop fragmentation. * * @param model - @see SpreadsheetModel to be acted on * @param columnToRemove - @see TableColumn representing column to remove. *///w ww. j ava2 s . c o m private void deleteColumn(SpreadsheetModel model, TableColumn columnToRemove) { int columnModelIndex = columnToRemove.getModelIndex(); Vector data = model.getDataVector(); Vector colIds = model.getColumnIdentifiers(); spreadsheet.getTable().removeColumn(columnToRemove); 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 spreadsheetColumns = spreadsheet.getTable().getColumnModel().getColumns(); while (spreadsheetColumns.hasMoreElements()) { TableColumn c = (TableColumn) spreadsheetColumns.nextElement(); if (c.getModelIndex() >= columnModelIndex) { c.setModelIndex(c.getModelIndex() - 1); } } // update the model model.fireTableStructureChanged(); }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * Remove a column from a spreadsheet.getTable() given a column name * * @param colName - Name of column to be removed. *///from w ww . j a va 2 s. co m public void removeColumnByName(String colName) { Enumeration<TableColumn> columns = spreadsheet.getTable().getColumnModel().getColumns(); while (columns.hasMoreElements()) { TableColumn col = columns.nextElement(); if (col.getHeaderValue().toString().equals(colName)) { spreadsheet.curColDelete = Utils.convertModelIndexToView(spreadsheet.getTable(), col.getModelIndex()); removeColumn(); removeDependentColumns(col); } } ((SpreadsheetModel) spreadsheet.getTable().getModel()).fireTableStructureChanged(); }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * Check to see if a column with a given name exists. * Result is always false if the column allows multiple values. * * @param colName name of column to check for. * @return true if it exists, false otherwise. *//*from w w w. ja va 2 s . co m*/ public int getModelIndexForColumn(String colName) { Enumeration<TableColumn> columns = spreadsheet.getTable().getColumnModel().getColumns(); // if the column can be referenced multiple times, then we should return false in this check. if (colName != null) { if (!spreadsheet.getTableReferenceObject().acceptsMultipleValues(colName)) { while (columns.hasMoreElements()) { TableColumn col = columns.nextElement(); if (col.getHeaderValue().toString().equalsIgnoreCase(colName)) { return col.getModelIndex(); } } } } return -1; }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * Adds a column to the table with a specified name * * @param headerLabel - name of column to be added *//*from www . j a v a 2 s . c o m*/ public TableColumn addColumn(Object headerLabel, boolean required) { SpreadsheetModel model = (SpreadsheetModel) spreadsheet.getTable().getModel(); TableColumn newColumn = new TableColumn(spreadsheet.getTable().getModel().getColumnCount()); newColumn.setHeaderValue(headerLabel); newColumn.setPreferredWidth(calcColWidths(headerLabel.toString())); newColumn.setHeaderRenderer(spreadsheet.columnRenderer); // add a cell editor (if available to the column) addCellEditor(newColumn); model.addToColumns(headerLabel.toString()); model.addColumn(headerLabel.toString()); spreadsheet.getTable().addColumn(newColumn); addFieldToRequiredCellRendererIfVisible(required, newColumn.getModelIndex()); model.fireTableStructureChanged(); model.fireTableDataChanged(); if (spreadsheet.getTable().getRowCount() > 0) { spreadsheet.getTable().setValueAt( spreadsheet.getTableReferenceObject().getDefaultValue(headerLabel.toString()), 0, spreadsheet.getTable().getColumnCount() - 1); copyColumnDownwards(0, spreadsheet.getTable().getColumnCount() - 1); spreadsheet.getTableReferenceObject().getDefaultValue(headerLabel.toString()); } spreadsheet.getTable().addNotify(); return newColumn; }
From source file:org.nuclos.client.ui.collect.result.ResultController.java
/** * adds the column with the given field name before column columnBefore to the table. * @param fields available and selected fields of the result table * @param columnBefore the column of the column model (as opposed to the column of the table model) * @param sFieldNameToAdd name of the column to add *//*w w w .j av a 2 s .co m*/ protected void cmdAddColumn(final ChoiceEntityFieldList fields, TableColumn columnBefore, final String sFieldNameToAdd) throws CommonBusinessException { // find the field with the given name in available fields: final CollectableEntityField clctef = CollectionUtils.findFirst(fields.getAvailableFields(), PredicateUtils.transformedInputEquals(new CollectableEntityField.GetName(), sFieldNameToAdd)); assert clctef != null; final CollectableTableModel<?> tblmodel = (CollectableTableModel<?>) getResultPanel().getResultTable() .getModel(); final CollectableEntityField clctefBefore = tblmodel .getCollectableEntityField(columnBefore.getModelIndex()); int insertPos = fields.getSelectedFields().indexOf(clctefBefore); insertPos = (insertPos >= 0) ? insertPos : 0; fields.moveToSelectedFields(insertPos, clctef); // Note that it is not enough to add the column to the result table model. // We must rebuild the table tblmodel's columns in order to sync it with the table column model: tblmodel.setColumns(fields.getSelectedFields()); }
From source file:org.pentaho.reporting.ui.datasources.table.TableEditor.java
public void addColumn(final TableColumn column) { stopEditing();/* ww w. j av a 2 s .c o m*/ if (column.getHeaderValue() == null) { final int modelColumn = column.getModelIndex(); final String columnName = getModel().getColumnName(modelColumn); if (modelColumn == 0) { column.setResizable(false); column.setHeaderValue(columnName); column.setPreferredWidth(30); column.setMaxWidth(30); column.setMinWidth(30); } else { final Class columnType = getModel().getColumnClass(modelColumn); column.setHeaderValue(new TypedHeaderInformation(columnType, columnName)); } } getColumnModel().addColumn(column); }