Search in sources :

Example 36 with SwingWorker

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();
}
Also used : Dimension(java.awt.Dimension) StoredObject(jgnash.engine.StoredObject) SwingWorker(javax.swing.SwingWorker) Budget(jgnash.engine.budget.Budget) Preferences(java.util.prefs.Preferences) ExecutionException(java.util.concurrent.ExecutionException)

Example 37 with SwingWorker

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();
}
Also used : Usuario(sic.modelo.Usuario) RenglonPedido(sic.modelo.RenglonPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) ArrayList(java.util.ArrayList) ResourceAccessException(org.springframework.web.client.ResourceAccessException) SwingWorker(javax.swing.SwingWorker) ArrayList(java.util.ArrayList) List(java.util.List) RestClientResponseException(org.springframework.web.client.RestClientResponseException) ExecutionException(java.util.concurrent.ExecutionException) Cliente(sic.modelo.Cliente)

Example 38 with SwingWorker

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();
}
Also used : FacturaVenta(sic.modelo.FacturaVenta) ArrayList(java.util.ArrayList) SwingWorker(javax.swing.SwingWorker) ArrayList(java.util.ArrayList) List(java.util.List) RestClientResponseException(org.springframework.web.client.RestClientResponseException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 39 with SwingWorker

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();
}
Also used : Taxa(dr.evolution.util.Taxa) SwingWorker(javax.swing.SwingWorker)

Example 40 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)

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