Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

1 vote



4 answers

Permanent link
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?

0 votes

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


Permanent link
Pugazh,

I think this might be rather an Eclipse question. Have you searched http://www.eclipse.org/?

0 votes


Permanent link
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;
      }

0 votes


Permanent link
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)

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Sep 20 '12, 12:47 a.m.

Question was seen: 8,007 times

Last updated: Oct 03 '12, 9:00 a.m.

Confirmation Cancel Confirm