List of usage examples for javax.swing.table TableModel getColumnCount
public int getColumnCount();
From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java
public Object[][] getValues() { TableModel model = table.getModel(); Object[][] data = new Object[getRootChildren().getChildNodes().size()][model.getColumnCount()]; int y = 0;/*from ww w .j a v a 2 s .c o m*/ for (XulComponent item : getRootChildren().getChildNodes()) { int x = 0; for (XulComponent tempCell : ((XulTreeItem) item).getRow().getChildNodes()) { SwingTreeCell cell = (SwingTreeCell) tempCell; switch (columns.getColumn(x).getColumnType()) { case CHECKBOX: Boolean flag = (Boolean) cell.getValue(); if (flag == null) { flag = Boolean.FALSE; } data[y][x] = flag; break; case COMBOBOX: Vector values = (Vector) cell.getValue(); int idx = cell.getSelectedIndex(); data[y][x] = values.get(idx); break; default: // label data[y][x] = cell.getLabel(); break; } x++; } y++; } // for(int row=0; row<this.rootChildren.getRowCount(); row++){ // for(int col=0; col<model.getColumnCount(); col++){ // data[row][col] = model.getValueAt(row,col); // } // } return data; }
From source file:org.rivalry.swingui.table.VisibleColumnsPopupMenu.java
/** * @param columnName Column name./*from w w w. j av a2 s . c om*/ * * @return the absolute column index. */ int determineColumnIndex(final String columnName) { int answer = -1; if (StringUtils.isNotEmpty(columnName)) { final TableModel dataModel = _tableModel.getDataModel(); final int size = dataModel.getColumnCount(); for (int i = 0; answer < 0 && i < size; i++) { if (columnName.equals(dataModel.getColumnName(i))) { answer = i; } } } return answer; }
From source file:org.wings.STable.java
/** * Creates the default columns of the table from the table model. *//*from w ww. j a va 2s . c o m*/ public void createDefaultColumnsFromModel() { TableModel tm = getModel(); if (tm != null) { STableColumnModel columnModel = getColumnModel(); while (columnModel.getColumnCount() > 0) columnModel.removeColumn(columnModel.getColumn(0)); for (int i = 0; i < tm.getColumnCount(); i++) { STableColumn column = new STableColumn(i); String columnName = tm.getColumnName(i); column.setHeaderValue(columnName); this.columnModel.addColumn(column); } } }
From source file:org.yccheok.jstock.file.Statements.java
/** * Construct Statements based on given TableModel. * * @param tableModel given TableModel//from w ww . jav a 2s.com * @return the constructed Statements. UNKNOWN_STATEMENTS if fail */ public static Statements newInstanceFromTableModel(TableModel tableModel, boolean languageIndependent) { final CSVHelper csvHelper = (CSVHelper) tableModel; final GUIBundleWrapper guiBundleWrapper = GUIBundleWrapper.newInstance( languageIndependent ? GUIBundleWrapper.Language.INDEPENDENT : GUIBundleWrapper.Language.DEFAULT); final int column = tableModel.getColumnCount(); final int row = tableModel.getRowCount(); List<String> strings = new ArrayList<String>(); for (int i = 0; i < column; i++) { final String type = languageIndependent ? csvHelper.getLanguageIndependentColumnName(i) : tableModel.getColumnName(i); final Class c = tableModel.getColumnClass(i); if (c.equals(Stock.class)) { final String code_string = guiBundleWrapper.getString("MainFrame_Code"); final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol"); strings.add(code_string); strings.add(symbol_string); } if (c.equals(StockInfo.class)) { final String code_string = guiBundleWrapper.getString("MainFrame_Code"); final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol"); strings.add(code_string); strings.add(symbol_string); } else { strings.add(type); } } // Comment handling. CommentableContainer commentableContainer = null; if (tableModel instanceof CommentableContainer) { commentableContainer = (CommentableContainer) tableModel; } Statement.What what = Statement.what(strings); final Statements s = new Statements(what.type, what.guiBundleWrapper); for (int i = 0; i < row; i++) { final List<Atom> atoms = new ArrayList<Atom>(); for (int j = 0; j < column; j++) { final String type = languageIndependent ? csvHelper.getLanguageIndependentColumnName(j) : tableModel.getColumnName(j); final Object object = tableModel.getValueAt(i, j); final Class c = tableModel.getColumnClass(j); if (c.equals(Stock.class)) { final Stock stock = (Stock) object; // There are no way to represent Stock in text form. We // will represent them in Code and Symbol. // Code first. Follow by symbol. final String code_string = guiBundleWrapper.getString("MainFrame_Code"); final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol"); atoms.add(new Atom(stock.code.toString(), code_string)); atoms.add(new Atom(stock.symbol.toString(), symbol_string)); } else if (c.equals(StockInfo.class)) { final StockInfo stockInfo = (StockInfo) object; final String code_string = guiBundleWrapper.getString("MainFrame_Code"); final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol"); atoms.add(new Atom(stockInfo.code.toString(), code_string)); atoms.add(new Atom(stockInfo.symbol.toString(), symbol_string)); } else if (c.equals(Date.class)) { atoms.add(new Atom(object != null ? org.yccheok.jstock.gui.Utils.commonDateFormat(((Date) object).getTime()) : "", type)); } else { // For fall below and rise above, null value is permitted. // Use empty string to represent null value. atoms.add(new Atom(object != null ? object : "", type)); } } // Comment handling. if (commentableContainer != null) { atoms.add(new Atom(commentableContainer.getCommentable(i).getComment(), guiBundleWrapper.getString("PortfolioManagementJPanel_Comment"))); } final Statement statement = new Statement(atoms); if (s.getType() != statement.getType()) { // Doesn't not match. Return UNKNOWN_STATEMENTS to indicate we fail to // construct Statements from TableModel. return UNKNOWN_STATEMENTS; } s.statements.add(statement); } // Any metadata? This is special hack since Android introduction. if (tableModel instanceof StockTableModel) { s.metadatas.put("timestamp", Long.toString(((StockTableModel) tableModel).getTimestamp())); } return s; }
From source file:org.yccheok.jstock.gui.JTableUtilities.java
public static int getModelColumnIndex(JTable jTable, Object value) { TableModel tableModel = jTable.getModel(); if (tableModel instanceof StockTableModel) { return ((StockTableModel) tableModel).findColumn(value.toString()); }/* ww w .j a va2 s.c om*/ try { TableColumn tableColumn = jTable.getColumn(value); return tableColumn.getModelIndex(); } // Anti-pattern. We are depending on the exception throwing. Bad! catch (java.lang.IllegalArgumentException exp) { final int columnCount = tableModel.getColumnCount(); for (int col = 0; col < columnCount; col++) { String s = tableModel.getColumnName(col); if (s.equals(value)) return col; } } return -1; }
From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java
public JXTablePerColumnFiltering(TableModel model) { super(model); this.model = (BeanTableModel<?>) model; // Create the 1-row filtering Table nColumns = model.getColumnCount(); // DependencyEngine e = new DependencyEngine(new BasicEngineProvider()); for (int row = 0; row < model.getRowCount(); row++) { for (int i = 0; i < nColumns; i++) { if (getColumnName(i).contains("userCell")) { // this is a column with cells that can contain formulas in addition to computed values } else { }//from w w w . j a v a 2s .co m } } filteringModel = new DefaultTableModel(1, nColumns); initializeFilterModel(); filteringTable = new JXTableBetterFocus(filteringModel); filteringTable.setTableHeader(null); for (int i = 0; i < nColumns; i++) { TableColumn fColumn = filteringTable.getColumn(i); MultiRenderer multiRenderer = getMultiRenderer(); fColumn.setCellRenderer(multiRenderer); fColumn.setCellEditor(multiRenderer); fColumn.setWidth(getColumn(i).getWidth()); } this.setRowFilter(filter); JTableHeader header = this.getTableHeader(); if (tips == null) { tips = new ColumnHeaderToolTips(); } header.addMouseMotionListener(tips); }
From source file:pt.webdetails.cda.CdaQueryComponent.java
private IPentahoResultSet convertTableToResultSet(TableModel tableModel) { List<String> columnNames = new ArrayList<String>(); for (int i = 0; i < tableModel.getColumnCount(); i++) { columnNames.add(tableModel.getColumnName(i)); }/* w w w . jav a2s . c o m*/ MemoryMetaData metadata = new MemoryMetaData(columnNames); MemoryResultSet resultSet = new MemoryResultSet(); resultSet.setMetaData(metadata); for (int i = 0; i < tableModel.getRowCount(); i++) { Object row[] = new Object[tableModel.getColumnCount()]; for (int j = 0; j < tableModel.getColumnCount(); j++) { row[j] = tableModel.getValueAt(i, j); } resultSet.addRow(row); } return resultSet; }
From source file:pt.webdetails.cda.dataaccess.AbstractDataAccess.java
/** * Get a value iterator from a $FOREACH directive * * @return Iterable over values, or null if no results *//*w w w . j a v a 2 s . c o m*/ private Iterable<String> expandParameterIteration(String dataAccessId, int outColumnIdx, String[] dataAccessParameters) throws QueryException { final String EXC_TEXT = "Unable to expand parameter iteration. "; QueryOptions queryOptions = new QueryOptions(); queryOptions.setDataAccessId(dataAccessId); //set query parameters if (dataAccessParameters != null) { for (String paramDef : dataAccessParameters) { int attribIdx = StringUtils.indexOf(paramDef, '='); if (attribIdx > 0) { String paramName = StringUtils.trim(StringUtils.substring(paramDef, 0, attribIdx)); String paramValue = StringUtils.trim(StringUtils.substring(paramDef, attribIdx + 1)); queryOptions.addParameter(paramName, paramValue); } else { logger.error("Bad parameter definition, skipping: " + paramDef); } } } //do query and get selected columns logger.debug("expandParameterIteration: Doing inner query on CdaSettings [ " + cdaSettings.getId() + " (" + queryOptions.getDataAccessId() + ")]"); try { DataAccess dataAccess = getCdaSettings().getDataAccess(queryOptions.getDataAccessId()); TableModel tableModel = dataAccess.doQuery(queryOptions); if (outColumnIdx < 0 || outColumnIdx >= tableModel.getColumnCount()) { throw new QueryException(EXC_TEXT, new IllegalArgumentException("Output column index " + outColumnIdx + " out of range.")); } if (tableModel.getRowCount() < 1) { return null; } return new StringColumnIterable(tableModel, outColumnIdx); } catch (UnknownDataAccessException e) { throw new QueryException(EXC_TEXT, e); } }
From source file:pt.webdetails.cda.dataaccess.JoinCompoundDataAccess.java
protected TableModel queryDataSource(final QueryOptions queryOptions) throws QueryException { TableModel output;/*w w w . ja v a2 s. com*/ inputCallables.clear(); try { QueryOptions croppedOptions = (QueryOptions) queryOptions.clone(); croppedOptions.setSortBy(new ArrayList<String>()); croppedOptions.setPageSize(0); croppedOptions.setPageStart(0); final TableModel tableModelA = this.getCdaSettings().getDataAccess(leftId).doQuery(croppedOptions); final TableModel tableModelB = this.getCdaSettings().getDataAccess(rightId).doQuery(croppedOptions); if (tableModelA.getColumnCount() == 0 || tableModelB.getColumnCount() == 0) { return new MetadataTableModel(new String[0], new Class[0], 0); } String[] leftColumnNames = new String[leftKeys.length]; for (int i = 0; i < leftKeys.length; i++) { leftColumnNames[i] = tableModelA.getColumnName(Integer.parseInt(leftKeys[i])); } String[] rightColumnNames = new String[rightKeys.length]; for (int i = 0; i < rightKeys.length; i++) { rightColumnNames[i] = tableModelB.getColumnName(Integer.parseInt(rightKeys[i])); } String sortLeftXML = getSortXmlStep("sortLeft", leftColumnNames); String sortRightXML = getSortXmlStep("sortRight", rightColumnNames); String mergeJoinXML = getMergeJoinXml(leftColumnNames, rightColumnNames); DynamicTransMetaConfig transMetaConfig = new DynamicTransMetaConfig(Type.EMPTY, "JoinCompoundData", null, null); DynamicTransConfig transConfig = new DynamicTransConfig(); String input1Xml = getInjectorStepXmlString("input1", tableModelA); String input2Xml = getInjectorStepXmlString("input2", tableModelB); transConfig.addConfigEntry(EntryType.STEP, "input1", input1Xml); transConfig.addConfigEntry(EntryType.STEP, "input2", input2Xml); transConfig.addConfigEntry(EntryType.STEP, "sortLeft", sortLeftXML); transConfig.addConfigEntry(EntryType.STEP, "sortRight", sortRightXML); transConfig.addConfigEntry(EntryType.STEP, "mergeJoin", mergeJoinXML); transConfig.addConfigEntry(EntryType.HOP, "input1", "sortLeft"); transConfig.addConfigEntry(EntryType.HOP, "input2", "sortRight"); transConfig.addConfigEntry(EntryType.HOP, "sortLeft", "mergeJoin"); transConfig.addConfigEntry(EntryType.HOP, "sortRight", "mergeJoin"); TableModelInput input1 = new TableModelInput(); transConfig.addInput("input1", input1); inputCallables.add(input1.getCallableRowProducer(tableModelA, true)); TableModelInput input2 = new TableModelInput(); transConfig.addInput("input2", input2); inputCallables.add(input2.getCallableRowProducer(tableModelB, true)); RowMetaToTableModel outputListener = new RowMetaToTableModel(false, true, false); transConfig.addOutput("mergeJoin", outputListener); DynamicTransformation trans = new DynamicTransformation(transConfig, transMetaConfig); trans.executeCheckedSuccess(null, null, this); logger.info(trans.getReadWriteThroughput()); output = outputListener.getRowsWritten(); if (output == null) { return new MetadataTableModel(new String[0], new Class[0], 0); } } catch (UnknownDataAccessException e) { throw new QueryException("Unknown Data access in CompoundDataAccess ", e); } catch (Exception e) { throw new QueryException("Exception during query ", e); } return output; }
From source file:pt.webdetails.cda.dataaccess.JoinCompoundDataAccess.java
private String getInjectorStepXmlString(String name, TableModel t) { StringBuilder xml = new StringBuilder("<step><name>"); Class<?> columnClass;//from w w w .j a va 2 s . c o m xml.append(name).append("</name><type>Injector</type><copies>1</copies>"); int maxRowsTypeSearch = getMaxTypeSearchRowCount(t); // If we have metadata information, put it here if (t.getColumnCount() > 0) { xml.append("<fields>"); for (int i = 0; i < t.getColumnCount(); i++) { /* The proper way to get the column class is from t.getColumnClass(). * However, this always returns Object when the column at hand is a * Calculated Column -- and we have no idea what to do with Objects. * Therefore, we try to infer the correct type from the getClass() of * the chosen column, first row, as that can't be worse than trying * to deal with Object. */ columnClass = t.getColumnClass(i); if (columnClass.equals(Object.class) && t.getRowCount() > 0) { for (int j = 0; j < maxRowsTypeSearch; j++) { if (t.getValueAt(j, i) != null) { columnClass = t.getValueAt(j, i).getClass(); break; } } } xml.append("<field>"); xml.append("<name>").append(t.getColumnName(i)).append("</name>"); xml.append("<type>").append(getKettleTypeFromColumnClass(columnClass)).append("</type>"); xml.append("<length>-1</length><precision>-1</precision></field>"); } xml.append("</fields>"); } xml.append("</step>"); return xml.toString(); }