List of usage examples for javax.swing.table TableModel getRowCount
public int getRowCount();
From source file:pkgnew.line.PluginDialog.java
private void uninstallPluginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uninstallPluginActionPerformed List<Plugin> plugins = PluginManager.getInstance().getPlugins(); TableModel model = TablePlugins.getModel(); int rowCount = model.getRowCount(); File[] files = ((File) new File("plugins/")).listFiles(); for (int i = 0; i < rowCount; i++) { boolean isSelected = (boolean) model.getValueAt(i, 0); if (isSelected) { plugins.get(i).suspend();/*ww w . j a v a 2 s . c o m*/ for (File file : files) { System.out.println("comparing " + file.getName() + " and " + plugins.get(i).getName()); if (file.getName().startsWith(plugins.get(i).getName())) { file.delete(); plugins.remove(i); } } } } listPlugins(); }
From source file:pt.webdetails.cda.cache.monitor.ExtraCacheInfo.java
public ExtraCacheInfo(String cdaSettingsId, String dataAccessId, long queryDurationMs, TableModel tm) { this.cdaSettingsId = cdaSettingsId; this.dataAccessId = dataAccessId; this.queryDurationMs = queryDurationMs; this.nbrRows = tm.getRowCount(); JsonExporter exporter = new JsonExporter(null); try {/*from ww w . ja v a 2 s . co m*/ this.tableSnapshot = exporter.getTableAsJson(tm, TABLE_SNAPSHOT_ROWS); } catch (Exception e) { logger.error("Error exporting table snapshot as json.", e); } }
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)); }/*from www. j av a 2s . c om*/ 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 *//*from w w w. j a v a 2s .com*/ 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
private String getInjectorStepXmlString(String name, TableModel t) { StringBuilder xml = new StringBuilder("<step><name>"); Class<?> columnClass;//w ww . j ava 2 s. c om 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(); }
From source file:pt.webdetails.cda.dataaccess.JoinCompoundDataAccess.java
private int getMaxTypeSearchRowCount(TableModel t) { int maxRowsTypeSearch = DEFAULT_MAX_ROWS_VALUE_TYPE_SEARCH; String maxRowsTypeSearchProperty = CdaEngine.getInstance() .getConfigProperty(MAX_ROWS_VALUE_TYPE_SEARCH_PROPERTY); if (!StringUtils.isEmpty(maxRowsTypeSearchProperty)) { try {/* w w w .jav a2 s .c o m*/ maxRowsTypeSearch = Integer.parseInt(maxRowsTypeSearchProperty); } catch (NumberFormatException nfe) { logger.error(MAX_ROWS_VALUE_TYPE_SEARCH_PROPERTY + ":" + maxRowsTypeSearchProperty + " not a valid integer."); } } if (maxRowsTypeSearch <= 0) { maxRowsTypeSearch = t.getRowCount(); } else { maxRowsTypeSearch = Math.min(maxRowsTypeSearch, t.getRowCount()); } return maxRowsTypeSearch; }
From source file:pt.webdetails.cda.exporter.HtmlExporter.java
@Override public void export(OutputStream out, TableModel tableModel) throws ExporterException { final Document document = DocumentHelper.createDocument(); Element table = null;// w w w. j a va 2s . c o m if (fullHtml) { final Element html = document.addElement("html"); final Element head = html.addElement("head"); head.addElement("title").addText(title); table = html.addElement("body").addElement("table"); } else { table = document.addElement("table"); } final int columnCount = tableModel.getColumnCount(); //table headers final Element headerRow = table.addElement("tr"); for (int i = 0; i < columnCount; i++) { String colName = tableModel.getColumnName(i); headerRow.addElement("th").addText(colName); } //table body for (int i = 0; i < tableModel.getRowCount(); i++) { Element row = table.addElement("tr"); for (int j = 0; j < columnCount; j++) { Element tableCell = row.addElement("td"); Object value = tableModel.getValueAt(i, j); tableCell.setText(valueToText(value)); if (value instanceof Date) { tableCell.setText(format.format(value)); } else if (value != null) { // numbers can be safely converted via toString, as they use a well-defined format there tableCell.setText(value.toString()); } } } try { document.setXMLEncoding("UTF-8"); OutputFormat outFormat = new OutputFormat(); outFormat.setOmitEncoding(true); outFormat.setSuppressDeclaration(true);//otherwise msexcel/oocalc may not recognize content outFormat.setNewlines(true); outFormat.setIndentSize(columnCount); final Writer writer = new BufferedWriter(new OutputStreamWriter(out)); XMLWriter xmlWriter = new XMLWriter(writer, outFormat); xmlWriter.write(document); xmlWriter.flush(); } catch (IOException e) { throw new ExporterException("IO Exception converting to utf-8", e); } }
From source file:pt.webdetails.cda.exporter.JsonExporter.java
public JSONObject getTableAsJson(TableModel tableModel, Integer rowLimit) throws JSONException, ExporterException { JSONObject json = new JSONObject(); // Generate metadata final JSONArray metadataArray = new JSONArray(); final int columnCount = tableModel.getColumnCount(); int rowCount = tableModel.getRowCount(); if (rowLimit != null) { rowCount = Math.min(rowCount, rowLimit); }// w w w. j av a2s . com boolean[] isColumnDouble = new boolean[columnCount]; for (int i = 0; i < columnCount; i++) { JSONObject info = new JSONObject(); info.put("colIndex", i); info.put("colName", tableModel.getColumnName(i)); Class<?> columnClass = tableModel.getColumnClass(i); isColumnDouble[i] = (columnClass.isAssignableFrom(Double.class)); info.put("colType", getColType(columnClass)); metadataArray.put(info); } json.put("metadata", metadataArray); if (tableModel instanceof MetadataTableModel) { json.put("queryInfo", ((MetadataTableModel) tableModel).getAllMetadata()); } final JSONArray valuesArray = new JSONArray(); for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) { final JSONArray rowArray = new JSONArray(); for (int colIdx = 0; colIdx < columnCount; colIdx++) { Object value = tableModel.getValueAt(rowIdx, colIdx); try { if (value != null && isColumnDouble[colIdx] && ((Double) value).isInfinite()) { value = null; //value = Double.POSITIVE_INFINITY == (Double) value ? "Infinity" : "-Infinity";//workaround for JSON // issue with Infinity } } catch (ClassCastException e) { } //just because it says Double doesn't mean we don't get oranges rowArray.put(value); } valuesArray.put(rowArray); } json.put("resultset", valuesArray); return json; }
From source file:pt.webdetails.cda.exporter.XmlExporter.java
public void export(final OutputStream out, final TableModel tableModel) throws ExporterException { final Document document = DocumentHelper.createDocument(); // Generate metadata final Element root = document.addElement("CdaExport"); final Element metadata = root.addElement("MetaData"); final int columnCount = tableModel.getColumnCount(); final int rowCount = tableModel.getRowCount(); for (int i = 0; i < columnCount; i++) { final Element columnInfo = metadata.addElement("ColumnMetaData"); columnInfo.addAttribute("index", (String.valueOf(i))); columnInfo.addAttribute("type", getColType(tableModel.getColumnClass(i))); columnInfo.addAttribute("name", tableModel.getColumnName(i)); }//from w ww . j av a 2s.c o m SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); final Element resultSet = root.addElement("ResultSet"); for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) { final Element row = resultSet.addElement("Row"); for (int colIdx = 0; colIdx < columnCount; colIdx++) { final Element col = row.addElement("Col"); final Object value = tableModel.getValueAt(rowIdx, colIdx); if (value instanceof Date) { col.setText(format.format(value)); } else if (value != null) { // numbers can be safely converted via toString, as they use a well-defined format there col.setText(value.toString()); } else { col.addAttribute("isNull", "true"); } } } try { final Writer writer = new BufferedWriter(new OutputStreamWriter(out)); document.setXMLEncoding("UTF-8"); document.write(writer); writer.flush(); } catch (IOException e) { throw new ExporterException("IO Exception converting to utf-8", e); } }
From source file:pt.webdetails.cda.filetests.CacheKeysTest.java
@Test public void testParam() throws Exception { final CdaSettings cdaSettings = parseSettingsFile("sample-securityParam.cda"); QueryOptions queryOptions = new QueryOptions(); queryOptions.setDataAccessId("junitDataAccess"); TableModel tableModel = cdaSettings.getDataAccess(queryOptions.getDataAccessId()).doQuery(queryOptions); assertEquals(1, tableModel.getRowCount()); assertEquals(1, tableModel.getColumnCount()); String result = (String) tableModel.getValueAt(0, 0); assertEquals("thisIsAGoodValue", result); }