Search in sources :

Example 31 with SwingWorker

use of javax.swing.SwingWorker in project jdk8u_jdk by JetBrains.

the class XSheet method displayMBeanOperationsNode.

// Call on EDT
private void displayMBeanOperationsNode(final DefaultMutableTreeNode node) {
    final XNodeInfo uo = (XNodeInfo) node.getUserObject();
    if (!uo.getType().equals(Type.OPERATIONS)) {
        return;
    }
    mbean = (XMBean) uo.getData();
    SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {

        @Override
        public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
            return mbean.getMBeanInfo();
        }

        @Override
        protected void done() {
            try {
                MBeanInfo mbi = get();
                if (mbi != null) {
                    if (!isSelectedNode(node, currentNode)) {
                        return;
                    }
                    mbeanOperations.loadOperations(mbean, mbi);
                    invalidate();
                    mainPanel.removeAll();
                    JPanel borderPanel = new JPanel(new BorderLayout());
                    borderPanel.setBorder(BorderFactory.createTitledBorder(Messages.OPERATION_INVOCATION));
                    borderPanel.add(new JScrollPane(mbeanOperations));
                    mainPanel.add(borderPanel, BorderLayout.CENTER);
                    southPanel.setVisible(false);
                    southPanel.removeAll();
                    validate();
                    repaint();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem displaying MBean " + "operations for MBean [" + mbean.getObjectName() + "]");
                    t.printStackTrace();
                }
                showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
            }
        }
    };
    sw.execute();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MBeanInfo(javax.management.MBeanInfo) BorderLayout(java.awt.BorderLayout) SwingWorker(javax.swing.SwingWorker) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) IOException(java.io.IOException)

Example 32 with SwingWorker

use of javax.swing.SwingWorker in project jdk8u_jdk by JetBrains.

the class XMBeanAttributes method refreshAttributes.

// refreshAttributes(false) is called by tableChanged().
// in this case we must not call stopCellEditing, because it's already
// been called - e.g.
// lostFocus/mousePressed -> stopCellEditing -> setValueAt -> tableChanged
//                        -> refreshAttributes(false)
//
// Can be called in EDT - as long as the implementation of
// mbeansTab.getCachedMBeanServerConnection() and mbsc.flush() doesn't
// change
//
private void refreshAttributes(final boolean stopCellEditing) {
    SwingWorker<Void, Void> sw = new SwingWorker<Void, Void>() {

        @Override
        protected Void doInBackground() throws Exception {
            SnapshotMBeanServerConnection mbsc = mbeansTab.getSnapshotMBeanServerConnection();
            mbsc.flush();
            return null;
        }

        @Override
        protected void done() {
            try {
                get();
                if (stopCellEditing)
                    stopCellEditing();
                loadAttributes(mbean, mbeanInfo);
            } catch (Exception x) {
                if (JConsole.isDebug()) {
                    x.printStackTrace();
                }
            }
        }
    };
    mbeansTab.workerAdd(sw);
}
Also used : SwingWorker(javax.swing.SwingWorker) SnapshotMBeanServerConnection(sun.tools.jconsole.ProxyClient.SnapshotMBeanServerConnection) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JMException(javax.management.JMException)

Example 33 with SwingWorker

use of javax.swing.SwingWorker in project JMRI by JMRI.

the class ControlPanelEditor method init.

@Override
protected void init(String name) {
    setVisible(false);
    java.awt.Container contentPane = this.getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    // make menus
    setGlobalSetsLocalFlag(false);
    setUseGlobalFlag(false);
    _menuBar = new JMenuBar();
    _circuitBuilder = new CircuitBuilder(this);
    _shapeDrawer = new ShapeDrawer(this);
    makeDrawMenu();
    makeWarrantMenu(false);
    makeIconMenu();
    makeZoomMenu();
    makeMarkerMenu();
    makeOptionMenu();
    makeEditMenu();
    makeFileMenu();
    setJMenuBar(_menuBar);
    addHelpMenu("package.jmri.jmrit.display.ControlPanelEditor", true);
    super.setTargetPanel(null, null);
    super.setTargetPanelSize(300, 300);
    makeDataFlavors();
    // set scrollbar initial state
    setScroll(SCROLL_BOTH);
    scrollBoth.setSelected(true);
    super.setDefaultToolTip(new ToolTip(null, 0, 0, new Font("Serif", Font.PLAIN, 12), Color.black, new Color(255, 250, 210), Color.black));
    // register the resulting panel for later configuration
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerUser(this);
    }
    pack();
    setVisible(true);
    class makeCatalog extends SwingWorker<CatalogPanel, Object> {

        @Override
        public CatalogPanel doInBackground() {
            return CatalogPanel.makeDefaultCatalog();
        }
    }
    (new makeCatalog()).execute();
    log.debug("Init SwingWorker launched");
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) BoxLayout(javax.swing.BoxLayout) Color(java.awt.Color) Font(java.awt.Font) ShapeDrawer(jmri.jmrit.display.controlPanelEditor.shape.ShapeDrawer) ConfigureManager(jmri.ConfigureManager) SwingWorker(javax.swing.SwingWorker) Container(java.awt.Container) JMenuBar(javax.swing.JMenuBar)

