Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Problems extending the application model with PartDescriptor's.
Problems extending the application model with PartDescriptor's. [message #508621] Tue, 19 January 2010 16:17 Go to next message
Jens Keller is currently offline Jens KellerFriend
Messages: 50
Registered: December 2009
Location: Leipzig, Germany
Member
Hello,

i tried to extend my application model with PartDescriptor's and took the photo demo and org.eclipse.e4.ide.application as an example. So i created an components.e4xmi file with one descriptor and registered it through the org.eclipse.e4.workbench.model extension point. But when i start the application i get the following error:

java.lang.ClassCastException: org.eclipse.e4.ui.model.application.impl.ModelComponentsImpl cannot be cast to org.eclipse.e4.ui.model.application.MApplicationElement
at org.eclipse.e4.workbench.ui.internal.E4XMIResource.getID(E4X MIResource.java:82)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.attachedHelpe r(XMLResourceImpl.java:460)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.attached(Re sourceImpl.java:859)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl$ContentsELi st.inverseAdd(ResourceImpl.java:416)
at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:318)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processTopObject(X MLHandler.java:1484)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1336)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1468)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:1019)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:83)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:1001)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:712)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:169)
......

I'm also getting a FeatureNotFoundException (for label, ModelComponents, containerData etc.) when i try to open the e4xmi-files with the emf-editor and i don't have these features as design-elements in the context-menu.

I'm using eclipse 3.6M4 and e4M3 as target.


Thanks in advance,

Jens Keller
Re: Problems extending the application model with PartDescriptor's. [message #510431 is a reply to message #508621] Wed, 27 January 2010 14:15 Go to previous messageGo to next message
Remy Suen is currently offline Remy SuenFriend
Messages: 462
Registered: July 2009
Senior Member
Jens Keller wrote on Tue, 19 January 2010 11:17
But when i start the application i get the following error:

java.lang.ClassCastException: org.eclipse.e4.ui.model.application.impl.ModelComponentsImpl cannot be cast to org.eclipse.e4.ui.model.application.MApplicationElement
at org.eclipse.e4.workbench.ui.internal.E4XMIResource.getID(E4X MIResource.java:82)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.attachedHelpe r(XMLResourceImpl.java:460)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.attached(Re sourceImpl.java:859)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl$ContentsELi st.inverseAdd(ResourceImpl.java:416)
at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:318)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processTopObject(X MLHandler.java:1484)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1336)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1468)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:1019)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:83)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:1001)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:712)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:169)
Please open a bug about this in Bugzilla.
Re: Problems extending the application model with PartDescriptor's. [message #510757 is a reply to message #510431] Thu, 28 January 2010 14:51 Go to previous messageGo to next message
Jens Keller is currently offline Jens KellerFriend
Messages: 50
Registered: December 2009
Location: Leipzig, Germany
Member
I found the solution. I forgot the xmi:id-attribut in the application element of the components.e4xmi-file.


Thats the steps i took to integrate a PartDescriptor (which i can now use at runtime but now i'm having problems showing this part):

I used two plugins de.sampleapp.client & de.sampleapp.data.ui

1. create a e4xmi-file to define the PartDescriptor in the de.sampleapp.data.ui plugin

<?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.eco re " xmi:id="which_i_forgot">
<components parentID="sampleApp">
<descriptors
URI=" platform:/plugin/de.sampleapp.data.ui/de.sampleapp.data.ui.T estView "
label="TestView"
category="viewStack"/>
</components>
</application:ModelComponents>


2. register this components.e4xmi definition via an extension in the de.sampleapp.data.ui plugin

<extension
id="SampleApp"
name="SampleApp"
point="org.eclipse.e4.workbench.model">
<snippet
uri="xmi/components.e4xmi">
</snippet>
</extension>


3. use the PartDescriptor in the de.sampleapp.client plugin in a self defined action

public void perform( MyActionEvent event ) {
IEclipseContext context = event.getContext();
MWindow window = (MWindow) context.get( EPartService.PART_SERVICE_ROOT );
MApplication app = (MApplication) (MUIElement) window.getParent();
EList<MPartDescriptor> desc = app.getDescriptors();

EPartService serviceP = (EPartService) context.get( EPartService.class.getName() );
if( !desc.isEmpty()){
serviceP.showPart( desc.get( 0 ).getId() );
Collection<MPart> partCollection = serviceP.getParts();
}
}

The PartDescriptor is now in the descriptor list of the MApplication and i can call EPartService.showPart() without an error
and after that the part is in the Collection of the EPartService.getParts() method. But the problem is, that the part
doesn't show up in the application.

And thats the part i try to show:

public class TestView {

@Inject
private Composite parent;

private Image image;

@PostConstruct
void init(){
parent.setLayout(new FillLayout());
image = new Image(Display.getDefault(),getClass().getResourceAsStream( "/images/karte.jpg" ));
Canvas canvas = new Canvas(parent,SWT.NO_REDRAW_RESIZE);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.drawImage(image,0,0);
}
});
}

