Introduction
Eclipse E4 (Eclipse 4) has been the default architecture for the Eclipse platform since the Juno release (4.2) in June 2012. Since then, all Eclipse 3.x applications continue to function, but they run in compatibility mode, which provides backwards compatibility but doesn’t let you use the new E4 features directly. This compatibility layer will be maintained, but migrating to native E4 offers numerous advantages.
Advantages of Migrating to Eclipse E4
- Model-based UI: E4 uses a declarative application model that separates UI structure from implementation, making it more flexible and easier to modify.
- Dependency Injection: Built-in DI reduces coupling between components and makes code more testable.
- CSS Styling: E4 allows you to style your application using CSS, making it easier to create consistent themes and customize appearance.
- Modular Services: The service-oriented architecture makes it easier to replace, extend or mock components.
- Simplified Programming Model: Many common tasks require less code in E4 than in 3.x.
- Live Model Editing: The application model can be modified at runtime, allowing for dynamic UI changes.
- Better Resource Management: Improved resource tracking and cleanup with annotation-based lifecycle management.
- Future-proof: As Eclipse continues to evolve, 3.x compatibility mode may eventually be deprecated.
Before You Start
Before migration, make sure you understand these important concepts:
- Application Model: E4 uses a declarative model for UI elements
- Dependency Injection: E4 uses this pattern extensively
- CSS Styling: E4 allows styling UI components with CSS
- Services: E4 uses services for many platform functions
(IMG-PLACEHOLDER: Eclipse 3.x vs E4 architecture comparison)
Migration Strategy
Step 1: Assess Your Application
First, evaluate your application to identify which parts should be migrated first:
- Components with minimal dependencies
- Non-UI plugins before UI plugins
- Extension points that have direct E4 equivalents
Step 2: Update Dependencies
Add these required dependencies to your plugin’s MANIFEST.MF file:
org.eclipse.e4.core.di
org.eclipse.e4.core.contexts
org.eclipse.e4.ui.model.workbench
org.eclipse.e4.ui.workbench
BashStep 3: Migrate Core Plugins First
Start with plugins that don’t depend on UI elements. This makes testing easier and reduces compatibility issues.
Migration Components Guide
Migrating Menus, Commands, and Handlers
In Eclipse 3.x, menus and commands are defined using extension points in plugin.xml:
<extension point="org.eclipse.ui.commands">
<command id="sample.command" name="Sample Command"/>
</extension>
XMLIn E4, they are defined in the application model:
- Create or modify the application model file (Application.e4xmi)
- Add commands to the Commands section
- Create handlers using the @Execute annotation:
public class SampleHandler {
@Execute
public void execute() {
// Handler logic here
}
}
Java(IMG-PLACEHOLDER: Application.e4xmi editor screenshot)
Migrating Lifecycle Management
Eclipse 3.x manages lifecycle with:
- IStartup extension point
- Plugin activator classes
E4 uses:
- @PostConstruct and @PreDestroy annotations
- Lifecycle hooks in the application model
- E4 service addons
Example E4 lifecycle hook:
public class MyAddon {
@PostConstruct
public void init(IEclipseContext context) {
// Initialization code
}
@PreDestroy
public void dispose() {
// Cleanup code
}
}
JavaMigrating Views and Editors
- Replace IViewPart implementations with POJO classes
- Use @Inject to receive workbench services
- Add view to the application model instead of using extension points
Example E4 view:
public class SampleView {
@Inject
public SampleView(Composite parent, MPart part) {
// Create view contents
}
}
JavaMigrating Selection Service
Replace:
ISelectionService selectionService = getSite().getWorkbenchWindow().getSelectionService();
JavaWith:
@Inject
ESelectionService selectionService;
JavaCommon Issues and Solutions
- Mixed Mode Operation: During migration, your application will have both 3.x and E4 components. Use IEclipseContext to bridge between them.
- Extension Point Changes: Many 3.x extension points don’t exist in E4. Use the application model or services instead.
- Context Access: In 3.x, you often use static methods for access. In E4, use dependency injection.
Testing Your Migration
- Start with a small feature set
- Create isolated test plugins
- Use the compatibility layer as a fallback during migration
- Test in both 3.x compatibility and pure E4 mode
(IMG-PLACEHOLDER: Testing workflow diagram)
Recommended Migration Order
- Core services and non-UI plugins
- Commands and handlers
- Views and editors
- Perspectives
- Preference pages
- Actions and menus
Key Considerations for Migration Evaluation
When to Migrate
- Large Applications: Consider a gradual migration, component by component
- New Features: If you need E4-specific features like flexible UI layouts or CSS styling
- Long-term Maintenance: Applications with long lifecycles will benefit from migrating sooner
When to Stay with 3.x Compatibility
- Stable Applications: If your application is stable and doesn’t need new E4 features
- Short Project Timeline: If you have tight deadlines, the compatibility layer may be sufficient
- Legacy Components: If you depend on 3.x-specific APIs with no E4 equivalents
Migration Effort Estimation
- Small Applications (5-10 plugins): 1-2 months for a full migration
- Medium Applications (10-50 plugins): 3-6 months
- Large Applications (50+ plugins): 6+ months, consider a phased approach
Tools to Help Migration
- Eclipse E4 Tools: Provide visual editors for application models
- Eclipse Migration Guide: Available in the Eclipse help system
- Migration analyzers: Can help identify which components need changes
References and Resources
- Eclipse E4 Wiki
- Vogella E4 Tutorials
- Eclipse E4 Tools
- Eclipse Platform Newsgroup
- Eclipse E4 Migration Guide
- Eclipse Wiki: E4 Running the compatibility Layer
Conclusion
Migrating from Eclipse 3.x to E4 requires careful planning but offers significant benefits in terms of maintainability, flexibility, and future-proofing. The most important aspects are understanding the application model, properly using dependency injection, and migrating core components first. While the process may seem complex, taking a systematic approach will lead to a cleaner, more maintainable application that can take full advantage of the modern Eclipse platform.
Remember that your migration doesn’t have to happen all at once. The compatibility layer allows you to migrate components gradually, testing each one thoroughly before moving on to the next. This incremental approach helps manage risk and allows your team to become familiar with E4 concepts over time.
0 Comments