Example usage for com.google.gwt.requestfactory.shared Receiver Receiver

List of usage examples for com.google.gwt.requestfactory.shared Receiver Receiver

Introduction

In this page you can find the example usage for com.google.gwt.requestfactory.shared Receiver Receiver.

Prototype

Receiver

Source Link

Usage

From source file:com.acme.gwt.client.presenter.ShowDetailPresenter.java

License:Apache License

@Override
public void start(final AcceptsOneWidget panel, EventBus eventBus) {
    view.setPresenter(this);
    //load it and show it
    rf.find(place.getId()).with(view.getEditor().getPaths()).to(new Receiver<TvShowProxy>() {
        @Override/*from w w  w  .j  a v  a2s.c  o  m*/
        public void onSuccess(TvShowProxy response) {
            //deal with data, wire into view
            view.getEditor().display(response);

            //show view
            panel.setWidget(view);
        }
    }).fire();
}

From source file:com.acme.gwt.client.TvGuide.java

License:Apache License

public void onModuleLoad() {

    //code from jnorthrup's fork, will be moved to a presenter soon enough
    EventBus eventBus = GWT.create(SimpleEventBus.class);
    final MyRequestFactory rf = GWT.create(MyRequestFactory.class);
    rf.initialize(eventBus);//from www.j a  v a2  s . c  o m
    final GateKeeper gateKeeper = new GateKeeper();
    new DialogBox() {
        {
            final TextBox email = new TextBox() {
                {
                    setText("you@example.com");
                }
            };
            final PasswordTextBox passwordTextBox = new PasswordTextBox();
            setText("please log in");
            setWidget(new VerticalPanel() {
                {
                    add(new HorizontalPanel() {
                        {
                            add(new Label("email"));
                            add(email);
                        }
                    });
                    add(new HorizontalPanel() {
                        {
                            add(new Label("Password"));
                            add(passwordTextBox);
                        }
                    });
                    add(new Button("OK!!") {
                        {
                            addClickHandler(new ClickHandler() {
                                @Override
                                public void onClick(ClickEvent event) {
                                    String text = passwordTextBox.getText();
                                    String digest = Md5.md5Hex(text);
                                    Request<TvViewerProxy> authenticate = rf.reqViewer()
                                            .authenticate(email.getText(), digest);
                                    authenticate
                                            .with("geo", "name", "favoriteShows.name",
                                                    "favoriteShows.description")
                                            .to(gateKeeper).fire(new Receiver<Void>() {
                                                @Override
                                                public void onSuccess(Void response) {
                                                    hide(); //todo: review for a purpose
                                                    removeFromParent();
                                                }
                                            });
                                }
                            });
                        }
                    });
                }
            });
            center();
            show();
        }
    };
}

From source file:com.eatrightapp.admin.client.activity.UserAccountsActivity.java

License:Apache License

@Override
public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
    userAccountsView = clientFactory.getUserAccountsView();
    userAccountsView.setPresenter(this);

    final LoginWidget loginWidget = userAccountsView.getLoginWidget();
    Receiver<UserInformationProxy> receiver = new Receiver<UserInformationProxy>() {
        @Override//from  ww  w  .jav  a2 s.c o m
        public void onSuccess(UserInformationProxy userInformationRecord) {
            loginWidget.setUserInformation(userInformationRecord);
        }
    };
    requestFactory.userInformationRequest().getCurrentUserInformation(Location.getHref()).fire(receiver);

    containerWidget.setWidget(userAccountsView.asWidget());
}

From source file:com.google.gwt.sample.expenses.client.ExpenseDetails.java

License:Apache License

public void onExpenseRecordChanged(EntityProxyChange<ExpenseProxy> event) {
    final EntityProxyId<ExpenseProxy> proxyId = event.getProxyId();

    int index = 0;
    final List<ExpenseProxy> list = items.getList();
    for (ExpenseProxy r : list) {
        if (items.getKey(r).equals(proxyId)) {
            final int i = index;
            expensesRequestFactory.find(proxyId).fire(new Receiver<ExpenseProxy>() {
                @Override/*from   www .j a  va  2 s.  c  om*/
                public void onSuccess(ExpenseProxy newRecord) {
                    list.set(i, newRecord);

                    // Update the view data if the approval has been updated.
                    ApprovalViewData avd = approvalCell.getViewData(proxyId);
                    if (avd != null && avd.getPendingApproval().equals(newRecord.getApproval())) {
                        syncCommit(newRecord, null);
                    }
                }
            });
        }
        index++;
    }

    refreshCost();
    if (lastComparator != null) {
        sortExpenses(list, lastComparator);
    }
}

