1 package org.netbeans.modules.xml.xam; 2 3 import java.beans.PropertyChangeListener ; 4 import java.beans.PropertyChangeSupport ; 5 import java.io.IOException ; 6 import javax.swing.event.UndoableEditListener ; 7 import org.openide.util.Lookup; 8 import org.openide.util.lookup.Lookups; 9 10 14 public class TestModel extends AbstractModel<TestComponent> implements Model<TestComponent> { 15 TestComponent testRoot; 16 TestAccess access; 17 18 19 public TestModel() { 20 super(createModelSource()); 21 try { 22 super.sync(); 23 } catch(Exception e) { 24 throw new RuntimeException (e); 25 } 26 } 27 28 public static ModelSource createModelSource() { 29 Lookup lookup = Lookups.fixed(new Object [] { } ); 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 pcs = new PropertyChangeSupport (this); 61 62 public void removeUndoableEditListener(UndoableEditListener listener) { 63 } 65 66 public void addUndoableEditListener(UndoableEditListener listener) { 67 } 69 70 public Model.State sync() throws IOException { 71 return Model.State.VALID; 72 } 73 74 public void prepareForUndoRedo() { 75 } 76 77 Long lastFlushTime = null; 78 public void flush() { 79 Long currentTime = new Long (System.currentTimeMillis()); 80 pcs.firePropertyChange("flushed", lastFlushTime, currentTime); 81 lastFlushTime = currentTime; 82 } 83 84 public void finishUndoRedo() { 85 } 86 87 public void addFlushListener(PropertyChangeListener l) { 88 pcs.addPropertyChangeListener(l); 89 } 90 91 public void removeFlushListener(PropertyChangeListener l) { 92 pcs.removePropertyChangeListener(l); 93 } 94 } 95 } 96 | Popular Tags |