Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Switch workspace question
Switch workspace question [message #460127] Thu, 14 December 2006 09:08 Go to next message
Eclipse UserFriend
Originally posted by: janky.hot.ee

Hi,
i'm trying to implement the switch workspace action. So my question is
how and when i could change to directory i get with
Platform.getInstanceLocation()?

I don't want to add the org.eclipse.ui.ide library to my applicatin.
I'd be very appreciated if someone could guide or link me to right place.
Re: Switch workspace question [message #460128 is a reply to message #460127] Thu, 14 December 2006 09:38 Go to previous messageGo to next message
Eclipse UserFriend
VJ wrote:

> Hi,
> i'm trying to implement the switch workspace action. So my question is
> how and when i could change to directory i get with
> Platform.getInstanceLocation()?
>
> I don't want to add the org.eclipse.ui.ide library to my applicatin.
> I'd be very appreciated if someone could guide or link me to right place.

Workspace location can be either set in your Application.run() method, by
calling Platform.getInstanceLocation().setURL(), or by restarting Eclipse
instance with substituted command line arguments, like they do in
OpenWorkspaceAction
( http://www.koders.com/java/fid5F6054C787BB6E91B1813280EC757F 57AB0E6613.aspx).

--
With best regards, Michael Spector
Re: Switch workspace question [message #460130 is a reply to message #460128] Thu, 14 December 2006 09:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: janky.hot.ee

If i do the the first example then i get an exception
java.lang.IllegalStateException: Cannot change the location once it is
set. So the following code is not OK, or it's not possible to do this way???

public Object run(Object args) throws Exception {
URL newLoc = new File("H:/newworkspace/").toURL();
Platform.getInstanceLocation().setURL(newLoc, false);

Display display = PlatformUI.createDisplay();

try {
int returnCode = PlatformUI.createAndRunWorkbench(display, new
ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART) {
return IPlatformRunnable.EXIT_RESTART;
}
return IPlatformRunnable.EXIT_OK;
} finally {
display.dispose();
}
}


Michael Spector wrote:
> VJ wrote:
>
>> Hi,
>> i'm trying to implement the switch workspace action. So my question is
>> how and when i could change to directory i get with
>> Platform.getInstanceLocation()?
>>
>> I don't want to add the org.eclipse.ui.ide library to my applicatin.
>> I'd be very appreciated if someone could guide or link me to right place.
>
> Workspace location can be either set in your Application.run() method, by
> calling Platform.getInstanceLocation().setURL(), or by restarting Eclipse
> instance with substituted command line arguments, like they do in
> OpenWorkspaceAction
> ( http://www.koders.com/java/fid5F6054C787BB6E91B1813280EC757F 57AB0E6613.aspx).
>
Re: Switch workspace question [message #460131 is a reply to message #460127] Thu, 14 December 2006 09:51 Go to previous messageGo to next message
Eclipse UserFriend
VJ wrote:
> Hi,
> i'm trying to implement the switch workspace action. So my question is
> how and when i could change to directory i get with
> Platform.getInstanceLocation()?
>
> I don't want to add the org.eclipse.ui.ide library to my applicatin.
> I'd be very appreciated if someone could guide or link me to right place.

When: It must be done, *before* PlatformUI.createAndRunWorkbench has
been called, so the latest point is inside your IPlatformRunnable.run
implementation just before you call PlatformUI.createAndRunWorkbench.

How: Have a look at org\eclipse\ui\internal\ide\IDEApplication.java
from the org.eclipse.ui.ide plugin.

Basically you need a sequence similar to:

File fUserWorkspace = ... // your workspace

final Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc == null) {
.. //error
}

// Note: Don't use File.toURL()!
String path = fUserWorkspace.getAbsolutePath().replace(
File.separatorChar, '/');
URL userWSURL = new URL("file", null, path);

if (instanceLoc.isSet()) {
if (!userWSURL.sameFile(instanceLoc.getURL())) {
... // error
}
} else {
if (!fUserWorkspace.exists()) {
if (!fUserWorkspace.mkdirs()) {
... // error
}
}

// You can use another locking policy as well:
final boolean doLock = false;

if (!instanceLoc.setURL(userWSURL, doLock) == doLock) {
... // error
}
}

Greetings from Bremen,

Daniel Krügler
Re: Switch workspace question [message #460133 is a reply to message #460130] Thu, 14 December 2006 09:58 Go to previous messageGo to next message
Eclipse UserFriend
VJ wrote:

> If i do the the first example then i get an exception
> java.lang.IllegalStateException: Cannot change the location once it is
> set. So the following code is not OK, or it's not possible to do this
> way???
>

Have a look at the IDEApplication class, you'll find how they do it exactly.

--
With best regards, Michael Spector
Re: Switch workspace question [message #460148 is a reply to message #460133] Fri, 15 December 2006 02:55 Go to previous message
Eclipse UserFriend
Originally posted by: janky.hot.ee

Michael Spector wrote:
> VJ wrote:
>
>> If i do the the first example then i get an exception
>> java.lang.IllegalStateException: Cannot change the location once it is
>> set. So the following code is not OK, or it's not possible to do this
>> way???
>>
>
> Have a look at the IDEApplication class, you'll find how they do it exactly.
>


thx all of you, classes IDEApplication and OpenWorkspaceAction were
quite useful to study.
Previous Topic:How to use OleFrame within a ScrolledComposite?
Next Topic:java.lang.NullPointer
Goto Forum:
  


Current Time: Fri Mar 21 23:44:27 EDT 2025

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

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

Back to the top