Skip to main content



      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 06:29 Go to next message
Eclipse UserFriend
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 07:21 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Creating PARENT-5-PROJECT_LOC links programmatically [message #1830042 is a reply to message #1829992] Thu, 16 July 2020 02:51 Go to previous messageGo to next message
Eclipse UserFriend
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 02:57 Go to previous message
Eclipse UserFriend
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: Sat Mar 22 19:16:36 EDT 2025

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

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

Back to the top