Skip to content

Commit b26036d

Browse files
Copilotlaeubi
andcommitted
Address review feedback: update to jakarta, add Eclipse4_Model.md, and clarify best practices
Co-authored-by: laeubi <[email protected]>
1 parent 666515d commit b26036d

File tree

2 files changed

+137
-10
lines changed

2 files changed

+137
-10
lines changed

docs/Eclipse4_Migration.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ Before you begin migrating individual components, ensure you have:
2323

2424
3. **Annotation Support**: For dependency injection to work, add to your MANIFEST.MF:
2525
```
26-
Import-Package: javax.annotation;version="1.1.0",
27-
javax.inject;version="1.0.0"
26+
Import-Package: jakarta.annotation;version="1.1.0",
27+
jakarta.inject;version="1.0.0"
2828
```
2929

30+
4. **Preserve Element IDs**: When migrating from E3 to E4, always use the same IDs! The E3 command/view/handler ID should match the E4 elementId to ensure compatibility and avoid breaking existing configurations.
31+
3032
### Creating Model Fragments
3133

3234
Model fragments allow you to contribute UI elements to the E4 application model. To create a model fragment:
@@ -58,7 +60,7 @@ The fragment structure typically looks like:
5860
</fragment:ModelFragments>
5961
```
6062

61-
For more details, see the Eclipse Wiki article: [Contributing to the Model](https://wiki.eclipse.org/Eclipse4/RCP/Modeled_UI/Contributing_to_the_Model)
63+
For more details, see [Eclipse4 Model](Eclipse4_Model.md).
6264

6365
## Migrate a Command
6466

@@ -208,7 +210,7 @@ The handler class uses dependency injection:
208210
```java
209211
package com.example.handlers;
210212

