List of usage examples for com.google.gwt.i18n.client.constants DateTimeConstants firstDayOfTheWeek
String firstDayOfTheWeek();
From source file:org.sigmah.client.page.project.calendar.ProjectCalendarView.java
License:Open Source License
@SuppressWarnings("rawtypes") public ProjectCalendarView(final CalendarWidget calendar, final ListStore<CalendarWrapper> calendarStore, final CheckBoxSelectionModel<CalendarWrapper> selectionModel, final Dispatcher dispatcher, final Authentication authentication) { final BorderLayout borderLayout = new BorderLayout(); borderLayout.setContainerStyle("x-border-layout-ct main-background"); setLayout(borderLayout);//from www. j a va 2 s.c o m final ContentPanel calendarList = new ContentPanel(new FitLayout()); calendarList.setHeading(I18N.CONSTANTS.projectTabCalendar()); final BorderLayoutData calendarListData = new BorderLayoutData(LayoutRegion.WEST, 250); calendarListData.setCollapsible(true); add(calendarList, calendarListData); // Calendar list final ColumnConfig calendarName = new ColumnConfig("name", I18N.CONSTANTS.name(), 180); final ColumnConfig calendarColor = new ColumnConfig("color", "", 20); calendarColor.setStyle(""); calendarColor.setRenderer(new GridCellRenderer() { @Override public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore store, Grid grid) { final CalendarWrapper calendarWrapper = (CalendarWrapper) model; final SimplePanel panel = new SimplePanel(); panel.setPixelSize(14, 14); panel.getElement().getStyle().setMarginLeft(3, Unit.PX); panel.setStyleName("calendar-fullday-event-" + calendarWrapper.getCalendar().getStyle()); return panel; } }); final ColumnModel calendarColumnModel = new ColumnModel( Arrays.asList(selectionModel.getColumn(), calendarName, calendarColor)); final Grid<CalendarWrapper> calendarGrid = new Grid<CalendarWrapper>(calendarStore, calendarColumnModel); calendarGrid.setAutoExpandColumn("name"); calendarGrid.setSelectionModel(selectionModel); calendarGrid.addPlugin(selectionModel); calendarGrid.getView().setForceFit(true); calendarList.add(calendarGrid); // Calendar selectionModel.addSelectionChangedListener(new SelectionChangedListener<CalendarWrapper>() { @Override public void selectionChanged(SelectionChangedEvent<CalendarWrapper> se) { final List<CalendarWrapper> wrappers = se.getSelection(); final ArrayList<Calendar> calendars = new ArrayList<Calendar>(); for (final CalendarWrapper wrapper : wrappers) { calendars.add(wrapper.getCalendar()); } calendar.setCalendars(calendars); } }); // Defining the first day of the week // LocaleInfo uses 1 for Sunday and 2 for Monday. Substracting 1 since // Date starts with 0 for Sunday. final DateTimeConstants constants = LocaleInfo.getCurrentLocale().getDateTimeConstants(); calendar.setFirstDayOfWeek(Integer.parseInt(constants.firstDayOfTheWeek()) - 1); final ContentPanel calendarView = new ContentPanel(new FitLayout()); // Retrieving the current calendar header calendarView.setHeading(calendar.getHeading()); // Listening for further calendar header changes calendar.setListener(new CalendarWidget.CalendarListener() { @Override public void afterRefresh() { calendarView.setHeading(calendar.getHeading()); } }); // Toolbar final ToolBar toolbar = new ToolBar(); // Today button - center the calendar on the current day final Button todayButton = new Button(I18N.CONSTANTS.today()); todayButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { calendar.today(); } }); toolbar.add(todayButton); toolbar.add(new SeparatorToolItem()); // Week button - changes the calendar to display weeks final Button weekButton = new Button(I18N.CONSTANTS.week()); weekButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { calendar.setDisplayMode(CalendarWidget.DisplayMode.WEEK); } }); toolbar.add(weekButton); // Week button - changes the calendar to display monthes final Button monthButton = new Button(I18N.CONSTANTS.month()); monthButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { calendar.setDisplayMode(CalendarWidget.DisplayMode.MONTH); } }); toolbar.add(monthButton); toolbar.add(new SeparatorToolItem()); // Previous button - move back from one unit of time (week / month) final Button previousButton = new Button(I18N.CONSTANTS.previous()); previousButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { calendar.previous(); } }); toolbar.add(previousButton); // Next button - move forward from one unit of time (week / month) final Button nextButton = new Button(I18N.CONSTANTS.next()); nextButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { calendar.next(); } }); toolbar.add(nextButton); toolbar.add(new SeparatorToolItem()); addEventButton = new Button(I18N.CONSTANTS.calendarAddEvent()); addEventButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { // Displays an "Add Event" popup getEditPersonalEventDialog(null, calendarStore, calendar, dispatcher).show(); } }); if (ProfileUtils.isGranted(authentication, GlobalPermissionEnum.EDIT_PROJECT) && ProfileUtils.isGranted(authentication, GlobalPermissionEnum.EDIT_AGENDA)) { toolbar.add(addEventButton); } calendarView.setTopComponent(toolbar); final FitData fitData = new FitData(16); calendarView.addStyleName("panel-background"); calendarView.add(calendar, fitData); // Configuring calendar delegate calendar.setDelegate(new CalendarWidget.Delegate() { @Override public void edit(Event event, CalendarWidget calendarWidget) { getEditPersonalEventDialog(event, calendarStore, calendar, dispatcher).show(); } @Override public void delete(final Event event, final CalendarWidget calendarWidget) { final Delete delete = new Delete("calendar.PersonalEvent", (Integer) event.getIdentifier()); dispatcher.execute(delete, null, new AsyncCallback<VoidResult>() { @Override public void onFailure(Throwable caught) { MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError(), null); } @Override public void onSuccess(VoidResult result) { final List<Event> oldEventList = event.getParent().getEvents() .get(new Date(event.getDtstart().getYear(), event.getDtstart().getMonth(), event.getDtstart().getDate())); oldEventList.remove(event); calendarWidget.refresh(); } }); } }); final BorderLayoutData calendarViewData = new BorderLayoutData(LayoutRegion.CENTER); calendarViewData.setMargins(new Margins(0, 0, 0, 8)); add(calendarView, calendarViewData); }
From source file:org.ssgwt.client.ui.datagrid.filter.DateFilter.java
License:Apache License
/** * This function will set the date boxes to certain dates, depending on what option was selected * from the filter list.// www . jav a 2 s.co m * * @param currentDate Date object containing the current date * @param range String describing what date range should be set * * @author Lodewyk Duminy <lodewyk.duminy@a24group.com> * @since 15 Aug 2012 * * @return void */ @SuppressWarnings("deprecation") protected void setDates(Date currentDate, String range) { Date fromDate = (Date) currentDate.clone(); Date toDate = (Date) currentDate.clone(); if (range.equals("Customised date range")) { toDateBox.setValue(null); fromDateBox.setValue(null); } else if (range.equals("Today")) { toDateBox.setValue(currentDate); fromDateBox.setValue(currentDate); } else if (range.equals("Yesterday")) { Date date = currentDate; date.setDate(date.getDate() - 1); toDateBox.setValue(date); fromDateBox.setValue(date); } else if (range.equals("This week (Mon-Today)")) { DateTimeConstants constants = LocaleInfo.getCurrentLocale().getDateTimeConstants(); // THIS GETS -1 BECAUSE firstDayOfTheWeek() ADDS A DAY FOR SOME REASON. int firstDay = Integer.parseInt(constants.firstDayOfTheWeek()) - 1; // Get the offset that will be used to calculate what date the Monday is on. int offset = firstDay - fromDate.getDay(); fromDate.setDate(fromDate.getDate() + offset); fromDateBox.setValue(fromDate); toDateBox.setValue(currentDate); } else if (range.equals("Last 7 days")) { fromDate.setDate(fromDate.getDate() - 7); toDateBox.setValue(toDate); fromDateBox.setValue(fromDate); } else if (range.equals("Last week (Mon-Sun)")) { DateTimeConstants constants = LocaleInfo.getCurrentLocale().getDateTimeConstants(); // THIS GETS -1 BECAUSE firstDayOfTheWeek() ADDS A DAY FOR SOME REASON. int firstDay = Integer.parseInt(constants.firstDayOfTheWeek()) - 1; // Get the offset that will be used to calculate what date the Monday is on. int offset = (firstDay - fromDate.getDay()) - 7; fromDate.setDate(fromDate.getDate() + offset); toDate.setDate(fromDate.getDate() + 6); toDateBox.setValue(toDate); fromDateBox.setValue(fromDate); } else if (range.equals("Last working week (Mon-Fri)")) { DateTimeConstants constants = LocaleInfo.getCurrentLocale().getDateTimeConstants(); // THIS GETS -1 BECAUSE firstDayOfTheWeek() ADDS A DAY FOR SOME REASON. int firstDay = Integer.parseInt(constants.firstDayOfTheWeek()) - 1; // Get the offset that will be used to calculate what date the Monday is on. int offset = (firstDay - fromDate.getDay()) - 7; fromDate.setDate(fromDate.getDate() + offset); toDate.setDate(fromDate.getDate() + 4); toDateBox.setValue(toDate); fromDateBox.setValue(fromDate); } else if (range.equals("Last 14 days")) { fromDate.setDate(fromDate.getDate() - 14); toDateBox.setValue(toDate); fromDateBox.setValue(fromDate); } else if (range.equals("This month")) { int offset = fromDate.getDate() - 1; fromDate.setDate(fromDate.getDate() - offset); toDateBox.setValue(currentDate); fromDateBox.setValue(fromDate); } else if (range.equals("Last 30 days")) { fromDate.setDate(fromDate.getDate() - 30); System.out.println(fromDate); toDateBox.setValue(toDate); fromDateBox.setValue(fromDate); } else if (range.equals("Last month")) { int year = toDate.getYear(); int month = toDate.getMonth() - 1; // If the current month is january, this will make sure we get december of the previous year's info. if (month < 0) { --year; month = 11; } toDate.setDate(toDate.getDate() - toDate.getDate()); fromDate = new Date(year, month, 1); toDateBox.setValue(toDate); fromDateBox.setValue(fromDate); } }