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 30 public class BookToolBarMVElement extends ToolBarMultiViewElement { 31 private ToolBarDesignEditor comp; 32 private SectionView view; 33 private BookDataObject dObj; 34 private PanelFactory factory; 35 36 37 public BookToolBarMVElement(BookDataObject dObj) { 38 super(dObj); 39 this.dObj=dObj; 40 comp = new ToolBarDesignEditor(); 41 factory=new PanelFactory(comp,dObj); 42 setVisualEditor(comp); 43 } 44 45 public SectionView getSectionView() { 46 return view; 47 } 48 49 public void componentShowing() { 50 super.componentShowing(); 51 view=new BookView(dObj); 52 comp.setContentView(view); 53 try { 54 view.openPanel(dObj.getBook()); 55 } catch(java.io.IOException ex){} 56 view.checkValidity(); 57 } 58 59 private class BookView extends SectionView { 60 BookView(BookDataObject dObj) { 61 super(factory); 62 63 Children rootChildren = new Children.Array(); 64 Node root = new AbstractNode(rootChildren); 65 try { 66 Book book = dObj.getBook(); 67 Node bookNode = new BookNode(book); 68 69 Chapter[] chapters = book.getChapter(); 70 Node[] chapterNode = new Node[chapters.length]; 71 Children ch = new Children.Array(); 72 for (int i=0;i<chapters.length;i++) { 73 chapterNode[i] = new ChapterNode(chapters[i]); 74 } 75 ch.add(chapterNode); 76 Node chaptersNode = new SectionContainerNode(ch); 77 chaptersNode.setDisplayName("Chapters"); 78 rootChildren.add(new Node[]{bookNode,chaptersNode}); 79 addSection(new SectionPanel(this,bookNode,book)); 82 SectionContainer chaptersCont = new SectionContainer(this,chaptersNode,"Chapters"); 83 85 SectionPanel[] pan = new SectionPanel[chapters.length]; 87 for (int i=0;i<chapters.length;i++) { 88 pan[i] = new SectionPanel(this, chapterNode[i], chapters[i]); 89 chaptersCont.addSection(pan[i]); 91 } 92 addSection(chaptersCont); 93 } catch (java.io.IOException ex) { 94 System.out.println("ex="+ex); 95 root.setDisplayName("Invalid Book"); 96 } 97 setRoot(root); 98 } 99 100 public Error validateView() { 101 try { 102 Book book = dObj.getBook(); 103 String title = book.getTitle(); 104 if (title==null || title.length()==0) { 105 Error.ErrorLocation loc = new Error.ErrorLocation (book,"title"); return new Error (Error.MISSING_VALUE_MESSAGE, "Title", loc); 107 } 108 Chapter[] chapters = book.getChapter(); 109 for (int i=0;i<chapters.length;i++) { 110 title = chapters[i].getTitle(); 111 if (title==null || title.length()==0) { 112 Error.ErrorLocation loc = new Error.ErrorLocation (chapters[i],"title"); 113 return new Error (Error.MISSING_VALUE_MESSAGE, "Title", loc); 114 } 115 for (int j=0;j<chapters.length;j++) { 116 String tit = chapters[j].getTitle(); 117 if (i!=j && title.equals(tit)) { 118 Error.ErrorLocation loc = new Error.ErrorLocation (chapters[i],"title"); 119 return new Error (Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, title, loc); 120 } 121 } 122 } 123 } catch (java.io.IOException ex){} 124 return null; 125 } 126 } 127 128 private class BookNode extends org.openide.nodes.AbstractNode { 129 BookNode(Book book) { 130 super(org.openide.nodes.Children.LEAF); 131 setDisplayName(book.getTitle()); 132 } 134 } 135 private class ChapterNode extends org.openide.nodes.AbstractNode { 136 ChapterNode(Chapter chapter) { 137 super(org.openide.nodes.Children.LEAF); 138 setDisplayName(chapter.getTitle()); 139 } 141 } 142 143 } 144 | Popular Tags |