1 19 20 package org.netbeans.modules.debugger.jpda.ui.models; 21 22 import com.sun.jdi.ClassLoaderReference; 23 import com.sun.jdi.ClassType; 24 import com.sun.jdi.InterfaceType; 25 import com.sun.jdi.ReferenceType; 26 import org.netbeans.api.debugger.Properties; 27 import org.netbeans.spi.viewmodel.NodeModel; 28 import org.netbeans.spi.viewmodel.TreeModel; 29 import org.netbeans.spi.viewmodel.ModelListener; 30 import org.netbeans.spi.viewmodel.UnknownTypeException; 31 import org.openide.util.NbBundle; 32 33 36 public class ClassesNodeModel implements NodeModel { 37 38 private static final String CLASS = 39 "org/netbeans/modules/debugger/jpda/resources/class"; 40 private static final String INTERFACE = 41 "org/netbeans/modules/debugger/jpda/resources/interface"; 42 private static final String PACKAGE = 43 "org/netbeans/modules/debugger/jpda/resources/package"; 44 private static final String FIELD = 45 "org/netbeans/modules/debugger/jpda/resources/field"; 46 private static final String CLASS_LOADER = 47 "org/netbeans/modules/debugger/jpda/resources/classLoader"; 48 49 private Properties classesProperties = Properties.getDefault(). 50 getProperties("debugger").getProperties("classesView"); 52 53 public String getDisplayName (Object o) throws UnknownTypeException { 54 if (o == TreeModel.ROOT) 55 return NbBundle.getBundle (ClassesNodeModel.class).getString 56 ("CTL_ClassesModel_Column_Name_Name"); 57 if (o instanceof Object []) { 58 String name = (String ) ((Object []) o) [0]; 59 boolean flat = classesProperties.getBoolean("flat", true); 60 if (!flat) { 61 int i = name.lastIndexOf ('.'); 62 if (i >= 0) 63 name = name.substring (i + 1); 64 } 65 return name; 66 } 67 if (o instanceof ReferenceType) { 68 String name = ((ReferenceType) o).name (); 69 int i = name.lastIndexOf ('.'); 70 if (i >= 0) 71 name = name.substring (i + 1); 72 i = name.lastIndexOf ('$'); 73 if (i >= 0) 74 name = name.substring (i + 1); 75 return name; 76 } 77 if (o instanceof ClassLoaderReference) { 78 String name = ((ClassLoaderReference) o).referenceType ().name (); 79 if (name.endsWith ("AppClassLoader")) 80 return NbBundle.getBundle (ClassesNodeModel.class).getString 81 ("CTL_ClassesModel_Column_Name_AppClassLoader"); 82 return java.text.MessageFormat.format (NbBundle.getBundle 83 (ClassesNodeModel.class).getString ( 84 "CTL_ClassesModel_Column_Name_ClassLoader"), 85 new Object [] {name} 86 ); 87 } 88 if (o instanceof Integer ) { 89 return NbBundle.getBundle (ClassesNodeModel.class).getString 90 ("CTL_ClassesModel_Column_Name_SystemClassLoader"); 91 } 92 throw new UnknownTypeException (o); 93 } 94 95 public String getShortDescription (Object o) throws UnknownTypeException { 96 if (o == TreeModel.ROOT) 97 return NbBundle.getBundle (ClassesNodeModel.class).getString 98 ("CTL_ClassesModel_Column_Name_Desc"); 99 if (o instanceof Object []) 100 return java.text.MessageFormat.format (NbBundle.getBundle 101 (ClassesNodeModel.class).getString ( 102 "CTL_ClassesModel_Column_Name_Package"), 103 (Object []) o 104 ); 105 if (o instanceof ReferenceType) { 106 String format = (o instanceof ClassType) ? 107 NbBundle.getBundle (ClassesNodeModel.class).getString 108 ("CTL_ClassesModel_Column_Name_Class") : 109 NbBundle.getBundle (ClassesNodeModel.class).getString 110 ("CTL_ClassesModel_Column_Name_Interface"); 111 String name = java.text.MessageFormat.format ( 112 format, 113 new Object [] {((ReferenceType) o).name ()} 114 ); 115 ClassLoaderReference cl = ((ReferenceType) o).classLoader (); 116 if (cl != null) { 117 name += " " + java.text.MessageFormat.format ( 118 NbBundle.getBundle (ClassesNodeModel.class).getString ( 119 "CTL_ClassesModel_Column_Name_LoadedBy"), 120 new Object [] {cl.referenceType ().name ()} 121 ); 122 } 123 return name; 124 } 125 if (o instanceof ClassLoaderReference) 126 return null; 127 if (o instanceof Integer ) 128 return null; 129 throw new UnknownTypeException (o); 130 } 131 132 public String getIconBase (Object o) throws UnknownTypeException { 133 if (o == TreeModel.ROOT) 134 return CLASS; 135 if (o instanceof Object []) 136 return PACKAGE; 137 if (o instanceof ClassType) 138 return CLASS; 139 if (o instanceof InterfaceType) 140 return INTERFACE; 141 if (o instanceof ClassLoaderReference) 142 return CLASS_LOADER; 143 if (o instanceof Integer ) 144 return CLASS_LOADER; 145 throw new UnknownTypeException (o); 146 } 147 148 152 public void addModelListener (ModelListener l) { 153 } 154 155 159 public void removeModelListener (ModelListener l) { 160 } 161 162 163 165 170 public static class DefaultClassesColumn extends 171 SourcesModel.AbstractColumn { 172 173 178 public String getID () { 179 return "DefaultClassesColumn"; 180 } 181 182 187 public String getDisplayName () { 188 return NbBundle.getBundle (DefaultClassesColumn.class). 189 getString ("CTL_ClassesModel_Column_Name_Name"); 190 } 191 192 public Character getDisplayedMnemonic() { 193 return new Character (NbBundle.getBundle (DefaultClassesColumn.class). 194 getString ("CTL_ClassesModel_Column_Name_Mnc").charAt(0)); 195 } 196 197 202 public String getShortDescription () { 203 return NbBundle.getBundle (DefaultClassesColumn.class).getString 204 ("CTL_ClassesModel_Column_Name_Desc"); 205 } 206 207 212 public Class getType () { 213 return null; 214 } 215 } 216 } 217 | Popular Tags |