Search in sources :

Example 21 with SwingWorker

use of javax.swing.SwingWorker in project jgnash by ccavanaugh.

the class RecurringPanel method showRecurringDialog.

private synchronized void showRecurringDialog() {
    // exit if engine is not running or a dialog is already visible
    if (showingDialog || EngineFactory.getEngine(EngineFactory.DEFAULT) == null) {
        return;
    }
    SwingWorker<List<PendingReminder>, Void> worker = new SwingWorker<List<PendingReminder>, Void>() {

        @Override
        protected List<PendingReminder> doInBackground() throws Exception {
            final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
            Objects.requireNonNull(engine);
            return engine.getPendingReminders();
        }

        @Override
        protected void done() {
            try {
                List<PendingReminder> reminders = get();
                // Event occurs on the EDT, so no need to invoke later
                if (!reminders.isEmpty()) {
                    showingDialog = true;
                    Preferences p = Preferences.userNodeForPackage(getClass());
                    int snooze = p.getInt(SNOOZE, DEFAULT_SNOOZE);
                    // display the notification dialog
                    snooze = NotificationDialog.showDialog(reminders, snooze);
                    p.putInt(SNOOZE, snooze);
                    if (timer != null) {
                        if (snooze != 0) {
                            timer.setDelay(snooze);
                            timer.setInitialDelay(snooze);
                            timer.restart();
                        } else {
                            timer.stop();
                        }
                    } else {
                        throw new RuntimeException("Lost the timer!");
                    }
                    showingDialog = false;
                }
            } catch (final InterruptedException | ExecutionException | RuntimeException e) {
                logSevere(RecurringPanel.class, e);
            }
        }
    };
    worker.execute();
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) SwingWorker(javax.swing.SwingWorker) List(java.util.List) Preferences(java.util.prefs.Preferences) ExecutionException(java.util.concurrent.ExecutionException) Engine(jgnash.engine.Engine)

Example 22 with SwingWorker

use of javax.swing.SwingWorker in project zookeeper by apache.

the class ZooInspectorTreeViewer method refreshView.

/**
     * Refresh the tree view
     */
public void refreshView() {
    final Set<TreePath> expandedNodes = new LinkedHashSet<TreePath>();
    int rowCount = tree.getRowCount();
    for (int i = 0; i < rowCount; i++) {
        TreePath path = tree.getPathForRow(i);
        if (tree.isExpanded(path)) {
            expandedNodes.add(path);
        }
    }
    final TreePath[] selectedNodes = tree.getSelectionPaths();
    SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {

        @Override
        protected Boolean doInBackground() throws Exception {
            tree.setModel(new DefaultTreeModel(new ZooInspectorTreeNode("/", null)));
            return true;
        }

        @Override
        protected void done() {
            for (TreePath path : expandedNodes) {
                tree.expandPath(path);
            }
            tree.getSelectionModel().setSelectionPaths(selectedNodes);
        }
    };
    worker.execute();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TreePath(javax.swing.tree.TreePath) SwingWorker(javax.swing.SwingWorker) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 23 with SwingWorker

use of javax.swing.SwingWorker in project zookeeper by apache.

the class NodeViewerACL method nodeSelectionChanged.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.apache.zookeeper.inspector.gui.nodeviewer.ZooInspectorNodeViewer#
     * nodeSelectionChanged(java.util.Set)
     */
@Override
public void nodeSelectionChanged(List<String> selectedNodes) {
    this.aclDataPanel.removeAll();
    if (selectedNodes.size() > 0) {
        this.selectedNode = selectedNodes.get(0);
        SwingWorker<List<Map<String, String>>, Void> worker = new SwingWorker<List<Map<String, String>>, Void>() {

            @Override
            protected List<Map<String, String>> doInBackground() throws Exception {
                return NodeViewerACL.this.zooInspectorManager.getACLs(NodeViewerACL.this.selectedNode);
            }

            @Override
            protected void done() {
                List<Map<String, String>> acls = null;
                try {
                    acls = get();
                } catch (InterruptedException e) {
                    acls = new ArrayList<Map<String, String>>();
                    LoggerFactory.getLogger().error("Error retrieving ACL Information for node: " + NodeViewerACL.this.selectedNode, e);
                } catch (ExecutionException e) {
                    acls = new ArrayList<Map<String, String>>();
                    LoggerFactory.getLogger().error("Error retrieving ACL Information for node: " + NodeViewerACL.this.selectedNode, e);
                }
                aclDataPanel.setLayout(new GridBagLayout());
                int j = 0;
                for (Map<String, String> data : acls) {
                    int rowPos = 2 * j + 1;
                    JPanel aclPanel = new JPanel();
                    aclPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
                    aclPanel.setBackground(Color.WHITE);
                    aclPanel.setLayout(new GridBagLayout());
                    int i = 0;
                    for (Map.Entry<String, String> entry : data.entrySet()) {
                        int rowPosACL = 2 * i + 1;
                        JLabel label = new JLabel(entry.getKey());
                        JTextField text = new JTextField(entry.getValue());
                        text.setEditable(false);
                        GridBagConstraints c1 = new GridBagConstraints();
                        c1.gridx = 1;
                        c1.gridy = rowPosACL;
                        c1.gridwidth = 1;
                        c1.gridheight = 1;
                        c1.weightx = 0;
                        c1.weighty = 0;
                        c1.anchor = GridBagConstraints.NORTHWEST;
                        c1.fill = GridBagConstraints.BOTH;
                        c1.insets = new Insets(5, 5, 5, 5);
                        c1.ipadx = 0;
                        c1.ipady = 0;
                        aclPanel.add(label, c1);
                        GridBagConstraints c2 = new GridBagConstraints();
                        c2.gridx = 3;
                        c2.gridy = rowPosACL;
                        c2.gridwidth = 1;
                        c2.gridheight = 1;
                        c2.weightx = 0;
                        c2.weighty = 0;
                        c2.anchor = GridBagConstraints.NORTHWEST;
                        c2.fill = GridBagConstraints.BOTH;
                        c2.insets = new Insets(5, 5, 5, 5);
                        c2.ipadx = 0;
                        c2.ipady = 0;
                        aclPanel.add(text, c2);
                        i++;
                    }
                    GridBagConstraints c = new GridBagConstraints();
                    c.gridx = 1;
                    c.gridy = rowPos;
                    c.gridwidth = 1;
                    c.gridheight = 1;
                    c.weightx = 1;
                    c.weighty = 1;
                    c.anchor = GridBagConstraints.NORTHWEST;
                    c.fill = GridBagConstraints.NONE;
                    c.insets = new Insets(5, 5, 5, 5);
                    c.ipadx = 0;
                    c.ipady = 0;
                    aclDataPanel.add(aclPanel, c);
                }
                NodeViewerACL.this.aclDataPanel.revalidate();
                NodeViewerACL.this.aclDataPanel.repaint();
            }
        };
        worker.execute();
    }
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) SwingWorker(javax.swing.SwingWorker) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map)

