1 19 23 24 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common; 25 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Map ; 31 import java.util.Set ; 32 33 37 public abstract class MultiMethodTableModel extends MethodTableModel{ 38 39 private Map selectionToDDMethodsMap; 41 42 private Map selectionToMethodsMap; 44 45 private String selection; 46 47 48 public MultiMethodTableModel(Map selectionToMethodsMap, Map 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 67 68 public void setData(Map selectionToMethodsMap, Map selectionToDDMethodsMap) { 69 this.selectionToMethodsMap = selectionToMethodsMap; 70 this.selectionToDDMethodsMap = selectionToDDMethodsMap; 71 72 75 setSel(); 76 setMap(); 77 fireTableDataChanged(); 78 } 79 80 81 public void setSelectionToDDMethodsMap(Map selectionToDDMethodsMap){ 82 this.selectionToDDMethodsMap = selectionToDDMethodsMap; 83 } 84 85 86 public void setSelection(String selection){ 87 setSel(selection); 88 setMap(); 89 } 91 92 93 public String [] getSelections(){ 94 String [] strings = {""}; Set selectionSet = selectionToMethodsMap.keySet(); 96 Iterator iterator = selectionSet.iterator(); 97 while(iterator.hasNext()){ 98 Object object = iterator.next(); 99 } 100 101 if(!selectionSet.isEmpty()){ 102 Object [] objects = selectionSet.toArray(); 103 int size = objects.length; 104 strings = new String [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 getDDMethod(Object method, String selection); 115 116 117 private void setSel(){ 118 String selection = null; 119 if(selectionToMethodsMap != null){ 120 if(!selectionToMethodsMap.isEmpty()){ 122 Set selectionSet = selectionToMethodsMap.keySet(); 123 selection = (String )selectionSet.toArray()[0]; 124 } 125 setSel(selection); 126 } 127 } 128 129 130 private void setSel(String selection){ 131 this.selection = selection; 132 133 if(selection != null){ 134 List methods = null; 135 List 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 )selectionToMethodsMap.get(selection); 143 if (methods != null) { 144 145 this.methods = new ArrayList (); 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 )selectionToDDMethodsMap.get(selection); 155 if (ddMethods != null) { 156 this.ddMethods = new ArrayList (); 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 getDDMethod(Object method){ 167 return getDDMethod(method, selection); 168 } 169 170 171 private Object getDDObject(Object method){ 172 return getDDMethod(method, selection); 173 } 174 175 176 private void printMap(Map map){ 177 System.out.println("map: " + map); System.out.println("map toString: " + map.toString()); System.out.println("map size: " + map.size()); Set keySet = map.keySet(); 181 if(keySet.isEmpty()){ 182 System.out.println("map keySet Empty: "); }else{ 184 Iterator it = keySet.iterator(); 185 while(it.hasNext()){ 186 Object object = it.next(); 187 System.out.println("map keySet Object: " + object); System.out.println("map keySet Object toString: " + object.toString()); System.out.println("map keySet Object type: " + object.getClass().getName()); } 191 } 192 193 Collection values = map.values(); 194 if(values.isEmpty()){ 195 System.out.println("map values Empty: "); }else{ 197 Iterator it = values.iterator(); 198 while(it.hasNext()){ 199 Object object = it.next(); 200 System.out.println("map values Object: " + object); System.out.println(" map values Object toString: " + object.toString()); System.out.println("map values Object type: " + object.getClass().getName()); } 204 } 205 } 206 207 208 public List getMethods(){ 211 if(selection != null){ 212 return (List )selectionToMethodsMap.get(selection); 213 } 214 return null; 215 } 216 } 217 | Popular Tags |