View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.oodt.profile.gui;
19  
20  import javax.swing.JSeparator;
21  import javax.swing.JMenuItem;
22  import javax.swing.JMenu;
23  import javax.swing.JMenuBar;
24  import javax.swing.JPanel;
25  import javax.swing.JEditorPane;
26  import javax.swing.JScrollPane;
27  import java.awt.event.ActionListener;
28  import java.awt.event.ActionEvent;
29  import java.awt.BorderLayout;
30  import javax.swing.tree.DefaultTreeModel;
31  import javax.swing.tree.DefaultMutableTreeNode;
32  import javax.swing.tree.TreeNode;
33  import javax.swing.tree.TreeModel;
34  import javax.swing.JFileChooser;
35  
36  import org.apache.oodt.profile.Profile;
37  import org.apache.oodt.profile.ProfileElement;
38  import org.apache.oodt.profile.RangedProfileElement;
39  import org.apache.oodt.profile.gui.profileTree;
40  
41  import org.apache.oodt.profile.gui.pstructs.ProfilePrinter;
42  
43  
44  import java.util.Iterator;
45  import java.util.Enumeration;
46  import java.util.List;
47  
48  
49  import java.io.File;
50  import java.io.FileOutputStream;
51  import java.io.FileReader;
52  import java.io.FileNotFoundException;
53  import java.io.IOException;
54  
55  import javax.swing.JButton;
56  import org.xml.sax.SAXException;
57  
58  /**
59  * This code was generated using CloudGarden's Jigloo
60  * SWT/Swing GUI Builder, which is free for non-commercial
61  * use. If Jigloo is being used commercially (ie, by a
62  * for-profit company or business) then you should purchase
63  * a license - please visit www.cloudgarden.com for details.
64  */
65  public class ProfileBuilderGUI extends javax.swing.JFrame {
66  	private JButton jButton1;
67  	private JEditorPane jEditorPane1;
68  	private JScrollPane jPanel3;
69  	private profileTree jTree1;
70  	private JScrollPane jPanel2;
71  	private JPanel jPanel1;
72  	private JMenuItem helpMenuItem;
73  	private JMenu jMenu5;
74  	private JMenuItem deleteMenuItem;
75  	private JSeparator jSeparator1;
76  	private JMenuItem pasteMenuItem;
77  	private JMenuItem copyMenuItem;
78  	private JMenuItem cutMenuItem;
79  	private JMenu jMenu4;
80  	private JMenuItem exitMenuItem;
81  	private JSeparator jSeparator2;
82  	private JMenuItem closeFileMenuItem;
83  	private JMenuItem saveMenuItem;
84  	private JMenuItem openFileMenuItem;
85  	private JMenuItem newFileMenuItem;
86  	private JMenu jMenu3;
87  	private JMenuBar jMenuBar1;
88  	
89  	private Profile createdProfile=null;
90  	
91  
92  	public ProfileBuilderGUI() {
93  		initGUI();
94  	}
95  
96  	/**
97  	* Initializes the GUI.
98  	* Auto-generated code - any changes you make will disappear.
99  	*/
100 	public void initGUI(){
101 		try {
102 			preInitGUI();
103 	
104 			try {
105 				javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
106 			} catch(Exception e) {
107 				e.printStackTrace();
108 			}
109 			jPanel1 = new JPanel();
110 			jPanel2 = new JScrollPane();
111 			jTree1 = new profileTree();
112 			jPanel3 = new JScrollPane();
113 			jEditorPane1 = new JEditorPane();
114 			jButton1 = new JButton();
115 	
116 			BorderLayout thisLayout = new BorderLayout();
117 			this.getContentPane().setLayout(thisLayout);
118 			thisLayout.setHgap(0);
119 			thisLayout.setVgap(0);
120 			this.setTitle("OODT Profile Builder");
121 			this.setSize(new java.awt.Dimension(682,387));
122 	
123 			BorderLayout jPanel1Layout = new BorderLayout();
124 			jPanel1.setLayout(jPanel1Layout);
125 			jPanel1Layout.setHgap(0);
126 			jPanel1Layout.setVgap(0);
127 			this.getContentPane().add(jPanel1, BorderLayout.CENTER);
128 	
129 			jPanel2.setPreferredSize(new java.awt.Dimension(231,339));
130 			jPanel2.setAutoscrolls(true);
131 			jPanel1.add(jPanel2, BorderLayout.WEST);
132 	
133 			jTree1.setEditable(true);
134 			jTree1.setPreferredSize(new java.awt.Dimension(426,800));
135 			jTree1.setAutoscrolls(true);
136 			jTree1.setMaximumSize(new java.awt.Dimension(426,800));
137 			jTree1.setOpaque(true);
138 			jTree1.setSize(new java.awt.Dimension(426,800));
139 			jPanel2.add(jTree1);
140 			jPanel2.setViewportView(jTree1);
141 	
142 			jPanel3.setPreferredSize(new java.awt.Dimension(444,339));
143 			jPanel3.setAutoscrolls(true);
144 			jPanel1.add(jPanel3, BorderLayout.EAST);
145 	
146 			jEditorPane1.setEditable(false);
147 			jEditorPane1.setPreferredSize(new java.awt.Dimension(414,320));
148 			jEditorPane1.setAutoscrolls(true);
149 			jPanel3.add(jEditorPane1);
150 			jPanel3.setViewportView(jEditorPane1);
151 	
152 			jButton1.setText("Show XML");
153 			this.getContentPane().add(jButton1, BorderLayout.SOUTH);
154 			jButton1.addActionListener( new ActionListener() {
155 				public void actionPerformed(ActionEvent evt) {
156 					jButton1ActionPerformed(evt);
157 				}
158 			});
159 			jMenuBar1 = new JMenuBar();
160 			jMenu3 = new JMenu();
161 			newFileMenuItem = new JMenuItem();
162 			openFileMenuItem = new JMenuItem();
163 			saveMenuItem = new JMenuItem();
164 			closeFileMenuItem = new JMenuItem();
165 			jSeparator2 = new JSeparator();
166 			exitMenuItem = new JMenuItem();
167 			jMenu4 = new JMenu();
168 			cutMenuItem = new JMenuItem();
169 			copyMenuItem = new JMenuItem();
170 			pasteMenuItem = new JMenuItem();
171 			jSeparator1 = new JSeparator();
172 			deleteMenuItem = new JMenuItem();
173 			jMenu5 = new JMenu();
174 			helpMenuItem = new JMenuItem();
175 	
176 			setJMenuBar(jMenuBar1);
177 	
178 			jMenu3.setText("File");
179 			jMenu3.setVisible(true);
180 			jMenuBar1.add(jMenu3);
181 	
182 			newFileMenuItem.setText("New Profile");
183 			newFileMenuItem.setVisible(true);
184 			newFileMenuItem.setPreferredSize(new java.awt.Dimension(28,16));
185 			newFileMenuItem.setBounds(new java.awt.Rectangle(5,5,28,16));
186 			jMenu3.add(newFileMenuItem);
187 			newFileMenuItem.addActionListener( new ActionListener() {
188 				public void actionPerformed(ActionEvent evt) {
189 					newFileMenuItemActionPerformed(evt);
190 				}
191 			});
192 	
193 			openFileMenuItem.setText("Open Profile");
194 			openFileMenuItem.setVisible(true);
195 			openFileMenuItem.setBounds(new java.awt.Rectangle(5,5,60,30));
196 			jMenu3.add(openFileMenuItem);
197 			openFileMenuItem.addActionListener( new ActionListener() {
198 				public void actionPerformed(ActionEvent evt) {
199 					openFileMenuItemActionPerformed(evt);
200 				}
201 			});
202 	
203 			saveMenuItem.setText("Save Profile");
204 			saveMenuItem.setVisible(true);
205 			saveMenuItem.setVerifyInputWhenFocusTarget(false);
206 			saveMenuItem.setBounds(new java.awt.Rectangle(5,5,60,30));
207 			jMenu3.add(saveMenuItem);
208 			saveMenuItem.addActionListener( new ActionListener() {
209 				public void actionPerformed(ActionEvent evt) {
210 					saveMenuItemActionPerformed(evt);
211 				}
212 			});
213 	
214 			closeFileMenuItem.setText("Close");
215 			closeFileMenuItem.setVisible(true);
216 			closeFileMenuItem.setBounds(new java.awt.Rectangle(5,5,60,30));
217 			jMenu3.add(closeFileMenuItem);
218 	
219 			jSeparator2.setVisible(true);
220 			jSeparator2.setBounds(new java.awt.Rectangle(5,5,60,30));
221 			jMenu3.add(jSeparator2);
222 	
223 			exitMenuItem.setText("Exit");
224 			exitMenuItem.setVisible(true);
225 			exitMenuItem.setBounds(new java.awt.Rectangle(5,5,60,30));
226 			jMenu3.add(exitMenuItem);
227 			exitMenuItem.addActionListener( new ActionListener() {
228 				public void actionPerformed(ActionEvent evt) {
229 					exitMenuItemActionPerformed(evt);
230 				}
231 			});
232 	
233 			jMenu4.setText("Edit");
234 			jMenu4.setVisible(true);
235 			jMenuBar1.add(jMenu4);
236 	
237 			cutMenuItem.setText("Cut");
238 			cutMenuItem.setVisible(true);
239 			cutMenuItem.setPreferredSize(new java.awt.Dimension(27,16));
240 			cutMenuItem.setBounds(new java.awt.Rectangle(5,5,27,16));
241 			jMenu4.add(cutMenuItem);
242 	
243 			copyMenuItem.setText("Copy");
244 			copyMenuItem.setVisible(true);
245 			copyMenuItem.setBounds(new java.awt.Rectangle(5,5,60,30));
246 			jMenu4.add(copyMenuItem);
247 	
248 			pasteMenuItem.setText("Paste");
249 			pasteMenuItem.setVisible(true);
250 			pasteMenuItem.setBounds(new java.awt.Rectangle(5,5,60,30));
251 			jMenu4.add(pasteMenuItem);
252 	
253 			jSeparator1.setVisible(true);
254 			jSeparator1.setBounds(new java.awt.Rectangle(5,5,60,30));
255 			jMenu4.add(jSeparator1);
256 	
257 			deleteMenuItem.setText("Delete");
258 			deleteMenuItem.setVisible(true);
259 			deleteMenuItem.setBounds(new java.awt.Rectangle(5,5,60,30));
260 			jMenu4.add(deleteMenuItem);
261 	
262 			jMenu5.setText("Help");
263 			jMenu5.setVisible(true);
264 			jMenuBar1.add(jMenu5);
265 	
266 			helpMenuItem.setText("Help");
267 			helpMenuItem.setVisible(true);
268 			helpMenuItem.setPreferredSize(new java.awt.Dimension(31,16));
269 			helpMenuItem.setBounds(new java.awt.Rectangle(5,5,31,16));
270 			jMenu5.add(helpMenuItem);
271 	
272 			postInitGUI();
273 		} catch (Exception e) {
274 			e.printStackTrace();
275 		}
276 	}
277 	/** Add your pre-init code in here 	*/
278 	public void preInitGUI(){
279 	}
280 
281 	/** Add your post-init code in here 	*/
282 	public void postInitGUI(){
283 	}
284 
285 	/** Auto-generated main method */
286 	public static void main(String[] args){
287 		//showGUI();
288 		showMainGUI();
289 	}
290 
291 	public static void showMainGUI(){
292 		try {
293 			ProfileBuilderGUI inst = new ProfileBuilderGUI();
294 			inst.setVisible(true);
295 			inst.getJTree1().addMouseListener(new LeafListener(inst.getJTree1()));
296 		    inst.getJTree1().setExpandsSelectedPaths(true);
297 		} catch (Exception e) {
298 			e.printStackTrace();
299 		}
300 	}
301 
302 
303 
304 	
305 	
306 	
307 	/**
308 	* This static method creates a new instance of this class and shows
309 	* it inside a new JFrame, (unless it is already a JFrame).
310 	*
311 	* It is a convenience method for showing the GUI, but it can be
312 	* copied and used as a basis for your own code.	*
313 	* It is auto-generated code - the body of this method will be
314 	* re-generated after any changes are made to the GUI.
315 	* However, if you delete this method it will not be re-created.	*/
316 	public static void showGUI(){
317 		try {
318 			ProfileBuilderGUI inst = new ProfileBuilderGUI();
319 			inst.setVisible(true);
320 		} catch (Exception e) {
321 			e.printStackTrace();
322 		}
323 	}
324 /**
325 * Auto-generated method
326 */public JPanel getJPanel1(){
327 return jPanel1;	}
328 /**
329 * Auto-generated method
330 */public JScrollPane getJPanel2(){
331 return jPanel2;	}
332 /**
333 * Auto-generated method
334 */public profileTree getJTree1(){
335 return jTree1;	}
336 
337 public void setJTree1(profileTree jt){
338 	jTree1 = jt;
339 	repaint();
340 }
341 /**
342 * Auto-generated method
343 */public JScrollPane getJPanel3(){
344 return jPanel3;	}
345 /**
346 * Auto-generated method
347 */public JEditorPane getJEditorPane1(){
348 return jEditorPane1;	}
349 
350 
351 
352 	/** Auto-generated event handler method */
353 	protected void newFileMenuItemActionPerformed(ActionEvent evt){
354 		//TODO add your handler code here
355 		
356 			createdProfile = new Profile();
357 			jEditorPane1.setText(new ProfilePrinter(createdProfile,"http://oodt.jpl.nasa.gov/dtd/prof.dtd").toXMLString());
358 			
359 			getJTree1().setModel(generateModelFromProfile(createdProfile));
360 			//getJTree1().addMouseListener(new LeafListener(getJTree1()));
361 	}
362 
363 	/** Auto-generated event handler method */
364 	protected void exitMenuItemActionPerformed(ActionEvent evt){
365 		//TODO add your handler code here
366 		System.exit(1);
367 	}
368 	
369 	private void addElementsFromTreeNode(TreeNode t, List multiValueElem){
370 		for(Enumeration i = t.children(); i.hasMoreElements(); ){
371             DefaultMutableTreeNode theNode = (DefaultMutableTreeNode)i.nextElement();
372             
373             String theStr = (String)theNode.getUserObject();
374             multiValueElem.add(theStr);    
375 		}
376 	}
377 	
378 	
379 	
380 	private Profile generateProfileFromModel(TreeModel dtm){
381 		
382 		Profile p = new Profile();
383 		DefaultMutableTreeNode theProfileRoot = (DefaultMutableTreeNode)dtm.getRoot();
384 		
385 		//get the profile attributes
386 		//children List
387 		//id String
388 		//parent String
389 		//regAuthority String
390 		//revisionNotes List
391 		//securityType String
392 		//statusID String
393 		//type String
394 		//version String
395 		TreeNode theProfAttrRoot = theProfileRoot.getChildAt(0);
396 
397 		TreeNode theProfAttr_Children = theProfAttrRoot.getChildAt(0);
398 		addElementsFromTreeNode(theProfAttr_Children,p.getProfileAttributes().getChildren());
399 
400 		TreeNode theProfAttr_IDRoot = theProfAttrRoot.getChildAt(1);
401 		DefaultMutableTreeNode theProfAttr_ID = (DefaultMutableTreeNode)theProfAttr_IDRoot.getChildAt(0);
402 		p.getProfileAttributes().setID((String)theProfAttr_ID.getUserObject());
403 		
404 		TreeNode theProfAttr_ParentRoot = theProfAttrRoot.getChildAt(2);
405 		DefaultMutableTreeNode theProfAttr_Parent = (DefaultMutableTreeNode)theProfAttr_ParentRoot.getChildAt(0);
406 		p.getProfileAttributes().setParent((String)theProfAttr_Parent.getUserObject());
407 		
408 		
409 		TreeNode theProfAttr_RegAuthorityRoot = theProfAttrRoot.getChildAt(3);
410 		DefaultMutableTreeNode theProfAttr_RegAuthority = (DefaultMutableTreeNode)theProfAttr_RegAuthorityRoot.getChildAt(0);
411 		p.getProfileAttributes().setRegAuthority((String)theProfAttr_RegAuthority.getUserObject());
412 		
413 		TreeNode theProfAttr_revNotes = theProfAttrRoot.getChildAt(4);
414 		addElementsFromTreeNode(theProfAttr_revNotes,p.getProfileAttributes().getRevisionNotes());
415 
416 		TreeNode theProfAttr_SecurityTypeRoot = theProfAttrRoot.getChildAt(5);
417 		DefaultMutableTreeNode theProfAttr_SecurityType = (DefaultMutableTreeNode)theProfAttr_SecurityTypeRoot.getChildAt(0);
418 		p.getProfileAttributes().setSecurityType((String)theProfAttr_SecurityType.getUserObject());
419 		
420 		TreeNode theProfAttr_StatusIDRoot = theProfAttrRoot.getChildAt(6);
421 		DefaultMutableTreeNode theProfAttr_StatusID = (DefaultMutableTreeNode)theProfAttr_StatusIDRoot.getChildAt(0);
422 		p.getProfileAttributes().setStatusID((String)theProfAttr_StatusID.getUserObject());
423 		
424 		TreeNode theProfAttr_TypeRoot = theProfAttrRoot.getChildAt(7);
425 		DefaultMutableTreeNode theProfAttr_Type = (DefaultMutableTreeNode)theProfAttr_TypeRoot.getChildAt(0);
426 		p.getProfileAttributes().setType((String)theProfAttr_Type.getUserObject());
427 		
428 		TreeNode theProfAttr_VersionRoot = theProfAttrRoot.getChildAt(8);
429 		DefaultMutableTreeNode theProfAttr_Version = (DefaultMutableTreeNode)theProfAttr_VersionRoot.getChildAt(0);
430 		p.getProfileAttributes().setVersion((String)theProfAttr_Version.getUserObject());
431 				
432 
433 		//resource attributes
434 		//aggregation - string
435 		//class - string
436 		//contexts - list
437 		//contributors - list
438 		//coverages - list
439 		//creators - list
440 		//dates - list
441 		//description - string
442 		//formats - list
443 		//identifier - string
444 		//languages - list
445 		//locations - list
446 		//publishers - list
447 		//relations - list
448 		//rights - list
449 		//sources - list
450 		//subjects - list
451 		//title - string
452 		//types - list
453 		
454 		TreeNode theResAttrRoot = theProfileRoot.getChildAt(1);
455 		
456 		TreeNode ra_aggRoot=theResAttrRoot.getChildAt(0);
457 		TreeNode ra_classRoot=theResAttrRoot.getChildAt(1);
458 		TreeNode ra_contextRoot=theResAttrRoot.getChildAt(2);
459 		TreeNode ra_contribRoot=theResAttrRoot.getChildAt(3);
460 		TreeNode ra_coverageRoot=theResAttrRoot.getChildAt(4);
461 		TreeNode ra_creatorRoot=theResAttrRoot.getChildAt(5);
462 		TreeNode ra_datesRoot=theResAttrRoot.getChildAt(6);
463 		TreeNode ra_descRoot=theResAttrRoot.getChildAt(7);
464 		TreeNode ra_formatsRoot=theResAttrRoot.getChildAt(8);
465 		TreeNode ra_identifierRoot=theResAttrRoot.getChildAt(9);
466 		TreeNode ra_langRoot=theResAttrRoot.getChildAt(10);
467 		TreeNode ra_locationRoot=theResAttrRoot.getChildAt(11);
468 		TreeNode ra_publishersRoot=theResAttrRoot.getChildAt(12);
469 		TreeNode ra_relationsRoot=theResAttrRoot.getChildAt(13);
470 		TreeNode ra_rightsRoot=theResAttrRoot.getChildAt(14);
471 		TreeNode ra_sourcesRoot=theResAttrRoot.getChildAt(15);
472 		TreeNode ra_subjectsRoot=theResAttrRoot.getChildAt(16);
473 		TreeNode ra_titleRoot=theResAttrRoot.getChildAt(17);
474 		TreeNode ra_typesRoot=theResAttrRoot.getChildAt(18);
475 		
476 		DefaultMutableTreeNode ra_agg = (DefaultMutableTreeNode)ra_aggRoot.getChildAt(0);
477 		DefaultMutableTreeNode ra_class = (DefaultMutableTreeNode)ra_classRoot.getChildAt(0);
478 		
479 		
480 		p.getResourceAttributes().setResAggregation((String)ra_agg.getUserObject());
481 		p.getResourceAttributes().setResClass((String)ra_class.getUserObject());
482 		addElementsFromTreeNode(ra_contextRoot,p.getResourceAttributes().getResContexts());
483 		addElementsFromTreeNode(ra_contribRoot,p.getResourceAttributes().getContributors());
484 		addElementsFromTreeNode(ra_coverageRoot,p.getResourceAttributes().getCoverages());
485 		addElementsFromTreeNode(ra_creatorRoot,p.getResourceAttributes().getCreators());
486 		addElementsFromTreeNode(ra_datesRoot,p.getResourceAttributes().getDates());
487 		
488 		DefaultMutableTreeNode ra_desc = (DefaultMutableTreeNode)ra_descRoot.getChildAt(0);
489 		DefaultMutableTreeNode ra_identifier = (DefaultMutableTreeNode)ra_identifierRoot.getChildAt(0);
490 		
491 		p.getResourceAttributes().setDescription((String)ra_desc.getUserObject());
492 		p.getResourceAttributes().setIdentifier((String)ra_identifier.getUserObject());
493 		
494 		addElementsFromTreeNode(ra_formatsRoot,p.getResourceAttributes().getFormats());
495 		addElementsFromTreeNode(ra_langRoot,p.getResourceAttributes().getLanguages());
496 		addElementsFromTreeNode(ra_locationRoot,p.getResourceAttributes().getResLocations());
497 		addElementsFromTreeNode(ra_publishersRoot,p.getResourceAttributes().getPublishers());
498 		addElementsFromTreeNode(ra_relationsRoot,p.getResourceAttributes().getRelations());
499 		addElementsFromTreeNode(ra_rightsRoot,p.getResourceAttributes().getRights());
500 		addElementsFromTreeNode(ra_sourcesRoot,p.getResourceAttributes().getSources());
501 		addElementsFromTreeNode(ra_subjectsRoot,p.getResourceAttributes().getSubjects());
502 		addElementsFromTreeNode(ra_typesRoot,p.getResourceAttributes().getTypes());
503 		
504 		DefaultMutableTreeNode ra_title = (DefaultMutableTreeNode)ra_titleRoot.getChildAt(0);
505 		p.getResourceAttributes().setTitle((String)ra_title.getUserObject());
506 		
507 		//handle profile elements here
508 		TreeNode theProfElemRoot = theProfileRoot.getChildAt(2);
509 		
510 		for(Enumeration e = theProfElemRoot.children(); e.hasMoreElements(); ){
511 			DefaultMutableTreeNode profElemN_Root = (DefaultMutableTreeNode)e.nextElement();
512 			System.out.println("Got Profile Element "+(String)profElemN_Root.getUserObject());
513 			ProfileElement profElem = makeProfileElementFromTreeNode(p,profElemN_Root);
514 			
515 			if(profElem != null){
516 				System.out.println("Making profile element");
517 				System.out.println(profElem.toString());
518 				
519 				p.getProfileElements().put((String)profElemN_Root.getUserObject(),profElem);
520 			}
521 			
522 			
523 		}
524 		
525 		
526 		return p;
527 	}
528 	
529 	private ProfileElement makeProfileElementFromTreeNode(Profile theProfile,DefaultMutableTreeNode tn){
530 		
531 		ProfileElement theProfileElement = new RangedProfileElement(theProfile);
532 		
533 		DefaultMutableTreeNode commentRoot = (DefaultMutableTreeNode)tn.getChildAt(0);
534 		DefaultMutableTreeNode descRoot = (DefaultMutableTreeNode)tn.getChildAt(1);
535 		DefaultMutableTreeNode idRoot = (DefaultMutableTreeNode)tn.getChildAt(2);
536 		DefaultMutableTreeNode moRoot = (DefaultMutableTreeNode)tn.getChildAt(3);
537 		DefaultMutableTreeNode synRoot = (DefaultMutableTreeNode)tn.getChildAt(4);
538 		DefaultMutableTreeNode typeRoot = (DefaultMutableTreeNode)tn.getChildAt(5);
539 		DefaultMutableTreeNode unitRoot = (DefaultMutableTreeNode)tn.getChildAt(6);
540 		
541 		DefaultMutableTreeNode pe_Comments = (DefaultMutableTreeNode)commentRoot.getChildAt(0);
542 		DefaultMutableTreeNode pe_desc = (DefaultMutableTreeNode)descRoot.getChildAt(0);
543 		DefaultMutableTreeNode pe_id = (DefaultMutableTreeNode)idRoot.getChildAt(0);
544 		DefaultMutableTreeNode pe_mo = (DefaultMutableTreeNode)moRoot.getChildAt(0);
545 		DefaultMutableTreeNode pe_type = (DefaultMutableTreeNode)typeRoot.getChildAt(0);
546 		DefaultMutableTreeNode pe_unit = (DefaultMutableTreeNode)unitRoot.getChildAt(0);
547 		
548 		addElementsFromTreeNode(synRoot,theProfileElement.getSynonyms());
549 		
550 		theProfileElement.setName((String)tn.getUserObject());
551 		theProfileElement.setComments((String)pe_Comments.getUserObject());
552 		theProfileElement.setDescription((String)pe_desc.getUserObject());
553 		theProfileElement.setID((String)pe_id.getUserObject());
554 		theProfileElement.setMaxOccurrence(Integer.parseInt((String)pe_mo.getUserObject()));
555 		theProfileElement.setType((String)pe_type.getUserObject());
556 		theProfileElement.setUnit((String)pe_unit.getUserObject());
557 		
558 		return theProfileElement;
559 		
560 		//return new RangedProfileElement(new Profile());
561 	}
562 	
563 	
564 	
565 	private DefaultTreeModel generateModelFromProfile(Profile p){
566 		DefaultMutableTreeNode root = new DefaultMutableTreeNode("Profile");
567 		DefaultMutableTreeNode resAttrRoot = new DefaultMutableTreeNode("Resource Attributes");
568 		DefaultMutableTreeNode profAttrRoot = new DefaultMutableTreeNode("Profile Attributes");
569 		DefaultMutableTreeNode profElemRoot = new DefaultMutableTreeNode("Profile Elements");
570 		
571 		//do the Profile Attributes here
572 		//children List
573 		//id String
574 		//parent String
575 		//regAuthority String
576 		//revisionNotes List
577 		//securityType String
578 		//statusID String
579 		//type String
580 		//version String
581 		
582 		DefaultMutableTreeNode profAttr_children = new DefaultMutableTreeNode("Children");
583 		
584 		for(Iterator i = p.getProfileAttributes().getChildren().iterator(); i.hasNext(); ){
585 			String theChild = (String)i.next();
586 			
587 			DefaultMutableTreeNode profAttr_childN = new DefaultMutableTreeNode(theChild);
588 			profAttr_children.add(profAttr_childN);
589 		}
590 		
591 		
592 		DefaultMutableTreeNode profAttr_id = new DefaultMutableTreeNode("Id");
593 		profAttr_id.add(new DefaultMutableTreeNode(p.getProfileAttributes().getID()));
594 
595 		DefaultMutableTreeNode profAttr_parent = new DefaultMutableTreeNode("Parent");
596 		profAttr_parent.add(new DefaultMutableTreeNode(p.getProfileAttributes().getParent()));		
597 
598 		DefaultMutableTreeNode profAttr_regAuth = new DefaultMutableTreeNode("Registration Authority");
599 		profAttr_regAuth.add(new DefaultMutableTreeNode(p.getProfileAttributes().getRegAuthority()));		
600 		
601 		DefaultMutableTreeNode profAttr_revNotes = new DefaultMutableTreeNode("Revision Notes");
602 		
603 		for(Iterator i = p.getProfileAttributes().getRevisionNotes().iterator(); i.hasNext(); ){
604 			String revNoteString = (String)i.next();
605 			
606 			DefaultMutableTreeNode revNote_Child = new DefaultMutableTreeNode(revNoteString);
607 			profAttr_revNotes.add(revNote_Child);
608 		}
609 
610 		DefaultMutableTreeNode profAttr_securityType = new DefaultMutableTreeNode("Security Type");
611 		profAttr_securityType.add(new DefaultMutableTreeNode(p.getProfileAttributes().getSecurityType()));		
612 		
613 		DefaultMutableTreeNode profAttr_statusID = new DefaultMutableTreeNode("Status ID");
614 		profAttr_statusID.add(new DefaultMutableTreeNode(p.getProfileAttributes().getStatusID()));		
615 		
616 		DefaultMutableTreeNode profAttr_type = new DefaultMutableTreeNode("Type");
617 		profAttr_type.add(new DefaultMutableTreeNode(p.getProfileAttributes().getType()));		
618 		
619 		DefaultMutableTreeNode profAttr_version = new DefaultMutableTreeNode("Version");
620 		profAttr_version.add(new DefaultMutableTreeNode(p.getProfileAttributes().getVersion()));		
621 		
622 		profAttrRoot.add(profAttr_children);
623 		profAttrRoot.add(profAttr_id);
624 		profAttrRoot.add(profAttr_parent);
625 		profAttrRoot.add(profAttr_regAuth);
626 		profAttrRoot.add(profAttr_revNotes);
627 		profAttrRoot.add(profAttr_securityType);
628 		profAttrRoot.add(profAttr_statusID);
629 		profAttrRoot.add(profAttr_type);
630 		profAttrRoot.add(profAttr_version);
631 		
632 		//resource attributes
633 		//aggregation - string
634 		//class - string
635 		//contexts - list
636 		//contributors - list
637 		//coverages - list
638 		//creators - list
639 		//dates - list
640 		//description - string
641 		//formats - list
642 		//identifier - string
643 		//languages - list
644 		//locations - list
645 		//publishers - list
646 		//relations - list
647 		//rights - list
648 		//sources - list
649 		//subjects - list
650 		//title - string
651 		//types - list
652 		
653 		DefaultMutableTreeNode resAttr_aggregation = new DefaultMutableTreeNode("Aggregation");
654 		resAttr_aggregation.add(new DefaultMutableTreeNode(p.getResourceAttributes().getResAggregation()));		
655 
656 		DefaultMutableTreeNode resAttr_class = new DefaultMutableTreeNode("Class");
657 		resAttr_class.add(new DefaultMutableTreeNode(p.getResourceAttributes().getResClass()));		
658 		
659 		
660 		DefaultMutableTreeNode resAttr_contexts = new DefaultMutableTreeNode("Contexts");
661 		
662 		for(Iterator i = p.getResourceAttributes().getResContexts().iterator(); i.hasNext(); ){
663 			String theContext = (String)i.next();
664 			
665 			DefaultMutableTreeNode resAttr_contextN = new DefaultMutableTreeNode(theContext);
666 			resAttr_contexts.add(resAttr_contextN);
667 		}
668 
669 		DefaultMutableTreeNode resAttr_contributors = new DefaultMutableTreeNode("Contributors");
670 		
671 		for(Iterator i = p.getResourceAttributes().getContributors().iterator(); i.hasNext(); ){
672 			String theContributor = (String)i.next();
673 			
674 			DefaultMutableTreeNode resAttr_contribN = new DefaultMutableTreeNode(theContributor);
675 			resAttr_contributors.add(resAttr_contribN);
676 		}
677 		
678 		DefaultMutableTreeNode resAttr_coverages = new DefaultMutableTreeNode("Coverages");
679 		
680 		for(Iterator i = p.getResourceAttributes().getCoverages().iterator(); i.hasNext(); ){
681 			String theCoverage = (String)i.next();
682 			
683 			DefaultMutableTreeNode resAttr_coverageN= new DefaultMutableTreeNode(theCoverage);
684 			resAttr_coverages.add(resAttr_coverageN);
685 		}
686 		
687 		DefaultMutableTreeNode resAttr_creators = new DefaultMutableTreeNode("Creators");
688 		
689 		for(Iterator i = p.getResourceAttributes().getCreators().iterator(); i.hasNext(); ){
690 			String theCreator = (String)i.next();
691 			
692 			DefaultMutableTreeNode resAttr_creatorN = new DefaultMutableTreeNode(theCreator);
693 			resAttr_creators.add(resAttr_creatorN);
694 		}
695 
696 		DefaultMutableTreeNode resAttr_dates = new DefaultMutableTreeNode("Dates");
697 		
698 		for(Iterator i = p.getResourceAttributes().getDates().iterator(); i.hasNext(); ){
699 			String theDate = (String)i.next();
700 			
701 			DefaultMutableTreeNode resAttr_dateN = new DefaultMutableTreeNode(theDate);
702 			resAttr_dates.add(resAttr_dateN);
703 		}
704 	
705 		DefaultMutableTreeNode resAttr_description = new DefaultMutableTreeNode("Description");
706 		resAttr_description.add(new DefaultMutableTreeNode(p.getResourceAttributes().getDescription()));		
707 
708 		DefaultMutableTreeNode resAttr_formats = new DefaultMutableTreeNode("Formats");
709 		
710 		for(Iterator i = p.getResourceAttributes().getFormats().iterator(); i.hasNext(); ){
711 			String theFormat = (String)i.next();
712 			
713 			DefaultMutableTreeNode resAttr_formatN = new DefaultMutableTreeNode(theFormat);
714 			resAttr_formats.add(resAttr_formatN);
715 		}
716 		
717 		DefaultMutableTreeNode resAttr_identifier = new DefaultMutableTreeNode("Identifier");
718 		resAttr_identifier.add(new DefaultMutableTreeNode(p.getResourceAttributes().getIdentifier()));		
719 
720 		DefaultMutableTreeNode resAttr_languages = new DefaultMutableTreeNode("Languages");
721 		
722 		for(Iterator i = p.getResourceAttributes().getLanguages().iterator(); i.hasNext(); ){
723 			String theLanguage = (String)i.next();
724 			
725 			DefaultMutableTreeNode resAttr_langN = new DefaultMutableTreeNode(theLanguage);
726 			resAttr_languages.add(resAttr_langN);
727 		}
728 		
729 		DefaultMutableTreeNode resAttr_locations = new DefaultMutableTreeNode("Resource Locations");
730 		
731 		for(Iterator i = p.getResourceAttributes().getResLocations().iterator(); i.hasNext(); ){
732 			String theLoc = (String)i.next();
733 			
734 			DefaultMutableTreeNode resAttr_locN = new DefaultMutableTreeNode(theLoc);
735 			resAttr_locations.add(resAttr_locN);
736 		}
737 
738 		DefaultMutableTreeNode resAttr_publishers = new DefaultMutableTreeNode("Publishers");
739 		
740 		for(Iterator i = p.getResourceAttributes().getPublishers().iterator(); i.hasNext(); ){
741 			String thePublisher = (String)i.next();
742 			
743 			DefaultMutableTreeNode resAttr_pubN = new DefaultMutableTreeNode(thePublisher);
744 			resAttr_publishers.add(resAttr_pubN);
745 		}
746 		
747 		DefaultMutableTreeNode resAttr_relations = new DefaultMutableTreeNode("Relations");
748 		
749 		for(Iterator i = p.getResourceAttributes().getRelations().iterator(); i.hasNext(); ){
750 			String theRelation = (String)i.next();
751 			
752 			DefaultMutableTreeNode resAttr_relationN = new DefaultMutableTreeNode(theRelation);
753 			resAttr_relations.add(resAttr_relationN);
754 		}
755 
756 		
757 		DefaultMutableTreeNode resAttr_rights = new DefaultMutableTreeNode("Rights");
758 		
759 		for(Iterator i = p.getResourceAttributes().getRights().iterator(); i.hasNext(); ){
760 			String theRight = (String)i.next();
761 			
762 			DefaultMutableTreeNode resAttr_rightN = new DefaultMutableTreeNode(theRight);
763 			resAttr_rights.add(resAttr_rightN);
764 		}
765 
766 		DefaultMutableTreeNode resAttr_sources = new DefaultMutableTreeNode("Sources");
767 		
768 		for(Iterator i = p.getResourceAttributes().getSources().iterator(); i.hasNext(); ){
769 			String theSource = (String)i.next();
770 			
771 			DefaultMutableTreeNode resAttr_sourceN = new DefaultMutableTreeNode(theSource);
772 			resAttr_sources.add(resAttr_sourceN);
773 		}
774 
775 		DefaultMutableTreeNode resAttr_subjects = new DefaultMutableTreeNode("Subjects");
776 		
777 		for(Iterator i = p.getResourceAttributes().getSubjects().iterator(); i.hasNext(); ){
778 			String theSubject = (String)i.next();
779 			
780 			DefaultMutableTreeNode resAttr_subjectN = new DefaultMutableTreeNode(theSubject);
781 			resAttr_subjects.add(resAttr_subjectN);
782 		}
783 
784 		DefaultMutableTreeNode resAttr_title = new DefaultMutableTreeNode("Title");
785 		resAttr_title.add(new DefaultMutableTreeNode(p.getResourceAttributes().getTitle()));		
786 	
787 		DefaultMutableTreeNode resAttr_types = new DefaultMutableTreeNode("Types");
788 		
789 		for(Iterator i = p.getResourceAttributes().getTypes().iterator(); i.hasNext(); ){
790 			String theType = (String)i.next();
791 			
792 			DefaultMutableTreeNode resAttr_typeN = new DefaultMutableTreeNode(theType);
793 			resAttr_types.add(resAttr_typeN);
794 		}
795 	
796 
797 		resAttrRoot.add(resAttr_aggregation);
798 		resAttrRoot.add(resAttr_class);
799 		resAttrRoot.add(resAttr_contexts);
800 		resAttrRoot.add(resAttr_contributors);
801 		resAttrRoot.add(resAttr_coverages);
802 		resAttrRoot.add(resAttr_creators);
803 		resAttrRoot.add(resAttr_dates);
804 		resAttrRoot.add(resAttr_description);
805 		resAttrRoot.add(resAttr_formats);
806 		resAttrRoot.add(resAttr_identifier);
807 		resAttrRoot.add(resAttr_languages);
808 		resAttrRoot.add(resAttr_locations);
809 		resAttrRoot.add(resAttr_publishers);
810 		resAttrRoot.add(resAttr_relations);
811 		resAttrRoot.add(resAttr_rights);
812 		resAttrRoot.add(resAttr_sources);
813 		resAttrRoot.add(resAttr_subjects);
814 		resAttrRoot.add(resAttr_title);
815 		resAttrRoot.add(resAttr_types);
816 
817         for(Iterator i = p.getProfileElements().keySet().iterator(); i.hasNext(); ){
818         	String peKey = (String)i.next();
819         	
820         	ProfileElement theProfileElement = (ProfileElement)p.getProfileElements().get(peKey);
821         	DefaultMutableTreeNode thePENode = new DefaultMutableTreeNode(theProfileElement.getName());
822         	DefaultMutableTreeNode theCommentsRoot = new DefaultMutableTreeNode("Comments");
823         	DefaultMutableTreeNode theComments = new DefaultMutableTreeNode(theProfileElement.getComments());
824         	
825         	theCommentsRoot.add(theComments);
826         	
827         	DefaultMutableTreeNode theDesc = new DefaultMutableTreeNode(theProfileElement.getDescription());
828         	DefaultMutableTreeNode theDescRoot = new DefaultMutableTreeNode("Description");
829         	
830         	theDescRoot.add(theDesc);
831         	
832         	
833         	
834         	DefaultMutableTreeNode theID = new DefaultMutableTreeNode(theProfileElement.getID());
835         	DefaultMutableTreeNode theIDRoot = new DefaultMutableTreeNode("ID");
836         	
837         	theIDRoot.add(theID);
838         	
839         	DefaultMutableTreeNode theMO = new DefaultMutableTreeNode(new Integer(theProfileElement.getMaxOccurrence()).toString());
840         	DefaultMutableTreeNode theMORoot = new DefaultMutableTreeNode("Max Occurence");
841         	theMORoot.add(theMO);
842         	
843         	DefaultMutableTreeNode theSynonyms = new DefaultMutableTreeNode("Synonyms");
844         	
845         	for(Iterator i2 = theProfileElement.getSynonyms().iterator(); i2.hasNext(); ){
846         		String theSynonym = (String)i2.next();
847         		DefaultMutableTreeNode sNode = new DefaultMutableTreeNode(theSynonym);
848         		theSynonyms.add(sNode);
849         	}
850 
851         	DefaultMutableTreeNode theType = new DefaultMutableTreeNode(theProfileElement.getType());
852         	DefaultMutableTreeNode theTypeRoot = new DefaultMutableTreeNode("Type");
853         	theTypeRoot.add(theType);
854         	
855         	
856         	DefaultMutableTreeNode theUnit = new DefaultMutableTreeNode(theProfileElement.getUnit());
857         	DefaultMutableTreeNode theUnitRoot = new DefaultMutableTreeNode("Unit");
858         	theUnitRoot.add(theUnit);
859         	
860         	thePENode.add(theCommentsRoot);
861         	thePENode.add(theDescRoot);
862         	thePENode.add(theIDRoot);
863         	thePENode.add(theMORoot);
864         	thePENode.add(theSynonyms);
865         	thePENode.add(theTypeRoot);
866         	thePENode.add(theUnitRoot);
867         	
868         	profElemRoot.add(thePENode);
869         }
870 		
871 		root.add(profAttrRoot);
872 		root.add(resAttrRoot);
873 		root.add(profElemRoot);
874 		
875 		return new DefaultTreeModel(root);		
876 		
877 		
878 	}
879 
880 	/** Auto-generated event handler method */
881 	protected void openFileMenuItemActionPerformed(ActionEvent evt){
882 		//TODO add your handler code here
883 		
884 	    String filename = File.separator+"tmp";
885 	    JFileChooser fc = new JFileChooser(new File(filename));
886 	    
887 	    // Show open dialog; this method does not return until the dialog is closed
888 	    int decision = fc.showOpenDialog(this);
889 	    
890 	    if(decision != JFileChooser.APPROVE_OPTION){
891 	    	return; 
892 	    }
893 	    
894 	    File selFile = fc.getSelectedFile();
895 	    
896 	    //create a buffered reader, read it in, create a new profile from that file
897 	    FileReader fr = null;
898 	    
899 	    try{
900 	    	fr = new FileReader(selFile);
901 	    }
902 	    catch(FileNotFoundException fne){
903 	    	fne.printStackTrace();
904 	    	System.out.println(fne.getMessage());
905 	    }
906 	    
907 	    char [] buf = new char[256];
908 	    StringBuffer sb = new StringBuffer();
909 	    
910 	    int numRead = -1;
911 	    
912 	    try{
913 		    while((numRead = fr.read(buf,0,256)) != -1){
914 		      sb.append(buf,0,numRead);
915 		      buf = new char[256];
916 		    }
917 	    }
918 	    catch(IOException ioe){
919 	    	ioe.printStackTrace();
920 	    	System.out.println(ioe.getMessage());	    	
921 	    }
922 	    
923 	    System.out.println("Read in "+sb.toString());
924 	    try{
925 	    	createdProfile = new Profile(sb.toString());        
926 	    	jEditorPane1.setText(new ProfilePrinter(createdProfile,"http://oodt.jpl.nasa.gov/dtd/prof.dtd").toXMLString());
927 			
928 			getJTree1().setModel(generateModelFromProfile(createdProfile));
929 			//getJTree1().addMouseListener(new LeafListener(getJTree1()));
930 	    }catch(SAXException se){
931 	    	se.printStackTrace();
932 	    	System.out.println(se.getMessage());
933 	    }
934 
935 	    
936 	}
937 
938 	/** Auto-generated event handler method */
939 	protected void jButton1ActionPerformed(ActionEvent evt){
940 		//TODO add your handler code here
941 		
942 		//basically we want to set the createdProfile to be generated from the current tree model
943 		//then we want to set the jeditor pane to have the createdProfileText
944 		
945 		createdProfile = generateProfileFromModel(getJTree1().getModel());
946 		//jEditorPane1.setText(createdProfile.toString());
947 		jEditorPane1.setText(new ProfilePrinter(createdProfile,"http://oodt.jpl.nasa.gov/dtd/prof.dtd").toXMLString());
948 		
949 	}
950 
951 	/** Auto-generated event handler method */
952 	protected void saveMenuItemActionPerformed(ActionEvent evt){
953 		//TODO add your handler code here
954 	    
955 		
956 	    JFileChooser fc = new JFileChooser();
957 	    int decision = fc.showSaveDialog(this);
958 	    
959 	    if(decision != JFileChooser.APPROVE_OPTION){
960 	    	return; 
961 	    }
962 	    
963 	    //first thing -- set the created profile to the current tree
964 	    createdProfile = generateProfileFromModel(getJTree1().getModel());
965 	    
966 		File file = fc.getSelectedFile();
967         FileOutputStream fos = null;
968         
969         try{
970         	System.out.println("Trying to write to "+file.getAbsolutePath());
971         	fos = new FileOutputStream (file.getAbsolutePath());
972         	fos.write(new ProfilePrinter(createdProfile,"http://oodt.jpl.nasa.gov/dtd/prof.dtd").toXMLString().getBytes());
973         }
974         catch(FileNotFoundException fne){
975         	fne.printStackTrace();
976         	System.out.println(fne.getMessage());
977         }
978         catch(IOException ioe){
979         	ioe.printStackTrace();
980         	System.out.println(ioe.getMessage());
981         }
982         finally{
983         	try{
984         		fos.close();
985         	}catch(Exception ignore){
986         		//ignore
987         	}
988         }
989 
990 	}
991 }