1 19 package org.netbeans.modules.xml.multiview.test; 20 21 import org.netbeans.modules.xml.multiview.*; 22 import org.netbeans.modules.xml.multiview.ui.*; 23 import org.openide.nodes.*; 24 import org.netbeans.modules.xml.multiview.test.bookmodel.*; 25 import org.netbeans.modules.xml.multiview.Error; 26 import javax.swing.*; 27 31 public class BookTreePanelMVElement extends TreePanelMultiViewElement { 32 private TreePanelDesignEditor comp; 33 private BookDataObject dObj; 34 private PanelView view; 35 37 38 public BookTreePanelMVElement(BookDataObject dObj) { 39 super(dObj); 40 this.dObj=dObj; 41 view = new BookView(dObj); 42 comp = new TreePanelDesignEditor(view); 43 setVisualEditor(comp); 44 } 45 46 public void componentShowing() { 47 super.componentShowing(); 48 } 49 50 private class BookView extends TreePanelView { 51 BookView(BookDataObject dObj) { 52 super(); 53 Children rootChildren = new Children.Array(); 54 Node root = new AbstractNode(rootChildren); 55 try { 56 Book book = dObj.getBook(); 57 Node bookNode = new BookNode(book); 58 59 Chapter[] chapters = book.getChapter(); 60 Node[] chapterNode = new Node[chapters.length]; 61 Children ch = new Children.Array(); 62 for (int i=0;i<chapters.length;i++) { 63 chapterNode[i] = new ChapterNode(chapters[i]); 64 } 65 ch.add(chapterNode); 66 Node chaptersNode = new SectionContainerNode(ch); 67 chaptersNode.setDisplayName("Chapters"); 68 rootChildren.add(new Node[]{bookNode,chaptersNode}); 69 } catch (java.io.IOException ex) { 71 System.out.println("ex="+ex); 72 root.setDisplayName("Invalid Book"); 73 } 74 setRoot(root); 75 } 76 92 public Error validateView() { 93 try { 94 Book book = dObj.getBook(); 95 String title = book.getTitle(); 96 if (title==null || title.length()==0) { 97 Error.ErrorLocation loc = new Error.ErrorLocation (book,"title"); return new Error (Error.MISSING_VALUE_MESSAGE, "Title", loc); 99 } 100 Chapter[] chapters = book.getChapter(); 101 for (int i=0;i<chapters.length;i++) { 102 title = chapters[i].getTitle(); 103 if (title==null || title.length()==0) { 104 Error.ErrorLocation loc = new Error.ErrorLocation (chapters[i],"title"); 105 return new Error (Error.MISSING_VALUE_MESSAGE, "Title", loc); 106 } 107 for (int j=0;j<chapters.length;j++) { 108 String tit = chapters[j].getTitle(); 109 if (i!=j && title.equals(tit)) { 110 Error.ErrorLocation loc = new Error.ErrorLocation (chapters[i],"title"); 111 return new Error (Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, title, loc); 112 } 113 } 114 } 115 } catch (java.io.IOException ex){} 116 return null; 117 } 118 } 119 120 static class BookNode extends org.openide.nodes.AbstractNode implements TreeNode { 121 Book book; 122 BookNode(Book book) { 123 super(org.openide.nodes.Children.LEAF); 124 setDisplayName(book.getTitle()); 125 this.book=book; 126 } 128 public TreePanel getPanel() { 129 return new BookTreePanel(); 130 } 131 public String getPanelId() { 132 return "book"; 133 } 134 135 public Book getBook() { 136 return book; 137 } 138 } 139 static class ChapterNode extends org.openide.nodes.AbstractNode implements TreeNode { 140 private Chapter chapter; 141 ChapterNode(Chapter chapter) { 142 super(org.openide.nodes.Children.LEAF); 143 setDisplayName(chapter.getTitle()); 144 this.chapter=chapter; 145 } 147 public TreePanel getPanel() { 148 return new ChapterTreePanel(); 149 } 150 public String getPanelId() { 151 return "chapter"; 152 } 153 154 public Chapter getChapter() { 155 return chapter; 156 } 157 } 158 159 } 160 | Popular Tags |