Example usage for javax.swing.table TableCellEditor cancelCellEditing

List of usage examples for javax.swing.table TableCellEditor cancelCellEditing

Introduction

In this page you can find the example usage for javax.swing.table TableCellEditor cancelCellEditing.

Prototype

public void cancelCellEditing();

Source Link

Document

Tells the editor to cancel editing and not accept any partially edited value.

Usage

From source file:com.frostwire.gui.library.LibraryDeviceTableMediator.java

/**
 * Cancels all editing of fields in the tree and table.
 *///ww w .  j a va  2  s .  c o m
void cancelEditing() {
    if (TABLE.isEditing()) {
        TableCellEditor editor = TABLE.getCellEditor();
        editor.cancelCellEditing();
    }
}

From source file:com.ibm.issw.odc.gui.BPMArgumentsPanel.java

/**
 * Cancel cell editing if it is being edited
 *//*from   www.ja va2  s . com*/
private void cancelEditing() {
    // If a table cell is being edited, we must cancel the editing before
    // deleting the row
    if (table.isEditing()) {
        TableCellEditor cellEditor = table.getCellEditor(table.getEditingRow(), table.getEditingColumn());
        cellEditor.cancelCellEditing();
    }
}

From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheet.java

public void graphicNodesCompositeEvent(CompositeCacheEvent compositeEvent) {
    //System.out.println("cache event -> editCellAt");
    if (isEditing()) {
        int row = getEditingRow();
        int col = getEditingColumn();
        TableCellEditor editor = getCellEditor();
        editor.cancelCellEditing();
        editCellAt(row, col);//from   w  w w .j  av a 2s. com
    }
}

From source file:it.staiger.jmeter.protocol.http.config.gui.DynamicFilePanel.java

/**
  * runs specified command on currently selected file.
  */*from   w w  w  .  j  a  va2  s. c o m*/
  * @param command specifies which process will be done on selected
  * file. it's coming from action command currently catched by
  * action listener.
  *
  * @see runCommandOnRow
  */
private void runCommandOnSelectedFile(String command) {
    // If a table cell is being edited, we must cancel the editing before
    // deleting the row
    if (table.isEditing()) {
        TableCellEditor cellEditor = table.getCellEditor(table.getEditingRow(), table.getEditingColumn());
        cellEditor.cancelCellEditing();
    }
    int rowSelected = table.getSelectedRow();
    if (rowSelected >= 0) {
        runCommandOnRow(command, rowSelected);
        tableModel.fireTableDataChanged();
        // Disable DELETE and BROWSE if there are no rows in the table to delete.
        checkDeleteAndBrowseStatus();
        // Table still contains one or more rows, so highlight (select)
        // the appropriate one.
        if (tableModel.getRowCount() != 0) {
            int rowToSelect = rowSelected;
            if (rowSelected >= tableModel.getRowCount()) {
                rowToSelect = rowSelected - 1;
            }
            table.setRowSelectionInterval(rowToSelect, rowToSelect);
        }
    }
}

From source file:com.limegroup.gnutella.gui.library.LibraryTableMediator.java

/**
 * Override the default removal so we can actually stop sharing
 * and delete the file./*from   w  ww.  j  a  v a 2s  .c  o m*/
* Deletes the selected rows in the table.
* CAUTION: THIS WILL DELETE THE FILE FROM THE DISK.
*/
public void removeSelection() {
    String msgKey = "MESSAGE_CONFIRM_FILE_DELETE";
    int response = GUIMediator.showYesNoMessage(msgKey);
    if (response != GUIMediator.YES_OPTION)
        return;

    int[] rows = TABLE.getSelectedRows();
    if (rows.length <= 0)
        return;

    Arrays.sort(rows);

    if (TABLE.isEditing()) {
        TableCellEditor editor = TABLE.getCellEditor();
        editor.cancelCellEditing();
    }

    ArrayList errors = new ArrayList();

    for (int i = rows.length - 1; i >= 0; i--) {
        File file = ((LibraryTableModel) DATA_MODEL).getFile(rows[i]);
        FileDesc fd = ((LibraryTableModel) DATA_MODEL).getFileDesc(rows[i]);

        if (fd instanceof IncompleteFileDesc)
            RouterService.getDownloadManager().getIncompleteFileManager().removeEntry(file);
        else
            RouterService.getFileManager().removeFileIfShared(file);

        boolean removed = file.delete();
        if (!removed && fd != null) {
            // try again, telling UploadManager to kill any uploads
            RouterService.getUploadManager().killUploadsForFileDesc(fd);
            removed = file.delete();
        }

        if (removed)
            DATA_MODEL.remove(rows[i]);
        else
            errors.add(file.getName());
    }

    clearSelection();

    // go through the errors and tell them what couldn't be deleted.
    for (int i = 0; i < errors.size(); i++) {
        String name = (String) errors.get(i);
        final String key1 = "MESSAGE_UNABLE_TO_DELETE_FILE_START";
        final String key2 = "MESSAGE_UNABLE_TO_DELETE_FILE_END";
        final String msg = "'" + name + "'.";
        // notify the user that deletion failed
        GUIMediator.showError(key1, msg, key2);
    }
}

