private void addTabs()

in dbus-java-utils/src/main/java/org/freedesktop/dbus/viewer/DBusViewer.java [110:174]


    private void addTabs(final JTabbedPane tabbedPane, final Map<String, DBusBusType> connectionTypes) {
        for (final String key : connectionTypes.keySet()) {
            final JLabel label = new JLabel("Processing DBus for " + key);
            tabbedPane.addTab(key, label);
        }
        Runnable loader = new Runnable() {
            @Override
            public void run() {
                boolean users = true, owners = true;
                for (final String key : connectionTypes.keySet()) {
                    try {
                        DBusConnection conn = DBusConnection.getConnection(connectionTypes.get(key));
                        connections.add(conn);

                        final TableModel tableModel = listDBusConnection(users, owners, conn);

                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                int index = tabbedPane.indexOfTab(key);
                                final JTable table = new JTable(tableModel);

                                JScrollPane scrollPane = new JScrollPane(table);

                                JPanel tab = new JPanel(new BorderLayout());
                                tab.add(scrollPane, BorderLayout.CENTER);

                                JPanel southPanel = new JPanel();
                                final JButton button = new JButton(new IntrospectAction(table));
                                southPanel.add(button);

                                tab.add(southPanel, BorderLayout.SOUTH);

                                tabbedPane.setComponentAt(index, tab);

                            }
                        });
                    } catch (final DBusException e) {
                        e.printStackTrace();
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                int index = tabbedPane.indexOfTab(key);
                                JLabel label = (JLabel) tabbedPane.getComponentAt(index);
                                label.setText("Could not load Dbus information for " + key + ":" + e.getMessage());
                            }
                        });
                    } catch (final DBusExecutionException e) {
                        e.printStackTrace();
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                int index = tabbedPane.indexOfTab(key);
                                JLabel label = (JLabel) tabbedPane.getComponentAt(index);
                                label.setText("Could not load Dbus information for " + key + ":" + e.getMessage());
                            }
                        });
                    }
                }
            }
        };
        final Thread thread = new Thread(loader);
        thread.setName("DBus Loader");
        thread.start();
    }