KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xam > TestModel


1 package org.netbeans.modules.xml.xam;
2
3 import java.beans.PropertyChangeListener JavaDoc;
4 import java.beans.PropertyChangeSupport JavaDoc;
5 import java.io.IOException JavaDoc;
6 import javax.swing.event.UndoableEditListener JavaDoc;
7 import org.openide.util.Lookup;
8 import org.openide.util.lookup.Lookups;
9
10 /**
11  *
12  * @author Nam Nguyen
13  */

14 public class TestModel extends AbstractModel<TestComponent> implements Model<TestComponent> {
15     TestComponent testRoot;
16     TestAccess access;
17     
18     /** Creates a new instance of TestModel */
19     public TestModel() {
20         super(createModelSource());
21         try {
22             super.sync();
23         } catch(Exception JavaDoc e) {
24             throw new RuntimeException JavaDoc(e);
25         }
26     }
27     
28     public static ModelSource createModelSource() {
29         Lookup lookup = Lookups.fixed(new Object JavaDoc[] { } );
30         return new ModelSource(lookup, true);
31     }
32     
33     public TestComponent getRootComponent() {
34         if (testRoot == null) {
35             testRoot = new TestComponent(this, 0);
36         }
37         return testRoot;
38     }
39
40     public void addChildComponent(Component target, Component child, int index) {
41         TestComponent parent = (TestComponent) target;
42         TestComponent tc = (TestComponent) child;
43         parent.insertAtIndex(tc.getName(), tc, index > -1 ? index : parent.getChildren().size());
44     }
45
46     public void removeChildComponent(Component child) {
47         TestComponent tc = (TestComponent) child;
48         tc.getParent().removeChild(tc.getName(), tc);
49     }
50
51     
52     public TestAccess getAccess() {
53         if (access == null) {
54             access = new TestAccess();
55         }
56         return access;
57     }
58     
59     public static class TestAccess extends ModelAccess {
60         PropertyChangeSupport JavaDoc pcs = new PropertyChangeSupport JavaDoc(this);
61         
62         public void removeUndoableEditListener(UndoableEditListener JavaDoc listener) {
63             //TODO
64
}
65
66         public void addUndoableEditListener(UndoableEditListener JavaDoc listener) {
67             //TODO
68
}
69
70         public Model.State sync() throws IOException JavaDoc {
71             return Model.State.VALID;
72         }
73
74         public void prepareForUndoRedo() {
75         }
76
77         Long JavaDoc lastFlushTime = null;
78         public void flush() {
79             Long JavaDoc currentTime = new Long JavaDoc(System.currentTimeMillis());
80             pcs.firePropertyChange("flushed", lastFlushTime, currentTime);
81             lastFlushTime = currentTime;
82         }
83
84         public void finishUndoRedo() {
85         }
86         
87         public void addFlushListener(PropertyChangeListener JavaDoc l) {
88             pcs.addPropertyChangeListener(l);
89         }
90         
91         public void removeFlushListener(PropertyChangeListener JavaDoc l) {
92             pcs.removePropertyChangeListener(l);
93         }
94     }
95 }
96
Popular Tags