Пример #1
0
  public iCalCalendarPanel() {

    // style this element as absolute position
    DOM.setStyleAttribute(this.getElement(), "position", "absolute");
    DOM.setStyleAttribute(this.getElement(), "top", "0px");
    DOM.setStyleAttribute(this.getElement(), "left", "0px");
    DOM.setStyleAttribute(this.getElement(), "padding", "0px");

    DOM.setStyleAttribute(DOM.getElementById("messageBox"), "display", "none");

    mainLayoutPanel.setWidth("100%");
    add(mainLayoutPanel);

    // add header
    headerPanel.setStyleName("gwt-cal-HeaderPanel");
    DOM.setInnerHTML(headerPanel.getElement(), " ");
    footerPanel.setStyleName("gwt-cal-FooterPanel");
    DOM.setInnerHTML(headerPanel.getElement(), " ");
    mainLayoutPanel.add(headerPanel, DockPanel.NORTH);
    mainLayoutPanel.add(footerPanel, DockPanel.SOUTH);

    // add left panel
    datePicker.setValue(new Date());
    dateLayoutPanel.add(datePicker, DockPanel.SOUTH);
    dateLayoutPanel.add(splitterPanel, DockPanel.SOUTH);
    splitterPanel.setStyleName("splitter");
    mainLayoutPanel.add(dateLayoutPanel, DockPanel.WEST);

    // CalendarFormat.INSTANCE.setFirstDayOfWeek(1);

    // change hour offset to false to facilitate iCal style
    settings.setOffsetHourLabels(true);
    settings.setTimeBlockClickNumber(Click.Double);
    // create day view
    calendar = new Calendar();
    calendar.setSettings(settings);
    // set style as google-cal
    calendar.setWidth("100%");
    // set today as default date
    mainLayoutPanel.add(calendar, DockPanel.CENTER);
    mainLayoutPanel.setCellVerticalAlignment(dateLayoutPanel, HasAlignment.ALIGN_BOTTOM);
    dateLayoutPanel.setCellVerticalAlignment(datePicker, HasAlignment.ALIGN_BOTTOM);
    dateLayoutPanel.setWidth("168px");

    // add today button
    todayButton.setStyleName("todayButton");
    todayButton.setText("Today");
    todayButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            datePicker.setValue(new Date(), true);
            // dayView.setDate(new Date());
          }
        });
    previousDayButton.setStyleName("previousButton");
    previousDayButton.setHTML("«");
    previousDayButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            Date d = datePicker.getValue();
            d.setDate(d.getDate() - 1);
            datePicker.setValue(d, true);
          }
        });
    nextDayButton.setStyleName("nextButton");
    nextDayButton.setHTML("»");
    nextDayButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            Date d = datePicker.getValue();
            d.setDate(d.getDate() + 1);
            datePicker.setValue(d, true);
          }
        });
    headerPanelLayout.setWidget(0, 0, todayButton);
    headerPanelLayout.setWidget(0, 1, previousDayButton);

    oneDayButton.setText("1 Day");
    oneDayButton.setStyleName("dayButton");
    threeDayButton.setText("3 Day");
    threeDayButton.setStyleName("dayButton");
    threeDayButton.addStyleName("active");
    activeDayButton = threeDayButton;
    weekDayButton.setText("Work Week");
    weekDayButton.setStyleName("dayButton");
    monthButton.setText("Month");
    monthButton.setStyleName("dayButton");
    headerPanelLayout.setWidget(0, 2, oneDayButton);
    headerPanelLayout.setWidget(0, 3, threeDayButton);
    headerPanelLayout.setWidget(0, 4, weekDayButton);
    headerPanelLayout.setWidget(0, 5, monthButton);
    headerPanelLayout.setWidget(0, 6, nextDayButton);
    headerPanelLayout.setHTML(0, 7, " ");

    headerPanelLayout.getCellFormatter().setWidth(0, 0, "50%");
    headerPanelLayout.getCellFormatter().setWidth(0, 7, "50%");

    headerPanelLayout.setWidth("100%");
    headerPanelLayout.setCellPadding(0);
    headerPanelLayout.setCellSpacing(0);
    headerPanel.add(headerPanelLayout);

    footerPanel.add(
        new HTML(
            "<a href='http://code.google.com/p/gwt-cal'>gwt-cal</a> widget for Google Web Toolkit, GPLv3, by <a href='http://www.google.com/profiles/Brad.Rydzewski'>Brad Rydzewski</a>"));

    oneDayButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            activeDayButton.removeStyleName("active");
            activeDayButton = oneDayButton;
            activeDayButton.addStyleName("active");
            calendar.setView(CalendarViews.DAY, 1);
            // calendar.scrollToHour(6);
          }
        });
    threeDayButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            activeDayButton.removeStyleName("active");
            activeDayButton = threeDayButton;
            activeDayButton.addStyleName("active");
            calendar.setView(CalendarViews.DAY, 3);
            // calendar.scrollToHour(6);
          }
        });
    weekDayButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            activeDayButton.removeStyleName("active");
            activeDayButton = weekDayButton;
            activeDayButton.addStyleName("active");
            calendar.setView(CalendarViews.DAY, 5);
            // calendar.scrollToHour(6);
          }
        });
    monthButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            activeDayButton.removeStyleName("active");
            activeDayButton = monthButton;
            activeDayButton.addStyleName("active");
            calendar.setView(CalendarViews.MONTH);
          }
        });

    datePicker.addValueChangeHandler(
        new ValueChangeHandler<Date>() {
          public void onValueChange(ValueChangeEvent<Date> event) {
            calendar.setDate(event.getValue());
          }
        });
    calendar.addDeleteHandler(
        new DeleteHandler<Appointment>() {
          public void onDelete(DeleteEvent<Appointment> event) {
            boolean commit =
                Window.confirm(
                    "Are you sure you want to delete appointment \""
                        + event.getTarget().getTitle()
                        + "\"");
            if (commit == false) {
              event.setCancelled(true);
              System.out.println("cancelled appointment deletion");
            }
          }
        });
    calendar.addOpenHandler(
        new OpenHandler<Appointment>() {
          public void onOpen(OpenEvent<Appointment> event) {
            Window.alert("You double-clicked appointment \"" + event.getTarget().getTitle() + "\"");
          }
        });

    calendar.addSelectionHandler(
        new SelectionHandler<Appointment>() {
          public void onSelection(SelectionEvent<Appointment> event) {
            System.out.println("selected " + event.getSelectedItem().getTitle());
          }
        });

    calendar.addTimeBlockClickHandler(
        new TimeBlockClickHandler<Date>() {
          public void onTimeBlockClick(TimeBlockClickEvent<Date> event) {
            Window.alert("you clicked time block " + event.getTarget());
          }
        });

    /* Generate random appointments */
    AppointmentBuilder.appointmentsPerDay = 5;
    AppointmentBuilder.HOURS = new Integer[] {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
    AppointmentBuilder.MINUTES = new Integer[] {0, 30};
    AppointmentBuilder.DURATIONS = new Integer[] {60, 90, 120, 180, 240, 600};
    AppointmentBuilder.DESCRIPTIONS[1] = "Best show on TV!";

    ArrayList<Appointment> appointments = AppointmentBuilder.build(AppointmentBuilder.ICAL_STYLES);
    /* Add appointments to day view */
    calendar.suspendLayout();
    calendar.addAppointments(appointments);

    calendar.resumeLayout();

    // window events to handle resizing
    Window.enableScrolling(false);
    Window.addResizeHandler(
        new ResizeHandler() {
          public void onResize(ResizeEvent event) {
            int h = event.getHeight();
            calendar.setHeight(
                h - headerPanel.getOffsetHeight() - footerPanel.getOffsetHeight() + "px");
          }
        });
    Scheduler.get()
        .scheduleDeferred(
            new ScheduledCommand() {
              public void execute() {
                calendar.setHeight(
                    Window.getClientHeight()
                        - headerPanel.getOffsetHeight()
                        - footerPanel.getOffsetHeight()
                        + "px");
                calendar.scrollToHour(6);
              }
            });
  }
