Add CoreExpression support for handler enablement in E4 model #3420
+617
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds support for
enabledWhencore expressions to E4 handlers, bringing feature parity with E3 handlers and simplifying migration from E3 to E4. Previously, E4 handlers could only use@CanExecuteannotations for enablement, while E3 handlers had rich declarative<enabledWhen>expressions. This made migration more difficult and required rewriting declarative expressions as imperative code.Problem
In E3, handlers could use declarative core expressions for enablement:
In E4, developers had to convert these to
@CanExecutemethods, which was problematic for complex expressions and required understanding the imperative API.Solution
This PR adds an optional
enabledWhenfield to the E4 Handler model that accepts core expressions, similar to the existingvisibleWhensupport for menu items.Changes Made
Model Definition: Added
enabledWhenreference toHandlerinUIElements.ecoreMExpression(supportsMCoreExpressionand others)Expression Evaluation Infrastructure:
IHandlerWithExpressioninterface inorg.eclipse.e4.core.commandsto avoid circular dependenciesHandlerEnabledWhenWrapperthat evaluates expressions and delegates to the wrapped handlerHandlerProcessingAddonto wrap handlers with enabledWhen expressions during activationHandlerServiceHandlerto check enabledWhen before consulting@CanExecuteDocumentation: Enhanced
Eclipse4_Migration.mdwith:<enabledWhen>to E4 core expressionsCommand_Core_Expressions.mdfor expression syntaxTests: Added
HandlerEnabledWhenTestcovering:Usage Example
Define a core expression in plugin.xml:
In the E4 Model Editor, add an "Enabled When" core expression to your handler with ID
com.example.handler.enabled.Expression Precedence
When both
enabledWhenexpression and@CanExecuteare present:enabledWhenexpression is evaluated first@CanExecute)@CanExecutemethod is calledThis allows combining declarative expressions for complex conditions with programmatic logic when needed.
Migration Path
E3 handlers with
<enabledWhen>can now migrate to E4 by:This approach maintains the declarative nature of E3 expressions while leveraging E4's model-based architecture.
Fixes #[issue-number]
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
repo.eclipse.org/usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/eclipse.platform.ui/eclipse.platform.ui org.codehaus.plexus.classworlds.launcher.Launcher clean compile -Pbuild-individual-bundles(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.