Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "E4/Snippets"
< E4
Line 1: | Line 1: | ||
Here you can find '''snippets''' and '''practical tips''' covering '''Eclipse e4'''. | Here you can find '''snippets''' and '''practical tips''' covering '''Eclipse e4'''. | ||
− | + | = Parts = | |
− | + | == Open a part dynamically == | |
+ | |||
+ | Define a part descriptor and open the part with the help of the EPartService. | ||
+ | |||
+ | Create a components.e4xmi file to define the part descriptor. | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <?xml version="1.0" encoding="ASCII"?> | ||
+ | <application:ModelComponents | ||
+ | xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
+ | xmlns:application="http://www.eclipse.org/ui/2008/UIModel" | ||
+ | xsi:schemaLocation="http://www.eclipse.org/ui/2008/UIModel ../../org.eclipse.e4.ui.model.workbench/model/UIElements.ecore " xmi:id="abc"> | ||
+ | <components | ||
+ | parentID="sampleApp"> | ||
+ | <descriptors | ||
+ | URI="platform:/plugin/de.sampleapp.data.ui/de.sampleapp.data.ui.TestView " | ||
+ | label="TestView" | ||
+ | category="viewStack"/> | ||
+ | </components> | ||
+ | </application:ModelComponents> | ||
+ | </source><br> | ||
+ | |||
+ | Register the components.e4xmi definition through an extension. | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <extension | ||
+ | id="SampleApp" | ||
+ | name="SampleApp" | ||
+ | point="org.eclipse.e4.workbench.model"> | ||
+ | <snippet | ||
+ | uri="xmi/components.e4xmi"> | ||
+ | </snippet> | ||
+ | </extension> | ||
+ | </source><br> | ||
+ | |||
+ | Get the part descriptor at runtime and open it. For this step you need the IEclipseContext. You can get it either through dependency injection or passing it from another class. You can also try to get the MApplication through dependency injection, but in my case that didn't worked. | ||
+ | |||
+ | <source lang="java"> | ||
+ | MWindow window = (MWindow) context.get( EPartService.PART_SERVICE_ROOT ); | ||
+ | MApplication app = (MApplication) (MUIElement) window.getParent(); | ||
+ | EList<MPartDescriptor> descriptorList = app.getDescriptors(); | ||
+ | for( MPartDescriptor descriptorList : desc ){ | ||
+ | if( partDesc.getId().equals( PartToOpen.ID ) ){ | ||
+ | MPart part = servicePart.showPart( partDesc.getId() ); | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | </source> |
Revision as of 06:39, 3 February 2010
Here you can find snippets and practical tips covering Eclipse e4.
Parts
Open a part dynamically
Define a part descriptor and open the part with the help of the EPartService.
Create a components.e4xmi file to define the part descriptor.
<?xml version="1.0" encoding="ASCII"?> <application:ModelComponents xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2008/UIModel" xsi:schemaLocation="http://www.eclipse.org/ui/2008/UIModel ../../org.eclipse.e4.ui.model.workbench/model/UIElements.ecore " xmi:id="abc"> <components parentID="sampleApp"> <descriptors URI="platform:/plugin/de.sampleapp.data.ui/de.sampleapp.data.ui.TestView " label="TestView" category="viewStack"/> </components> </application:ModelComponents>
Register the components.e4xmi definition through an extension.
<extension id="SampleApp" name="SampleApp" point="org.eclipse.e4.workbench.model"> <snippet uri="xmi/components.e4xmi"> </snippet> </extension>
Get the part descriptor at runtime and open it. For this step you need the IEclipseContext. You can get it either through dependency injection or passing it from another class. You can also try to get the MApplication through dependency injection, but in my case that didn't worked.
MWindow window = (MWindow) context.get( EPartService.PART_SERVICE_ROOT ); MApplication app = (MApplication) (MUIElement) window.getParent(); EList<MPartDescriptor> descriptorList = app.getDescriptors(); for( MPartDescriptor descriptorList : desc ){ if( partDesc.getId().equals( PartToOpen.ID ) ){ MPart part = servicePart.showPart( partDesc.getId() ); break; } }