211-
import javax.inject.Named;
213+
import jakarta.inject.Named;
212214
import org.eclipse.e4.core.di.annotations.Execute;
213215
import org.eclipse.e4.core.di.annotations.CanExecute;
214216
import org.eclipse.e4.ui.services.IServiceConstants;
@@ -284,12 +286,14 @@ public class MyHandler {
284286

285287
7. **Update MANIFEST.MF**: Ensure you import the injection packages:
286288
```
287-
Import-Package: javax.inject;version="1.0.0",
288-
javax.annotation;version="1.1.0"
289+
Import-Package: jakarta.inject;version="1.0.0",
290+
jakarta.annotation;version="1.1.0"
289291
```
290292
291293
### Common Injection Patterns for Handlers
292294
295+
**Important**: Always inject dependencies in the `@Execute` and `@CanExecute` methods rather than using field injection. This ensures you always receive the most recent values from the context, which is critical for handlers that may be executed multiple times with different contexts.
296+
293297
```java
294298
// Active shell
295299
@Named(IServiceConstants.ACTIVE_SHELL) Shell shell
@@ -392,9 +396,9 @@ The view class uses dependency injection:
392396
```java
393397
package com.example.views;
394398

395-
import javax.annotation.PostConstruct;
396-
import javax.annotation.PreDestroy;
397-
import javax.inject.Inject;
399+
import jakarta.annotation.PostConstruct;
400+
import jakarta.annotation.PreDestroy;
401+
import jakarta.inject.Inject;
398402
import org.eclipse.swt.widgets.Composite;
399403
import org.eclipse.e4.ui.di.Focus;
400404

@@ -805,9 +809,9 @@ After migrating components, test thoroughly:
805809
- [Eclipse4 RCP FAQ](Eclipse4_RCP_FAQ.md) - Common questions and answers
806810
- [Eclipse4 RCP Dependency Injection](Eclipse4_RCP_Dependency_Injection.md) - DI details
807811
- [Eclipse4 RCP Contexts](Eclipse4_RCP_Contexts.md) - Context hierarchy
812+
- [Eclipse4 Model](Eclipse4_Model.md) - Contributing to the E4 application model
808813
- [Platform Command Framework](PlatformCommandFramework.md) - Command details
809814
- [Menu Contributions](Menu_Contributions.md) - E3 menu contribution patterns
810-
- [Eclipse Wiki - Contributing to the Model](https://wiki.eclipse.org/Eclipse4/RCP/Modeled_UI/Contributing_to_the_Model)
811815

812816
## Contributing
813817

docs/Eclipse4_Model.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Eclipse 4 Model
2+
3+
## Contributing to the E4 Application Model
4+
5+
This document provides guidance on contributing to the Eclipse 4 application model through model fragments and extensions.
6+
7+
## Model Fragments
8+
9+
Model fragments allow you to contribute UI elements to the E4 application model declaratively. All E4 contributions are made through model fragments rather than traditional Eclipse 3.x extension points.
10+
11+
### Creating a Model Fragment
12+
13+
1. **Create the fragment file**: Create a `fragment.e4xmi` file in your bundle's root or in a `model/` folder.
14+
15+
2. **Register in plugin.xml**: Add an extension to your plugin.xml:
16+
```xml
17+
<extension
18+
id="fragment"
19+
point="org.eclipse.e4.workbench.model">
20+
<fragment
21+
uri="fragment.e4xmi">
22+
</fragment>
23+
</extension>
24+
```
25+
26+
3. **Edit with E4 Model Editor**: Open the fragment.e4xmi with the "Eclipse 4 Model Editor" (right-click → Open With → E4 Model Editor).
27+
28+
### Fragment Structure
29+
30+
A basic fragment structure looks like:
31+
32+
```xml
33+
<?xml version="1.0" encoding="ASCII"?>
34+
<fragment:ModelFragments xmi:version="2.0"
35+
xmlns:xmi="http://www.omg.org/XMI"
36+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
37+
xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands"
38+
xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment">
39+
<!-- fragments go here -->
40+
</fragment:ModelFragments>
41+
```
42+
43+
### Types of Contributions
44+
45+
Model fragments can contribute various elements:
46+
47+
- **Commands**: Define semantic actions
48+
- **Handlers**: Implement command behavior
49+
- **Parts (Views/Editors)**: UI containers via PartDescriptors
50+
- **Menu Contributions**: Menus, toolbars, and context menus
51+
- **Key Bindings**: Keyboard shortcuts
52+
- **Addons**: Application lifecycle hooks
53+
54+
### String Model Fragments
55+
56+
The most common fragment type is `StringModelFragment`, which targets a specific feature of a parent element:
57+
58+
```xml
59+
<fragments xsi:type="fragment:StringModelFragment"
60+
featurename="commands"
61+
parentElementId="org.eclipse.e4.legacy.ide.application">
62+
<elements xsi:type="commands:Command"
63+
elementId="com.example.mycommand"
64+
commandName="My Command"/>
65+
</fragments>
66+
```
67+
68+
Key attributes:
69+
- **featurename**: The model feature to contribute to (e.g., `commands`, `handlers`, `descriptors`, `menuContributions`)
70+
- **parentElementId**: The ID of the parent element (typically your application ID or `org.eclipse.e4.legacy.ide.application`)
71+
72+
### Importing Model Elements
73+
74+
To reference elements defined in other fragments or the application model:
75+
76+
1. Select "Imports" in the fragment editor
77+
2. Add the appropriate import type (Command, Part, etc.)
78+
3. Set the Element ID to match the target element's ID
79+
80+
**Note**: Only fragments can import elements from the application model or other fragments. Application models cannot import from fragments.
81+
82+
### Element IDs
83+
84+
- Element IDs (`elementId`) are used to identify model elements
85+
- Unlike EMF's internal `xmi:id`, element IDs should be human-readable
86+
- For certain elements (like Commands), element IDs must be unique
87+
- When migrating from E3, always preserve the original IDs
88+
89+
### Model Editor Tips
90+
91+
- Use the E4 Model Editor (included in Eclipse IDE for RCP development)
92+
- The editor provides validation and helps ensure proper model structure
93+
- Changes to fragments require `-clearPersistedState` flag during development to see effects
94+
95+
## Application Model
96+
97+
The application model (`Application.e4xmi`) defines the core structure of your E4 application:
98+
99+
- **Windows**: Top-level containers
100+
- **Perspectives**: Layouts of parts
101+
- **Part Stacks**: Containers for parts (views/editors)
102+
- **Trim Bars**: Toolbars and status bars
103+
- **Handlers**: Global command handlers
104+
- **Bindings**: Key bindings
105+
- **Snippets**: Reusable UI fragments
106+
107+
## Additional Resources
108+
109+
- [Eclipse4 RCP FAQ](Eclipse4_RCP_FAQ.md) - Common questions about E4
110+
- [Eclipse4 Migration Guide](Eclipse4_Migration.md) - Migrating from E3 to E4
111+
- [Eclipse Wiki - Contributing to the Model](https://wiki.eclipse.org/Eclipse4/RCP/Modeled_UI/Contributing_to_the_Model) - Detailed Wiki article
112+
113+
## Best Practices
114+
115+
1. **Use meaningful element IDs**: Choose descriptive IDs that clearly indicate purpose
116+
2. **Keep fragments focused**: Create separate fragments for different contribution types
117+
3. **Document your model**: Add descriptions to help others understand your contributions
118+
4. **Test with -clearPersistedState**: Model changes only apply when state is cleared
119+
5. **Preserve E3 IDs when migrating**: Maintain compatibility by keeping the same IDs
120+
121+
---
122+
123+
*This guide is maintained as part of the Eclipse Platform UI project and evolves with the codebase.*

0 commit comments

Comments
 (0)