From source file:com.frostwire.gui.library.LibraryFilesTableMediator.java

/**
 * Override the default removal so we can actually stop sharing
 * and delete the file./*from  w  w  w .j  av a2  s  .  c  o m*/
 * Deletes the selected rows in the table.
 * CAUTION: THIS WILL DELETE THE FILE FROM THE DISK.
 */
public void removeSelection() {
    int[] rows = TABLE.getSelectedRows();
    if (rows.length == 0)
        return;

    if (TABLE.isEditing()) {
        TableCellEditor editor = TABLE.getCellEditor();
        editor.cancelCellEditing();
    }

    List<File> files = new ArrayList<File>(rows.length);

    // sort row indices and go backwards so list indices don't change when
    // removing the files from the model list
    Arrays.sort(rows);
    for (int i = rows.length - 1; i >= 0; i--) {
        File file = DATA_MODEL.getFile(rows[i]);
        files.add(file);
    }

    CheckBoxListPanel<File> listPanel = new CheckBoxListPanel<File>(files, new FileTextProvider(), true);
    listPanel.getList().setVisibleRowCount(4);

    // display list of files that should be deleted
    Object[] message = new Object[] { new MultiLineLabel(I18n.tr(
            "Are you sure you want to delete the selected file(s), thus removing it from your computer?"), 400),
            Box.createVerticalStrut(ButtonRow.BUTTON_SEP), listPanel,
            Box.createVerticalStrut(ButtonRow.BUTTON_SEP) };

    // get platform dependent options which are displayed as buttons in the dialog
    Object[] removeOptions = createRemoveOptions();

    int option = JOptionPane.showOptionDialog(MessageService.getParentComponent(), message, I18n.tr("Message"),
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, removeOptions,
            removeOptions[0] /* default option */);

    if (option == removeOptions.length - 1 /* "cancel" option index */
            || option == JOptionPane.CLOSED_OPTION) {
        return;
    }

    // remove still selected files
    List<File> selected = listPanel.getSelectedElements();
    List<String> undeletedFileNames = new ArrayList<String>();

    for (File file : selected) {
        // stop seeding if seeding
        BittorrentDownload dm = null;
        if ((dm = TorrentUtil.getDownloadManager(file)) != null) {
            dm.setDeleteDataWhenRemove(false);
            dm.setDeleteTorrentWhenRemove(false);
            BTDownloadMediator.instance().remove(dm);
        }

        // close media player if still playing
        if (MediaPlayer.instance().isThisBeingPlayed(file)) {
            MediaPlayer.instance().stop();
            MPlayerMediator.instance().showPlayerWindow(false);
        }

        // removeOptions > 2 => OS offers trash options
        boolean removed = FileUtils.delete(file,
                removeOptions.length > 2 && option == 0 /* "move to trash" option index */);
        if (removed) {

            DATA_MODEL.remove(DATA_MODEL.getRow(file));
        } else {
            undeletedFileNames.add(getCompleteFileName(file));
        }
    }

    clearSelection();

    if (undeletedFileNames.isEmpty()) {
        return;
    }

    // display list of files that could not be deleted
    message = new Object[] { new MultiLineLabel(I18n.tr(
            "The following files could not be deleted. They may be in use by another application or are currently being downloaded to."),
            400), Box.createVerticalStrut(ButtonRow.BUTTON_SEP),
            new JScrollPane(createFileList(undeletedFileNames)) };

    JOptionPane.showMessageDialog(MessageService.getParentComponent(), message, I18n.tr("Error"),
            JOptionPane.ERROR_MESSAGE);

    super.removeSelection();
}

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();
            }//from w w w.j ava2s  .  c  o  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);
        }
    }
}