Search in sources :

Example 91 with JTable

use of javax.swing.JTable in project knime-core by knime.

the class AggregationSettingsButtonCellRenderer method mouseReleased.

/**
 * {@inheritDoc}
 */
@Override
public void mouseReleased(final MouseEvent e) {
    JTable table = m_rootPanel.getTable();
    if (m_isButtonColumnEditor && table.isEditing()) {
        table.getCellEditor().stopCellEditing();
    }
    m_isButtonColumnEditor = false;
}
Also used : JTable(javax.swing.JTable)

Example 92 with JTable

use of javax.swing.JTable in project knime-core by knime.

the class AggregationSettingsButtonCellRenderer method openSettingsDialog.

private void openSettingsDialog() {
    final JTable table = m_rootPanel.getTable();
    final int rowIdx = table.convertRowIndexToModel(table.getEditingRow());
    fireEditingStopped();
    final AggregationFunctionRow<?> row = m_rootPanel.getTableModel().getRow(rowIdx);
    if (!row.getFunction().hasOptionalSettings()) {
        // the operator has no additional settings
        return;
    }
    // figure out the parent to be able to make the dialog modal
    Frame f = null;
    Container c = m_rootPanel.getComponentPanel().getParent();
    final Component root = SwingUtilities.getRoot(c);
    if (root instanceof Frame) {
        f = (Frame) root;
    }
    while (f == null && c != null) {
        if (c instanceof Frame) {
            f = (Frame) c;
            break;
        }
        c = c.getParent();
    }
    try {
        final AggregationSettingsDialog dialog = new AggregationSettingsDialog(f, row.getFunction(), m_rootPanel.getInputTableSpec());
        // center the dialog
        dialog.setLocationRelativeTo(c);
        dialog.pack();
        // show it
        dialog.setVisible(true);
    } catch (NotConfigurableException e) {
        // show the error message
        JOptionPane.showMessageDialog(m_rootPanel.getComponentPanel(), e.getMessage(), "Unable to open dialog", JOptionPane.ERROR_MESSAGE);
        return;
    }
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) Frame(java.awt.Frame) Container(java.awt.Container) JTable(javax.swing.JTable) Component(java.awt.Component)

Example 93 with JTable

use of javax.swing.JTable in project vcell by virtualcell.

the class ServerManageConsole method getQueryResultTable.

