/** * Repopulates the data in the table and then alters any observers of the table that the data has * changed. */ private void refreshTableData() { model.setBundleData(callback.getBundleData()); table.tableChanged(new TableModelEvent(model)); }
/** * Creates the context menu for the table * * @param rowNum the rown number in the table from which to build the context * @return a context menu */ private JPopupMenu createContextMenu(int rowNum) { final Long bundleId = model.getBundleIdFromRow(rowNum); JMenuItem start = new JMenuItem("start bundle " + bundleId); start.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { try { callback.startBundle(bundleId); refreshTableData(); } catch (BundleGuiException bge) { JOptionPane.showMessageDialog( table, "When calling start on Bundle [" + bundleId + "] the following exception was caught:\n" + Arrays.toString(bge.getStackTrace()), "Bundle exception", JOptionPane.ERROR_MESSAGE); } } }); JMenuItem stop = new JMenuItem("stop bundle " + bundleId); stop.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { try { callback.stopBundle(bundleId); refreshTableData(); } catch (BundleGuiException bge) { JOptionPane.showMessageDialog( table, "When calling stop on Bundle [" + bundleId + "] the following exception was caught:\n" + Arrays.toString(bge.getStackTrace()), "Bundle exception", JOptionPane.ERROR_MESSAGE); } } }); JMenuItem update = new JMenuItem("update bundle " + bundleId); update.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { try { callback.updateBundle(bundleId); refreshTableData(); } catch (BundleGuiException bge) { JOptionPane.showMessageDialog( table, "When calling update on Bundle [" + bundleId + "] the following exception was caught:\n" + Arrays.toString(bge.getStackTrace()), "Bundle exception", JOptionPane.ERROR_MESSAGE); } } }); JMenuItem uninstall = new JMenuItem("uninstall bundle " + bundleId); uninstall.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { try { callback.removeBundle(bundleId); refreshTableData(); } catch (BundleGuiException bge) { JOptionPane.showMessageDialog( table, "When calling uninstall on Bundle [" + bundleId + "] the following exception was caught:\n" + Arrays.toString(bge.getStackTrace()), "Bundle exception", JOptionPane.ERROR_MESSAGE); } } }); JPopupMenu ret = new JPopupMenu(); ret.add(start); ret.add(stop); ret.add(update); ret.add(uninstall); return ret; }