Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Creating PARENT-5-PROJECT_LOC links programmatically
Creating PARENT-5-PROJECT_LOC links programmatically [message #1829991] Wed, 15 July 2020 10:29 Go to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 209
Registered: June 2010
Senior Member
Hi,

According to documentation, IFolder.createLink​(URI location, requires the the location URI to be either absolute or starting with a PathVariable.

Inspecting a .project file in where I manually imporated a number of links reveals that PARENT-n-PROJECT_LOC is a valid variable referring to the directory that is n levels higher then the project location.

Is it possible to create links like this using IFolder.createLink? Is there a better way to create (programmatically) links to folders/files that are expressed relative to the project location?

Regards,
Wilbert.
Re: Creating PARENT-5-PROJECT_LOC links programmatically [message #1829992 is a reply to message #1829991] Wed, 15 July 2020 11:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
I tried created a folder in the UI using" advanced" and then using something like PROJECT_LOC/../../eclipse and that worked. I see it's saved like this:
	<linkedResources>
		<link>
			<name>foo</name>
			<type>2</type>
			<locationURI>PARENT-2-PROJECT_LOC/eclipse</locationURI>
		</link>
	</linkedResources>
I think this code handles the PARENT_N_LOC stuff:

https://git.eclipse.org/c/platform/eclipse.platform.resources.git/tree/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/projectvariables/ParentVariableResolver.java

It looks a little as if the PROJECT_LOC followed by a relative path with .. is converted automatically, but I'm not sure if that conversion is done in the dialog or somewhere deeper. You should just try these approaches out to see what works.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Creating PARENT-5-PROJECT_LOC links programmatically [message #1830042 is a reply to message #1829992] Thu, 16 July 2020 06:51 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
There is a org.eclipse.core.internal.resources.PathVariableUtil.buildParentPathVariable(String, int, boolean) method that generates the 'PARENT-count-' string.

Snippets from the call hierarchy:
org.eclipse.core.internal.resources.PathVariableUtil.convertToRelative(IPathVariableManager, URI, IResource, boolean, String)
org.eclipse.core.internal.resources.ProjectPathVariableManager.convertToRelative(URI, boolean, String)
org.eclipse.ui.wizards.datatransfer.ImportOperation.createRelativePath(IPath, IResource)
org.eclipse.ui.wizards.datatransfer.ImportOperation.importFolder(Object, int, IProgressMonitor) [line 730]

You probably want to use ProjectPathVariableManager.convertToRelative. ImportOperation.createRelativePath and ImportOperation.importFolder should give you enough context on how to use it.
Re: Creating PARENT-5-PROJECT_LOC links programmatically [message #1830088 is a reply to message #1830042] Fri, 17 July 2020 06:57 Go to previous message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 209
Registered: June 2010
Senior Member
Hi,

Thanks for the suggestions. Indeed, the suggestion from Rolf worked. Though PathVariableUtil is not 'public API', it does exactly what I need.

Regards,
Wilbert.
Previous Topic:eclipse error
Next Topic:FilteredTree repaint issues with DND enabled
Goto Forum:
  


Current Time: Tue Apr 16 22:38:44 GMT 2024

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

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

Back to the top