use of javax.swing.SwingWorker in project zaproxy by zaproxy.
the class ExtensionAutoUpdate method uninstallAddOnsWithView.
boolean uninstallAddOnsWithView(final Window caller, final Set<AddOn> addOns, final boolean updates, final Set<AddOn> failedUninstallations) {
if (addOns == null || addOns.isEmpty()) {
return true;
}
if (!EventQueue.isDispatchThread()) {
try {
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
uninstallAddOnsWithView(caller, addOns, updates, failedUninstallations);
}
});
} catch (InvocationTargetException | InterruptedException e) {
logger.error("Failed to uninstall add-ons:", e);
return false;
}
return failedUninstallations.isEmpty();
}
final Window parent = getWindowParent(caller);
final UninstallationProgressDialogue waitDialogue = new UninstallationProgressDialogue(parent, addOns);
waitDialogue.addAddOnUninstallListener(new AddOnUninstallListener() {
@Override
public void uninstallingAddOn(AddOn addOn, boolean updating) {
if (updating) {
String message = MessageFormat.format(Constant.messages.getString("cfu.output.replacing") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion()));
getView().getOutputPanel().append(message);
}
}
@Override
public void addOnUninstalled(AddOn addOn, boolean update, boolean uninstalled) {
if (uninstalled) {
if (!update && addonsDialog != null) {
addonsDialog.notifyAddOnUninstalled(addOn);
}
String message = MessageFormat.format(Constant.messages.getString("cfu.output.uninstalled") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion()));
getView().getOutputPanel().append(message);
} else {
if (addonsDialog != null) {
addonsDialog.notifyAddOnFailedUninstallation(addOn);
}
String message;
if (update) {
message = MessageFormat.format(Constant.messages.getString("cfu.output.replace.failed") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion()));
} else {
message = MessageFormat.format(Constant.messages.getString("cfu.output.uninstall.failed") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion()));
}
getView().getOutputPanel().append(message);
}
}
});
SwingWorker<Void, UninstallationProgressEvent> a = new SwingWorker<Void, UninstallationProgressEvent>() {
@Override
protected void process(List<UninstallationProgressEvent> events) {
waitDialogue.update(events);
}
@Override
protected Void doInBackground() {
UninstallationProgressHandler progressHandler = new UninstallationProgressHandler() {
@Override
protected void publishEvent(UninstallationProgressEvent event) {
publish(event);
}
};
for (AddOn addOn : addOns) {
if (!uninstall(addOn, updates, progressHandler)) {
failedUninstallations.add(addOn);
}
}
if (!failedUninstallations.isEmpty()) {
logger.warn("Not all add-ons were successfully uninstalled: " + failedUninstallations);
}
return null;
}
};
waitDialogue.bind(a);
a.execute();
waitDialogue.setSynchronous(updates);
waitDialogue.setVisible(true);
return failedUninstallations.isEmpty();
}
use of javax.swing.SwingWorker in project jdk8u_jdk by JetBrains.
the class XSheet method displayMBeanAttributesNode.
// Call on EDT
private void displayMBeanAttributesNode(final DefaultMutableTreeNode node) {
final XNodeInfo uo = (XNodeInfo) node.getUserObject();
if (!uo.getType().equals(Type.ATTRIBUTES)) {
return;
}
mbean = (XMBean) uo.getData();
final XMBean xmb = mbean;
SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {
@Override
public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
MBeanInfo mbi = xmb.getMBeanInfo();
return mbi;
}
@Override
protected void done() {
try {
MBeanInfo mbi = get();
if (mbi != null && mbi.getAttributes() != null && mbi.getAttributes().length > 0) {
mbeanAttributes.loadAttributes(xmb, mbi);
if (!isSelectedNode(node, currentNode)) {
return;
}
invalidate();
mainPanel.removeAll();
JPanel borderPanel = new JPanel(new BorderLayout());
borderPanel.setBorder(BorderFactory.createTitledBorder(Messages.ATTRIBUTE_VALUES));
borderPanel.add(new JScrollPane(mbeanAttributes));
mainPanel.add(borderPanel, BorderLayout.CENTER);
// add the refresh button to the south panel
southPanel.removeAll();
southPanel.add(refreshButton, BorderLayout.SOUTH);
southPanel.setVisible(true);
refreshButton.setEnabled(true);
validate();
repaint();
}
} catch (Exception e) {
Throwable t = Utils.getActualException(e);
if (JConsole.isDebug()) {
System.err.println("Problem displaying MBean " + "attributes 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 XSheet method displayMBeanNode.
// Call on EDT
private void displayMBeanNode(final DefaultMutableTreeNode node) {
final XNodeInfo uo = (XNodeInfo) node.getUserObject();
if (!uo.getType().equals(Type.MBEAN)) {
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;
}
mbeanInfo.addMBeanInfo(mbean, mbi);
invalidate();
mainPanel.removeAll();
mainPanel.add(mbeanInfo, BorderLayout.CENTER);
southPanel.setVisible(false);
southPanel.removeAll();
validate();
repaint();
}
} catch (Exception e) {
Throwable t = Utils.getActualException(e);
if (JConsole.isDebug()) {
System.err.println("Couldn't get MBeanInfo for MBean [" + mbean.getObjectName() + "]");
t.printStackTrace();
}
showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
}
}
};
sw.execute();
}
use of javax.swing.SwingWorker in project jabref by JabRef.
the class PreviewPrefsTab method setValues.
@Override
public void setValues() {
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences();
chosenModel.clear();
boolean isPreviewChosen = false;
for (String style : previewPreferences.getPreviewCycle()) {
if (CitationStyle.isCitationStyleFile(style)) {
chosenModel.addElement(CitationStyle.createCitationStyleFromFile(style));
} else {
if (isPreviewChosen) {
LOGGER.error("Preview is already in the list, something went wrong");
continue;
}
isPreviewChosen = true;
chosenModel.addElement(Localization.lang("Preview"));
}
}
availableModel.clear();
if (!isPreviewChosen) {
availableModel.addElement(Localization.lang("Preview"));
}
btnLeft.setEnabled(!chosen.isSelectionEmpty());
btnRight.setEnabled(!available.isSelectionEmpty());
btnUp.setEnabled(!chosen.isSelectionEmpty());
btnDown.setEnabled(!chosen.isSelectionEmpty());
if (discoverCitationStyleWorker != null) {
discoverCitationStyleWorker.cancel(true);
}
discoverCitationStyleWorker = new SwingWorker<List<CitationStyle>, Void>() {
@Override
protected List<CitationStyle> doInBackground() throws Exception {
return CitationStyle.discoverCitationStyles();
}
@Override
public void done() {
if (this.isCancelled()) {
return;
}
try {
get().stream().filter(style -> !previewPreferences.getPreviewCycle().contains(style.getFilepath())).sorted((style0, style1) -> style0.getTitle().compareTo(style1.getTitle())).forEach(availableModel::addElement);
btnRight.setEnabled(!availableModel.isEmpty());
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("something went wrong while adding the discovered CitationStyles to the list ");
}
}
};
discoverCitationStyleWorker.execute();
layout.setText(Globals.prefs.getPreviewPreferences().getPreviewStyle().replace("__NEWLINE__", "\n"));
}
use of javax.swing.SwingWorker in project beast-mcmc by beast-dev.
the class TreesTableModel method loadTreeFile.
// END: doLoadTreeFile
private void loadTreeFile(final File file, final int row) {
frame.setBusy();
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
// Executed in background thread
public Void doInBackground() {
try {
Tree tree = Utils.importTreeFromFile(file);
tree.setId(file.getName());
setRow(row, new TreesTableRecord(tree.getId(), tree));
} catch (Exception e) {
Utils.handleException(e);
}
return null;
}
// END: doInBackground()
// Executed in event dispatch thread
public void done() {
frame.setIdle();
frame.fireTaxaChanged();
}
};
worker.execute();
}
Aggregations