use of javax.swing.SwingWorker in project jgnash by ccavanaugh.
the class BudgetPanel method initBudgetCombo.
private void initBudgetCombo() {
budgetCombo = new BudgetComboBox();
SwingWorker<StoredObject, Void> worker = new SwingWorker<StoredObject, Void>() {
@Override
protected StoredObject doInBackground() throws Exception {
Preferences preferences = Preferences.userNodeForPackage(BudgetPanel.class);
String lastBudgetUUID = preferences.get(LAST_BUDGET, null);
StoredObject o = null;
if (lastBudgetUUID != null) {
o = engine.getBudgetByUuid(lastBudgetUUID);
}
return o;
}
@Override
protected void done() {
try {
StoredObject o = get();
if (o != null && o instanceof Budget) {
budgetCombo.setSelectedBudget((Budget) o);
activeBudget = (Budget) o;
}
if (activeBudget == null) {
List<Budget> budgets = engine.getBudgetList();
if (!budgets.isEmpty()) {
budgetCombo.setSelectedBudget(budgets.get(0));
activeBudget = budgets.get(0);
}
}
// the combo takes the full toolbar space unless limited
budgetCombo.setMaximumSize(new Dimension(COMBO_BOX_WIDTH, budgetCombo.getPreferredSize().height * 3));
budgetCombo.addActionListener(e -> {
if (activeBudget != budgetCombo.getSelectedBudget()) {
refreshDisplay();
}
});
} catch (final InterruptedException | ExecutionException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
};
worker.execute();
}
use of javax.swing.SwingWorker in project sic by belluccifranco.
the class PedidosGUI method buscar.
public void buscar() {
this.cambiarEstadoEnabled(false);
pb_Filtro.setIndeterminate(true);
SwingWorker<List<Pedido>, Void> worker = new SwingWorker<List<Pedido>, Void>() {
@Override
protected List<Pedido> doInBackground() throws Exception {
String URI = "/pedidos/busqueda/criteria?idEmpresa=" + EmpresaActiva.getInstance().getEmpresa().getId_Empresa();
if (chk_Fecha.isSelected()) {
URI += "&desde=" + dc_FechaDesde.getDate().getTime();
URI += "&hasta=" + dc_FechaHasta.getDate().getTime();
}
if (chk_NumeroPedido.isSelected()) {
URI += "&nroPedido=" + Long.valueOf(txt_NumeroPedido.getText());
}
if (chk_Cliente.isSelected()) {
URI += "&idCliente=" + ((Cliente) cmb_Cliente.getSelectedItem()).getId_Cliente();
}
if (chk_Vendedor.isSelected()) {
URI += "&idUsuario=" + ((Usuario) cmb_Vendedor.getSelectedItem()).getId_Usuario();
}
pedidos = new ArrayList(Arrays.asList(RestClient.getRestTemplate().getForObject(URI, Pedido[].class)));
cambiarEstadoEnabled(true);
cargarResultadosAlTable();
return pedidos;
}
@Override
protected void done() {
pb_Filtro.setIndeterminate(false);
try {
if (get().isEmpty()) {
JOptionPane.showInternalMessageDialog(getParent(), ResourceBundle.getBundle("Mensajes").getString("mensaje_busqueda_sin_resultados"), "Aviso", JOptionPane.INFORMATION_MESSAGE);
}
} catch (InterruptedException ex) {
String msjError = "La tarea que se estaba realizando fue interrumpida. Intente nuevamente.";
LOGGER.error(msjError + " - " + ex.getMessage());
JOptionPane.showInternalMessageDialog(getParent(), msjError, "Error", JOptionPane.ERROR_MESSAGE);
cambiarEstadoEnabled(true);
} catch (ExecutionException ex) {
if (ex.getCause() instanceof RestClientResponseException) {
JOptionPane.showMessageDialog(getParent(), ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
} else if (ex.getCause() instanceof ResourceAccessException) {
LOGGER.error(ex.getMessage());
JOptionPane.showMessageDialog(getParent(), ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
} else {
String msjError = "Se produjo un error en la ejecuciĆ³n de la tarea solicitada. Intente nuevamente.";
LOGGER.error(msjError + " - " + ex.getMessage());
JOptionPane.showInternalMessageDialog(getParent(), msjError, "Error", JOptionPane.ERROR_MESSAGE);
}
cambiarEstadoEnabled(true);
}
}
};
worker.execute();
}
use of javax.swing.SwingWorker in project sic by belluccifranco.
the class FacturasVentaGUI method buscar.
private void buscar() {
this.limpiarJTable();
cambiarEstadoEnabled(false);
pb_Filtro.setIndeterminate(true);
SwingWorker<List<FacturaVenta>, Void> worker = new SwingWorker<List<FacturaVenta>, Void>() {
@Override
protected List<FacturaVenta> doInBackground() throws Exception {
String uriCriteria = getUriCriteria();
facturas = new ArrayList(Arrays.asList(RestClient.getRestTemplate().getForObject("/facturas/venta/busqueda/criteria?" + uriCriteria, Factura[].class)));
cargarResultadosAlTable();
calcularResultados(uriCriteria);
cambiarEstadoEnabled(true);
return facturas;
}
@Override
protected void done() {
pb_Filtro.setIndeterminate(false);
try {
if (get().isEmpty()) {
JOptionPane.showInternalMessageDialog(getParent(), ResourceBundle.getBundle("Mensajes").getString("mensaje_busqueda_sin_resultados"), "Aviso", JOptionPane.INFORMATION_MESSAGE);
}
} catch (InterruptedException ex) {
String msjError = "La tarea que se estaba realizando fue interrumpida. Intente nuevamente.";
LOGGER.error(msjError + " - " + ex.getMessage());
JOptionPane.showInternalMessageDialog(getParent(), msjError, "Error", JOptionPane.ERROR_MESSAGE);
cambiarEstadoEnabled(true);
} catch (ExecutionException ex) {
if (ex.getCause() instanceof RestClientResponseException) {
JOptionPane.showMessageDialog(getParent(), ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
} else if (ex.getCause() instanceof ResourceAccessException) {
LOGGER.error(ex.getMessage());
JOptionPane.showMessageDialog(getParent(), ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
} else {
String msjError = "Se produjo un error en la ejecuciĆ³n de la tarea solicitada. Intente nuevamente.";
LOGGER.error(msjError + " - " + ex.getMessage());
JOptionPane.showInternalMessageDialog(getParent(), msjError, "Error", JOptionPane.ERROR_MESSAGE);
}
cambiarEstadoEnabled(true);
}
}
};
worker.execute();
}
use of javax.swing.SwingWorker in project beast-mcmc by beast-dev.
the class TaxaEditor method doOk.
// END: ListenOk
private void doOk() {
frame.setBusy();
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
// Executed in background thread
public Void doInBackground() {
try {
// delete taxa connected to this row
String value = dataList.recordsList.get(row).getName();
Utils.removeTaxaWithAttributeValue(dataList, Utils.TREE_FILENAME, value);
String name = String.valueOf("TaxaSet").concat(String.valueOf(row + 1));
Taxa taxa = taxaEditorTableModel.getTaxaSet();
TreesTableRecord record = new TreesTableRecord(name, taxa);
dataList.recordsList.set(row, record);
dataList.allTaxa.addTaxa(taxa);
// treesTableModel.setRow(row, record);
} catch (Exception e) {
Utils.handleException(e);
}
return null;
}
// END: doInBackground()
// Executed in event dispatch thread
public void done() {
frame.setIdle();
frame.fireTaxaChanged();
window.setVisible(false);
}
};
worker.execute();
}
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();
}
Aggregations