Example usage for javax.swing JTable getEditingRow

List of usage examples for javax.swing JTable getEditingRow

Introduction

In this page you can find the example usage for javax.swing JTable getEditingRow.

Prototype

public int getEditingRow() 

Source Link

Document

Returns the index of the row that contains the cell currently being edited.

Usage

From source file:edu.harvard.mcz.imagecapture.ui.ButtonEditor.java

@Override
public void actionPerformed(ActionEvent e) {

    // Action might not be event_button_pressed on all systems.
    log.debug("Button event actionCommand: " + e.getActionCommand());
    if (e.getActionCommand().equals(EVENT_PRESSED)) {
        // Event is a click on the cell
        // Identify the row that was clicked on.
        JTable table = (JTable) ((JButton) e.getSource()).getParent();
        log.debug(e.getSource());/*from ww w .j  av  a 2  s  .com*/
        log.debug(table);
        int row = table.getEditingRow();
        // Stop editing - note, we need to have gotten e.getSource.getParent and getEditingRow first.
        fireEditingStopped(); //Make the renderer reappear.
        Singleton.getSingletonInstance().getMainFrame()
                .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        switch (formToOpen) {
        case OPEN_SPECIMEN_DETAILS:
            // Load the selected specimen record from its ID (the data value behind the button).
            //SpecimenLifeCycle sls = new SpecimenLifeCycle();
            //Specimen specimen = sls.findById((Long)targetId);
            //if (specimen!=null) {
            if (targetId != null) {
                // a specimen with this ID exists, bring up the details editor.
                try {
                    //SpecimenControler sc = new SpecimenControler(specimen);
                    if (((Specimen) targetId).getSpecimenId() != null) {
                        if (((Specimen) targetId).isStateDone()) {
                            // Specimens in state_done are no longer editable
                            JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                                    "This Specimen record has been migrated and can no longer be edited here ["
                                            + ((Specimen) targetId).getLoadFlags()
                                            + "].\nSee: http://mczbase.mcz.harvard.edu/guid/MCZ:Ent:"
                                            + ((Specimen) targetId).getCatNum(),
                                    "Migrated Specimen", JOptionPane.WARNING_MESSAGE);
                        } else {
                            // Specimen is still editable
                            if (table != null) {
                                // Pass the specimen object for the row, the table model, and the row number on to the specimen controler.
                                try {
                                    SpecimenControler sc = new SpecimenControler((Specimen) targetId,
                                            (SpecimenListTableModel) table.getModel(), table, row);
                                    if (table.getParent().getParent().getParent().getParent()
                                            .getClass() == SpecimenBrowser.class) {
                                        sc.addListener((DataChangeListener) table.getParent());
                                    } else {
                                        Component x = table;
                                        boolean done = false;
                                        while (!done) {
                                            log.debug(x.getParent());
                                            x = x.getParent();
                                            if (x.getClass() == SpecimenBrowser.class) {
                                                sc.addListener((DataChangeListener) x);
                                                done = true;
                                            }
                                        }
                                    }
                                    sc.displayInEditor();
                                } catch (java.lang.ClassCastException eNotSp) {
                                    // Request isn't coming from a SpecimenListTableModel
                                    // View just the specimen record.
                                    SpecimenControler sc = new SpecimenControler((Specimen) targetId);
                                    sc.displayInEditor();
                                }
                            } else {
                                log.debug(e.getSource());
                                //SpecimenControler sc = new SpecimenControler((Specimen)targetId);
                                //sc.displayInEditor();
                            }
                        }
                    } else {
                        log.debug("User clicked on table row containing a new Specimen()");
                        JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                                "No Specimen for this image", "Load Specimen Failed",
                                JOptionPane.WARNING_MESSAGE);
                    }
                } catch (NoSuchRecordException e1) {
                    log.error("Tested for specimen!=null, but SpecimenControler threw null specimen exception");
                    log.error(e1);
                }
            } else {
                log.debug("No matches found to specimen id=" + targetId);
                // TODO: Create new specimen record and bring up dialog
                JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                        "No specimen record.");
            }
            break;
        case OPEN_TEMPLATE:
            // Load the selected specimen record from its ID (the data value behind the button).
            try {
                // a template with this targetID exists, display it.
                ((PositionTemplateEditor) parentComponent).setTemplate((String) targetId);
            } catch (NoSuchTemplateException e1) {
                log.error("No such template on button press on a template in list.");
                log.error(e1);
                log.trace(e1);
            }

            break;
        case OPEN_USER:
            //TODO: tie to user
            log.debug("Open user");
            ((UserListBrowser) parentComponent).getEditUserPanel().setUser((Users) targetId);
            break;
        case OPEN_SPECIMEN_VERBATIM:
            log.debug("Open Verbatim Transcription");
            SpecimenLifeCycle sls = new SpecimenLifeCycle();
            List<Specimen> toTranscribe = sls.findForVerbatim(((GenusSpeciesCount) targetId).getGenus(),
                    ((GenusSpeciesCount) targetId).getSpecificEpithet(), WorkFlowStatus.STAGE_1);
            log.debug(toTranscribe.size());
            SpecimenListTableModel stm = new SpecimenListTableModel(toTranscribe);
            JTable stable = new JTable();
            stable.setModel(stm);
            SpecimenControler verbCont;
            try {
                verbCont = new SpecimenControler(toTranscribe.get(0), stm, stable, 0);
                VerbatimCaptureDialog dialog = new VerbatimCaptureDialog(toTranscribe.get(0), verbCont);
                dialog.setVisible(true);
            } catch (NoSuchRecordException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            break;
        case OPEN_VERBATIM_CLASSIFY:
            log.debug("Open Verbatim Classify dialog");
            try {
                VerbatimClassifyDialog dialog = new VerbatimClassifyDialog(
                        (VerbatimCount) table.getModel().getValueAt(row, 0));
                dialog.setVisible(true);
            } catch (ClassCastException e1) {
                log.error(e1.getMessage(), e1);
            }
            break;
        case ACTION_CANCEL_JOB:
            log.debug("Action Cancel requested on job " + targetId);
            Singleton.getSingletonInstance().getJobList().getJobAt((Integer) targetId).cancel();
            break;
        case OPEN_SPECIMENPARTATTRIBUTES:
            SpecimenPartAttributeDialog attrDialog = new SpecimenPartAttributeDialog((SpecimenPart) targetId);
            attrDialog.setVisible(true);
            break;
        }
        Singleton.getSingletonInstance().getMainFrame()
                .setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        System.gc();
    }
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Stop the cell editors to ensure data is flushed
 *///from   w  w  w. j a va2  s  . c  o m
