KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > projects > SourcesNodeModel


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
20 package org.netbeans.modules.debugger.jpda.projects;
21
22 import java.io.File JavaDoc;
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 /**
37  * @author Jan Jancura
38  */

39 public class SourcesNodeModel implements NodeModel {
40
41     public static final String JavaDoc SOURCE_ROOT =
42         "org/netbeans/modules/debugger/jpda/resources/root";
43     public static final String JavaDoc FILTER =
44         "org/netbeans/modules/debugger/jpda/resources/Filter";
45     
46     
47     public String JavaDoc getDisplayName (Object JavaDoc 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 JavaDoc) {
52             File JavaDoc f = new File JavaDoc ((String JavaDoc) 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 JavaDoc [] { f.getPath(), pi.getDisplayName() });
61                 }
62                 return java.text.MessageFormat.format(NbBundle.getBundle(SourcesNodeModel.class).getString(
63                         "CTL_SourcesModel_Column_Name_LibrarySources"), new Object JavaDoc [] { f.getPath() });
64             } else
65             return (String JavaDoc) o;
66         } else
67         throw new UnknownTypeException (o);
68     }
69     
70     public String JavaDoc getShortDescription (Object JavaDoc 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 JavaDoc) {
74             if (((String JavaDoc) 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 JavaDoc getIconBase (Object JavaDoc o) throws UnknownTypeException {
83         if (o instanceof String JavaDoc) {
84             if (((String JavaDoc) 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