/**
 * Return the QueryResultTable property value.
 * @return cbit.vcell.messaging.admin.sorttable.JSortTable
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private JSortTable getQueryResultTable() {
    if (ivjQueryResultTable == null) {
        try {
            ivjQueryResultTable = new JSortTable();
            ivjQueryResultTable.setName("QueryResultTable");
            ivjQueryResultTable.setModel(new JobTableModel());
            ivjQueryResultTable.disableUneditableForeground();
            final JPopupMenu popup = new JPopupMenu();
            JMenuItem viewMongoMenuItem = new JMenuItem("View Mongo Log Info...");
            popup.add(viewMongoMenuItem);
            viewMongoMenuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    try {
                        Number simID = (Number) ivjQueryResultTable.getModel().getValueAt(ivjQueryResultTable.getSelectedRow(), JobTableModel.columnIndex_SimID);
                        String userid = (String) ivjQueryResultTable.getModel().getValueAt(ivjQueryResultTable.getSelectedRow(), JobTableModel.columnIndex_UserID);
                        System.out.println("----- user=" + userid + " simID=" + simID);
                        String mongoDbHost = PropertyLoader.getRequiredProperty(PropertyLoader.mongodbHostInternal);
                        // default 27017
                        int mongoDbPort = Integer.parseInt(PropertyLoader.getRequiredProperty(PropertyLoader.mongodbPortInternal));
                        Mongo m = new Mongo(mongoDbHost, mongoDbPort);
                        String mongoDbDatabaseName = PropertyLoader.getRequiredProperty(PropertyLoader.mongodbDatabase);
                        DB db = m.getDB(mongoDbDatabaseName);
                        String mongoDbLoggingCollectionName = PropertyLoader.getRequiredProperty(PropertyLoader.mongodbLoggingCollection);
                        DBCollection dbCollection = db.getCollection(mongoDbLoggingCollectionName);
                        BasicDBObject query = new BasicDBObject();
                        query.put(VCMongoMessage.MongoMessage_simId, simID.intValue() + "");
                        DBCursor cur = dbCollection.find(query);
                        TreeMap<String, Integer> mapKeyToColumnIndex = new TreeMap<String, Integer>();
                        Vector<DBObject> dbObjV = new Vector<DBObject>();
                        while (cur.hasNext()) {
                            DBObject dbObject = cur.next();
                            dbObjV.add(dbObject);
                            Set<String> keys = dbObject.keySet();
                            Iterator<String> iter = keys.iterator();
                            while (iter.hasNext()) {
                                String key = iter.next();
                                Integer columnIndex = mapKeyToColumnIndex.get(key);
                                if (columnIndex == null) {
                                    columnIndex = mapKeyToColumnIndex.size();
                                    mapKeyToColumnIndex.put(key, columnIndex);
                                }
                            }
                        }
                        int msgTimeColumnIndex = -1;
                        if (mapKeyToColumnIndex.size() > 0) {
                            String[] columnNames = new String[mapKeyToColumnIndex.size()];
                            Iterator<String> keyIter = mapKeyToColumnIndex.keySet().iterator();
                            while (keyIter.hasNext()) {
                                String key = keyIter.next();
                                int columnIndex = mapKeyToColumnIndex.get(key);
                                columnNames[columnIndex] = key;
                                if (key.equals(VCMongoMessage.MongoMessage_msgTime)) {
                                    msgTimeColumnIndex = columnIndex;
                                }
                            }
                            // //Ask which columns to view
                            // Object[][] colrowdata = new Object[columnNames.length][1];
                            // for (int i = 0; i < colrowdata.length; i++) {
                            // colrowdata[i][0] = columnNames[i];
                            // }
                            // int[] showcolArr =
                            // DialogUtils.showComponentOKCancelTableList(ServerManageConsole.this, "Select Columns to View...", new String[] {"Column Names"}, colrowdata, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
                            Object[][] rowData = new Object[dbObjV.size()][columnNames.length];
                            for (int i = 0; i < rowData.length; i++) {
                                DBObject dbObj = dbObjV.get(i);
                                Set<String> keys = dbObj.keySet();
                                Iterator<String> iter = keys.iterator();
                                while (iter.hasNext()) {
                                    String key = iter.next();
                                    rowData[i][mapKeyToColumnIndex.get(key)] = dbObj.get(key);
                                }
                            }
                            // sort by msgtime
                            final int msgTimeColumnIndexFinal = msgTimeColumnIndex;
                            if (msgTimeColumnIndex != -1) {
                                Arrays.sort(rowData, new Comparator<Object[]>() {

                                    public int compare(Object[] o1, Object[] o2) {
                                        Long o1Long = (Long) o1[msgTimeColumnIndexFinal];
                                        Long o2Long = (Long) o2[msgTimeColumnIndexFinal];
                                        int result = (int) (o2Long - o1Long);
                                        return result;
                                    }
                                });
                            }
                            DialogUtils.showComponentOptionsTableList(ServerManageConsole.this, "Mongo Log Info (" + rowData.length + ") " + userid + " " + simID, columnNames, rowData, ListSelectionModel.SINGLE_SELECTION, null, null, null, null, false);
                        } else {
                            DialogUtils.showWarningDialog(ServerManageConsole.this, "No Mongo Log Info found for simID=" + simID.intValue());
                        }
                    } catch (UserCancelException uce) {
                    // ignore
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            });
            ivjQueryResultTable.addMouseListener(new MouseAdapter() {

                public void mouseReleased(MouseEvent e) {
                    if (e.isPopupTrigger()) {
                        JTable source = (JTable) e.getSource();
                        int row = source.rowAtPoint(e.getPoint());
                        int column = source.columnAtPoint(e.getPoint());
                        if (!source.isRowSelected(row))
                            source.changeSelection(row, column, false, false);
                        popup.show(e.getComponent(), e.getX(), e.getY());
                    }
                }
            });
        // user code begin {1}
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    return ivjQueryResultTable;
}
Also used : Set(java.util.Set) ActionEvent(java.awt.event.ActionEvent) UserCancelException(org.vcell.util.UserCancelException) BigString(org.vcell.util.BigString) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Comparator(java.util.Comparator) DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) Iterator(java.util.Iterator) JMenuItem(javax.swing.JMenuItem) Vector(java.util.Vector) MouseEvent(java.awt.event.MouseEvent) Mongo(com.mongodb.Mongo) MouseAdapter(java.awt.event.MouseAdapter) TreeMap(java.util.TreeMap) JPopupMenu(javax.swing.JPopupMenu) UserCancelException(org.vcell.util.UserCancelException) JSortTable(org.vcell.util.gui.sorttable.JSortTable) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DB(com.mongodb.DB)

Example 94 with JTable

use of javax.swing.JTable in project megameklab by MegaMek.

the class CriticalTransferHandler method createTransferable.

@Override
protected Transferable createTransferable(JComponent c) {
    if (c instanceof JTable) {
        JTable table = (JTable) c;
        Mounted mount = (Mounted) ((CriticalTableModel) table.getModel()).getValueAt(table.getSelectedRow(), CriticalTableModel.EQUIPMENT);
        return new StringSelection(Integer.toString(getUnit().getEquipmentNum(mount)));
    } else if (c instanceof DropTargetCriticalList) {
        DropTargetCriticalList<?> list = (DropTargetCriticalList<?>) c;
        Mounted mount = list.getMounted();
        if (mount != null) {
            return new StringSelection(Integer.toString(getUnit().getEquipmentNum(mount)));
        }
    }
    return null;
}
Also used : Mounted(megamek.common.Mounted) JTable(javax.swing.JTable) StringSelection(java.awt.datatransfer.StringSelection)

Example 95 with JTable

use of javax.swing.JTable in project megameklab by MegaMek.

the class CriticalTransferHandler method createTransferable.

@Override
protected Transferable createTransferable(JComponent c) {
    JTable table = (JTable) c;
    Mounted mount = (Mounted) ((CriticalTableModel) table.getModel()).getValueAt(table.getSelectedRow(), CriticalTableModel.EQUIPMENT);
    return new StringSelection(Integer.toString(getUnit().getEquipmentNum(mount)));
}
Also used : Mounted(megamek.common.Mounted) JTable(javax.swing.JTable) StringSelection(java.awt.datatransfer.StringSelection)

Aggregations

JTable (javax.swing.JTable)584 JScrollPane (javax.swing.JScrollPane)282 JPanel (javax.swing.JPanel)217 Dimension (java.awt.Dimension)145 JButton (javax.swing.JButton)139 BorderLayout (java.awt.BorderLayout)133 JLabel (javax.swing.JLabel)129 ActionEvent (java.awt.event.ActionEvent)109 ActionListener (java.awt.event.ActionListener)81 TableColumn (javax.swing.table.TableColumn)79 DefaultTableModel (javax.swing.table.DefaultTableModel)75 Component (java.awt.Component)66 BoxLayout (javax.swing.BoxLayout)66 FlowLayout (java.awt.FlowLayout)58 MouseEvent (java.awt.event.MouseEvent)58 JTextField (javax.swing.JTextField)57 TableColumnModel (javax.swing.table.TableColumnModel)52 GridBagConstraints (java.awt.GridBagConstraints)46 TableCellRenderer (javax.swing.table.TableCellRenderer)43 Test (org.junit.Test)43