PageRenderTime 19ms CodeModel.GetById 8ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://ftr-gwt-library.googlecode.com/
Java | 180 lines | 139 code | 41 blank | 0 comment | 10 complexity | 9637765d2908c687a007bce1b26c1443 MD5 | raw file
  1package eu.future.earth.gwt.client.hordate;
  2
  3import java.util.ArrayList;
  4import java.util.Date;
  5import java.util.HashMap;
  6
  7import com.google.gwt.user.client.ui.Label;
  8import com.google.gwt.user.client.ui.Widget;
  9
 10import eu.future.earth.gwt.client.date.DateEvent.DateEventActions;
 11import eu.future.earth.gwt.client.date.DateEventListener;
 12import eu.future.earth.gwt.client.date.DefaultEventData;
 13import eu.future.earth.gwt.client.date.EventPanel;
 14import eu.future.earth.gwt.client.date.horizontal.BaseHorizontalDateRenderer;
 15import eu.future.earth.gwt.client.date.horizontal.HorizontalAddCallBackHandler;
 16import eu.future.earth.gwt.client.date.horizontal.HorizontalRemoveCallBackHandler;
 17import eu.future.earth.gwt.client.date.horizontal.HorizontalUpdateCallBackHandler;
 18import eu.future.earth.gwt.client.date.horizontal.HorizontalViewPanelNoDays;
 19
 20public class HorizontalDateRendererDemo extends BaseHorizontalDateRenderer<DefaultEventData, UserDemo> implements DemoHandler {
 21
 22	public int getEndHour() {
 23		return 23;
 24	}
 25
 26	public int getStartHour() {
 27		return 0;
 28	}
 29
 30	public boolean enableDragAndDrop() {
 31		return true;
 32	}
 33
 34	public void createNewAfterClick(UserDemo theMaster, Date currentDate, Date endTime, DateEventListener<DefaultEventData> listener) {
 35		UserDemo master = (UserDemo) theMaster;
 36		if (theMaster == null) {
 37			return;
 38		}
 39		final DefaultEventData data = new DefaultEventData(System.currentTimeMillis());
 40		data.setStartTime(currentDate);
 41
 42		data.setMasterId(master.getId());
 43		data.setEndTime(endTime);
 44		final DefaultStringEventDataDialog dialog = new DefaultStringEventDataDialog(this, data);
 45		dialog.addDateEventHandler(listener);
 46		dialog.show();
 47		dialog.center();
 48
 49	}
 50
 51	public void createNewAfterClick(UserDemo theMaster, Date currentDate, DateEventListener<DefaultEventData> listener) {
 52		UserDemo master = (UserDemo) theMaster;
 53		if (theMaster == null) {
 54			return;
 55		}
 56		final DefaultEventData data = new DefaultEventData(System.currentTimeMillis());
 57		data.setStartTime(currentDate);
 58		data.setMasterId(master.getId());
 59		final DefaultStringEventDataDialog dialog = new DefaultStringEventDataDialog(this, data);
 60		dialog.addDateEventHandler(listener);
 61		dialog.show();
 62		dialog.center();
 63
 64	}
 65
 66	public EventPanel<DefaultEventData> createPanel(DefaultEventData newData) {
 67		final DefaultHorizontalDayField panel = new DefaultHorizontalDayField(this, newData);
 68		return panel;
 69	}
 70
 71	public void editAfterClick(UserDemo theMaster, DefaultEventData data, DateEventListener<DefaultEventData> listener) {
 72		final DefaultStringEventDataDialog dialog = new DefaultStringEventDataDialog(this, data, DateEventActions.UPDATE);
 73		dialog.addDateEventHandler(listener);
 74		dialog.show();
 75		dialog.center();
 76
 77	}
 78
 79	public Date getEndTime(DefaultEventData data) {
 80
 81		return data.getEndTime();
 82	}
 83
 84	public Date getStartTime(DefaultEventData data) {
 85
 86		return data.getStartTime();
 87	}
 88
 89	public void setEndTime(DefaultEventData data, Date newEnd) {
 90
 91		data.setEndTime(newEnd);
 92
 93	}
 94
 95	public void setStartTime(DefaultEventData data, Date newStart) {
 96
 97		data.setStartTime(newStart);
 98	}
 99
100	public boolean isDurationAcceptable(int minutes) {
101		return minutes >= (60 / getIntervalsPerHour());
102	}
103
104	public boolean isMaster(UserDemo theMaster, DefaultEventData theDateObject) {
105		UserDemo master = (UserDemo) theMaster;
106
107		DefaultEventData real = (DefaultEventData) theDateObject;
108		if (real.getMasterId() == master.getId()) {
109			return true;
110		}
111		return false;
112	}
113
114	public Widget getLabelForMaster(UserDemo theMaster) {
115		UserDemo master = (UserDemo) theMaster;
116		if (theMaster != null) {
117			return new Label(master.getName());
118		}
119		return null;
120	}
121
122	public boolean isSameMaster(UserDemo theMaster, UserDemo theOtherMaster) {
123		UserDemo master = (UserDemo) theMaster;
124		UserDemo sec = (UserDemo) theOtherMaster;
125		return sec.getId() == master.getId();
126	}
127
128	public void getMaster(HorizontalViewPanelNoDays<DefaultEventData, UserDemo> caller, DefaultEventData real) {
129		UserDemo test = new UserDemo(real.getMasterId(), "Not set");
130		caller.addRow(test);
131		caller.addEventData(real);
132	}
133
134	@Override
135	public boolean equal(DefaultEventData one, DefaultEventData two) {
136		return one.getIdentifier().equals(two.getIdentifier());
137	}
138
139	@Override
140	public String getId(DefaultEventData data) {
141		return data.getIdentifier();
142	}
143
144	@Override
145	public void getEventsForRange(HorizontalViewPanelNoDays<DefaultEventData, UserDemo> view) {
146		ArrayList<DefaultEventData> found = new ArrayList<DefaultEventData>();
147		java.util.Iterator<DefaultEventData> walker = items.values().iterator();
148		while (walker.hasNext()) {
149			DefaultEventData data = (DefaultEventData) walker.next();
150			found.add(data);
151		}
152		view.setEvents(found);
153	}
154
155	@Override
156	public void addEvent(HorizontalAddCallBackHandler<DefaultEventData, UserDemo> callback) {
157		items.put(callback.getData().getIdentifier(), callback.getData());
158		callback.onSuccess(callback.getData());
159	}
160
161	@Override
162	public void updateEvent(HorizontalUpdateCallBackHandler<DefaultEventData, UserDemo> callback) {
163		items.put(callback.getData().getIdentifier(), callback.getData());
164		callback.succes();
165
166	}
167
168	@Override
169	public void removeEvent(HorizontalRemoveCallBackHandler<DefaultEventData, UserDemo> callback) {
170		items.put(callback.getData().getIdentifier(), callback.getData());
171		callback.succes();
172	}
173
174	private HashMap<String, DefaultEventData> items = new HashMap<String, DefaultEventData>();
175
176	public void addEvent(DefaultEventData example) {
177
178	}
179
180}