Question

My MainPresenter has a CellTable with a button column. When u hit a button the presenter calls "addToPopupSlot(editPopup, true)". A editPopup appears with several settings u can make there. After pressing the save button on the popup view it sends data to the database which the CellTable in the MainPresenter wants to get.

My problem is: When I click on the save button, the table doesnt get updated. I have to either refresh the page or navigate from another Presenter back to the MainPresenter.

EditPopupPresenter

 @Override
protected void onBind() {
super.onBind();
this.username = Cookies.getCookie("domusr");
// hours and minutes displayed in listboxes
for (int i = 0; i < TimeSettings.HOURS_RANGE; i++) {
    getView().getBeginHoursLBX().addItem(String.valueOf(i));
    getView().getEndHoursLBX().addItem(String.valueOf(i));
    getView().getPauseHoursLBX().addItem(String.valueOf(i));
}

for (int i = 0; i < 60; i += TimeSettings.MINUTES_RANGE) {
    getView().getBeginMinutesLBX().addItem(String.valueOf(i));
    getView().getEndMinutesLBX().addItem(String.valueOf(i));
    getView().getPauseMinutesLBX().addItem(String.valueOf(i));
}

getView().getSaveBTN().addClickHandler(new ClickHandler() {

    @Override
    public void onClick(ClickEvent event) {
    DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd");
    final String startHours = getView()
        .getBeginHoursLBX()
        .getValue(
            getView().getBeginHoursLBX().getSelectedIndex());
    final String startMinutes = getView().getBeginMinutesLBX()
        .getValue(
            getView().getBeginMinutesLBX()
                .getSelectedIndex());
    final String endHours = getView().getEndHoursLBX().getValue(
        getView().getEndHoursLBX().getSelectedIndex());
    final String endMinutes = getView()
        .getEndMinutesLBX()
        .getValue(
            getView().getEndMinutesLBX().getSelectedIndex());
    final String pauseHours = getView()
        .getPauseHoursLBX()
        .getValue(
            getView().getPauseHoursLBX().getSelectedIndex());
    final String pauseMinutes = getView().getPauseMinutesLBX()
        .getValue(
            getView().getPauseMinutesLBX()
                .getSelectedIndex());
    final String projectId = getView().getProjectIdLBL().getText();
    final java.sql.Date date = new java.sql.Date(dtf.parse(
        getView().getDateLBL().getText()).getTime());
    dispatcher.execute(
        new InsertTimesIntoDB(Integer.parseInt(startHours),
            Integer.parseInt(startMinutes), Integer
                .parseInt(endHours), Integer
                .parseInt(endMinutes), Integer
                .parseInt(pauseHours), Integer
                .parseInt(pauseMinutes), Integer
                .parseInt(projectId), date, username),
        new AsyncCallback<InsertTimesIntoDBResult>() {

            @Override
            public void onFailure(Throwable caught) {

            }

            @Override
            public void onSuccess(InsertTimesIntoDBResult result) {

            }
        });

    getView().hide();

    }
});
}

editColumn in MainPresenter (onBind())

// edit column
    Column<Booking, String> editColumn = new Column<Booking, String>(
        new ButtonCell()) {
    @Override
    public String getValue(Booking booking) {
        return "edit";
    }
    };
    editColumn.setFieldUpdater(new FieldUpdater<Booking, String>() {

    @Override
    public void update(int index, Booking object, String value) {
        // pop up widget addToSlot call

        editPopup.getView().getDateLBL()
            .setText(String.valueOf(object.getFullDate()));
        editPopup.getView().getProjectIdLBL()
            .setText(String.valueOf(1234567));

        editPopup.getView().getBeginHoursLBX()
            .setItemSelected(object.getStartHours(), true);
        editPopup
            .getView()
            .getBeginMinutesLBX()
            .setItemText(
                minutesRange.getIndex(object
                    .getEndMinutes()),
                String.valueOf(object.getStartMinutes()));
        editPopup.getView().getEndHoursLBX()
            .setItemSelected(object.getEndHours(), true);
        editPopup
            .getView()
            .getEndMinutesLBX()
            .setItemText(
                minutesRange.getIndex(object
                    .getEndMinutes()),
                String.valueOf(object.getEndMinutes()));
        editPopup.getView().getPauseHoursLBX()
            .setItemSelected(object.getPauseHours(), true);
        editPopup
            .getView()
            .getPauseMinutesLBX()
            .setItemText(
                minutesRange.getIndex(object
                    .getEndMinutes()),
                String.valueOf(object.getPauseMinutes()));
        addToPopupSlot(editPopup, true);
    }
    });
    getView().getTimeTable().addColumn(editColumn);
Was it helpful?

Solution

I think you have some solutions here. If I were you I would do next steps:

  1. Create a listener of events in the MainPresenter.
  2. When you finished update your DB (after pressing save in your popup); I´d fire an event.
  3. When the MainPresenter receives the event, you go to the DB and fetch the data (filtering it using getVisibleRange()).
  4. Refresh the CellTable using setRowData(...) method (passing correctly the arguments)

Other option is create a ListDataProvider associate with the CellTable, and call refresh on it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top