Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to get the Command elements from a xsd component
How to get the Command elements from a xsd component [message #398619] Sun, 19 February 2006 22:58 Go to next message
frank chen is currently offline frank chenFriend
Messages: 63
Registered: July 2009
Member
I was using the following lines to get my original list of commands:
//c is an instanceof XSDConcreteComponent
XSDItemProviderAdapterFactory ipaf = new XSDItemProviderAdapterFactory();
BasicCommandStack commandStack= new BasicCommandStack();
AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(m_ipaf , m_commandStack, new HashMap());
ItemProviderAdapter ipa = (ItemProviderAdapter)ipaf.createAdapter(c);
Collection cd = ipa.getNewChildDescriptors(c, editingDomain, null);
if(cd.size() > 0) {
  Iterator iter = cd.iterator();
  CommandParameter cp = null;
  while (iter.hasNext()) {
    cp = (CommandParameter)iter.next();
    CreateChildCommand ccc = new CreateChildCommand(m_editingDomain, c, cp.getEStructuralFeature(), cp.getEValue(), cd, ipa);
    //Do something with the create child command here
  }
}

After your(Ed Merks) suggestion that i use the adapt method instead of casting directly, i adapted it to IEditingDomainItemProvider, which is the clostest i can find that fits what i need.
so the new code is:
IEditingDomainItemProvider edip = (IEditingDomainItemProvider)ipaf.adapt(c, IEditingDomainItemProvider.class);
Collection cd = edip.getNewChildDescriptors(c, editingDomain, null);
if(cd.size() > 0) {
  Iterator iter = cd.iterator();
  CommandParameter cp = null;
  while (iter.hasNext()) {
    cp = (CommandParameter)iter.next();
    Command ccc = edip.createCommand(c, m_editingDomain, CreateChildCommand.class, cp);
    //Do something with the command here
  }
}


When i do this however, during runtime i get the exception
java.lang.ClassCastException
at org.eclipse.emf.edit.provider.ItemProviderAdapter.createComm and(ItemProviderAdapter.java:855)

What am I doing wrong
Re: How to get the Command elements from a xsd component [message #398625 is a reply to message #398619] Mon, 20 February 2006 12:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Frank,

Try using CreateChildCommand.create (the way CreateChildAction does)
instead calling createCommand directly on the item provider.


frank wrote:

>I was using the following lines to get my original list of commands:
>
>//c is an instanceof XSDConcreteComponent
>XSDItemProviderAdapterFactory ipaf = new XSDItemProviderAdapterFactory();
>BasicCommandStack commandStack= new BasicCommandStack();
>AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(m_ipaf , m_commandStack, new HashMap());
>ItemProviderAdapter ipa = (ItemProviderAdapter)ipaf.createAdapter(c);
>Collection cd = ipa.getNewChildDescriptors(c, editingDomain, null);
>if(cd.size() > 0) {
>  Iterator iter = cd.iterator();
>  CommandParameter cp = null;
>  while (iter.hasNext()) {
>    cp = (CommandParameter)iter.next();
>    CreateChildCommand ccc = new CreateChildCommand(m_editingDomain, c, cp.getEStructuralFeature(), cp.getEValue(), cd, ipa);
>    //Do something with the create child command here
>  }
>}
>

>After your(Ed Merks) suggestion that i use the adapt method instead of casting directly, i adapted it to IEditingDomainItemProvider, which is the clostest i can find that fits what i need.
>so the new code is:
>
>IEditingDomainItemProvider edip = (IEditingDomainItemProvider)ipaf.adapt(c, IEditingDomainItemProvider.class);
>Collection cd = edip.getNewChildDescriptors(c, editingDomain, null);
>if(cd.size() > 0) {
>  Iterator iter = cd.iterator();
>  CommandParameter cp = null;
>  while (iter.hasNext()) {
>    cp = (CommandParameter)iter.next();
>    Command ccc = edip.createCommand(c, m_editingDomain, CreateChildCommand.class, cp);
>    //Do something with the command here
>  }
>}
>

>
>When i do this however, during runtime i get the exception
>java.lang.ClassCastException
> at org.eclipse.emf.edit.provider.ItemProviderAdapter.createComm and(ItemProviderAdapter.java:855)
>
>What am I doing wrong
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to get the Command elements from a xsd component [message #398631 is a reply to message #398625] Mon, 20 February 2006 14:12 Go to previous messageGo to next message
frank chen is currently offline frank chenFriend
Messages: 63
Registered: July 2009
Member
I still get the same error
java.lang.ClassCastException

at org.eclipse.emf.edit.provider.ItemProviderAdapter.createComm and(ItemProviderAdapter.java:855)

at org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.crea teCommand(AdapterFactoryEditingDomain.java:397)

at org.eclipse.emf.edit.command.CreateChildCommand.create(Creat eChildCommand.java:64)

I have the source for the non-standalone emf. Although at line 855 in ItemProviderAdaptor doesn't seem to match the error, I'm guessing the class cast error occurs at the block
else if (commandClass == CreateChildCommand.class)
    {
      CommandParameter newChildParameter = (CommandParameter)commandParameter.getValue();
      result = 
        createCreateChildCommand
          (domain,
           commandParameter.getEOwner(), 
           newChildParameter.getEStructuralFeature(), 
           newChildParameter.getValue(),
           newChildParameter.getIndex(),
           commandParameter.getCollection());      
    }

It seems to cast the CommandParameter value to another CommandParameter, from what I see, the CommandParameter I'm passing in has a value that's not an instanceof CommandParameter. The code I'm using is
Command ccc = CreateChildCommand.create(editingDomain, cp.getFeature(), cp.getValue(), cp.getCollection());

where cp is gotten as in the previous message thread
Re: How to get the Command elements from a xsd component [message #398633 is a reply to message #398631] Mon, 20 February 2006 14:21 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060301060001000403010107
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Frank,

It doesn't look like you are passing the right arguments for this method:

public static Command create(EditingDomain domain, Object owner,
Object newChildDescriptor,
Collection selection)
{
return domain.createCommand(
CreateChildCommand.class,
new CommandParameter(owner, null, newChildDescriptor, selection));
}

It's good to look at CreateChildAction because that works for sure.


frank wrote:

>I still get the same error
>java.lang.ClassCastException
>
> at org.eclipse.emf.edit.provider.ItemProviderAdapter.createComm and(ItemProviderAdapter.java:855)
>
> at org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.crea teCommand(AdapterFactoryEditingDomain.java:397)
>
> at org.eclipse.emf.edit.command.CreateChildCommand.create(Creat eChildCommand.java:64)
>
>I have the source for the non-standalone emf. Although at line 855 in ItemProviderAdaptor doesn't seem to match the error, I'm guessing the class cast error occurs at the block
>
>else if (commandClass == CreateChildCommand.class)
>    {
>      CommandParameter newChildParameter = (CommandParameter)commandParameter.getValue();
>      result = 
>        createCreateChildCommand
>          (domain,
>           commandParameter.getEOwner(), 
>           newChildParameter.getEStructuralFeature(), 
>           newChildParameter.getValue(),
>           newChildParameter.getIndex(),
>           commandParameter.getCollection());      
>    }
>

>It seems to cast the CommandParameter value to another CommandParameter, from what I see, the CommandParameter I'm passing in has a value that's not an instanceof CommandParameter. The code I'm using is
>
>Command ccc = CreateChildCommand.create(editingDomain, cp.getFeature(), cp.getValue(), cp.getCollection());
>

>where cp is gotten as in the previous message thread
>
>


--------------060301060001000403010107
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Frank,<br>
<br>
It doesn't look like you are passing the right arguments for this
method:<br>
<blockquote>&nbsp; public static Command create(EditingDomain domain, Object
owner,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Object newChildDescriptor,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Collection selection)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; return domain.createCommand(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CreateChildCommand.class,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new CommandParameter(owner, null, newChildDescriptor, selection));<br>
&nbsp; }<br>
</blockquote>
It's good to look at CreateChildAction because that works for sure.<br>
<br>
<br>
frank wrote:
<blockquote
cite="mid27573387.1140444787696.JavaMail.root@cp1.javalobby.org"
type="cite">
<pre wrap="">I still get the same error
java.lang.ClassCastException

at org.eclipse.emf.edit.provider.ItemProviderAdapter.createComm and(ItemProviderAdapter.java:855)

at org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.crea teCommand(AdapterFactoryEditingDomain.java:397)

at org.eclipse.emf.edit.command.CreateChildCommand.create(Creat eChildCommand.java:64)

I have the source for the non-standalone emf. Although at line 855 in ItemProviderAdaptor doesn't seem to match the error, I'm guessing the class cast error occurs at the block
else if (commandClass == CreateChildCommand.class)
    {
      CommandParameter newChildParameter = (CommandParameter)commandParameter.getValue();
      result = 
        createCreateChildCommand
          (domain,
           commandParameter.getEOwner(), 
           newChildParameter.getEStructuralFeature(), 
           newChildParameter.getValue(),
           newChildParameter.getIndex(),
           commandParameter.getCollection());      
    }

It seems to cast the CommandParameter value to another CommandParameter, from what I see, the CommandParameter I'm passing in has a value that's not an instanceof CommandParameter. The code I'm using is
Command ccc = CreateChildCommand.create(editingDomain, cp.getFeature(), cp.getValue(), cp.getCollection());

where cp is gotten as in the previous message thread
</pre>
</blockquote>
<br>
</body>
</html>

--------------060301060001000403010107--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Dynamic generation of an EClass from an arbitrary Java class
Next Topic:Additional code in the model
Goto Forum:
  


Current Time: Fri Apr 26 21:59:22 GMT 2024

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

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

Back to the top