private void stopCellEditors() {
    final Iterator<JTable> iter = _tables.values().iterator();
    while (iter.hasNext()) {
        final JTable table = iter.next();
        final int editingColumn = table.getEditingColumn();
        final int editingRow = table.getEditingRow();
        if (editingColumn > -1) {
            final TableCellEditor cellEditor = table.getCellEditor(editingRow, editingColumn);
            if (null != cellEditor) {
                cellEditor.stopCellEditing();
            }
        }
    }
}

From source file:gdt.jgui.entity.fields.JFieldsEditor.java

private String getEditCellLocator() {
    try {/*from   w  ww.  ja  v  a 2 s.  co m*/
        save();
        String locator$ = getLocator();
        if (entihome$ != null)
            locator$ = Locator.append(locator$, Entigrator.ENTIHOME, entihome$);
        if (entityKey$ != null)
            locator$ = Locator.append(locator$, EntityHandler.ENTITY_KEY, entityKey$);
        JTable table = (JTable) scrollPane.getViewport().getView();
        int x = table.getEditingRow();
        int y = table.getEditingColumn();
        String cellField$ = CELL_FIELD_NAME;
        if (y == 1)
            cellField$ = CELL_FIELD_VALUE;
        TableModel model = table.getModel();
        text$ = (String) model.getValueAt(x, y);
        String fieldName$ = (String) model.getValueAt(x, 0);
        locator$ = Locator.append(locator$, JTextEditor.TEXT, text$);
        locator$ = Locator.append(locator$, CELL_FIELD, cellField$);
        locator$ = Locator.append(locator$, CELL_FIELD_NAME, fieldName$);
        if (requesterResponseLocator$ != null)
            locator$ = Locator.append(locator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                    requesterResponseLocator$);
        locator$ = Locator.append(locator$, BaseHandler.HANDLER_METHOD, JFacetOpenItem.METHOD_RESPONSE);
        // System.out.println("FieldsEditor:getEditCellLocator:END:"+locator$);
        return locator$;
    } catch (Exception e) {
        LOGGER.severe(e.toString());
        return null;
    }
}

