Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » ClassCastException
ClassCastException [message #188269] Wed, 21 May 2008 15:42 Go to next message
paolo russian is currently offline paolo russianFriend
Messages: 34
Registered: July 2009
Member
public void setInput(IWorkbenchPart part, ISelection selection) {

System.out.println("selection="+selection.toString());
if (selection instanceof IStructuredSelection) {
System.out.println("isStructuredSelection test passed");
JollyWidgetEditPart editPart = (JollyWidgetEditPart)
((IStructuredSelection) selection).getFirstElement();
System.out.println("JWEditPart="+editPart.toString());
JollyWidget JW = (View) editPart.getModel());

this last line throws me a classcastexception, does anyone know how to
bypass my issue?

stack:
JWEditPart=JollyWidgetEditPart(
org.eclipse.gmf.runtime.notation.impl.NodeImpl@1747f59 (visible: true,
type: 2034, mutable: false) )
java.lang.ClassCastException:
org.eclipse.gmf.runtime.notation.impl.NodeImpl
at
components.diagram.sheet.CodePropertySection.setInput(CodePr opertySection.java:74)
Re: ClassCastException [message #188329 is a reply to message #188269] Wed, 21 May 2008 16:31 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Paolo,

Try:
JollyWidget JW = (JollyWidget) ((View) editPart.getModel()).getElement();

-----------------
Alex Shatalin
Re: ClassCastException [message #188430 is a reply to message #188329] Thu, 22 May 2008 08:14 Go to previous messageGo to next message
paolo russian is currently offline paolo russianFriend
Messages: 34
Registered: July 2009
Member
same identical error :( what I want to do is simply have one of the custom
values (from the model ecore, an EAttribute) to be displayed and edited
in a separate tabbed property view, I can have the customized tabbed
property displayed only when I click on the jollywidget (as I wanted) but
when I try to fill the textarea with the value it spits out the stacktrace
classcastexception etc..

this is the full tabbed property code:


package components.diagram.sheet;

import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.text.View;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.ui.provider.PropertySource;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import
org.eclipse.gmf.runtime.diagram.ui.properties.sections.Advan cedPropertySection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.IPropertySourceProvider;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySecti on;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPa ge;

import components.JollyWidget;
import components.diagram.edit.parts.JollyWidgetEditPart;

/**
* @generated not
*/
public class CodePropertySection extends AbstractPropertySection {


private Text codeText;


@Override

public void createControls(Composite parent, TabbedPropertySheetPage
tabbedPropertySheetPage) {

FormToolkit toolkit = new FormToolkit(parent.getDisplay());
Form form = toolkit.createForm(parent);

form.setText( "Custom code:" );

TableWrapLayout layout = new TableWrapLayout();
Composite body = form.getBody();


body.setLayout(layout);



codeText = toolkit.createText(body, "" ,
SWT.BORDER|SWT.MULTI|SWT.H_SCROLL|SWT.V_SCROLL);
codeText.setLayoutData( new TableWrapData(TableWrapData.FILL_GRAB));
}

@Override
public void setInput(IWorkbenchPart part, ISelection selection) {

System.out.println("selection="+selection.toString());
if (selection instanceof IStructuredSelection) {
System.out.println("isStructuredSelection test passed");
JollyWidgetEditPart editPart = (JollyWidgetEditPart)
((IStructuredSelection) selection).getFirstElement();
System.out.println("JWEditPart="+editPart.toString());
JollyWidget JW = (JollyWidget) ((View)
editPart.getModel()).getElement();
//View view = (View) editPart.getModel();
//System.out.println("view = "+ view);
// JollyWidget JW = (JollyWidget) view.getElement();
System.out.println("JW="+JW);
// if (null != JW.getTitle())
// codeText.setText(JW.getValue());
//
}
}





}
Re: ClassCastException [message #188588 is a reply to message #188430] Thu, 22 May 2008 09:05 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Paolo,

> JollyWidgetEditPart editPart = (JollyWidgetEditPart)
Well, can you please put a break point into this line to see what is editPart
and how can you access corresponding domain model element from it in a debugger?..
In general each editPart has View instance specified as a model, each View
has domain model element associated and available via getElement() method.

-----------------
Alex Shatalin
Re: ClassCastException [message #188617 is a reply to message #188588] Thu, 22 May 2008 10:04 Go to previous messageGo to next message
paolo russian is currently offline paolo russianFriend
Messages: 34
Registered: July 2009
Member
well placing a breakpoint there and watching "editPart" I cannot find any
"view" subnode on the debugger, anyway I've got these data (I list some of
them, tell me if you need some other in particular):

"editPart"= JollyWidgetEditPart (id=104)
accessibleEP= GraphicalEditPart$4 (id=176)
cachedFontData= FontData (id=178)
children= ArrayList<E> (id=181)
contentPane= JollyWidgetEditPart$JollyWidgetFigure (id=193)
editingDomain= DiagramEditingDomainFactory$DiagramEditingDomain (id=195)
elementGuid= "_XR66oCceEd2i7qwPE91RNA"
eventListeners= EventListenerList (id=199)
figure= DefaultSizeNodeFigure (id=214)
flags= 1
isEditable= true
listenerFilters= HashMap<K,V> (id=219)
model= NodeImpl (id=223)
parent= EditorEditPart (id=237)
policies= Object[24] (id=239)
primaryShape= JollyWidgetEditPart$JollyWidgetFigure (id=193)
selected= 2
sourceConnections= null
targetConnections= null

where have I got to look to find the view data? Tried but can't find :\


Alex Shatalin wrote:

> Hello Paolo,

>> JollyWidgetEditPart editPart = (JollyWidgetEditPart)
> Well, can you please put a break point into this line to see what is
editPart
> and how can you access corresponding domain model element from it in a
debugger?..
> In general each editPart has View instance specified as a model, each View
> has domain model element associated and available via getElement() method.

> -----------------
> Alex Shatalin
Re: ClassCastException [message #188689 is a reply to message #188617] Thu, 22 May 2008 10:50 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Paolo,

> "editPart"= JollyWidgetEditPart (id=104)
....
> model= NodeImpl (id=223)
Node is a subclass of View.

-----------------
Alex Shatalin
Re: ClassCastException [message #188736 is a reply to message #188689] Thu, 22 May 2008 11:57 Go to previous messageGo to next message
paolo russian is currently offline paolo russianFriend
Messages: 34
Registered: July 2009
Member
well I'm not sure this concept is fully clear to me, I added a

System.out.println("test1 = " + ((GraphicalEditPart) editPart).getModel());

System.out.println("test2 = " + (View) ((GraphicalEditPart)
editPart).getModel()););

and I got this more detailed error on the second line:
ClassCastException: Cannot cast
org.eclipse.gmf.runtime.notation.impl.NodeImpl (id=952) to
javax.swing.text.View
Re: ClassCastException [message #188778 is a reply to message #188689] Thu, 22 May 2008 13:44 Go to previous messageGo to next message
paolo russian is currently offline paolo russianFriend
Messages: 34
Registered: July 2009
Member
(View) editPart.getModel() this crashes in all the way I tried. I'm
currently obtaining the instance of my selected node in all the way I can
think of, and keep feeding this (View)<-nodeimpl cast but it's a no way
operation! Looks like it's like converting a carrot into a squirrel, at
least it seems!

That's weird because I've found a bit of examples around and they do this
way to display an EAttribute on their custom sheet tab... but it's not
working for me, so I wonder (since the 70% of google findings refer to
obsolete gmf version, the remaining 30% it's not declared :) ) maybe I've
got sample code for old gmf!?

:'( I want to read my custom node eattribute from my custom tab, not any
other gmf magic!
Re: ClassCastException [message #188802 is a reply to message #188736] Thu, 22 May 2008 13:55 Go to previous messageGo to next message
Mariot Chauvin is currently offline Mariot ChauvinFriend
Messages: 174
Registered: July 2009
Senior Member
Hi Paolo,

You imported the wrong View class.

Replace "import javax.swing.text.View;" with "import org.eclipse.gmf.runtime.notation.View;" in your code.

Regards,

Mariot

paolo a écrit :
> well I'm not sure this concept is fully clear to me, I added a
>
> System.out.println("test1 = " + ((GraphicalEditPart) editPart).getModel());
>
> System.out.println("test2 = " + (View) ((GraphicalEditPart)
> editPart).getModel()););
>
> and I got this more detailed error on the second line:
> ClassCastException: Cannot cast
> org.eclipse.gmf.runtime.notation.impl.NodeImpl (id=952) to
> javax.swing.text.View
>
Re: ClassCastException [message #188809 is a reply to message #188778] Thu, 22 May 2008 14:03 Go to previous message
paolo russian is currently offline paolo russianFriend
Messages: 34
Registered: July 2009
Member
Thanks a lot you've really saved the day!!!!! (and the week...)
best regards ;)

Paolo Russian
Previous Topic:Launch DiagramGeneration from my own Plugin
Next Topic:Implementation of a new FileSystem based on Reusable Asset
Goto Forum:
  


Current Time: Fri Apr 26 17:27:15 GMT 2024

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

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

Back to the top