KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > multiview > test > BookToolBarMVElement


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /**
27  *
28  * @author mkuchtiak
29  */

30 public class BookToolBarMVElement extends ToolBarMultiViewElement {
31     private ToolBarDesignEditor comp;
32     private SectionView view;
33     private BookDataObject dObj;
34     private PanelFactory factory;
35     
36     /** Creates a new instance of DesignMultiViewElement */
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 JavaDoc 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                 // add panels
80
addSection(new SectionPanel(this,bookNode,book)); //NOI18N
81

82                 SectionContainer chaptersCont = new SectionContainer(this,chaptersNode,"Chapters");
83                 //jspPGCont.setHeaderActions(new javax.swing.Action[]{addAction});
84

85                 // creatings section panels for Chapters
86
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                     //pan[i].setHeaderActions(new javax.swing.Action[]{removeAction});
90
chaptersCont.addSection(pan[i]);
91                 }
92                 addSection(chaptersCont);
93             } catch (java.io.IOException JavaDoc ex) {
94                 System.out.println("ex="+ex);
95                 root.setDisplayName("Invalid Book");
96             }
97             setRoot(root);
98         }
99         
100         public Error JavaDoc validateView() {
101             try {
102                 Book book = dObj.getBook();
103                 String JavaDoc title = book.getTitle();
104                 if (title==null || title.length()==0) {
105                     Error.ErrorLocation JavaDoc loc = new Error.ErrorLocation JavaDoc(book,"title"); //NOI18N
106
return new Error JavaDoc(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 JavaDoc loc = new Error.ErrorLocation JavaDoc(chapters[i],"title");
113                         return new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "Title", loc);
114                     }
115                     for (int j=0;j<chapters.length;j++) {
116                         String JavaDoc tit = chapters[j].getTitle();
117                         if (i!=j && title.equals(tit)) {
118                             Error.ErrorLocation JavaDoc loc = new Error.ErrorLocation JavaDoc(chapters[i],"title");
119                             return new Error JavaDoc(Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, title, loc);
120                         }
121                     }
122                 }
123             } catch (java.io.IOException JavaDoc 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             //setIconBase("org/netbeans/modules/web/dd/multiview/resources/class"); //NOI18N
133
}
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             //setIconBase("org/netbeans/modules/web/dd/multiview/resources/class"); //NOI18N
140
}
141     }
142     
143 }
144
Popular Tags