The tree of workspace [message #604839] |
Mon, 01 March 2010 02:16 |
Caio Lima Messages: 6 Registered: March 2010 |
Junior Member |
|
|
Hi guys... :d
This is my first topic on forum...xP
Well...I want know how can i get workspace tree in my plug-in...
The Resoruce API of PDE have any Class, method or interface to do/aux it??
I write this code to access a source...but i need to access all files, of all open projects
See that =D
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
public class ShowTesteSource implements IWorkbenchWindowActionDelegate {
private IWorkbenchWindow window;
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void init(IWorkbenchWindow window) {
this.window = window;
}
@Override
public void run(IAction action) {
IWorkspaceRoot rootW=ResourcesPlugin.getWorkspace().getRoot();
IResource project=rootW.findMember("Java");
IProject java=rootW.getProject("Java");
if(java.exists()){
IFile teste=java.getFile("/src/Teste.java");
IContainer[] files=rootW.findContainersForLocationURI(rootW.getLocationUR I());
if(teste.exists()){
//File testeJava=new File(teste.getLocationURI());
try {
BufferedReader sourceIn=new BufferedReader(new InputStreamReader(teste.getContents()));
String line,source="";
while((line=sourceIn.readLine())!=null){
source+=line+"\n";
}
MessageDialog.openInformation(window.getShell(), "Source", source);
} catch (FileNotFoundException e) {
MessageDialog.openInformation(window.getShell(), "Erro", "Arquivo não enconbtrado");
} catch(IOException iOE){
MessageDialog.openInformation(window.getShell(), "Erro", "Erro ao carregar o código!");
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
@Override
public void selectionChanged(IAction action, ISelection selection) {
// TODO Auto-generated method stub
}
}
I thank you now =D
Waiting for help
\o/
|
|
|
Re: The tree of workspace [message #604847 is a reply to message #604839] |
Tue, 02 March 2010 08:44 |
Vijay Raj Messages: 608 Registered: July 2009 |
Senior Member |
|
|
IWorkspaceRoot interface itself has a method getProjects()
which returns IProject instances....
IProject in tern has members method which returns IResource array... hence forth
You have to do thru the resource api fully...
if you want to handle a java project then jdt api has to be studied...
--
---------------------
Regards,
Vijay
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
|
|
|
|
Powered by
FUDForum. Page generated in 0.03020 seconds