Example 34 with SwingWorker

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

the class ExportAccountsAction method exportAccounts.

private static void exportAccounts() {
    final ResourceBundle rb = ResourceUtils.getBundle();
    final Preferences pref = Preferences.userNodeForPackage(ExportAccountsAction.class);
    JFileChooser chooser = new JFileChooser(pref.get(CURRENT_DIR, null));
    chooser.addChoosableFileFilter(new FileNameExtensionFilter(rb.getString("Label.XMLFiles") + " (*.xml)", "xml"));
    chooser.setMultiSelectionEnabled(false);
    if (chooser.showSaveDialog(UIApplication.getFrame()) == JFileChooser.APPROVE_OPTION) {
        pref.put(CURRENT_DIR, chooser.getCurrentDirectory().getAbsolutePath());
        // strip the file extension if added and ensure it ends with XML
        final Path file = Paths.get(FileUtils.stripFileExtension(chooser.getSelectedFile().getAbsolutePath()) + ".xml");
        final class Export extends SwingWorker<Void, Void> {

            @Override
            protected Void doInBackground() throws Exception {
                UIApplication.getFrame().displayWaitMessage(rb.getString("Message.PleaseWait"));
                AccountTreeXMLFactory.exportAccountTree(EngineFactory.getEngine(EngineFactory.DEFAULT), file);
                return null;
            }

            @Override
            protected void done() {
                UIApplication.getFrame().stopWaitMessage();
            }
        }
        new Export().execute();
    }
}
Also used : Path(java.nio.file.Path) JFileChooser(javax.swing.JFileChooser) SwingWorker(javax.swing.SwingWorker) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter)

Example 35 with SwingWorker

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

the class ImportAccountsAction method importAccounts.

private static void importAccounts() {
    final Preferences pref = Preferences.userNodeForPackage(ImportAccountsAction.class);
    final JFileChooser chooser = new JFileChooser(pref.get(ACCOUNTS_IMPORT_DIR, null));
    chooser.addChoosableFileFilter(new FileNameExtensionFilter(ResourceUtils.getString("Label.XMLFiles") + " (*.xml)", "xml"));
    chooser.setMultiSelectionEnabled(false);
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        final File file = chooser.getSelectedFile();
        pref.put(ACCOUNTS_IMPORT_DIR, chooser.getCurrentDirectory().getAbsolutePath());
        final class Import extends SwingWorker<Void, Void> {

            @Override
            protected Void doInBackground() throws Exception {
                UIApplication.getFrame().displayWaitMessage(ResourceUtils.getString("Message.ImportWait"));
                RootAccount root = AccountTreeXMLFactory.loadAccountTree(file.toPath());
                if (root != null) {
                    AccountTreeXMLFactory.mergeAccountTree(EngineFactory.getEngine(EngineFactory.DEFAULT), root);
                }
                return null;
            }

            @Override
            protected void done() {
                UIApplication.getFrame().stopWaitMessage();
                // Close and reopen, otherwise UI may link to some stale currency information
                EngineFactory.closeEngine(EngineFactory.DEFAULT);
                OpenAction.openLastAction();
            }
        }
        new Import().execute();
    }
}
Also used : RootAccount(jgnash.engine.RootAccount) JFileChooser(javax.swing.JFileChooser) SwingWorker(javax.swing.SwingWorker) Preferences(java.util.prefs.Preferences) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

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