KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > EmbeddedSchemaNode


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.wsdl.ui.view.treeeditor;
20
21 import java.io.IOException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.netbeans.modules.xml.schema.ui.nodes.SchemaComponentNode;
26 import org.netbeans.modules.xml.wsdl.model.Types;
27 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
28 import org.netbeans.modules.xml.wsdl.model.extensions.xsd.WSDLSchema;
29 import org.openide.cookies.SaveCookie;
30 import org.openide.nodes.FilterNode;
31 import org.openide.nodes.Node;
32 import org.openide.util.Lookup;
33 import org.openide.util.lookup.AbstractLookup;
34 import org.openide.util.lookup.InstanceContent;
35
36 public class EmbeddedSchemaNode extends FilterNode {
37
38     private WSDLSchema component;
39     
40     public EmbeddedSchemaNode(Node node, WSDLSchema schema, Lookup lookup) {
41         super(node, new EmbeddedSchemaChildren(node, lookup), lookup);
42         component = schema;
43     }
44
45     @Override JavaDoc
46     public boolean canDestroy() {
47         WSDLModel model = component.getModel();
48         return model != null && model.getModelSource().isEditable();
49     }
50
51     @Override JavaDoc
52     public void destroy() throws IOException JavaDoc {
53         SchemaComponentNode scn = (SchemaComponentNode) getOriginal().
54                 getCookie(SchemaComponentNode.class);
55         if (scn != null) {
56             // Let the schema node do its cleanup.
57
scn.destroy();
58         }
59         // Remove the schema root from the WSDL model.
60
WSDLModel model = component.getModel();
61         Types types = model.getDefinitions().getTypes();
62         model.startTransaction();
63         types.removeExtensibilityElement(component);
64             model.endTransaction();
65         super.destroy();
66     }
67     
68
69     
70     static class EmbeddedSchemaChildren extends FilterNode.Children {
71         
72         private Lookup parentLookup;
73         
74         public EmbeddedSchemaChildren(Node or, Lookup lookup) {
75             super(or);
76             parentLookup = lookup;
77         }
78         
79         @Override JavaDoc
80         protected Node[] createNodes(Node n) {
81             Node[] mynodes = super.createNodes(n);
82             List JavaDoc<Node> list = new ArrayList JavaDoc<Node>();
83             for (Node node : mynodes) {
84                 list.add(new FilterNode(node, new EmbeddedSchemaChildren(node, parentLookup), parentLookup));
85             }
86             return list.toArray(new Node[list.size()]);
87         }
88     }
89 }
90
Popular Tags