Search in sources :

Example 11 with SheetCloseListener

use of org.apache.pivot.wtk.SheetCloseListener in project pivot by apache.

the class ExpensesWindow method deleteSelectedExpense.

private void deleteSelectedExpense() {
    Object expense = expenseTableView.getSelectedRow();
    final int id = JSON.getInt(expense, "id");
    deleteConfirmationPrompt.open(this, new SheetCloseListener() {

        @Override
        public void sheetClosed(Sheet sheet) {
            if (sheet.getResult() && ((Prompt) sheet).getSelectedOptionIndex() == 1) {
                // DELETE expense from server and then remove from table
                Expenses expensesApplicationLocal = getExpensesApplication();
                DeleteQuery deleteExpenseQuery = new DeleteQuery(expensesApplicationLocal.getHostname(), expensesApplicationLocal.getPort(), "/pivot-tutorials/expenses/" + id, expensesApplicationLocal.isSecure());
                activityIndicatorBoxPane.setVisible(true);
                activityIndicator.setActive(true);
                deleteExpenseQuery.execute(new TaskAdapter<>(new TaskListener<Void>() {

                    @Override
                    public void taskExecuted(Task<Void> task) {
                        activityIndicatorBoxPane.setVisible(false);
                        activityIndicator.setActive(false);
                        // Find matching row and remove
                        @SuppressWarnings("unchecked") List<Object> expenses = (List<Object>) expenseTableView.getTableData();
                        for (int i = 0, n = expenses.getLength(); i < n; i++) {
                            if (JSON.get(expenses.get(i), "id").equals(id)) {
                                expenses.remove(i, 1);
                                break;
                            }
                        }
                    }

                    @Override
                    public void executeFailed(Task<Void> task) {
                        activityIndicatorBoxPane.setVisible(false);
                        activityIndicator.setActive(false);
                        Prompt.prompt(MessageType.ERROR, task.getFault().getMessage(), ExpensesWindow.this);
                    }
                }));
            }
        }
    });
}
Also used : TaskAdapter(org.apache.pivot.wtk.TaskAdapter) DeleteQuery(org.apache.pivot.web.DeleteQuery) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) Sheet(org.apache.pivot.wtk.Sheet)

Aggregations

Sheet (org.apache.pivot.wtk.Sheet)11 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)11 Button (org.apache.pivot.wtk.Button)8 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)7 PushButton (org.apache.pivot.wtk.PushButton)7 File (java.io.File)5 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)5 ListView (org.apache.pivot.wtk.ListView)4 IOException (java.io.IOException)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 ArrayList (org.apache.pivot.collections.ArrayList)3 HashMap (org.apache.pivot.collections.HashMap)3 List (org.apache.pivot.collections.List)3 TaskAdapter (org.apache.pivot.wtk.TaskAdapter)3 BoxPane (org.apache.pivot.wtk.BoxPane)2 Checkbox (org.apache.pivot.wtk.Checkbox)2 Frame (org.apache.pivot.wtk.Frame)2 ListButton (org.apache.pivot.wtk.ListButton)2 Color (java.awt.Color)1 Font (java.awt.Font)1