From source file:com.google.gwt.sample.expenses.client.ExpenseDetails.java

License:Apache License

public void onReportChanged(EntityProxyChange<ReportProxy> event) {
    EntityProxyId<ReportProxy> changed = event.getProxyId();
    if (report != null && report.getId().equals(changed)) {
        // Request the updated report.
        expensesRequestFactory.reportRequest().findReport(report.getId()).fire(new Receiver<ReportProxy>() {
            @Override//  w w w . j  a  va  2 s  . c  om
            public void onSuccess(ReportProxy response) {
                report = response;
                setNotesEditState(false, false, response.getNotes());
            }
        });
    }
}

From source file:com.google.gwt.sample.expenses.client.ExpenseDetails.java

License:Apache License

/**
 * Request the expenses./*w w w.  j a va2s .  c om*/
 */
private void requestExpenses() {
    // Cancel the timer since we are about to send a request.
    refreshTimer.cancel();
    lastReceiver = new Receiver<List<ExpenseProxy>>() {
        @Override
        public void onSuccess(List<ExpenseProxy> newValues) {
            if (this == lastReceiver) {
                List<ExpenseProxy> list = new ArrayList<ExpenseProxy>(newValues);
                if (lastComparator != null) {
                    sortExpenses(list, lastComparator);
                }
                items.setList(list);
                refreshCost();

                // Add the new keys and changed values to the known keys.
                boolean isInitialData = knownExpenseKeys == null;
                if (knownExpenseKeys == null) {
                    knownExpenseKeys = new HashMap<Object, ExpenseProxy>();
                }
                for (ExpenseProxy value : newValues) {
                    Object key = items.getKey(value);
                    if (!isInitialData) {
                        ExpenseProxy existing = knownExpenseKeys.get(key);
                        if (existing == null || !value.getAmount().equals(existing.getAmount())
                                || !value.getDescription().equals(existing.getDescription())
                                || !value.getCategory().equals(existing.getCategory())) {
                            (new PhaseAnimation.CellTablePhaseAnimation<ExpenseProxy>(table, value, items))
                                    .run();
                        }
                    }
                    knownExpenseKeys.put(key, value);
                }
            }

            // Reschedule the timer.
            refreshTimer.schedule(REFRESH_INTERVAL);
        }
    };

    expensesRequestFactory.expenseRequest().findExpensesByReport(report.getId()).with(getExpenseColumns())
            .fire(lastReceiver);
}

From source file:com.google.gwt.sample.expenses.client.ExpenseDetails.java

License:Apache License

/**
 * Save the notes that the user entered in the notes box.
 *//*w  w w  .java  2  s  .co  m*/
private void saveNotes() {
    // Early exit if the notes haven't changed.
    final String pendingNotes = notesBox.getText();
    if (pendingNotes.equals(report.getNotes())) {
        setNotesEditState(false, false, pendingNotes);
        return;
    }

    // Switch to the pending view.
    setNotesEditState(false, true, pendingNotes);

    // Submit the delta.
    ReportRequest editRequest = expensesRequestFactory.reportRequest();
    ReportProxy editableReport = editRequest.edit(report);
    editableReport.setNotes(pendingNotes);
    editRequest.persist().using(editableReport).fire(new Receiver<Void>() {
        @Override
        public void onSuccess(Void ignore) {
        }
    });
}

From source file:com.google.gwt.sample.expenses.client.ExpenseDetails.java

License:Apache License

private void updateExpenseRecord(final ExpenseProxy record, String approval, String reasonDenied) {
    // Verify that the total is under the cap.
    if (Expenses.Approval.APPROVED.is(approval) && !Expenses.Approval.APPROVED.is(record.getApproval())) {
        double amount = record.getAmount();
        if (amount + totalApproved > MAX_COST) {
            syncCommit(record,//from  w  w  w.  j  a  v  a2  s. c o  m
                    "The total approved amount for an expense report cannot exceed $" + MAX_COST + ".");
            return;
        }
    }

    // Create a delta and sync with the value store.
    ExpenseRequest editRequest = expensesRequestFactory.expenseRequest();
    ExpenseProxy editableRecord = editRequest.edit(record);
    editableRecord.setApproval(approval);
    editableRecord.setReasonDenied(reasonDenied);
    editRequest.persist().using(editableRecord).fire(new Receiver<Void>() {
        @Override
        public void onSuccess(Void ignore) {
        }

        // TODO: use onViolations for checking constraint violations.
    });
}

