Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to keep IDs consistent
How to keep IDs consistent [message #1776197] Mon, 13 November 2017 15:47 Go to next message
Felix Funke is currently offline Felix FunkeFriend
Messages: 6
Registered: October 2013
Junior Member
Hello,

I'm developing an e4 application and am really liking it.

But I have one problem with the IDs of the elements defined in the e4xmi. When I want to access any element from the XMI in my code I have to know the ID of the element. I would really like to have a string constant in my code with this ID.

Right now I would define some interface with a lot of constants and manually update those constants whenever we add or change a command, part etc.
But this is not fool proof. When someone forgets to change the constant after making changes in the XMI we get out of sync. Refactorings also won't work.

Is there any best practice on how to use the IDs in the XMI?

Thanks
Felix
Re: How to keep IDs consistent [message #1776745 is a reply to message #1776197] Tue, 21 November 2017 04:50 Go to previous messageGo to next message
Eclipse UserFriend
I think you might be referring to the xmi:id values? Those are internal identifiers assigned by EMF and you should not use or rely upon them.

Most E4 model elements support an `elementId` attribute which is generally under your control and should be preserved. It is a significant attribute for a number of objects, like MCommand objects where it defines the ID of the command which is referenced elsewhere.

Alternatively you can define your own custom ID and store it in the persistedState map attribute, which is supported by most model elements.

Brian.
Re: How to keep IDs consistent [message #1776834 is a reply to message #1776745] Wed, 22 November 2017 07:58 Go to previous messageGo to next message
Felix Funke is currently offline Felix FunkeFriend
Messages: 6
Registered: October 2013
Junior Member
No that is not what I meant.

For example in my application I habe a Command "Add Element". This has an ID (de.myapp.command.addElement), a Name and some parameters.

Now in my code I need to execute the command programatically. So I have to create a ParameterizedCommand like this:

ParameterizedCommand parameterizedCommand = commandService.createCommand("de.myapp.command.addElement", parameters);


What I don't like is having the String "de.myapp.command.addElement" in this call. I made it into a constant along with other IDs from the XMI file. But the constants and the identifiers from the XMI are not synced when doing refactorings etc.

Felix
Re: How to keep IDs consistent [message #1776892 is a reply to message #1776834] Wed, 22 November 2017 14:59 Go to previous messageGo to next message
Eclipse UserFriend
Two approaches come to mind.

First, use IDs that are independent of their container (i.e., don't use the Bundle Symbolic Name as the prefix of your identifiers). Then you don't need to change your identifiers during refactorings.

Second, create unit tests that parse content and verify that elements can be found that match the IDs in the constants. E.g., Apply XPath expressions against your .xmi or plugin.xml etc. This is surprisingly effective!

Brian.
Re: How to keep IDs consistent [message #1777060 is a reply to message #1776892] Fri, 24 November 2017 08:35 Go to previous messageGo to next message
Gernot Krause is currently offline Gernot KrauseFriend
Messages: 22
Registered: June 2014
Junior Member
Hi,

I figured out that in some cases the element IDs are parsed by the internal e4 classes:

For instances, I recently ran into an issue with
		partService.createPart(elementID)


The element ID described a part descriptor, and, although it was correctly spelled the part was not created. After debugging my code down into the e4 part service implementation, I figured out what the issue was:

My element ID contains an colon ":" and the part service implementation parses this ID and takes only the substring before the colon to find the part descriptor.

		// If the id contains a ':' use the part before it as the descriptor id
		int colonIndex = id == null ? -1 : id.indexOf(':');
		String descId = colonIndex == -1 ? id : id.substring(0, colonIndex);


Is there somewhere a documentation in what cases element IDs are parsed and how to use them? Sometimes I also see element IDs like "toolbar:org.eclipse.ui.main.toolbar". What is the "toolbar:" for and how is it parsed? What does it control?

By the way, is it a good practice that IDs are not just IDs but also used for kind of "coding" or "control"?

Thx!
Gernot.
Re: How to keep IDs consistent [message #1777149 is a reply to message #1777060] Sat, 25 November 2017 02:49 Go to previous messageGo to next message
Eclipse UserFriend
Although the elementId field is a free-form string, consumers of particular model elements may impose requirements. The EPartService, for example, generally assumes that parts are singletons within a window, unless additional information is provided which is encoded in the elementId (an approach that was inherited from E3.x). You're of course free to not use the Part Service, in which case you could use free-form identifiers.

The `toolbar:` prefix, and its cousins `popup:` and `menu:`, are used by the EMenuService for targeting contributions.

Brian.
Re: How to keep IDs consistent [message #1777543 is a reply to message #1776892] Thu, 30 November 2017 08:46 Go to previous message
Felix Funke is currently offline Felix FunkeFriend
Messages: 6
Registered: October 2013
Junior Member
Thanks Brian,

I think I'll implement the test cases.
Previous Topic:Dynamic CSS - Applied on Load of E4 Application
Next Topic:e4 Compatibility Mode > MinMaxAddon
Goto Forum:
  


Current Time: Thu Apr 25 10:43:13 GMT 2024

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

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

Back to the top