Пример #2
0
  @SuppressWarnings("deprecation")
  private void configureCalendar() {

    // change hour offset to false to facilitate google style
    settings.setOffsetHourLabels(false);
    //        settings.setTimeBlockClickNumber(CalendarSettings.Click.Single);
    settings.setEnableDragDrop(true);

    calendar = new Calendar();
    calendar.setSettings(settings);
    calendar.setView(CalendarViews.MONTH);
    calendar.setWidth("100%");

    // TODO: Preparar estes dois handlers para a SCHEDULED TASK
    calendar.addDeleteHandler(
        new DeleteHandler<Appointment>() {
          public void onDelete(DeleteEvent<Appointment> event) {
            boolean commit =
                Window.confirm(
                    HarvesterUI.CONSTANTS.deleteScheduledTaskConfirmMessage()
                        + " "
                        + event.getTarget().getTitle());
            if (!commit) {
              event.setCancelled(true);
            }
          }
        });
    calendar.addUpdateHandler(
        new UpdateHandler<Appointment>() {
          public void onUpdate(UpdateEvent<Appointment> event) {
            if (event.getTarget() != null) {
              CalendarAppointment appt = (CalendarAppointment) event.getTarget();
              if (appt.getHarvestTask() instanceof OldTaskUI) {
                HarvesterUI.UTIL_MANAGER.getErrorBox(
                    HarvesterUI.CONSTANTS.moveOldTasks(), HarvesterUI.CONSTANTS.moveOldTaskError());
                History.fireCurrentHistoryState();
              } else {
                if (appt.getStart().after(new Date())) {
                  if (appt.getHarvestTask() instanceof ScheduledTaskUI) {
                    final ScheduledTaskUI scheduledTaskUI = (ScheduledTaskUI) appt.getHarvestTask();
                    final Date date = appt.getStart();
                    scheduledTaskUI.setDate(date);

                    AsyncCallback<Boolean> callback =
                        new AsyncCallback<Boolean>() {
                          public void onFailure(Throwable caught) {
                            new ServerExceptionDialog(
                                    "Failed to get response from server", caught.getMessage())
                                .show();
                          }

                          public void onSuccess(Boolean result) {
                            if (!result) {
                              HarvesterUI.UTIL_MANAGER.getErrorBox(
                                  HarvesterUI.CONSTANTS.moveScheduledTask(),
                                  HarvesterUI.CONSTANTS.moveScheduledTaskError());
                              return;
                            }
                            DateTimeFormat fmt = DateTimeFormat.getFormat("dd/MM/yyyy");
                            scheduledTaskUI.createDateString(scheduledTaskUI.getScheduleType());
                            HarvesterUI.UTIL_MANAGER.getSaveBox(
                                HarvesterUI.CONSTANTS.moveScheduledTask(),
                                HarvesterUI.CONSTANTS.scheduleTaskMoved() + " " + fmt.format(date));
                          }
                        };
                    HarvestOperationsServiceAsync service =
                        (HarvestOperationsServiceAsync)
                            Registry.get(HarvesterUI.HARVEST_OPERATIONS_SERVICE);
                    service.updateScheduledTask(scheduledTaskUI, callback);
                  }
                } else {
                  HarvesterUI.UTIL_MANAGER.getErrorBox(
                      HarvesterUI.CONSTANTS.moveScheduledTask(),
                      HarvesterUI.CONSTANTS.moveScheduledTaskPrevDateError());
                }
                History.fireCurrentHistoryState();
              }
            }
          }
        });
    calendar.addOpenHandler(
        new OpenHandler<Appointment>() {
          public void onOpen(OpenEvent<Appointment> event) {
            if (event != null) {
              Appointment appt = event.getTarget();
              if (appt instanceof CalendarAppointment) {
                if (((CalendarAppointment) appt).getHarvestTask() instanceof OldTaskUI)
                  showPastScheduleDialog(((CalendarAppointment) appt).getHarvestTask());
                else if (((CalendarAppointment) appt).getHarvestTask() instanceof ScheduledTaskUI) {
                  ScheduledTaskUI scheduledTaskUI =
                      (ScheduledTaskUI) ((CalendarAppointment) appt).getHarvestTask();
                  if (scheduledTaskUI.getRecordsPerFile() == null) showScheduleDialog(appt);
                  else showScheduleExportDialog(appt);
                }
              }
            }
          }
        });

    //        calendar.addSelectionHandler(new SelectionHandler<Appointment>(){
    //            public void onSelection(SelectionEvent<Appointment> event) {
    //                if (event != null) {
    //                    Appointment appt = event.getSelectedItem();
    //                    if(appt instanceof CalendarAppointment)
    //                    {
    //                        Date now = new Date();
    //                        // TODO: hora do dia tambem
    //                        if(appt.getEnd().before(now))
    //                        {
    //                            showPastScheduleDialog(((CalendarAppointment)
    // appt).getHarvestTask());
    //                        }
    //                        else
    //                            showScheduleDialog(appt);
    //                    }
    //                    calendar.resetSelectedAppointment();
    //                }
    //            }
    //        });

    // Handler to show + items for a day
    calendar.addDateRequestHandler(
        new DateRequestHandler<Date>() {
          public void onDateRequested(DateRequestEvent<Date> event) {
            calendar.setDate(event.getTarget());
            calendar.setView(CalendarViews.DAY, 1);
          }
        });
  }