From source file:gdt.jgui.tool.JEntityEditor.java

private String getEditCellLocator() {
    try {//from   w  ww.  j a va2  s .c o  m
        save();
        JTextEditor textEditor = new JTextEditor();
        String locator$ = textEditor.getLocator();
        locator$ = Locator.merge(getLocator(), locator$);
        JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent();
        JTable table = (JTable) scrollPane.getViewport().getView();
        int i = tabbedPane.getSelectedIndex();
        String element$ = tabbedPane.getTitleAt(i);
        int x = table.getEditingRow();
        int y = table.getEditingColumn();
        String cellField$ = CELL_FIELD_TYPE;
        if (y == 1)
            cellField$ = CELL_FIELD_NAME;
        else if (y == 2)
            cellField$ = CELL_FIELD_VALUE;
        TableModel model = table.getModel();
        String text$ = (String) model.getValueAt(x, y);
        text$ = Locator.compressText(text$);
        locator$ = Locator.append(locator$, JTextEditor.IS_BASE64, Locator.LOCATOR_TRUE);
        String coreName$ = (String) model.getValueAt(x, 1);
        locator$ = Locator.append(locator$, JTextEditor.TEXT, text$);
        locator$ = Locator.append(locator$, ELEMENT, element$);
        locator$ = Locator.append(locator$, CELL_FIELD, cellField$);
        locator$ = Locator.append(locator$, CORE_NAME, coreName$);
        locator$ = Locator.append(locator$, JRequester.REQUESTER_ACTION, ACTION_EDIT_CELL);
        locator$ = Locator.append(locator$, Locator.LOCATOR_TITLE, "Edit item");
        locator$ = Locator.append(locator$, BaseHandler.HANDLER_CLASS, JTextEditor.class.getName());
        return locator$;
    } catch (Exception e) {
        LOGGER.severe(e.toString());
        return null;
    }
}

From source file:gdt.jgui.tool.JEntityEditor.java

private boolean hasEditingCell() {
    try {/*  www  .j  a  v a 2  s. co m*/
        JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent();
        JTable table = (JTable) scrollPane.getViewport().getView();
        //         System.out.println("Entityeditor:hasEditingCell:x="+table.getEditingRow()+" y="+table.getEditingColumn());
        if (table.getEditingColumn() > -1 && table.getEditingRow() > -1)
            return true;
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
    return false;
}

From source file:gdt.jgui.entity.fields.JFieldsEditor.java

private boolean hasEditingCell() {
    try {// www.j a  v a2  s.  c  om

        JTable table = (JTable) scrollPane.getViewport().getView();
        //System.out.println("Entityeditor:hasEditingCell:x="+table.getEditingRow()+" y="+table.getEditingColumn());
        if (table.getEditingColumn() > -1 && table.getEditingRow() > -1)
            return true;
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
    return false;
}

From source file:org.isatools.isacreator.api.utils.SpreadsheetUtils.java

public static void stopCellEditingInTable(JTable table) {
    if (table.getEditingColumn() != -1) {
        // the ontology cell editor is a JFrame, so closing it is useless since it will close when it loses focus anyway.
        if (!(table.getCellEditor() instanceof OntologyCellEditor)) {
            table.getCellEditor(table.getEditingRow(), table.getEditingColumn()).stopCellEditing();
        }//from w  w w . ja va2  s . co m
    }
}

From source file:org.openstreetmap.josm.gui.preferences.imagery.CacheContentsPanel.java

private static JTable getTableForCache(final CacheAccess<String, BufferedImageCacheEntry> cache,
        final TableModel tableModel) {
    final JTable ret = new JTable(tableModel);

    ButtonColumn buttonColumn = new ButtonColumn(new AbstractAction() {
        @Override//ww w . j ava  2 s .  c  om
        public void actionPerformed(ActionEvent e) {
            int row = ret.convertRowIndexToModel(ret.getEditingRow());
            tableModel.setValueAt("0", row, 1);
            cache.remove(ret.getValueAt(row, 0).toString() + ':');
        }
    });
    TableColumn tableColumn = ret.getColumnModel().getColumn(2);
    tableColumn.setCellRenderer(buttonColumn);
    tableColumn.setCellEditor(buttonColumn);
    return ret;
}