Lines 23-33
Link Here
|
23 |
|
23 |
|
24 |
import java.io.File; |
24 |
import java.io.File; |
25 |
import java.io.File; |
25 |
import java.io.File; |
|
|
26 |
import java.net.URL; |
26 |
import java.util.ArrayList; |
27 |
import java.util.ArrayList; |
27 |
import java.util.List; |
28 |
import java.util.List; |
28 |
import java.util.logging.Level; |
29 |
import java.util.logging.Level; |
29 |
import java.util.logging.Logger; |
30 |
import java.util.logging.Logger; |
30 |
import java.util.prefs.Preferences; |
31 |
import java.util.prefs.Preferences; |
|
|
32 |
import org.netbeans.api.java.classpath.ClassPath; |
33 |
import org.netbeans.api.java.queries.SourceForBinaryQuery; |
34 |
import org.netbeans.api.project.Project; |
31 |
|
35 |
|
32 |
import org.openide.filesystems.FileObject; |
36 |
import org.openide.filesystems.FileObject; |
33 |
import org.openide.filesystems.FileStateInvalidException; |
37 |
import org.openide.filesystems.FileStateInvalidException; |
Lines 35-40
Link Here
|
35 |
import org.openide.filesystems.FileSystem; |
39 |
import org.openide.filesystems.FileSystem; |
36 |
import org.openide.filesystems.FileUtil; |
40 |
import org.openide.filesystems.FileUtil; |
37 |
import org.openide.loaders.DataObject; |
41 |
import org.openide.loaders.DataObject; |
|
|
42 |
import org.openide.util.Exceptions; |
38 |
import org.openide.util.HelpCtx; |
43 |
import org.openide.util.HelpCtx; |
39 |
import org.openide.loaders.DataObjectNotFoundException; |
44 |
import org.openide.loaders.DataObjectNotFoundException; |
40 |
import org.openide.nodes.BeanNode; |
45 |
import org.openide.nodes.BeanNode; |
Lines 155-163
Link Here
|
155 |
} |
160 |
} |
156 |
|
161 |
|
157 |
/** Getter for last resource property. */ |
162 |
/** Getter for last resource property. */ |
|
|
163 |
@Deprecated |
158 |
public DataObject getLastResource2() { |
164 |
public DataObject getLastResource2() { |
|
|
165 |
return getLastResource2(null); |
166 |
} |
167 |
|
168 |
/** Getter for last resource property. */ |
169 |
public DataObject getLastResource2(DataObject srcDataObject) { |
159 |
String path = getPreferences().get(PROP_LAST_RESOURCE2,null); |
170 |
String path = getPreferences().get(PROP_LAST_RESOURCE2,null); |
160 |
FileObject f = (path != null) ? findFileObject(path) : null; |
171 |
if(path == null) { |
|
|
172 |
return null; |
173 |
} |
174 |
FileObject f = (srcDataObject != null) ? findFileObject(srcDataObject, path) : findFileObject(path); |
161 |
if ((f != null) && !f.isFolder() && f.isValid()) { |
175 |
if ((f != null) && !f.isFolder() && f.isValid()) { |
162 |
try { |
176 |
try { |
163 |
return DataObject.find(f); |
177 |
return DataObject.find(f); |
Lines 202-207
Link Here
|
202 |
return retval.toArray(new FileSystem[retval.size()]); |
216 |
return retval.toArray(new FileSystem[retval.size()]); |
203 |
} |
217 |
} |
204 |
|
218 |
|
|
|
219 |
@Deprecated |
205 |
private static FileObject findFileObject(String path) { |
220 |
private static FileObject findFileObject(String path) { |
206 |
for (FileSystem fileSystem : getFileSystems()) { |
221 |
for (FileSystem fileSystem : getFileSystems()) { |
207 |
FileObject retval = fileSystem.findResource(path); |
222 |
FileObject retval = fileSystem.findResource(path); |
Lines 212-217
Link Here
|
212 |
return null; |
227 |
return null; |
213 |
} |
228 |
} |
214 |
|
229 |
|
|
|
230 |
private static FileObject findFileObject(DataObject srcDataObject, String path) { |
231 |
FileObject pfo = srcDataObject.getPrimaryFile(); |
232 |
ClassPath cp = ClassPath.getClassPath(pfo, ClassPath.EXECUTE); |
233 |
|
234 |
for(FileObject fo : getRoots(cp)) { |
235 |
try { |
236 |
FileSystem fs = fo.getFileSystem(); |
237 |
if (fs != null) { |
238 |
FileObject retval = fs.findResource(path); |
239 |
if (retval != null) { |
240 |
return retval; |
241 |
} |
242 |
} |
243 |
} catch (FileStateInvalidException ex) { |
244 |
Logger.getLogger(I18nOptions.class.getName()).log(Level.INFO, null, ex); |
245 |
} |
246 |
} |
247 |
|
248 |
return null; |
249 |
} |
250 |
|
251 |
|
252 |
private static List<FileObject> getRoots(ClassPath cp) { |
253 |
ArrayList<FileObject> l = new ArrayList<FileObject>(cp.entries().size()); |
254 |
for (ClassPath.Entry e : cp.entries()) { |
255 |
|
256 |
// try to map it to sources |
257 |
URL url = e.getURL(); |
258 |
SourceForBinaryQuery.Result r= SourceForBinaryQuery.findSourceRoots(url); |
259 |
FileObject [] fos = r.getRoots(); |
260 |
if (fos.length > 0) { |
261 |
for (FileObject fo : fos) { |
262 |
l.add(fo); |
263 |
} |
264 |
} else { |
265 |
if (e.getRoot()!=null) |
266 |
l.add(e.getRoot()); // add the class-path location |
267 |
// directly |
268 |
} |
269 |
} |
270 |
|
271 |
return l; |
272 |
} |
273 |
|
215 |
private static BeanNode createViewNode() throws java.beans.IntrospectionException { |
274 |
private static BeanNode createViewNode() throws java.beans.IntrospectionException { |
216 |
return new BeanNode(I18nOptions.getDefault()); |
275 |
return new BeanNode(I18nOptions.getDefault()); |
217 |
} |
276 |
} |