Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Accessing files within a plugin: "Workspace is closed" error
Accessing files within a plugin: "Workspace is closed" error [message #443893] Mon, 06 February 2006 21:37 Go to next message
Eclipse UserFriend
Originally posted by: jkilbour.pol.net

I added a postWindowCreate() method to my
ApplicationWorkbenchWindowAdvisor class to read a file from a directory in
my project, but the "Workspace is closed" exception comes at the very
first line of this:
try{
IWorkspaceRoot myWorkspaceRoot =
ResourcesPlugin.getWorkspace().getRoot();
IProject myProject = myWorkspaceRoot.getProject("Hello");
if (myProject.exists() && !myProject.isOpen())
myProject.open(null);
IFolder dataFolder = myProject.getFolder("datafiles");
if (dataFolder.exists()) {
IFile infile = dataFolder.getFile("infile");
inStream = infile.getContents();
reader = new BufferedReader(new InputStreamReader(inStream));
}
while ((str = reader.readLine()) != null) {
System.out.println(str);
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Re: Accessing files within a plugin: "Workspace is closed" error [message #443897 is a reply to message #443893] Mon, 06 February 2006 22:14 Go to previous messageGo to next message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
Bizarre. Are you calling postWindowCreate() explicitly, from another part of your code? And if you comment the method's body out, does it get called when you expect it?

The workspace should be open after the org.eclipse.core.resources plugin has started. You shouldn't get any method calls like postWindowCreate() until after all the bundles are started up, which is why I was wondering if you've put in any calls to this (or other) methods referenced from static initialisers, constructors, or if you've done anything strange to try and auto-start the plugin. I'd say that you have to get the org.eclipse.core.resources plugin started prior to yours, but given that you must have it as a dependency (or else this wouldn't compile :-)

Print out start/stop methods in your bundle's activator to the log. It's my guess that this method is being called prior to all the plugins starting up, which is why it's inconsistent. But I can't see any way that this should fail i normal situations.

How are you testing it? By running a PDE workspace and switching perspective, or running as an RCP application extension?

Alex.
Re: Accessing files within a plugin: "Workspace is closed" error [message #443899 is a reply to message #443897] Mon, 06 February 2006 22:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jkilbour.pol.net

I found that I was including the plugin jar in the classpath but not
including it as a plugin dependency. Fixing that solved the "Workspace
closed" bit.

However, I cannot reference the project to get to the file, as the project
does not exist. The following prints "0" to the console:

IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = myWorkspaceRoot.getProjects();
System.out.println(projects.length);
Re: Accessing files within a plugin: "Workspace is closed" error [message #443911 is a reply to message #443899] Tue, 07 February 2006 08:41 Go to previous messageGo to next message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
Ah, yes, not including it in the class dependency would screw things up a little :-)

If you're running the plugin as a run-time PDE workbench, bear in mind that it has its own workspace (and for good reason; you don't want plugins hosing around with the main workbench whilst you're developing :-)

If you want to get access to an existing project in the runtime-workbench, I suggest that next time you run your plugin, go to the File -> Import -> Existing project into workspace option, then navigate to your original workspace and include the project (which will probably be ../workspace/MyProject if you run with the defaults). Note that this doesn't copy the project; it just brings it into the visibility of your runtime workspace, and has the advantage that anything you change in that project will be visible (after a suitable refresh) in the other.

Bear in mind that when you clean the workspace, this will be lost so you'll have to do it again. This is likely to be an issue if you clean your workspace on each launch (which frankly is probably a good idea, but causes these kind of problems during development :-)

HTH,

Alex.
Re: Accessing files within a plugin: "Workspace is closed" error [message #444024 is a reply to message #443911] Wed, 08 February 2006 14:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jkilbour.pol.net

Alex Blewitt wrote:


> If you want to get access to an existing project in the runtime-workbench, I
suggest that next time you run your plugin, go to the File -> Import ->
Existing project into workspace option, then navigate to your original
workspace and include the project (which will probably be
../workspace/MyProject if you run with the defaults). Note that this doesn't
copy the project; it just brings it into the visibility of your runtime
workspace, and has the advantage that anything you change in that project will
be visible (after a suitable refresh) in the other.

Can this be done programmatically? I am making an RCP, right now based on
the most basic hello world RCP, and so my plugin has no menu or workspace
options.

Thanks.
Re: Accessing files within a plugin: "Workspace is closed" error [message #444027 is a reply to message #444024] Wed, 08 February 2006 16:18 Go to previous message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
Yes, it can be; as for how, there's something called ExternalProjectImportWizard that does the job. It searches for .project files, and then groups them together with a project name, and then invokes createExistingProject() with the data. The method looks like:

IProject project = workspace.getRoot().getProject("My Project");
new WorkspaceModifyOperation() {
  protected void execute(IProgressMonitor monitor) {
    project.create(IDEWorkbenchPlugin.getPluginWorkspace().
    loadProjectDescription(pathToDotProjectFile),monitor);
    project.open(IResource.BACKGROUND_REFRESH,monitor);
  }
});


You can have a look in more detail by looking at the org.eclipse.ui.ide package; it's also available on the <a href=" http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.ide/ src/org/eclipse/ui/internal/wizards/datatransfer/WizardProje ctsImportPage.java?rev=HEAD&content-type=text/vnd.viewcv s-markup">On-line CVS site</a>.
Previous Topic:Actions in my ActionBarAdvisor
Next Topic:ITableColorProvider - color every other line (like greenbar paper)
Goto Forum:
  


Current Time: Fri Jan 03 06:04:17 GMT 2025

Powered by FUDForum. Page generated in 0.03169 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top