List of usage examples for javax.swing.table TableCellEditor stopCellEditing
public boolean stopCellEditing();
From source file:org.apache.jmeter.protocol.http.gui.CookiePanel.java
public void actionPerformed(ActionEvent e) { String action = e.getActionCommand(); if (action.equals(DELETE_COMMAND)) { if (tableModel.getRowCount() > 0) { // If a table cell is being edited, we must cancel the editing // before deleting the row. if (cookieTable.isEditing()) { TableCellEditor cellEditor = cookieTable.getCellEditor(cookieTable.getEditingRow(), cookieTable.getEditingColumn()); cellEditor.cancelCellEditing(); }// w w w. j ava 2 s . co m int rowSelected = cookieTable.getSelectedRow(); if (rowSelected != -1) { tableModel.removeRow(rowSelected); tableModel.fireTableDataChanged(); // Disable the DELETE and SAVE buttons if no rows remaining // after delete. if (tableModel.getRowCount() == 0) { deleteButton.setEnabled(false); saveButton.setEnabled(false); } // Table still contains one or more rows, so highlight // (select) the appropriate one. else { int rowToSelect = rowSelected; if (rowSelected >= tableModel.getRowCount()) { rowToSelect = rowSelected - 1; } cookieTable.setRowSelectionInterval(rowToSelect, rowToSelect); } } } } else if (action.equals(ADD_COMMAND)) { // If a table cell is being edited, we should accept the current // value and stop the editing before adding a new row. if (cookieTable.isEditing()) { TableCellEditor cellEditor = cookieTable.getCellEditor(cookieTable.getEditingRow(), cookieTable.getEditingColumn()); cellEditor.stopCellEditing(); } tableModel.addNewRow(); tableModel.fireTableDataChanged(); // Enable the DELETE and SAVE buttons if they are currently // disabled. if (!deleteButton.isEnabled()) { deleteButton.setEnabled(true); } if (!saveButton.isEnabled()) { saveButton.setEnabled(true); } // Highlight (select) the appropriate row. int rowToSelect = tableModel.getRowCount() - 1; cookieTable.setRowSelectionInterval(rowToSelect, rowToSelect); } else if (action.equals(LOAD_COMMAND)) { try { final String[] _txt = { ".txt" }; //$NON-NLS-1$ final JFileChooser chooser = FileDialoger.promptToOpenFile(_txt); if (chooser != null) { CookieManager manager = new CookieManager(); manager.addFile(chooser.getSelectedFile().getAbsolutePath()); for (int i = 0; i < manager.getCookieCount(); i++) { addCookieToTable(manager.get(i)); } tableModel.fireTableDataChanged(); if (tableModel.getRowCount() > 0) { deleteButton.setEnabled(true); saveButton.setEnabled(true); } } } catch (IOException ex) { log.error("", ex); } } else if (action.equals(SAVE_COMMAND)) { try { final JFileChooser chooser = FileDialoger.promptToSaveFile("cookies.txt"); //$NON-NLS-1$ if (chooser != null) { ((CookieManager) createTestElement()).save(chooser.getSelectedFile().getAbsolutePath()); } } catch (IOException ex) { log.error("", ex); } } }
From source file:org.codinjutsu.tools.mongo.view.MongoConfigurable.java
private void stopEditing() { if (table.isEditing()) { TableCellEditor editor = table.getCellEditor(); if (editor != null) { editor.stopCellEditing(); }/*from w w w. java2s .co m*/ } }
From source file:org.openmicroscopy.shoola.agents.measurement.view.ObjectInspector.java
/** * Sets the new figure retrieved from the passed collection. * //from w w w . j a va 2 s .co m * @param l The collection to handle. */ void setSelectedFigures(List<ROIShape> l) { FigureTableModel tableModel = (FigureTableModel) fieldTable.getModel(); Iterator<ROIShape> i = l.iterator(); //Register error and notify user. ROIShape shape; try { TableCellEditor editor = fieldTable.getCellEditor(); if (editor != null) editor.stopCellEditing(); while (i.hasNext()) { shape = i.next(); tableModel.setData(shape.getFigure()); fieldTable.repaint(); } } catch (Exception e) { MeasurementAgent.getRegistry().getLogger().info(this, "Figures selection" + e); } }
From source file:org.pentaho.reporting.designer.core.util.table.ElementMetaDataTable.java
public void stopEditing() { final TableCellEditor cellEditor = getCellEditor(); if (cellEditor != null) { cellEditor.stopCellEditing(); }/*w w w .j av a 2 s . c om*/ }
From source file:org.pentaho.reporting.ui.datasources.sequence.SequenceEditor.java
public void stopEditing() { final TableCellEditor cellEditor = propertyTable.getCellEditor(); if (cellEditor != null) { cellEditor.stopCellEditing(); }//ww w.j av a 2 s . co m }
From source file:org.yccheok.jstock.gui.analysis.ObjectInspectorJPanel.java
/** * Tells the editor to stop editing and accept any partially edited * value as the value of the editor. The editor returns false if * editing was not stopped; this is useful for editors that validate * and can not accept invalid entries./*from w ww .jav a2 s .co m*/ * * @return true if editing was stopped; false otherwise */ public boolean stopCellEditing() { final TableCellEditor editor = this.getTable().getCellEditor(); if (editor != null) { return editor.stopCellEditing(); } return true; }
From source file:org.yccheok.jstock.gui.portfolio.DividendSummaryJDialog.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // Returns the active cell editor, which is null if the table is not // currently editing. final TableCellEditor tableCellEditor = this.jTable1.getCellEditor(); if (tableCellEditor != null) { // Save the value to table model. final boolean status = tableCellEditor.stopCellEditing(); if (false == status) { // User enters an invalid value. Prevent user from closing // the dialog. return; }//from ww w . j a v a 2 s .c om } this.dividendSummaryAfterPressingOK = this.dividendSummary; Utils.removeMeaninglessRecords(this.dividendSummaryAfterPressingOK); this.setVisible(false); this.dispose(); }
From source file:org.yccheok.jstock.gui.StockDatabaseJDialog.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // We are no longer interest to receive any event from combo box. ((AjaxAutoCompleteJComboBox) this.jComboBox1).dettachAll(); // Returns the active cell editor, which is null if the table is not // currently editing. final TableCellEditor tableCellEditor = this.jTable2.getCellEditor(); if (tableCellEditor != null) { // Save the value to table model. final boolean status = tableCellEditor.stopCellEditing(); if (false == status) { // User enters an invalid value. Prevent user from closing // dialog. return; }/*from www. java2 s.c o m*/ } final StockInfoTableModel model = (StockInfoTableModel) (jTable2.getModel()); final List<StockInfo> stockInfos = model.getStockInfos(); /* Shall we check the returned code? */ this.stockInfoDatabase.removeAllUserDefinedStockInfos(); for (StockInfo stockInfo : stockInfos) { // In fact, we shouldn't need to trim the string again, as // MyTableCellEditor has done that for us. The code is here to fix // old user-defined-database.xml, with possibility to have data // begin and end with white space. This is because old version of // JStock (1.0.5r) doesn't perform trimming. final String codeStr = stockInfo.code.toString().trim(); if (codeStr.length() <= 0) { continue; } String symbolStr = stockInfo.symbol.toString().trim(); if (symbolStr.length() <= 0) { /* We allow empty symbol to be entered by user. In 0 length * symbol case, we will make it same as code. */ symbolStr = codeStr; } this.stockInfoDatabase.addUserDefinedStockInfo( StockInfo.newInstance(Code.newInstance(codeStr), Symbol.newInstance(symbolStr))); } this.result = this.stockInfoDatabase; this.setVisible(false); this.dispose(); }