How to read Projects and files from navigator explorer using eclipse client java
Hi,
i am developing client side UI plugin in RTC. when user entering some file name , i want to show all files with name like user given name from navigator explorer. Ex. Like file open dialog . Thanks in advance. Pugazh S |
4 answers
Ralph Schoon (63.6k●3●36●46)
| answered Sep 20 '12, 2:03 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I don't understand this question. Please provide more details, if you hope for an answer. The tag extending implies you want to do something with the API. Was that a wrong tag?
Comments Hi Schoon, i am developing client side UI plugin in RTC. when user entering some file name , i want to show all files with name like user given name from navigator explorer. Ex. Like file open dialog . Thanks for quick response. Pugazh S |
Ralph Schoon (63.6k●3●36●46)
| answered Sep 20 '12, 2:49 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Pugazh,
I think this might be rather an Eclipse question. Have you searched http://www.eclipse.org/? |
Hi ,
The following code will help you to read all files imported into workspace. Based on this code we can able to design custom File Open Dialog. try { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IPath location = root.getLocation(); File currentDir = new File(location+"\\.metadata\\.plugins\\org.eclipse.core.resources\\.projects"); if(currentDir.isDirectory()) { String[] files = currentDir.list(); for(int i = 0;i<files.length;i++){ String locfile = location+"\\.metadata\\.plugins\\org.eclipse.core.resources\\.projects\\"+files[i]+"\\.location"; File locationfile = new File(location+"\\.metadata\\.plugins\\org.eclipse.core.resources\\.projects\\"+files[i]+"\\.location"); if(locationfile.isFile()) { if(isInWorkSpace(locfile)){ //if this condition is true the imported projects available in current workspace }else{ // if it is not there in workspace then the path will be availble location file inside this project folder String locactpath = getFileActualPath(locfile,files[i]); } } } } } catch (IOException e) { e.printStackTrace(); } getFileActualPath private String getFileActualPath(String locfile,String projectname) throws IOException { FileInputStream fstream = new FileInputStream(locfile); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console if(strLine.contains("?file")){ int startindex = strLine.indexOf("file")+6; int endindex = strLine.lastIndexOf(projectname)+projectname.length(); return strLine.substring(startindex, endindex); } } //Close the input stream in.close(); return null; } isInWorkSpace public static boolean isInWorkSpace(String file) throws IOException { FileInputStream fstream = new FileInputStream(file); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console if(strLine.contains("?file")){ return false; } } //Close the input stream in.close(); return true; } |
I'm still not sure exactly what you are trying to do, but here are some hints that will hopefully help.
From the Eclipse side, there is API which can help you navigate the workspace's resource tree. The resource visitor pattern is useful.
IWorkspace ws = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = ws.getRoot();
root.accept(new IResourceProxyVisitor() {
public boolean visit(IResourceProxy proxy) throws CoreException {
if (proxy.getName().equals("my name"))
System.out.println("found it");
return true;
}
}, IResource.DEPTH_INFINITE);
Note you can also get the resource's location in the file-system by calling IResource#getLocation.
If you have a path in the filesystem and want to retrieve the workspace object used to represent that path, then you can use IWorkspaceRoot#findFilesForLocation(URI)
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.