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();
}
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);
}
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");
}
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();
}
}
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();
}
}
Aggregations