Example 24 with SwingWorker

use of javax.swing.SwingWorker in project Openfire by igniterealtime.

the class Launcher method installPlugin.

private void installPlugin(final File plugin) {
    final JDialog dialog = new JDialog(frame, "Installing Plugin", true);
    dialog.getContentPane().setLayout(new BorderLayout());
    JProgressBar bar = new JProgressBar();
    bar.setIndeterminate(true);
    bar.setString("Installing Plugin.  Please wait...");
    bar.setStringPainted(true);
    dialog.getContentPane().add(bar, BorderLayout.CENTER);
    dialog.pack();
    dialog.setSize(225, 55);
    final SwingWorker<File, Void> installerThread = new SwingWorker<File, Void>() {

        @Override
        public File doInBackground() {
            File pluginsDir = new File(binDir.getParentFile(), "plugins");
            String tempName = plugin.getName() + ".part";
            File tempPluginsFile = new File(pluginsDir, tempName);
            File realPluginsFile = new File(pluginsDir, plugin.getName());
            // Copy Plugin into Dir.
            try {
                // Just for fun. Show no matter what for two seconds.
                Thread.sleep(2000);
                copy(plugin.toURI().toURL(), tempPluginsFile);
                // If successfull, rename to real plugin name.
                tempPluginsFile.renameTo(realPluginsFile);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return realPluginsFile;
        }

        @Override
        public void done() {
            dialog.setVisible(false);
        }
    };
    // Start installation
    installerThread.execute();
    dialog.setLocationRelativeTo(frame);
    dialog.setVisible(true);
}
Also used : BorderLayout(java.awt.BorderLayout) JProgressBar(javax.swing.JProgressBar) SwingWorker(javax.swing.SwingWorker) File(java.io.File) JDialog(javax.swing.JDialog) BadLocationException(javax.swing.text.BadLocationException) FileNotFoundException(java.io.FileNotFoundException) AWTException(java.awt.AWTException) IOException(java.io.IOException)

Example 25 with SwingWorker

use of javax.swing.SwingWorker in project ACS by ACS-Community.

the class TreeMouseListener method getLogConfFromService.

private LoggingConfigurableOperations getLogConfFromService(final String serviceName) throws Exception {
    System.out.println("Getting LoggingConfigurable out of Manager for service " + serviceName);
    // Manager
    final Manager mgr = model.getManagerRef();
    if (mgr == null) {
        throw new Exception("Invalid manager reference");
    }
    SwingWorker<LoggingConfigurableOperations, Void> worker = new SwingWorker<LoggingConfigurableOperations, Void>() {

        protected LoggingConfigurableOperations doInBackground() throws Exception {
            LoggingConfigurableOperations logConf;
            try {
                logConf = LoggingConfigurableHelper.narrow(mgr.get_service(model.getAdminClient().getHandle(), serviceName, false));
            } catch (Throwable t) {
                throw new Exception("Error getting the LoggingConfigurable out of Manager for service " + serviceName + " :\n" + t.getMessage(), t);
            }
            return logConf;
        }
    };
    worker.execute();
    return worker.get();
}
Also used : LoggingConfigurableOperations(alma.Logging.LoggingConfigurableOperations) SwingWorker(javax.swing.SwingWorker) Manager(si.ijs.maci.Manager) LogPaneNotFoundException(alma.acs.gui.loglevel.LogPaneNotFoundException)

Aggregations

SwingWorker (javax.swing.SwingWorker)41 ExecutionException (java.util.concurrent.ExecutionException)15 IOException (java.io.IOException)14 List (java.util.List)10 ResourceBundle (java.util.ResourceBundle)10 ArrayList (java.util.ArrayList)9 Preferences (java.util.prefs.Preferences)8 File (java.io.File)6 JFileChooser (javax.swing.JFileChooser)6 JPanel (javax.swing.JPanel)6 BorderLayout (java.awt.BorderLayout)5 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)5 Engine (jgnash.engine.Engine)5 FileNotFoundException (java.io.FileNotFoundException)4 InstanceNotFoundException (javax.management.InstanceNotFoundException)4 IntrospectionException (javax.management.IntrospectionException)4 MBeanInfo (javax.management.MBeanInfo)4 ReflectionException (javax.management.ReflectionException)4 JScrollPane (javax.swing.JScrollPane)4 ResourceAccessException (org.springframework.web.client.ResourceAccessException)4