Project: Eclipse_Platform_UI
Bug 363961 Restructure UIEvents to increase clarity and performance
Reported: 2011-11-16 14:21:37 | Status: verified fixed

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.

Files changed in fix:
bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/cleanupaddon/CleanupAddon.java bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DnDAddon.java bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DnDManager.java bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/minmax/MinMaxAddon.java bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/minmax/TrimStack.java bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/AreaRenderer.java bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuItemRenderer.java bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SashRenderer.java bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolItemRenderer.java bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/GenTopic.java bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/util/BindingProcessingAddon.java bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionServiceImpl.java bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/CommandProcessingAddon.java bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/ContextProcessingAddon.java bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/UIEvents.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ViewIntroAdapterPart.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/HeadlessContextPresentationEngine.java tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UIEventsTest.java