KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > VariablesModelFilter


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.scripting.php.dbginterface;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.modules.scripting.php.dbginterface.api.VariableNode;
25 import org.netbeans.spi.viewmodel.NodeModel;
26 import org.netbeans.spi.viewmodel.NodeModelFilter;
27 import org.netbeans.spi.viewmodel.TableModel;
28 import org.netbeans.spi.viewmodel.TableModelFilter;
29 import org.netbeans.spi.viewmodel.TreeModel;
30 import org.netbeans.spi.viewmodel.TreeModelFilter;
31 import org.netbeans.spi.viewmodel.UnknownTypeException;
32
33 /**
34  *
35  * @author Peter Williams
36  */

37 public class VariablesModelFilter extends ModelSupport
38         implements TreeModelFilter, TableModelFilter, NodeModelFilter {
39     
40     // Temporary to default functions to off and test filtering code.
41
private static boolean [] filterMap = {
42         true, // LOCAL_VARIABLE
43
true, // SCRIPT_FIELD
44
true, // JAVA_FIELD
45
true, // UNDEFINED_FIELD
46
true, // SUPER
47
true, // SCRIPT_ADAPTER
48
false // FUNCTION
49
};
50     
51     public static boolean [] getFilterSettings() {
52 // return Arrays.copyOf(filterMap, filterMap.length);
53
boolean [] copy = new boolean [filterMap.length];
54         System.arraycopy(filterMap, 0, copy, 0, filterMap.length);
55         return copy;
56     }
57     
58     public static void setFilters(final boolean [] newFilterMap) {
59 // filterMap = Arrays.copyOf(newFilterMap, filterMap.length);
60
filterMap = new boolean [filterMap.length];
61         System.arraycopy(newFilterMap, 0, filterMap, 0, Math.min(filterMap.length, newFilterMap.length));
62     }
63     
64     // ------------------------------------------------------------------------
65
// TreeModel implementation
66
// ------------------------------------------------------------------------
67
public Object JavaDoc getRoot(TreeModel original) {
68         return original.getRoot();
69     }
70     
71     public Object JavaDoc[] getChildren(TreeModel original, Object JavaDoc parent, int from, int to) throws UnknownTypeException {
72         Object JavaDoc [] originalChildren = original.getChildren(parent, from, to);
73         List JavaDoc<Object JavaDoc> filteredChildren = new ArrayList JavaDoc<Object JavaDoc>(originalChildren.length);
74         for(int i = 0; i < originalChildren.length; i++) {
75             if(originalChildren[i] != null) {
76                 if(originalChildren[i] instanceof VariableNode) {
77                     if(filterMap[((VariableNode) originalChildren[i]).getType()]) {
78                         filteredChildren.add(originalChildren[i]);
79                     }
80                 } else {
81                     filteredChildren.add(originalChildren[i]);
82                 }
83             }
84         }
85         return filteredChildren.toArray(new Object JavaDoc[filteredChildren.size()]);
86     }
87     
88     public boolean isLeaf(TreeModel original, Object JavaDoc node) throws UnknownTypeException {
89         return original.isLeaf(node);
90     }
91     
92     public int getChildrenCount(TreeModel original, Object JavaDoc node) throws UnknownTypeException {
93         return original.getChildrenCount(node);
94     }
95
96     // ------------------------------------------------------------------------
97
// TableModel implementation
98
// ------------------------------------------------------------------------
99
public Object JavaDoc getValueAt(TableModel original, Object JavaDoc node, String JavaDoc columnID) throws UnknownTypeException {
100         return original.getValueAt(node, columnID);
101     }
102     
103     public boolean isReadOnly(TableModel original, Object JavaDoc node, String JavaDoc columnID) throws UnknownTypeException {
104         return original.isReadOnly(node, columnID);
105     }
106     
107     public void setValueAt(TableModel original, Object JavaDoc node, String JavaDoc columnID, Object JavaDoc value) throws UnknownTypeException {
108         original.setValueAt(node, columnID, value);
109     }
110     
111     // ------------------------------------------------------------------------
112
// NodeModel implementation
113
// ------------------------------------------------------------------------
114
public String JavaDoc getDisplayName(NodeModel original, Object JavaDoc node) throws UnknownTypeException {
115         return original.getDisplayName(node);
116     }
117     
118     public String JavaDoc getIconBase(NodeModel original, Object JavaDoc node) throws UnknownTypeException {
119         return original.getIconBase(node);
120     }
121     
122     public String JavaDoc getShortDescription(NodeModel original, Object JavaDoc node) throws UnknownTypeException {
123         return original.getShortDescription(node);
124     }
125 }
126
Popular Tags