01: /*******************************************************************************
02: * Copyright (c) 2007 MyGWT.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Darrell Meyer <darrell@mygwt.net> - initial API and implementation
10: *******************************************************************************/package net.mygwt.ui.client.viewer;
11:
12: import net.mygwt.ui.client.data.ChangeEvent;
13: import net.mygwt.ui.client.data.ChangeListener;
14: import net.mygwt.ui.client.data.Model;
15:
16: /**
17: * A <code>RemoteContentProvider</code> for model instances.
18: */
19: public abstract class ModelRemoteContentProvider extends
20: RemoteContentProvider implements ChangeListener {
21:
22: /**
23: * Specifies if model changes should be monitored. Default value is
24: * <code>true</code>.
25: */
26: public boolean monitorChanges = true;
27:
28: protected Viewer viewer;
29:
30: public void inputChanged(Viewer viewer, Object oldInput,
31: Object newInput) {
32: this .viewer = viewer;
33: if (monitorChanges) {
34: if (oldInput != null) {
35: Model m = (Model) oldInput;
36: m.removeChangeListener(this );
37: }
38: Model m = (Model) newInput;
39: m.addChangeListener(this );
40: }
41: }
42:
43: public void modelChanged(ChangeEvent event) {
44: int type = event.type;
45: switch (type) {
46: case Model.Add: {
47: viewer.add(event.item);
48: break;
49: }
50: case Model.Insert: {
51: viewer.insert(event.item, event.index);
52: break;
53: }
54: case Model.Remove: {
55: viewer.remove(event.item);
56: break;
57: }
58: case Model.Update: {
59: viewer.update(event.item);
60: break;
61: }
62: }
63: }
64:
65: }
|