Friday, November 22, 2013

Using DatePicker in CellTable

Dear Group,

I have two "probably simple" questions for using DatePicker in CellTable:

1. In case, no date had been specified yet, Is it possible to show a empty Datepicker field?
I get NPE if date is null, which is probably fine. At this moment, I populate the date field with current date, which works but is wrong.
I would like to show a message "not specified" and to pop-up a DatePicker when user clicks on it. ... How do I do this?

2. I ask user to confirm the new date before it is changed in the DB. How do I set date shown in the DatePickerCell back to the old one?
Basically what happens is that the new date shown in the DatePickerCell is changed to the new date as soon as user chooses a new date from the DatePicker.
I ask via: Window.confirm() if he is sure to change the date to the new one, and in case NO, I would like to set the date shown in the CellTable back to the old one. ... How do I do this?

Thank you in advance for your help:

Nermin B.

Here is my code. The blue marked part is concerned with Question1 and Red part with Question2.

        //=== JobOffeer VALID UNTIL COLUMN
        DatePickerCell jobOfferExipreDateCell = new DatePickerCell(DateTimeFormat.getFormat("dd.MM.yyy hh:mm"));
        Column<JobProxy, Date> jobExpireDateColumn = new Column<JobProxy, Date>(jobOfferExipreDateCell) {
            @Override
            public Date getValue(JobProxy object) {
                if(object.getExpireDate() == null) {
                   return new Date();
                } else {
                   return object.getExpireDate();
                }
            }
        };
        jobExpireDateColumn.setFieldUpdater(new FieldUpdater<JobProxy, Date>() {
            @Override
            public void update(int index, JobProxy currentJob, Date changedExpiredDate) {
                if(Window.confirm("Do you want to change expire date to "+DateTimeFormat.getFormat("dd.MM.yyy").format(changedExpiredDate)+"?")) {
                    //update job
                    JobRequest jobRequest = cp.getRequestFactory().jobRequest();
                    JobProxy editedJob = jobRequest.edit(currentJob);
                    //Set New Date
                    editedJob.setExpireDate(changedExpiredDate);
                    //(1)Receiver
                    Receiver<ProcessResponseProxy> receiver = new Receiver<ProcessResponseProxy>(){
                        @Override
                        public void onSuccess(ProcessResponseProxy response) {
                            cp.getEventBus().fireEvent(new LoadDataRequestEvent(LoadDataRequestType.LOGIN_USER));
                        }
                    };
                    //(2) Fire
                    jobRequest.update().using(editedJob).fire(receiver);
                } else {
                    //ToDo: Reset DatePicker back to currentJob.getExpireDate();
                }
            }
        });

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment