Krzysztof Chudzicki
Krzysztof Chudzicki

Reputation: 23

Eclipse RCP 4.x - Defining workspace location

I know that this question was asked many times, but I didn't find an exact answer which would fulfill my desires :)

Long story short: I've got simple E4 application, product project, feature and main plugin with simple trim window.

Works, after exporting works too.

Now. I add lifeCycleURI property, create bundleclass for it and create simple dialog with Text area and a Button. Run it\export it and it works, before running main Trim Window dialog is shown. Fine.. Cool etc.

But I want to enter location eg. C:\TEST and after clicking button I want it to be my workspace area for the application (with .metedata and so on). HOW ???

Of course I've tried with :

Location instanceLocation = Platform.getInstanceLocation();
instanceLocation.set(new URL("file", null, "C:\TEST"), false);

But... It says that I can't change location cause it is already set... Tried to use above in Activator. The same. Tried to add -data @noDefault in products Launching Arguments ... The same...

I always try to accomplish my tasks by myself but this.... this... ehh... Help ?

Upvotes: 2

Views: 1730

Answers (1)

greg-449
greg-449

Reputation: 111142

You should be able to do this in the @PostContextCreate method of the life cycle class. Don't specify the '-data' argument

@PostContextCreate
public void postContextCreate()
{   
  Location instanceLoc = Platform.getInstanceLocation();

  // Stop if location is set
  if (instanceLoc.isSet())
    return;

  File file = new File("C:\\TEST");

  instanceLocation.set(file.toURL(), false);
}

Note: You need '\\' in your file path.

This is adapted from code which I use in my e4 RCP.

If you are currently testing the application from within Eclipse you will need to clear the workspace location in the 'Run Configuration' for the application. Open 'Run > Run Configurations', find your application and clear the 'Location' field on the 'Main' tab.

Upvotes: 2

Related Questions