public void actionPerformed()

in dbus-java-utils/src/main/java/org/freedesktop/dbus/viewer/IntrospectAction.java [63:125]


    public void actionPerformed(ActionEvent e) {

        int row = table.getSelectedRow();
        DBusTableModel model = (DBusTableModel) table.getModel();
        if (row > -1 && row < model.getRowCount()) {
            DBusEntry entry = model.getEntry(row);
            final String xmlFile = entry.getName() + ".xml";
            final Introspectable introspectable = entry.getIntrospectable();
            new Thread(new Runnable() {
                @Override
                public void run() {

                    StringStreamFactory factory = new StringStreamFactory();
                    try {
                        String xml = introspectable.Introspect();

                        final JTabbedPane tabbedPane = new JTabbedPane();

                        tabbedPane.addTab(xmlFile, createSourceTab(xmlFile, xml));

                        for (String file : factory.streamMap.keySet()) {
                            final String source = factory.streamMap.get(file).toString();

                            tabbedPane.addTab(file, createSourceTab(file, source));
                        }
                        tabbedPane.setPreferredSize(new Dimension(600, 400));

                        final JPanel introspectionPanel = new JPanel(new BorderLayout());
                        introspectionPanel.add(tabbedPane, BorderLayout.CENTER);

                        JPanel southPanel = new JPanel();
                        southPanel.add(new JButton(new SaveFileAction(tabbedPane)));
                        southPanel.add(new JButton(new SaveAllAction(tabbedPane)));
                        introspectionPanel.add(southPanel, BorderLayout.SOUTH);

                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                JOptionPane.showMessageDialog(table, introspectionPanel, "Introspection", JOptionPane.PLAIN_MESSAGE);
                            }
                        });

                    } catch (final Exception e) {
                        e.printStackTrace();
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                JOptionPane.showMessageDialog(table, e.getMessage(), "Introspection Failed", JOptionPane.ERROR_MESSAGE);
                            }
                        });
                    }
                }

                private JScrollPane createSourceTab(String file, final String source) {
                    JTextArea area = new JTextArea(source);
                    area.setLineWrap(true);
                    area.setWrapStyleWord(true);
                    return new JScrollPane(area, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                }
            }).start();

        }
    }