1 19 20 package org.netbeans.modules.debugger.jpda.projects; 21 22 import java.io.File ; 23 24 import org.netbeans.api.project.FileOwnerQuery; 25 import org.netbeans.api.project.Project; 26 import org.netbeans.api.project.ProjectInformation; 27 28 import org.netbeans.spi.viewmodel.NodeModel; 29 import org.netbeans.spi.viewmodel.TreeModel; 30 import org.netbeans.spi.viewmodel.ModelListener; 31 import org.netbeans.spi.viewmodel.UnknownTypeException; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileUtil; 34 import org.openide.util.NbBundle; 35 36 39 public class SourcesNodeModel implements NodeModel { 40 41 public static final String SOURCE_ROOT = 42 "org/netbeans/modules/debugger/jpda/resources/root"; 43 public static final String FILTER = 44 "org/netbeans/modules/debugger/jpda/resources/Filter"; 45 46 47 public String getDisplayName (Object o) throws UnknownTypeException { 48 if (o == TreeModel.ROOT) { 49 return NbBundle.getBundle(SourcesNodeModel.class).getString("CTL_SourcesModel_Column_Name_Name"); 50 } else 51 if (o instanceof String ) { 52 File f = new File ((String ) o); 53 if (f.exists ()) { 54 FileObject fo = FileUtil.toFileObject (f); 55 Project p = FileOwnerQuery.getOwner (fo); 56 if (p != null) { 57 ProjectInformation pi = (ProjectInformation) p.getLookup (). 58 lookup (ProjectInformation.class); 59 return java.text.MessageFormat.format(NbBundle.getBundle(SourcesNodeModel.class).getString( 60 "CTL_SourcesModel_Column_Name_ProjectSources"), new Object [] { f.getPath(), pi.getDisplayName() }); 61 } 62 return java.text.MessageFormat.format(NbBundle.getBundle(SourcesNodeModel.class).getString( 63 "CTL_SourcesModel_Column_Name_LibrarySources"), new Object [] { f.getPath() }); 64 } else 65 return (String ) o; 66 } else 67 throw new UnknownTypeException (o); 68 } 69 70 public String getShortDescription (Object o) throws UnknownTypeException { 71 if (o == TreeModel.ROOT) 72 return NbBundle.getBundle(SourcesNodeModel.class).getString("CTL_SourcesModel_Column_Name_Desc"); 73 if (o instanceof String ) { 74 if (((String ) o).startsWith ("D")) 75 return NbBundle.getBundle(SourcesNodeModel.class).getString("CTL_SourcesModel_Column_Name_DescExclusion"); 76 else 77 return NbBundle.getBundle(SourcesNodeModel.class).getString("CTL_SourcesModel_Column_Name_DescRoot"); 78 } else 79 throw new UnknownTypeException (o); 80 } 81 82 public String getIconBase (Object o) throws UnknownTypeException { 83 if (o instanceof String ) { 84 if (((String ) o).startsWith ("D")) 85 return FILTER; 86 else 87 return SOURCE_ROOT; 88 } else 89 throw new UnknownTypeException (o); 90 } 91 92 public void addModelListener (ModelListener l) { 93 } 94 95 public void removeModelListener (ModelListener l) { 96 } 97 } 98 | Popular Tags |