private void jButton1ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed JFrame frame = new JFrame(); int result = JOptionPane.showConfirmDialog( frame, TIMSMessages.DELETE_CONFIRMATION, TIMSMessages.DELETE_CONFIRMATION_TITLE, JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { TableModel model = bransTB.getModel(); ArrayList<Integer> brandsIds = new ArrayList<Integer>(); for (int i = 0; i < model.getRowCount(); i++) { Boolean selected = (Boolean) model.getValueAt(i, 0); if (selected) { brandsIds.add((Integer) model.getValueAt(i, 1)); } } DeleteBransController dbc = new DeleteBransController(); dbc.setBrandIds(brandsIds); int count = dbc.deleteBrands(); if (count > 0) { JOptionPane.showMessageDialog(null, count + TIMSMessages.BRANDS_DELETE_SUCCESS); } else { JOptionPane.showMessageDialog(null, TIMSMessages.BRANDS_DELETE_FAIL); } ViewBrandController brandController = new ViewBrandController(); brandController.execute(); } } // GEN-LAST:event_jButton1ActionPerformed
private Object getValueWithoutWebEditorsFormat(int row, int column) { Object r = original.getValueAt(row, column); if (r instanceof Boolean) { if (((Boolean) r).booleanValue()) return XavaResources.getString(locale, "yes"); return XavaResources.getString(locale, "no"); } if (withValidValues) { MetaProperty p = getMetaProperty(column); if (p.hasValidValues()) { return p.getValidValueLabel(locale, original.getValueAt(row, column)); } } if (r instanceof java.util.Date) { MetaProperty p = getMetaProperty(column); // In order to use the type declared by the developer // and not the one returned by JDBC or the JPA engine if (java.sql.Time.class.isAssignableFrom(p.getType())) { return DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(r); } if (java.sql.Timestamp.class.isAssignableFrom(p.getType())) { DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); return dateFormat.format(r); } return DateFormat.getDateInstance(DateFormat.SHORT, locale).format(r); } if (r instanceof BigDecimal) { return formatBigDecimal(r, locale); } return r; }
/** * Macht die verschiedenen Schaltflächen benutzbar oder unbenutzbar, je nachdem, ob ein * Schlüssel-Wert-Paar ausgewählt wurde. */ private void updateView() { final TableModel model = itemsTable.getModel(); boolean selectedAreEditable = true; for (int selRowIndex : itemsTable.getSelectedRows()) { String key = (String) model.getValueAt(selRowIndex, 0); // Sonderfall: Dieses Property wird indirekt über das Symbol einer Location // gesetzt und sollte nicht direkt editierbar sein if (key.equals(ObjectPropConstants.LOC_DEFAULT_REPRESENTATION) || key.equals(ObjectPropConstants.LOCTYPE_DEFAULT_REPRESENTATION)) { selectedAreEditable = false; break; } } boolean enableEditing = false; boolean enableRemoval = false; // Only allow removal of properties if at least one is selected and all of // them are editable. if (itemsTable.getSelectedRowCount() > 0 && selectedAreEditable) { enableRemoval = true; } // Only allow editing for the selection if exactly one property is selected // and it is editable. if (itemsTable.getSelectedRowCount() == 1 && selectedAreEditable) { enableEditing = true; } editButton.setEnabled(enableEditing); removeButton.setEnabled(enableRemoval); }
private void clearModel() { for (int row = 0; row < lifeModel.getRowCount(); row++) { for (int col = 0; col < lifeModel.getColumnCount(); col++) { lifeModel.setValueAt(new LifeCell(), row, col); } } }
/** * Constructs a ClutoTree diaplay which is initialized with tableModel as the data model, and the * given selection model. * * @param clutoSolution The clustering solution * @param tableContext The context which manages views and selections. * @param tableModel the data model for the parallel coordinate display */ public ClutoTree(ClutoSolution clutoSolution, TableContext tableContext, TableModel tableModel) { ctx = tableContext; tm = tableModel; lsm = ctx.getRowSelectionModel(tm); // labelModel int ncol = tm.getColumnCount(); for (int i = 0; i < ncol; i++) { labelModel.addElement(tm.getColumnName(i)); } setLayout(new BorderLayout()); btnP = new JToolBar(); add(btnP, BorderLayout.NORTH); labelChoice.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { labelColumn = 0; String ln = (String) e.getItem(); if (ln != null) { for (int c = 0; c < tm.getColumnCount(); c++) { if (ln.equals(tm.getColumnName(c))) { labelColumn = c; break; } } } graph.invalidate(); validate(); repaint(); } } }); btnP.add(labelChoice); graph = new SimpleGraph(); graph.getGraphDisplay().setOpaque(true); graph.getGraphDisplay().setBackground(Color.white); graph.getGraphDisplay().setGridColor(new Color(220, 220, 220)); graph.showGrid(false); graph.showAxis(BorderLayout.WEST, false); graph.showAxis(BorderLayout.EAST, true); graph.getAxisDisplay(BorderLayout.EAST).setZoomable(true); graph.getAxisDisplay(BorderLayout.EAST).setAxisLabeler(labeler); ((LinearAxis) graph.getYAxis()).setTickIncrement(-1.); graph.getAxisDisplay(BorderLayout.SOUTH).setZoomable(true); gs = new GraphSegments(); gs.setColor(Color.blue); idxSelColor = new IndexSelectColor(Color.cyan, null, new DefaultListSelectionModel()); gs.setIndexedColor(idxSelColor); graph.addGraphItem(gs); graph.getGraphDisplay().addMouseListener(ma); add(graph); if (lsm != null) { lsm.addListSelectionListener(selListener); } display(makeTree(clutoSolution)); }
@Test public void testMaxRows() throws Exception { Table table = dataContext.getDefaultSchema().getTableByName(peopleIndexType); Query query = new Query().from(table).select(table.getColumns()).setMaxRows(5); DataSet dataSet = dataContext.executeQuery(query); TableModel tableModel = new DataSetTableModel(dataSet); assertEquals(5, tableModel.getRowCount()); }
/* * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent evt) { TableModel old = (TableModel) evt.getOldValue(); TableModel knew = (TableModel) evt.getNewValue(); if (old != null) old.removeTableModelListener(autoTailTracker_); if (knew != null) knew.addTableModelListener(autoTailTracker_); }
private void writerHeader(PrintWriter writer, TableModel model) { for (int i = 0; i < model.getColumnCount(); i++) { if (i > 0) writer.print(','); writer.print(model.getColumnName(i)); } writer.println(); }
public List<String> getSeletedTabs() { // TODO add your handling code here: TableModel model = dbTab.getModel(); for (int i = 0; i < model.getRowCount(); i++) { Boolean b = (Boolean) model.getValueAt(i, 0); if (b != null && b.booleanValue()) selectedTabs.add(model.getValueAt(i, 1).toString()); } return selectedTabs; }
/** * List all metadata items of the selected entries * * @param selected Is TRUE if some check boxes are checked * @param selectedRow Selected row of the table, is used only if selected = FALSE */ private void listItems(boolean selected, int selectedRow) { TableModel model = branchTable.getModel(); Collection searchResult = new HashSet(); if (selected) // some items are checked, delete them { // int [] selectedIndices = branches.getSelectedIndices(); for (int i = 0; i < myBranches.length; i++) { Boolean checked = (Boolean) model.getValueAt(i, 0); if (Boolean.TRUE.equals(checked)) { WaitDialog.showDialog(); String branchToBrowse = ((Branch) myBranches[i]).getAbbreviation(); Collection branchResult = Gui.dispatcher.getAllLibItemsFromBranch(branchToBrowse); searchResult.addAll(branchResult); WaitDialog.closeDialog(); } } } else // no checked items, delete only selected row { if (selectedRow >= 0) { WaitDialog.showDialog(); String branchToBrowse = ((Branch) myBranches[selectedRow]).getAbbreviation(); searchResult = Gui.dispatcher.getAllLibItemsFromBranch(branchToBrowse); WaitDialog.closeDialog(); } } if (searchResult.isEmpty()) // Result ist empty, show Warning { showNoResultMessage(); } else // Result is not empty, call BrowseMetadataResults { // Result-Frame ist allready opened, ask to overwrite int index = Configurator.getIntProperty("searchMetadataResult", 0, "gui-forms"); if (Gui.my_forms[index] != null && !Gui.my_forms[index].isClosed()) { int switch_frame = getNewSearchDialog(); if (switch_frame == JOptionPane.NO_OPTION) { Gui.my_forms[index].pack(); try { Gui.my_forms[index].setSelected(true); } catch (java.beans.PropertyVetoException ev) { } } else { Point location = Gui.my_forms[index].getLocation(); Gui.my_forms[index].dispose(); BrowseMetadataResults mdSearchResult = new BrowseMetadataResults( index, Gui.lang.getString("selected_branch_entries"), searchResult, location); } } else { // GEH�RT HIER NICHT REIN // Point location = Gui.my_forms[index].getLocation(); BrowseMetadataResults mdSearchResult = new BrowseMetadataResults( index, Gui.lang.getString("selected_branch_entries"), searchResult, null); } } }
/** Overrides <code>JComponent</code>'s <code>getToolTipText</code> */ public String getToolTipText(MouseEvent e) { String tip = null; java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); // int colIndex = columnAtPoint(p); // int realColumnIndex = convertColumnIndexToModel(colIndex); TableModel model = getModel(); tip = (String) model.getValueAt(rowIndex, 1); return tip; }
@Override public void tableChanged(TableModelEvent e) { int r = e.getFirstRow(); int c = e.getColumn(); if (e.getType() == TableModelEvent.UPDATE) { TableModel model = (TableModel) e.getSource(); Object data = model.getValueAt(r, c); DbManager.editAttribute(r, c, data, DbManager.VOLUNTEERS); } }
private void jButton1ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: TableModel model = dbTab.getModel(); for (int i = 0; i < model.getRowCount(); i++) { Boolean b = (Boolean) model.getValueAt(i, 0); if (b.booleanValue()) selectedTabs.add(model.getValueAt(i, 1).toString()); } this.dispose(); } // GEN-LAST:event_jButton1ActionPerformed
public void tableChanged(TableModelEvent e) { int baris = e.getFirstRow(); int kolom = e.getColumn(); System.out.print("Terjadi perubahan di "); System.out.print("baris " + baris); System.out.println("kolom " + kolom); TableModel model = (TableModel) e.getSource(); Object data = model.getValueAt(baris, kolom); System.out.println("Data baru : " + data); }
private void confColumnModel() { for (int row = 0; row < lifeModel.getRowCount(); row++) { for (int col = 0; col < lifeModel.getColumnCount(); col++) { lifeTable.getColumnModel().getColumn(col).setMaxWidth(CELL_SIZE); lifeTable.getColumnModel().getColumn(col).setMinWidth(CELL_SIZE); lifeTable.getColumnModel().getColumn(col).setPreferredWidth(CELL_SIZE); lifeTable.getColumnModel().getColumn(col).setResizable(false); } } }
@Override public int getRowHeight(int row) { TableModel tm = getModel(); int height = getFontMetrics(getFont()).getHeight(); for (int i = 0; i < getColumnModel().getColumnCount(); i++) { try { height = Math.max(height, getHeight(tm.getValueAt(row, i), i)); } catch (Exception e) { } } return height; }
/** * Validates that queries with empty results (no rows or no columns) are correctly handled by * CachingDataFactory. * * <p>http://jira.pentaho.com/browse/PRD-4628 */ public void testEmptyResult() throws ReportDataFactoryException { final String query = "SELECT NON EMPTY [Product].[All Products].[Classic Cars]" + ".[Highway 66 Mini Classics].[1985 Toyota Supra] " + "on 0 from SteelWheelsSales where measures.Sales\n"; DataFactory dataFactory = createDataFactory(query); final TableModel tableModel = ((CachingDataFactory) dataFactory).queryStatic("default", new ParameterDataRow()); assertEquals("results should be empty, rowcount should be 0.", 0, tableModel.getRowCount()); assertEquals( "results should be empty, columncount should be 0", 0, tableModel.getColumnCount()); }
@Nullable public GraphPrintCell getGraphPrintCellForRow(TableModel model, int rowIndex) { if (rowIndex >= model.getRowCount()) { return null; } Object commitValue = model.getValueAt(rowIndex, AbstractVcsLogTableModel.COMMIT_COLUMN); if (commitValue instanceof GraphCommitCell) { GraphCommitCell commitCell = (GraphCommitCell) commitValue; return commitCell.getPrintCell(); } return null; }
public void tableChanged(TableModelEvent e) { /*System.out.println("Column: " + e.getColumn()); System.out.println("First row: " + e.getFirstRow()); System.out.println("Source: " + e.getSource()); System.out.println("Type: " + e.getType()); TableModel tm = (TableModel) e.getSource(); System.out.println("Value: " + tm.getValueAt(e.getFirstRow(), e.getColumn())); System.out.println("obj: " + data[e.getFirstRow()][e.getColumn()]);*/ if (e.getColumn() != TableModelEvent.ALL_COLUMNS) { TableModel tm = (TableModel) e.getSource(); data[e.getFirstRow()][e.getColumn()] = tm.getValueAt(e.getFirstRow(), e.getColumn()); } }
// // Implement the PropertyChangeListener // public void propertyChange(PropertyChangeEvent e) { // When the TableModel changes we need to update the listeners // and column widths if ("model".equals(e.getPropertyName())) { TableModel model = (TableModel) e.getOldValue(); model.removeTableModelListener(this); model = (TableModel) e.getNewValue(); model.addTableModelListener(this); adjustColumns(); } }
/** * Produces a duration configuration from the table model. * * @return a new OnsetConfig holding the input duration config. */ public USConfiguration getConfig() { TableModel model = table.getModel(); try { double fwdDefault = current.getForwardDefault(); current = new USConfiguration(); current.setForwardDefault(fwdDefault); double offset = Double.parseDouble((String) model.getValueAt(0, 1)); current.setType((Relationship) model.getValueAt(0, 0)); current.setOffset(offset); } catch (NullPointerException e) { } return current; }
private int writeData(PrintWriter writer, TableModel model) { int c = 0; for (; c < model.getRowCount(); c++) { for (int i = 0; i < model.getColumnCount(); i++) { if (i > 0) writer.print(','); writer.print(model.getValueAt(c, i)); } writer.println(); } return c; }
public static boolean someCheckBoxIsTicked(JTable table, int column) { TableModel model = table.getModel(); int rowCount = model.getRowCount(); for (int row = 0; row < rowCount; row++) { boolean ticked = Boolean.parseBoolean(String.valueOf(model.getValueAt(row, column))); if (ticked) { return true; } } return false; }
@Override public void updateValues() { List<KeyValueProperty> items = new LinkedList<>(); TableModel model = itemsTable.getModel(); int size = model.getRowCount(); for (int i = 0; i < size; i++) { String key = (String) model.getValueAt(i, 0); String value = (String) model.getValueAt(i, 1); items.add(new KeyValueProperty(null, key, value)); } fProperty.setItems(items); }
private void printDebugData(JTable table) { int numRows = table.getRowCount(); int numCols = table.getColumnCount(); javax.swing.table.TableModel model = table.getModel(); System.out.println("Value of data: "); for (int i = 0; i < numRows; i++) { System.out.print(" row " + i + ":"); for (int j = 0; j < numCols; j++) { System.out.print(" " + model.getValueAt(i, j)); } System.out.println(); } System.out.println("--------------------------"); }
public static int countTickedCheckBox(JTable table, int column) { TableModel model = table.getModel(); int rowCount = model.getRowCount(); int count = 0; for (int row = 0; row < rowCount; row++) { boolean ticked = Boolean.parseBoolean(String.valueOf(model.getValueAt(row, column))); if (ticked) { count++; } } return count; }
private int[] getWidths(TableModel tableModel) { int[] widths = new int[tableModel.getColumnCount()]; for (int r = 0; r < Math.min(tableModel.getRowCount(), 500); r++) { // 500 is not for performance, but for using only a sample of data with huge table for (int c = 0; c < tableModel.getColumnCount(); c++) { Object o = tableModel.getValueAt(r, c); if (o instanceof String) { String s = ((String) o).trim(); if (s.length() > widths[c]) widths[c] = s.length(); } } } return widths; }
@Override public void setModel(final TableModel model) { super.setModel(model); if (model instanceof SortableColumnModel) { final SortableColumnModel sortableModel = (SortableColumnModel) model; if (sortableModel.isSortable()) { final TableRowSorter<TableModel> rowSorter = createRowSorter(model); rowSorter.setSortsOnUpdates(isSortOnUpdates()); setRowSorter(rowSorter); final RowSorter.SortKey sortKey = sortableModel.getDefaultSortKey(); if (sortKey != null && sortKey.getColumn() >= 0 && sortKey.getColumn() < model.getColumnCount()) { if (sortableModel.getColumnInfos()[sortKey.getColumn()].isSortable()) { rowSorter.setSortKeys(Arrays.asList(sortKey)); } } } else { final RowSorter<? extends TableModel> rowSorter = getRowSorter(); if (rowSorter instanceof DefaultColumnInfoBasedRowSorter) { setRowSorter(null); } } } }
public Object getValueAt(int row, int column) { if (myModel instanceof SortableColumnModel) { return ((SortableColumnModel) myModel).getRowValue(row); } return myModel.getValueAt(row, column); }
@Override public void mouseClicked(MouseEvent e) { int col = table.columnAtPoint(new Point(e.getX(), e.getY())); String header = table.getColumnName(col); if (columnHeader.contains(header)) { int row = table.rowAtPoint(new Point(e.getX(), e.getY())); TableModel tableModel = table.getModel(); Object val = tableModel.getValueAt( table.convertRowIndexToModel(row), table.convertColumnIndexToModel(col)); if (val != null) { String text = val.toString(); textDialog.setText(text); textDialog.setVisible(true); } } }