Using the model spy in Eclipse. This tutorial gives an description how to use the model spy in Eclipse RCP applications.
1. Using the application model spy
1.1. Analyzing the application model with the model spy
The application model of an Eclipse application is available at runtime. The application can access the model and change it via a defined API.
To analyzing and modify the runtime model, you can use a test tool from the e4 tools project which allows modifying the application model interactively. This tool is called Model Spy (used to be called: Live model editor) and can be integrated into your RCP application. Most changes are directly applied, e.g., if you change the orientation of a part sash container, your user interface is updated automatically.
In the model spy, you can select a part in the application model, right click on it and select Show Control to get the part highlighted.
1.2. Model spy and the Eclipse IDE
If installed you can also use the model spy to see the application model of the running Eclipse IDE itself. You can open it via the Alt+Shift+F9 shortcut.
If you modify the Eclipse IDE model, you should be careful as this might put the running Eclipse IDE into a bad state. To fix such issues, start the Eclipse IDE from the command line with the -clearPersistedState parameter.
2. Optional Exercise: Using the model spy
To test the application model dynamics, integrate the model spy and its dependencies into the run configuration of your application.
The model spy is a debug tool and not intended to be used in a productive application. So it might happen that this exercise does not work, or that you see additional exceptions in your log file, caused by the tool.
2.1. Add the spies to your target platform
Ensure you have the e4 spies installed. See [tutorial_installation_e4spies] for the update site.
If you are using a target platform, add the model spies plug-ins to your target platform. Otherwise the spies are not available to be integrated into your RCP application.
2.2. Adding the model spy to your runtime configuration
Open the run configuration of your product via the
org.eclipse.e4.tools.model.spy plug-in and its dependencies to it.
If you use the filter you have to remove it before the Add Required Plug-ins becomes active again.
Press the Validate button to ensure that all dependencies are included.
2.3. Use the model spy
After you have added the new plug-ins to your run configuration press the Run button in the run configuration you just added.
Do not start the application now via the product. Starting via the product resets your changes in the runtime configuration.
Start your application and use the Shift+Alt+F9 shortcut to open the model spy.
The code of the model spy adds this key binding to your application by modifying your application model at runtime. If you already defined key bindings this process might fail.
Use the model spy to change the runtime application model. For example, add a part (with a label) or change the size of the window. All changes should become immediately visible (except changes for new menu entries, due to a bug).
2.4. Cleanup - remove model spy from your run configuration
After testing with the tool enabled, start your application again from your product configuration file to remove the model spy plug-in from your run configuration.
If you leave the model spy included in your run configuration, it might cause side effects. For example, in the past it created exceptions if key bindings were present in the application.
3. Learn more about Eclipse 4 RCP development
I hope you enjoyed this tutorial. You find this tutorial and much more information also in the Eclipse 4 RCP book.
4. About this website
5. Eclipse 4 resources
5.1. vogella GmbH training and consulting support
|TRAINING||SERVICE & SUPPORT|
The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”.
The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers.
Appendix A: Copyright and License
Copyright © 2012-2016 vogella GmbH. Free use of the software examples is granted under the terms of the EPL License. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.