KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > grapheditor > widget > WidgetFilterNode


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.widget;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.ListIterator JavaDoc;
27 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.BindingAndServiceNewType;
28 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.BindingNewType;
29 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType;
30 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementChildNewType;
31 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ImportSchemaNewType;
32 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ImportWSDLNewType;
33 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ServiceNewType;
34 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ServicePortNewType;
35 import org.openide.nodes.FilterNode;
36 import org.openide.nodes.Node;
37 import org.openide.util.datatransfer.NewType;
38
39 /**
40  * Default filter node implementation for all widgets.
41  *
42  * @author Nathan Fiedler
43  */

44 public class WidgetFilterNode extends FilterNode {
45
46     private AbstractWidget widget;
47     
48     /**
49      * Creates a new instance of WidgetFilterNode.
50      *
51      * @param original the original Node.
52      */

53     public WidgetFilterNode(Node original) {
54         super(original);
55     }
56     
57     public WidgetFilterNode(Node original, AbstractWidget widget) {
58         this(original);
59         this.widget = widget;
60     }
61
62     @Override JavaDoc
63     public NewType[] getNewTypes() {
64         NewType[] types = super.getNewTypes();
65         List JavaDoc<NewType> list = new ArrayList JavaDoc<NewType>();
66         Collections.addAll(list, types);
67         updateNewTypes(list);
68         return list.toArray(new NewType[list.size()]);
69     }
70
71     /**
72      * Add/remove types from the given list of NewType instance. For
73      * instance, the default implementation removes the BindingNewType
74      * instance from the list provided by the backing Node (as well as
75      * several other NewType classes). Subclasses may add or remove
76      * additional types. To prevent removing the default types,
77      * override without calling this superclass method.
78      *
79      * @param types list of NewType instances to be updated.
80      */

81     protected void updateNewTypes(List JavaDoc<NewType> types) {
82         ListIterator JavaDoc<NewType> liter = types.listIterator();
83         while (liter.hasNext()) {
84             NewType type = liter.next();
85             if (type instanceof BindingNewType ||
86                     type instanceof BindingAndServiceNewType ||
87                     type instanceof DocumentationNewType ||
88                     type instanceof ExtensibilityElementChildNewType ||
89                     type instanceof ImportSchemaNewType ||
90                     type instanceof ImportWSDLNewType ||
91                     type instanceof ServiceNewType ||
92                     type instanceof ServicePortNewType) {
93                 liter.remove();
94             }
95         }
96     }
97
98     @Override JavaDoc
99     public void destroy() throws IOException JavaDoc {
100         if (widget != null) {
101             widget.deleteComponent();
102         }
103         super.destroy();
104         
105     }
106 }
107
Popular Tags