@PreDestroy
void dispose(){
if(!image.isDisposed())
image.dispose();
}
}
Re: Problems extending the application model with PartDescriptor's. [message #510954 is a reply to message #510757] Fri, 29 January 2010 10:03 Go to previous messageGo to next message
Jens Keller is currently offline Jens KellerFriend
Messages: 50
Registered: December 2009
Location: Leipzig, Germany
Member
I got it. You need to include org.eclipse.equinox.event to the runtime config.
So just follow steps 1-3 from the previous post and use this simple view:

public class TestView {

@Inject
private Composite parent;

@PostConstruct
void init( ){
parent.setLayout(new FillLayout());
Label label = new Label( parent, SWT.NULL);
label.setText( "Jaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" );
}

@PreDestroy
void dispose(){
}

}

Maybe someone can comment on this, if this is the right way to go. Especially on how to get the MApplication in step 3.

Jens Keller
Re: Problems extending the application model with PartDescriptor's. [message #511543 is a reply to message #510954] Mon, 01 February 2010 18:20 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 242
Registered: July 2009
Senior Member
Jens Keller wrote:
> Maybe someone can comment on this, if this is the right way to go.
Especially on how to get the MApplication in step 3.

Hi Jens. Can you not use injection to obtain the application?

public class TestView {
// ...
@Inject MApplication app;
// ...
}
Re: Problems extending the application model with PartDescriptor's. [message #511627 is a reply to message #511543] Tue, 02 February 2010 10:40 Go to previous messageGo to next message
Jens Keller is currently offline Jens KellerFriend
Messages: 50
Registered: December 2009
Location: Leipzig, Germany
Member
Thanks for your help. I tried that, but i'm using a self defined action (used in the context menu of a treeviewer) which opens the part descriptor and when i'm using dependency injection in that action the MApplication is always null. Right now i'm trying to pass through the MApplication when the action is called.
But you are right with your advice, when i'm using the dependency injection in the part i'm opening (or other parts) it works just fine.
Re: Problems extending the application model with PartDescriptor's. [message #568191 is a reply to message #510757] Fri, 29 January 2010 10:03 Go to previous messageGo to next message
Jens Keller is currently offline Jens KellerFriend
Messages: 50
Registered: December 2009
Location: Leipzig, Germany
Member
I got it. You need to include org.eclipse.equinox.event to the runtime config.
So just follow steps 1-3 from the previous post and use this simple view:

public class TestView {

@Inject
private Composite parent;

@PostConstruct
void init( ){
parent.setLayout(new FillLayout());
Label label = new Label( parent, SWT.NULL);
label.setText( "Jaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" );
}

@PreDestroy
void dispose(){
}

}

Maybe someone can comment on this, if this is the right way to go. Especially on how to get the MApplication in step 3.

Jens Keller
Re: Problems extending the application model with PartDescriptor's. [message #568227 is a reply to message #568191] Mon, 01 February 2010 22:50 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 242
Registered: July 2009
Senior Member
Jens Keller wrote:
> Maybe someone can comment on this, if this is the right way to go.
Especially on how to get the MApplication in step 3.

Hi Jens. Can you not use injection to obtain the application?

public class TestView {
// ...
@Inject MApplication app;
// ...
}
Re: Problems extending the application model with PartDescriptor's. [message #568247 is a reply to message #568227] Tue, 02 February 2010 10:40 Go to previous message
Jens Keller is currently offline Jens KellerFriend
Messages: 50
Registered: December 2009
Location: Leipzig, Germany
Member
Thanks for your help. I tried that, but i'm using a self defined action (used in the context menu of a treeviewer) which opens the part descriptor and when i'm using dependency injection in that action the MApplication is always null. Right now i'm trying to pass through the MApplication when the action is called.
But you are right with your advice, when i'm using the dependency injection in the part i'm opening (or other parts) it works just fine.
Previous Topic:Problems extending the application model with PartDescriptor's.
Next Topic:Setting the input on a dynamically opened part.
Goto Forum:
  


Current Time: Thu Apr 18 12:09:30 GMT 2024

Powered by FUDForum. Page generated in 0.03440 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top