1 package org.netbeans.modules.xml.xam; 2 3 import java.io.File ; 4 import javax.swing.text.Document ; 5 import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel; 6 import org.netbeans.modules.xml.xam.dom.DocumentModel; 7 import org.netbeans.modules.xml.xam.dom.DocumentModelAccess; 8 import org.netbeans.modules.xml.xam.dom.ReadOnlyAccess; 9 import org.openide.util.Lookup; 10 import org.openide.util.lookup.Lookups; 11 12 16 public class TestModel2 extends AbstractDocumentModel<TestComponent2> implements DocumentModel<TestComponent2> { 17 TestComponent2 testRoot; 18 ReadOnlyAccess access; 19 20 21 public TestModel2(Document doc) { 22 super(Util.createModelSource(doc)); 23 try { 24 super.sync(); 25 } catch(Exception e) { 26 throw new RuntimeException (e); 27 } 28 } 29 30 public TestModel2(ModelSource source) { 31 super(source); 32 } 33 34 private static Factory factory = null; 35 public static Factory factory() { 36 if (factory == null) { 37 factory = new Factory(); 38 } 39 return factory; 40 } 41 42 public static class Factory extends AbstractModelFactory<TestModel2> { 43 private Factory() { 44 super(); 45 } 46 47 protected TestModel2 createModel(ModelSource source) { 48 return new TestModel2(source); 49 } 50 51 public TestModel2 getModel(ModelSource source) { 52 return super.getModel(source); 53 } 54 } 55 56 public TestComponent2 getRootComponent() { 57 if (testRoot == null) { 58 testRoot = new TestComponent2(this, "test"); 59 } 60 return testRoot; 61 } 62 63 public void addChildComponent(Component target, Component child, int index) { 64 TestComponent2 parent = (TestComponent2) target; 65 TestComponent2 tc = (TestComponent2) child; 66 parent.insertAtIndex(tc.getName(), tc, index > -1 ? index : parent.getChildren().size()); 67 } 68 69 public void removeChildComponent(Component child) { 70 TestComponent2 tc = (TestComponent2) child; 71 tc.getParent().removeChild(tc.getName(), tc); 72 } 73 74 75 public DocumentModelAccess getAccess() { 76 if (access == null) { 77 access = new ReadOnlyAccess(this); 78 } 79 return access; 80 } 81 82 public TestComponent2 createRootComponent(org.w3c.dom.Element root) { 83 if (TestComponent2.NS_URI.equals(root.getNamespaceURI()) && 84 "test".equals(root.getLocalName())) { 85 testRoot = new TestComponent2(this, root); 86 } else { 87 testRoot = null; 88 } 89 return testRoot; 90 } 91 92 public TestComponent2 createComponent(TestComponent2 parent, org.w3c.dom.Element element) { 93 return TestComponent2.createComponent(this, parent, element); 94 } 95 96 protected ComponentUpdater<TestComponent2> getComponentUpdater() { 97 return null; 98 } 99 100 } 101 | Popular Tags |