| Summary: | Restructure UIEvents to increase clarity and performance | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Dean Roberts <dean.t.roberts> | ||||||||||||
| Component: | UI | Assignee: | Dean Roberts <dean.t.roberts> | ||||||||||||
| Status: | VERIFIED FIXED | QA Contact: | Dean Roberts <dean.t.roberts> | ||||||||||||
| Severity: | normal | ||||||||||||||
| Priority: | P3 | CC: | bsd, david_williams, emoffatt, pwebster, remy.suen | ||||||||||||
| Version: | 4.2 | Flags: | pwebster:
review+
|
||||||||||||
| Target Milestone: | 4.2 M4 | ||||||||||||||
| Hardware: | All | ||||||||||||||
| OS: | All | ||||||||||||||
| Whiteboard: | |||||||||||||||
| Attachments: |
|
||||||||||||||
While implementing the change to make the topic and attribute constants fully qualified I realized there was an issue. While the fully qualified names worked well in subscribe() calls, there where many handlers that used the attribute variables directly for purposes other than building topics. Typically they where using the attribute constants to test the attribute values in events being published by UIEventPublisher. There are two potential solutions to this issue: 1) Change event publisher to use the new fully qualified attribute name when creating the event. 2) Generate two constants in UIEvents public static final String TOPIC_ENABLED = "org/eclipse/e4/ui/model/menu/Item/enabled/*"; public static final String ENABLED = "enabled"; When subscribing to events you would always use the TOPIC_* constants, when testing events in handlers you would use the vanilla ENABLED constant. Since the constants in UIEvents are generated, it is simple to generate the two sets. The shorter strings should be more performant when used in the handlers. I plan on bringing this topic up in Thursday's call in case anybody has strong feelings on which directiong to go, or if they have issues with this restructuring in general. Created attachment 207168 [details]
Patch
This patch chnanges GenTopic. It also includes the modified UIEvents.java which has some hard coded changes, as well as the newly generated constants.
The buildTopic() methods have been removed and all callers have been updated.
Comment on attachment 207168 [details]
Patch
Doh.
Removing the patch for now, tesing showed some other issues.
Created attachment 207542 [details]
Correct patch
Found the problem with the last patch. Missed updating a few subscribe calls to the new TOPIC_ constants.
Not sure if it makes sense to release this patch now, or for me to wait until I have commit rights and commit them myself.
Created attachment 207679 [details]
Add deprecation to buildTopic methods and ALL constants
Apply AFTER the 1st patch to add back in the deprecated buildTopic methods and ALL constants.
Created attachment 207682 [details]
Patch 1
Created attachment 207683 [details]
Patch 2
The 2 patches were released to master: http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=6046e7de40a4c7dc7a70dd1580afb05a2d3a8e57 . Verified the correct source is in Build id: I20111205-2330 |
Adding a defect to capture information exchanged on the e4-dev mailing list about this topic. While trying to understand UIEvents and how the topics are built up for subscribe operations I found the buildTopic() cumbersome and a barrier to understanding what was really going on. I would like to make a suggestion that I think would 1) Make the code look cleaner 2) Make the concepts clearer 3) Improve run time performance (albeit marginally) For illustration purposes, here is an example of an interface definition from UIEvents for the UIElement model object generated by GenTopic public static interface UIElement { public static final String TOPIC = UIModelTopicBase + "/ui/UIElement"; //$NON-NLS-1$ public static final String ACCESSIBILITYPHRASE = "accessibilityPhrase"; //$NON-NLS-1$ public static final String CONTAINERDATA = "containerData"; //$NON-NLS-1$ public static final String CURSHAREDREF = "curSharedRef"; //$NON-NLS-1$ public static final String ONTOP = "onTop"; //$NON-NLS-1$ public static final String PARENT = "parent"; //$NON-NLS-1$ public static final String RENDERER = "renderer"; //$NON-NLS-1$ public static final String TOBERENDERED = "toBeRendered"; //$NON-NLS-1$ public static final String VISIBLE = "visible"; //$NON-NLS-1$ public static final String VISIBLEWHEN = "visibleWhen"; //$NON-NLS-1$ public static final String WIDGET = "widget"; //$NON-NLS-1$ } To subscribe to an event that tracks a UIElements visible change you would write eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC, UIEvents.UIElement.VISIBLE), visibilityHandler); To subscribe to all changes to UIElement you would write eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC), visibilityHandler); I think it would be much nicer to write, for the first case, eventBroker.subscribe(UIEvents.UIElement.VISIBLE), visibilityHandler); or, for the second case, eventBroker.subscribe(UIEvents.UIElement.ALL), visibilityHandler); To make this possible I propose that we would generate the UIElement interface definition like this. public static interface UIElement { public static final String ALL= UIModelTopicBase + "/ui/UIElement/*"; //$NON-NLS-1$ public static final String VISIBLE = UIModelTopicBase + "/ui/UIElement/" + "visible"; //$NON-NLS-1$ ... } This would allow us to delete the three buildTopic() methods and subscribe using the constants directly. The code would also be more efficient as we would be removing method calls that do string concatenation with simple static references. In fact, I believe the compiler will just in line the references at compile time. Although I would be a fan of simply making these changes and requiring consumers to make a few small simplifying changes, we could provide a stepping stone by regenerating the new shape, deprecating the buildTopic() methods and all the TOPIC fields. We would then change the implementation of the buildTopic methods to return the appropriate constant directly without concatenating.