From source file:com.google.gwt.sample.expenses.client.ExpenseList.java

License:Apache License

/**
 * Send a request for reports in the current range.
 *
 * @param isPolling true if this request is caused by polling
 *//*from  ww w. j  av  a2 s .co  m*/
private void requestReports(boolean isPolling) {
    // Cancel the refresh timer.
    refreshTimer.cancel();

    // Early exit if we don't have a request factory to request from.
    if (requestFactory == null) {
        return;
    }

    // Clear the known keys.
    if (!isPolling) {
        knownReportKeys = null;
    }

    // Get the parameters.
    String startsWith = startsWithSearch;
    if (startsWith == null || searchBox.getDefaultText().equals(startsWith)) {
        startsWith = "";
    }
    Range range = table.getVisibleRange();
    Long employeeId = employee == null ? -1 : new Long(employee.getId());
    String dept = department == null ? "" : department;

    // If a search string is specified, the results will not be sorted.
    if (startsWith.length() > 0) {
        for (SortableHeader header : allHeaders) {
            header.setSorted(false);
            header.setReverseSort(false);
        }
        table.redrawHeaders();
    }

    // Request the total data size.
    if (isCountStale) {
        isCountStale = false;
        if (!isPolling) {
            pager.startLoading();
        }
        lastDataSizeReceiver = new Receiver<Long>() {
            @Override
            public void onSuccess(Long response) {
                if (this == lastDataSizeReceiver) {
                    int count = response.intValue();
                    // Treat count == 1000 as inexact due to AppEngine limitation
                    reports.updateRowCount(count, count != 1000);
                }
            }
        };
        requestFactory.reportRequest().countReportsBySearch(employeeId, dept, startsWith)
                .fire(lastDataSizeReceiver);
    }

    // Request reports in the current range.
    lastDataReceiver = new Receiver<List<ReportProxy>>() {
        @Override
        public void onSuccess(List<ReportProxy> newValues) {
            if (this == lastDataReceiver) {
                int size = newValues.size();
                if (size < table.getPageSize()) {
                    // Now we know the exact data size
                    reports.updateRowCount(table.getPageStart() + size, true);
                }
                if (size > 0) {
                    reports.updateRowData(table.getPageStart(), newValues);
                }

                // Add the new keys to the known keys.
                boolean isInitialData = knownReportKeys == null;
                if (knownReportKeys == null) {
                    knownReportKeys = new HashSet<Object>();
                }
                for (ReportProxy value : newValues) {
                    Object key = reports.getKey(value);
                    if (!isInitialData && !knownReportKeys.contains(key)) {
                        (new PhaseAnimation.CellTablePhaseAnimation<ReportProxy>(table, value, reports)).run();
                    }
                    knownReportKeys.add(key);
                }
            }
            refreshTimer.schedule(REFRESH_INTERVAL);
        }
    };

    requestFactory.reportRequest().findReportEntriesBySearch(employeeId, dept, startsWith, orderBy,
            range.getStart(), range.getLength()).with(reportColumns).fire(lastDataReceiver);
}

From source file:com.google.gwt.sample.expenses.client.place.AbstractProxyEditActivity.java

License:Apache License

public void saveClicked() {
    if (!changed()) {
        return;/*from   w  ww  . ja v a  2s  .  c o  m*/
    }

    setWaiting(true);
    editorDriver.flush().fire(new Receiver<Void>() {
        /*
         * Callbacks do nothing if editorDriver is null, we were stopped in
         * midflight
         */
        @Override
        public void onFailure(ServerFailure error) {
            if (editorDriver != null) {
                setWaiting(false);
                super.onFailure(error);
            }
        }

        @Override
        public void onSuccess(Void ignore) {
            if (editorDriver != null) {
                // We want no warnings from mayStop, so:

                // Defeat isChanged check
                editorDriver = null;

                // Defeat call-in-flight check
                setWaiting(false);

                exit(true);
            }
        }

        @Override
        public void onViolation(Set<Violation> errors) {
            if (editorDriver != null) {
                setWaiting(false);
                editorDriver.setViolations(errors);
            }
        }
    });
}