private void createEventListeners()

in shell.gui.plugin/src/main/java/org/apache/felix/shell/gui/plugin/BundleListPlugin.java [108:271]


    private void createEventListeners()
    {
        // Listen for bundle events in order to update
        // the GUI bundle list.
        BundleListener bl = new BundleListener() {
            public void bundleChanged(BundleEvent event)
            {
                ((SimpleTableModel) m_bundleTable.getModel()).update();
            }
        };
        m_context.addBundleListener(bl);

        // Create action listeners.
        m_installButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event)
            {
                if (m_urlField.getText().length() > 0)
                {
                    try
                    {
                        m_context.installBundle(m_urlField.getText(), null);
                    }
                    catch (BundleException ex)
                    {
                        JOptionPane.showMessageDialog(
                            JOptionPane.getFrameForComponent(BundleListPlugin.this),
                            ex.getMessage(), "Error",
                            JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        });

        m_startButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event)
            {
                int[] rows = m_bundleTable.getSelectedRows();
                for (int i = 0; i < rows.length; i++)
                {
                    try
                    {
                        m_context.getBundles()[rows[i]].start();
                    }
                    catch (BundleException ex)
                    {
                        JOptionPane.showMessageDialog(
                            JOptionPane.getFrameForComponent(BundleListPlugin.this),
                            ex.getMessage(), "Error",
                            JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        });

        m_stopButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event)
            {
                int[] rows = m_bundleTable.getSelectedRows();
                for (int i = 0; i < rows.length; i++)
                {
                    try
                    {
                        m_context.getBundles()[rows[i]].stop();
                    }
                    catch (BundleException ex)
                    {
                        JOptionPane.showMessageDialog(
                            JOptionPane.getFrameForComponent(BundleListPlugin.this),
                            ex.getMessage(), "Error",
                            JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        });

        m_updateButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event)
            {
                int[] rows = m_bundleTable.getSelectedRows();
                for (int i = 0; i < rows.length; i++)
                {
                    try
                    {
                        m_context.getBundles()[rows[i]].update();
                    }
                    catch (BundleException ex)
                    {
                        JOptionPane.showMessageDialog(
                            JOptionPane.getFrameForComponent(BundleListPlugin.this),
                            ex.getMessage(), "Error",
                            JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        });

        m_refreshButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event)
            {
                // Get package admin service.
                ServiceReference ref = m_context.getServiceReference(
                    PackageAdmin.class.getName());
                if (ref == null)
                {
                    JOptionPane.showMessageDialog(
                        JOptionPane.getFrameForComponent(BundleListPlugin.this),
                        "Unable to obtain PackageAdmin service.", "Error",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                }

                PackageAdmin pa = (PackageAdmin) m_context.getService(ref);
                if (pa == null)
                {
                    JOptionPane.showMessageDialog(
                        JOptionPane.getFrameForComponent(BundleListPlugin.this),
                        "Unable to obtain PackageAdmin service.", "Error",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                }

                pa.refreshPackages(null);
            }
        });

        m_uninstallButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event)
            {
                int[] rows = m_bundleTable.getSelectedRows();
                // We need to uninstall in reverse order, otherwise
                // the index will get messed up.
                for (int i = rows.length - 1; i >= 0; i--)
                {
                    try
                    {
                        m_context.getBundles()[rows[i]].uninstall();
                    }
                    catch (BundleException ex)
                    {
                        JOptionPane.showMessageDialog(
                            JOptionPane.getFrameForComponent(BundleListPlugin.this),
                            ex.getMessage(), "Error",
                            JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        });

        m_shutdownButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event)
            {
                Bundle systembundle = m_context.getBundle(0);
                try
                {
                    systembundle.stop();
                }
                catch (Exception ex)
                {
                    System.out.println(ex.toString());
                    ex.printStackTrace(System.out);
                }
            }
        });
    }