It's all about the answers!

Ask a question

How to read Projects and files from navigator explorer using eclipse client java


pugazhenthi samidurai (26423942) | asked Sep 20 '12, 12:47 a.m.
edited Sep 20 '12, 2:21 a.m.
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



permanent link
DJ Houghton (2663) | answered Oct 03 '12, 8:43 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
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)

permanent link
pugazhenthi samidurai (26423942) | answered Oct 03 '12, 6:51 a.m.
edited Oct 03 '12, 9:00 a.m.
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;
      }


permanent link
Ralph Schoon (63.1k33645) | 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/?

permanent link
Ralph Schoon (63.1k33645) | 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
pugazhenthi samidurai commented Sep 20 '12, 2:20 a.m. | edited Sep 20 '12, 2:22 a.m.

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

Your answer


Register or to post 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.