Lines 44-59
Link Here
|
44 |
|
44 |
|
45 |
|
45 |
|
46 |
import java.io.File; |
46 |
import java.io.File; |
47 |
import java.io.File; |
47 |
import java.net.URL; |
48 |
import java.util.ArrayList; |
48 |
import java.util.ArrayList; |
49 |
import java.util.List; |
49 |
import java.util.List; |
50 |
import java.util.logging.Level; |
50 |
import java.util.logging.Level; |
51 |
import java.util.logging.Logger; |
51 |
import java.util.logging.Logger; |
52 |
import java.util.prefs.Preferences; |
52 |
import java.util.prefs.Preferences; |
|
|
53 |
import org.netbeans.api.java.classpath.ClassPath; |
54 |
import org.netbeans.api.java.queries.SourceForBinaryQuery; |
53 |
|
55 |
|
54 |
import org.openide.filesystems.FileObject; |
56 |
import org.openide.filesystems.FileObject; |
55 |
import org.openide.filesystems.FileStateInvalidException; |
57 |
import org.openide.filesystems.FileStateInvalidException; |
56 |
import org.openide.filesystems.FileSystem; |
|
|
57 |
import org.openide.filesystems.FileSystem; |
58 |
import org.openide.filesystems.FileSystem; |
58 |
import org.openide.filesystems.FileUtil; |
59 |
import org.openide.filesystems.FileUtil; |
59 |
import org.openide.loaders.DataObject; |
60 |
import org.openide.loaders.DataObject; |
Lines 177-185
Link Here
|
177 |
} |
178 |
} |
178 |
|
179 |
|
179 |
/** Getter for last resource property. */ |
180 |
/** Getter for last resource property. */ |
|
|
181 |
@Deprecated |
180 |
public DataObject getLastResource2() { |
182 |
public DataObject getLastResource2() { |
|
|
183 |
return getLastResource2(null); |
184 |
} |
185 |
|
186 |
/** Getter for last resource property. */ |
187 |
public DataObject getLastResource2(DataObject srcDataObject) { |
181 |
String path = getPreferences().get(PROP_LAST_RESOURCE2,null); |
188 |
String path = getPreferences().get(PROP_LAST_RESOURCE2,null); |
182 |
FileObject f = (path != null) ? findFileObject(path) : null; |
189 |
if(path == null) { |
|
|
190 |
return null; |
191 |
} |
192 |
FileObject f = (srcDataObject != null) ? findFileObject(srcDataObject, path) : findFileObject(path); |
183 |
if ((f != null) && !f.isFolder() && f.isValid()) { |
193 |
if ((f != null) && !f.isFolder() && f.isValid()) { |
184 |
try { |
194 |
try { |
185 |
return DataObject.find(f); |
195 |
return DataObject.find(f); |
Lines 224-229
Link Here
|
224 |
return retval.toArray(new FileSystem[retval.size()]); |
234 |
return retval.toArray(new FileSystem[retval.size()]); |
225 |
} |
235 |
} |
226 |
|
236 |
|
|
|
237 |
@Deprecated |
227 |
private static FileObject findFileObject(String path) { |
238 |
private static FileObject findFileObject(String path) { |
228 |
for (FileSystem fileSystem : getFileSystems()) { |
239 |
for (FileSystem fileSystem : getFileSystems()) { |
229 |
FileObject retval = fileSystem.findResource(path); |
240 |
FileObject retval = fileSystem.findResource(path); |
Lines 234-239
Link Here
|
234 |
return null; |
245 |
return null; |
235 |
} |
246 |
} |
236 |
|
247 |
|
|
|
248 |
private static FileObject findFileObject(DataObject srcDataObject, String path) { |
249 |
FileObject pfo = srcDataObject.getPrimaryFile(); |
250 |
ClassPath cp = ClassPath.getClassPath(pfo, ClassPath.EXECUTE); |
251 |
|
252 |
for(FileObject fo : getRoots(cp)) { |
253 |
try { |
254 |
FileSystem fs = fo.getFileSystem(); |
255 |
if (fs != null) { |
256 |
FileObject retval = fs.findResource(path); |
257 |
if (retval != null) { |
258 |
return retval; |
259 |
} |
260 |
} |
261 |
} catch (FileStateInvalidException ex) { |
262 |
Logger.getLogger(I18nOptions.class.getName()).log(Level.INFO, null, ex); |
263 |
} |
264 |
} |
265 |
|
266 |
return null; |
267 |
} |
268 |
|
269 |
|
270 |
private static List<FileObject> getRoots(ClassPath cp) { |
271 |
ArrayList<FileObject> l = new ArrayList<FileObject>(cp.entries().size()); |
272 |
for (ClassPath.Entry e : cp.entries()) { |
273 |
|
274 |
// try to map it to sources |
275 |
URL url = e.getURL(); |
276 |
SourceForBinaryQuery.Result r= SourceForBinaryQuery.findSourceRoots(url); |
277 |
FileObject [] fos = r.getRoots(); |
278 |
if (fos.length > 0) { |
279 |
for (FileObject fo : fos) { |
280 |
l.add(fo); |
281 |
} |
282 |
} else { |
283 |
if (e.getRoot()!=null) |
284 |
l.add(e.getRoot()); // add the class-path location |
285 |
// directly |
286 |
} |
287 |
} |
288 |
|
289 |
return l; |
290 |
} |
291 |
|
237 |
private static BeanNode createViewNode() throws java.beans.IntrospectionException { |
292 |
private static BeanNode createViewNode() throws java.beans.IntrospectionException { |
238 |
return new BeanNode(I18nOptions.getDefault()); |
293 |
return new BeanNode(I18nOptions.getDefault()); |
239 |
} |
294 |
} |