KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.swing.*;
27 /**
28  *
29  * @author mkuchtiak
30  */

31 public class BookTreePanelMVElement extends TreePanelMultiViewElement {
32     private TreePanelDesignEditor comp;
33     private BookDataObject dObj;
34     private PanelView view;
35     //private PanelFactory factory;
36

37     /** Creates a new instance of DesignMultiViewElement */
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                 // add panels
70
} catch (java.io.IOException JavaDoc ex) {
71                 System.out.println("ex="+ex);
72                 root.setDisplayName("Invalid Book");
73             }
74             setRoot(root);
75         }
76         /*
77         public void initComponents() {
78             setLayout(new java.awt.BorderLayout());
79             JPanel scrollPanel= new JPanel();
80             scrollPanel.add(new JButton("Hello"));
81             JScrollPane scrollPane = new javax.swing.JScrollPane();
82             scrollPane.setViewportView(scrollPanel);
83             //scrollPane.getVerticalScrollBar().setUnitIncrement(15);
84             //add (scrollPane, java.awt.BorderLayout.CENTER);
85             add(scrollPanel, java.awt.BorderLayout.CENTER);
86         }
87         
88         public void showSelection(Node[] node) {
89             System.out.println("showSelection()");
90         }
91         */

92         public Error JavaDoc validateView() {
93             try {
94                 Book book = dObj.getBook();
95                 String JavaDoc title = book.getTitle();
96                 if (title==null || title.length()==0) {
97                     Error.ErrorLocation JavaDoc loc = new Error.ErrorLocation JavaDoc(book,"title"); //NOI18N
98
return new Error JavaDoc(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 JavaDoc loc = new Error.ErrorLocation JavaDoc(chapters[i],"title");
105                         return new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "Title", loc);
106                     }
107                     for (int j=0;j<chapters.length;j++) {
108                         String JavaDoc tit = chapters[j].getTitle();
109                         if (i!=j && title.equals(tit)) {
110                             Error.ErrorLocation JavaDoc loc = new Error.ErrorLocation JavaDoc(chapters[i],"title");
111                             return new Error JavaDoc(Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, title, loc);
112                         }
113                     }
114                 }
115             } catch (java.io.IOException JavaDoc 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             //setIconBase("org/netbeans/modules/web/dd/multiview/resources/class"); //NOI18N
127
}
128         public TreePanel getPanel() {
129             return new BookTreePanel();
130         }
131         public String JavaDoc 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             //setIconBase("org/netbeans/modules/web/dd/multiview/resources/class"); //NOI18N
146
}
147         public TreePanel getPanel() {
148             return new ChapterTreePanel();
149         }
150         public String JavaDoc getPanelId() {
151             return "chapter";
152         }
153         
154         public Chapter getChapter() {
155             return chapter;
156         }
157     }
158     
159 }
160
Popular Tags