Search in sources :

Example 21 with Sheet

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

the class TerraSheetSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    Sheet sheet = (Sheet) getComponent();
    Component content = sheet.getContent();
    if (content != null) {
        if (height != -1) {
            height = Math.max(height - (padding.getHeight() + 2), 0);
        }
        preferredWidth = content.getPreferredWidth(height);
    }
    preferredWidth += (padding.getWidth() + 2);
    return preferredWidth;
}
Also used : Component(org.apache.pivot.wtk.Component) Sheet(org.apache.pivot.wtk.Sheet) Point(org.apache.pivot.wtk.Point)

Example 22 with Sheet

use of org.apache.pivot.wtk.Sheet 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)22 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)11 Button (org.apache.pivot.wtk.Button)9 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)8 PushButton (org.apache.pivot.wtk.PushButton)8 Component (org.apache.pivot.wtk.Component)6 Point (org.apache.pivot.wtk.Point)6 File (java.io.File)5 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)5 Frame (org.apache.pivot.wtk.Frame)4 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 Bounds (org.apache.pivot.wtk.Bounds)3 BoxPane (org.apache.pivot.wtk.BoxPane)3 TaskAdapter (org.apache.pivot.wtk.TaskAdapter)3 Window (org.apache.pivot.wtk.Window)3