@Override public void execute() { Date beginDate = CalendarUtil.copyDate(currentValue); Date endDate = CalendarUtil.copyDate(beginDate); CalendarUtil.addDaysToDate(endDate, 1); applyFilter(beginDate, endDate); }
@SuppressWarnings("unchecked") public List<Task> getWeekTasksStat(String name, String momin, Date startWeek) { Query query; List<Task> list; TimeZone.setDefault(TimeZone.getTimeZone("GMT")); query = em.createQuery( "select from " + Task.class.getName() + " t where t.mominId = :momin AND name =:name AND t.date >= :start AND t.date < :end order by date asc"); query.setParameter("name", name); Task.moveToDay(startWeek, -1); startWeek.setHours(0); startWeek.setMinutes(0); startWeek.setSeconds(0); Date end = CalendarUtil.copyDate(startWeek); CalendarUtil.addDaysToDate(end, 7); query.setParameter("momin", momin); query.setParameter("start", startWeek); // end.setTime(end.getTime()-2000); query.setParameter("end", end); list = query.getResultList(); // if(group == null) // getCache().put(keyWeek, list); return list; }
@Override public void execute() { Date date = CalendarUtil.copyDate(currentValue); Date beginDate = DateUtils.getFirstDayOfYear(date); Date endDate = CalendarUtil.copyDate(beginDate); CalendarUtil.addMonthsToDate(endDate, 12); applyFilter(beginDate, endDate); }
@Override public void execute() { Date now = new Date(); int qr = DateUtils.getMonth(now) / 3; Date beginDate = DateUtils.getFirstDayOfYear(now); CalendarUtil.addMonthsToDate(beginDate, 3 * qr); Date endDate = CalendarUtil.copyDate(beginDate); CalendarUtil.addMonthsToDate(endDate, 3); applyFilter(beginDate, endDate); }
/** * By passing around integers instead of Dates we can avoid the GWT formatting issues around * default format differences between prod and dev modes. * * @return Integer offset of current Date (i.e., yesterday is -1) */ public Integer getValueAsDays() { if (getValueAsDate() == null) { return null; } else { return CalendarUtil.getDaysBetween(new Date(), getValueAsDate()); } }
@SuppressWarnings("unchecked") public List<Task> getWeekTasks(String momin, String group, Date startWeek) { Query query; List<Task> list; TimeZone.setDefault(TimeZone.getTimeZone("GMT")); // String keyWeek = momin + startWeek.toGMTString().substring(0, 11); if (group == null) { query = em.createQuery( "select from " + Task.class.getName() + " t where t.mominId = :momin AND t.date >= :start AND t.date < :end order by date asc"); // list = (List<Task>) getCache().get(keyWeek); // if(list!=null) // return list; } else { query = em.createQuery( "select from " + Task.class.getName() + " t where t.mominId = :momin AND group =:group AND t.date >= :start AND t.date < :end order by date asc"); query.setParameter("group", Integer.parseInt(group)); } Date end = CalendarUtil.copyDate(startWeek); CalendarUtil.addDaysToDate(end, 7); query.setParameter("momin", momin); query.setParameter("start", startWeek); // end.setTime(end.getTime()-2000); query.setParameter("end", end); list = new ArrayList((List<Task>) query.getResultList()); // if(group == null) // getCache().put(keyWeek, list); return list; }
/** * Fires the value change event if needed. * * <p> * * @param oldValue the old value * @param newValue the new value */ protected void fireChange(Date oldValue, Date newValue) { ValueChangeEvent.<Date>fireIfNotEqual(this, oldValue, CalendarUtil.copyDate(newValue)); }
/** * ************************************* Sets a cookie with the user name for re-use on subsequent * logins. The expiration period of this cookie is 3 months. * * @param sUserName The user name to set */ protected void setUserNameCookie(String sUserName) { Date aExpiryDate = new Date(); CalendarUtil.addMonthsToDate(aExpiryDate, 3); Cookies.setCookie(sUserCookie, sUserName, aExpiryDate); }
@Override public boolean match(Record rec) { return !CalendarUtil.isSameDate(valueAdapter.getValue(rec), value) && super.match(rec); }
public Widget asWidget() { final Chart<Site> chart = new Chart<Site>(600, 400); chart.setDefaultInsets(20); final ListStore<Site> store = new ListStore<Site>(siteAccess.nameKey()); Date initial = f.parse("Feb 1"); for (int i = 0; i < 7; i++) { store.add( new Site(initial, Math.random() * 20 + 80, Math.random() * 20 + 40, Math.random() * 20)); initial = CalendarUtil.copyDate(initial); CalendarUtil.addDaysToDate(initial, 1); } chart.setStore(store); NumericAxis<Site> axis = new NumericAxis<Site>(); axis.setPosition(Position.LEFT); axis.addField(siteAccess.visits()); TextSprite title = new TextSprite("Number of Hits"); title.setFontSize(18); axis.setTitleConfig(title); axis.setDisplayGrid(true); axis.setMinimum(0); axis.setMaximum(100); chart.addAxis(axis); final TimeAxis<Site> time = new TimeAxis<Site>(); time.setField(siteAccess.date()); time.setStartDate(f.parse("Feb 1")); time.setEndDate(f.parse("Feb 7")); time.setLabelProvider( new LabelProvider<Date>() { @Override public String getLabel(Date item) { return f.format(item); } }); chart.addAxis(time); LineSeries<Site> series = new LineSeries<Site>(); series.setYAxisPosition(Position.LEFT); series.setYField(siteAccess.visits()); series.setStroke(new RGB(148, 174, 10)); series.setShowMarkers(true); series.setMarkerIndex(1); Sprite marker = Primitives.circle(0, 0, 6); marker.setFill(new RGB(148, 174, 10)); series.setMarkerConfig(marker); chart.addSeries(series); series = new LineSeries<Site>(); series.setYAxisPosition(Position.LEFT); series.setYField(siteAccess.views()); series.setStroke(new RGB(17, 95, 166)); series.setShowMarkers(true); series.setMarkerIndex(1); marker = Primitives.cross(0, 0, 6); marker.setFill(new RGB(17, 95, 166)); series.setMarkerConfig(marker); chart.addSeries(series); series = new LineSeries<Site>(); series.setYAxisPosition(Position.LEFT); series.setYField(siteAccess.veins()); series.setStroke(new RGB(166, 17, 32)); series.setShowMarkers(true); series.setMarkerIndex(1); marker = Primitives.diamond(0, 0, 6); marker.setFill(new RGB(166, 17, 32)); series.setMarkerConfig(marker); chart.addSeries(series); update = new Timer() { @Override public void run() { Date startDate = CalendarUtil.copyDate(time.getStartDate()); Date endDate = CalendarUtil.copyDate(time.getEndDate()); CalendarUtil.addDaysToDate(startDate, 1); CalendarUtil.addDaysToDate(endDate, 1); chart .getStore() .add( new Site( endDate, Math.random() * 20 + 80, Math.random() * 20 + 40, Math.random() * 20)); time.setStartDate(startDate); time.setEndDate(endDate); chart.redrawChart(); } }; update.scheduleRepeating(1000); ToggleButton animation = new ToggleButton("Animate"); animation.addValueChangeHandler( new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { chart.setAnimated(event.getValue()); } }); animation.setValue(true, true); ToolBar toolBar = new ToolBar(); toolBar.add(animation); ContentPanel panel = new FramedPanel(); panel.getElement().getStyle().setMargin(10, Unit.PX); panel.setCollapsible(true); panel.setHeadingText("Live Chart"); panel.setPixelSize(620, 500); panel.setBodyBorder(true); VerticalLayoutContainer layout = new VerticalLayoutContainer(); panel.add(layout); toolBar.setLayoutData(new VerticalLayoutData(1, -1)); layout.add(toolBar); chart.setLayoutData(new VerticalLayoutData(1, 1)); layout.add(chart); panel.addAttachHandler( new AttachEvent.Handler() { @Override public void onAttachOrDetach(AttachEvent event) { if (event.isAttached() == false) { update.cancel(); } } }); return panel; }