2013-06-06 40 views
0

我的MainPresenter具有帶按鈕列的CellTable。當你按下按鈕時,演示者將調用「addToPopupSlot(editPopup,true)」。出現一個editPopup,可以在其中進行多項設置。按下彈出視圖上的保存按鈕後,它將數據發送到MainPresenter中的CellTable想要獲取的數據庫。在彈出視圖隱藏後,從MainPresenter重繪CellTable

我的問題是:當我點擊保存按鈕時,表格不會更新。我必須刷新頁面或從另一個Presenter導航回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在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); 

回答

0

我覺得你有一些解決方案在這裏。如果我是你,我會做下一步:

  1. 在MainPresenter中創建一個事件監聽器。
  2. 當你完成 更新你的數據庫(按下保存在彈出窗口後);我會發起一個 事件。
  3. 當MainPresenter收到事件時,您轉到DB 並獲取數據(使用getVisibleRange()過濾數據)。
  4. 刷新使用setRowData(...)方法(傳遞正確的參數)

另一種選擇是創建一個CellTable一個ListDataProvider聯營CellTable,並呼籲它刷新。

+0

謝謝,沒有事件。剛剛添加了一個傾聽呼叫的聽衆 – kArvee

+0

不客氣!做得好! :D – apanizo

+0

我這樣做了以前的確切方式,但不是使用setter作爲監聽器,而是通過引發異常的杜松子將注入處理程序添加到構造函數中 – kArvee