PageRenderTime 39ms CodeModel.GetById 9ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/ftr-gwt-demo/src/main/java/eu/future/earth/gwt/client/OverviewPanelDemo.java

http://ftr-gwt-library.googlecode.com/
Java | 234 lines | 184 code | 32 blank | 18 comment | 11 complexity | ee319efb5aebce474074e94f3bcf0e80 MD5 | raw file
  1/*
  2 * Copyright 2007 Future Earth, info@future-earth.eu
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5 * use this file except in compliance with the License. You may obtain a copy of
  6 * the License at
  7 *
  8 * http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 13 * License for the specific language governing permissions and limitations under
 14 * the License.
 15 */
 16
 17package eu.future.earth.gwt.client;
 18
 19import java.util.ArrayList;
 20import java.util.Calendar;
 21import java.util.GregorianCalendar;
 22import java.util.List;
 23
 24import com.google.gwt.core.client.Scheduler;
 25import com.google.gwt.core.client.Scheduler.ScheduledCommand;
 26import com.google.gwt.dom.client.Style.Unit;
 27import com.google.gwt.event.dom.client.ClickEvent;
 28import com.google.gwt.event.dom.client.ClickHandler;
 29import com.google.gwt.i18n.client.DateTimeFormat;
 30import com.google.gwt.user.client.ui.DockLayoutPanel;
 31import com.google.gwt.user.client.ui.Grid;
 32import com.google.gwt.user.client.ui.Label;
 33import com.google.gwt.user.client.ui.ResizeComposite;
 34
 35import eu.future.earth.gwt.client.date.DateEvent;
 36import eu.future.earth.gwt.client.date.DateEventListener;
 37import eu.future.earth.gwt.client.date.DefaultEventData;
 38import eu.future.earth.gwt.client.date.DefaultStringPanelRenderer;
 39import eu.future.earth.gwt.client.date.MultiView;
 40import eu.future.earth.gwt.client.date.PanelType;
 41import eu.future.earth.gwt.client.date.picker.DatePickerMonthNavigator;
 42import eu.future.earth.gwt.client.date.picker.DateSelectEvent;
 43import eu.future.earth.gwt.client.date.picker.DateSelectListener;
 44import eu.future.earth.gwt.client.hordate.DemoHandler;
 45
 46public class OverviewPanelDemo extends ResizeComposite implements
 47		DateEventListener<DefaultEventData>, ClickHandler, DateSelectListener {
 48
 49	private Label feedback = new Label(" ");
 50
 51	private DefaultStringPanelRenderer contr = new DefaultStringPanelRenderer();
 52
 53	private MultiView<DefaultEventData> multiPanel = new MultiView<DefaultEventData>(
 54			contr);
 55
 56	private DatePickerMonthNavigator navigator = new DatePickerMonthNavigator(
 57			new NoMondaysDatePickerRenderer());
 58
 59	public OverviewPanelDemo() {
 60		super();
 61		DockLayoutPanel panel = new DockLayoutPanel(Unit.PX);
 62		initWidget(panel);
 63
 64		Grid topLeft = new Grid(1, 1);
 65		topLeft.setWidth("100%");
 66		topLeft.setWidget(0, 0, navigator);
 67
 68		panel.addNorth(feedback, 30);
 69		panel.addWest(topLeft, 200);
 70		panel.add(multiPanel);
 71
 72		multiPanel.addDateEventHandler(this);
 73		navigator.addDateSelectEventHandler(this);
 74		// setGrid.addClickListener(this);
 75		multiPanel.scrollToHour(9);
 76
 77		
 78	}
 79
 80	private boolean run = true;
 81	
 82	public static List<DefaultEventData> createPlanningSamples(DemoHandler contr) {
 83		DateTimeFormat format = DateTimeFormat.getFormat("HH:mm");
 84		long id = System.currentTimeMillis();
 85		List<DefaultEventData> data = new ArrayList<DefaultEventData>();
 86		{
 87			DefaultEventData example = new DefaultEventData(id++);
 88
 89			example.setData("example for Nettie");
 90			Calendar helper = new GregorianCalendar();
 91			helper.setTime(format.parse("10:30"));
 92			example.setStartTime(helper.getTime());
 93			helper.add(Calendar.MINUTE, 10);
 94			example.setEndTime(helper.getTime());
 95
 96			data.add(example);
 97			contr.addEvent(example);
 98		}
 99		{
100			DefaultEventData example = new DefaultEventData(id++);
101			example.setData("example whole for Nettie");
102			example.setWholeDay(true);
103			Calendar helper = new GregorianCalendar();
104			helper.setTime(format.parse("10:30"));
105			example.setStartTime(helper.getTime());
106			data.add(example);
107			contr.addEvent(example);
108		}
109		{
110			DefaultEventData example = new DefaultEventData(id++);
111			example.setData("example for Nettie");
112			Calendar helper = new GregorianCalendar();
113			// helper.setTime(format.parse("10:30"));
114			example.setStartTime(helper.getTime());
115			helper.add(Calendar.MINUTE, 60);
116			example.setEndTime(helper.getTime());
117
118			data.add(example);
119			contr.addEvent(example);
120		}
121
122		{
123			DefaultEventData example = new DefaultEventData(id++);
124			example.setData("example for Nettie 22");
125			Calendar helper = new GregorianCalendar();
126			helper.setTime(format.parse("12:30"));
127			example.setStartTime(helper.getTime());
128			helper.add(Calendar.MINUTE, 60);
129			example.setEndTime(helper.getTime());
130
131			data.add(example);
132			contr.addEvent(example);
133		}
134
135		{
136			DefaultEventData example = new DefaultEventData(id++);
137			example.setData("Multi day event");
138			Calendar helper = new GregorianCalendar();
139
140			helper.setTime(format.parse("22:30"));
141			helper.add(Calendar.DATE, 1);
142			example.setStartTime(helper.getTime());
143			helper.add(Calendar.HOUR, 4);
144			example.setEndTime(helper.getTime());
145			data.add(example);
146			contr.addEvent(example);
147		}
148		return data;
149	}
150
151	public void handleDateEvent(DateEvent<DefaultEventData> newEvent) {
152		switch (newEvent.getCommand()) {
153		case ADD: {
154			final DefaultEventData data = (DefaultEventData) newEvent.getData();
155			feedback.setText("Added event on " + data.getStartTime() + " - "
156					+ data.getEndTime());
157			break;
158		}
159		case SELECT_DAY: {
160			if (newEvent.getSource() == navigator) {
161				multiPanel.setDate(newEvent.getDate());
162			}
163			break;
164		}
165		case SELECT_MONTH: {
166			if (newEvent.getSource() == navigator) {
167				multiPanel.setType(PanelType.MONTH);
168				multiPanel.setDate(newEvent.getDate());
169			}
170			break;
171		}
172		case UPDATE: {
173			final DefaultEventData data = (DefaultEventData) newEvent.getData();
174			feedback.setText("Updated event on " + data.getStartTime() + " - "
175					+ data.getEndTime());
176			break;
177		}
178		case REMOVE: {
179			final DefaultEventData data = (DefaultEventData) newEvent.getData();
180			feedback.setText("Removed event on " + data.getStartTime() + " - "
181					+ data.getEndTime());
182			break;
183		}
184
185		case DRAG_DROP: {
186			final DefaultEventData data = (DefaultEventData) newEvent.getData();
187			feedback.setText("Removed event on " + data.getStartTime() + " - "
188					+ data.getEndTime());
189			break;
190		}
191		}
192
193	}
194
195	public void onClick(ClickEvent event) {
196		// TODO Auto-generated method stub
197
198	}
199
200	@Override
201	protected void onAttach() {
202		super.onAttach();
203if(run){
204	run = false;
205		Scheduler.get().scheduleDeferred(new ScheduledCommand() {
206			@Override
207			public void execute() {
208				List<DefaultEventData> data = createPlanningSamples(contr);
209				multiPanel.setEventsByList(data);
210			}
211
212		});
213}
214	}
215
216	@Override
217	public void handleDateSelectEvent(DateSelectEvent newEvent) {
218		switch (newEvent.getCommand()) {
219		case SELECT_DAY: {
220			if (newEvent.getSource() == navigator) {
221				multiPanel.setDate(newEvent.getDate());
222			}
223			break;
224		}
225		case SELECT_NEW_MONTH: {
226			if (newEvent.getSource() == navigator) {
227				multiPanel.setType(PanelType.MONTH);
228				multiPanel.setDate(newEvent.getDate());
229			}
230			break;
231		}
232		}
233	}
234}