KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > common > MultiMethodTableModel


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 /* * MultiMethodTableModel.java
20  *
21  * Created on February 4, 2005, 5:41 PM
22  */

23
24 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.Set JavaDoc;
32
33 /**
34  *
35  * @author Rajeshwar Patil
36  */

37 public abstract class MultiMethodTableModel extends MethodTableModel{
38
39     //Map of selection to DD Methods
40
private Map JavaDoc selectionToDDMethodsMap;
41
42     //Map of selection to Methods
43
private Map JavaDoc selectionToMethodsMap;
44
45     private String JavaDoc selection;
46
47
48     public MultiMethodTableModel(Map JavaDoc selectionToMethodsMap, Map JavaDoc selectionToDDMethodsMap) {
49         this.selectionToDDMethodsMap = selectionToDDMethodsMap;
50         this.selectionToMethodsMap = selectionToMethodsMap;
51
52         setSel();
53         setMap();
54         fireTableDataChanged();
55     }
56
57
58     public MultiMethodTableModel() {
59     }
60
61
62 // public MultiMethodTableModel(Map selectionToMethodsMap) {
63
// //super();
64
// this(selectionToDDMethodsMap, null);
65
// }
66

67
68     public void setData(Map JavaDoc selectionToMethodsMap, Map JavaDoc selectionToDDMethodsMap) {
69         this.selectionToMethodsMap = selectionToMethodsMap;
70         this.selectionToDDMethodsMap = selectionToDDMethodsMap;
71
72         //printMap(this.selectionToMethodsMap);
73
//printMap(this.selectionToDDMethodsMap);
74

75         setSel();
76         setMap();
77         fireTableDataChanged();
78     }
79
80     
81     public void setSelectionToDDMethodsMap(Map JavaDoc selectionToDDMethodsMap){
82         this.selectionToDDMethodsMap = selectionToDDMethodsMap;
83     }
84
85
86     public void setSelection(String JavaDoc selection){
87         setSel(selection);
88         setMap();
89         //fireTableDataChanged();
90
}
91
92
93     public String JavaDoc[] getSelections(){
94         String JavaDoc[] strings = {""}; //NOI18N
95
Set JavaDoc selectionSet = selectionToMethodsMap.keySet();
96         Iterator JavaDoc iterator = selectionSet.iterator();
97         while(iterator.hasNext()){
98             Object JavaDoc object = iterator.next();
99         }
100         
101         if(!selectionSet.isEmpty()){
102             Object JavaDoc[] objects = selectionSet.toArray();
103             int size = objects.length;
104             strings = new String JavaDoc[size];
105             for(int i=0; i<size; i++){
106                 strings[i] = objects[i].toString();
107             }
108
109         }
110         return strings;
111     }
112
113
114     protected abstract Object JavaDoc getDDMethod(Object JavaDoc method, String JavaDoc selection);
115
116
117    private void setSel(){
118        String JavaDoc selection = null;
119        if(selectionToMethodsMap != null){
120             //assert(!selectionToMethodsMap.isEmpty());
121
if(!selectionToMethodsMap.isEmpty()){
122                 Set JavaDoc selectionSet = selectionToMethodsMap.keySet();
123                 selection = (String JavaDoc)selectionSet.toArray()[0];
124             }
125             setSel(selection);
126        }
127     }
128
129
130    private void setSel(String JavaDoc selection){
131         this.selection = selection;
132       
133         if(selection != null){
134             List JavaDoc methods = null;
135             List JavaDoc ddMethods = null;
136             this.methods = null;
137             this.ddMethods = null;
138             this.selection = selection;
139
140             if(selectionToMethodsMap != null){
141                 assert(!selectionToMethodsMap.isEmpty());
142                 methods = (List JavaDoc)selectionToMethodsMap.get(selection);
143                 if (methods != null) {
144                     
145                     this.methods = new ArrayList JavaDoc();
146                     for(int i = 0;i < methods.size(); i++) {
147                             this.methods.add(methods.get(i));
148                     }
149                 }
150             }
151
152             if(selectionToDDMethodsMap != null){
153                 ddMethods =
154                     (List JavaDoc)selectionToDDMethodsMap.get(selection);
155                 if (ddMethods != null) {
156                     this.ddMethods = new ArrayList JavaDoc();
157                     for(int i = 0;i < ddMethods.size(); i++) {
158                         this.ddMethods.add(ddMethods.get(i));
159                     }
160                 }
161             }
162         }
163     }
164
165
166     protected Object JavaDoc getDDMethod(Object JavaDoc method){
167         return getDDMethod(method, selection);
168     }
169
170
171     private Object JavaDoc getDDObject(Object JavaDoc method){
172         return getDDMethod(method, selection);
173     }
174     
175     
176     private void printMap(Map JavaDoc map){
177         System.out.println("map: " + map); //NOI8N
178
System.out.println("map toString: " + map.toString()); //NOI8N
179
System.out.println("map size: " + map.size()); //NOI8N
180
Set JavaDoc keySet = map.keySet();
181         if(keySet.isEmpty()){
182             System.out.println("map keySet Empty: "); //NOI8N
183
}else{
184             Iterator JavaDoc it = keySet.iterator();
185             while(it.hasNext()){
186                 Object JavaDoc object = it.next();
187                 System.out.println("map keySet Object: " + object); //NOI8N
188
System.out.println("map keySet Object toString: " + object.toString()); //NOI8N
189
System.out.println("map keySet Object type: " + object.getClass().getName()); //NOI8N
190
}
191         }
192
193         Collection JavaDoc values = map.values();
194         if(values.isEmpty()){
195             System.out.println("map values Empty: "); //NOI8N
196
}else{
197             Iterator JavaDoc it = values.iterator();
198             while(it.hasNext()){
199                 Object JavaDoc object = it.next();
200                 System.out.println("map values Object: " + object); //NOI8N
201
System.out.println(" map values Object toString: " + object.toString()); //NOI8N
202
System.out.println("map values Object type: " + object.getClass().getName()); //NOI8N
203
}
204         }
205     }
206
207
208     //returns List of all the Methods for the current selection
209
//return null if current selection is null.
210
public List JavaDoc getMethods(){
211         if(selection != null){
212             return (List JavaDoc)selectionToMethodsMap.get(selection);
213         }
214         return null;
215     }
216 }
217
Popular Tags