Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » ID-number for states?
ID-number for states? [message #215872] Tue, 20 January 2009 12:23 Go to next message
Anna is currently offline AnnaFriend
Messages: 34
Registered: July 2009
Member
Not sure whether this is the right group to place this question, but since
I'm doing a GMF project I'll try here...

I have created an editor where I can draw a diagram called
'file.myeditor_diagram', and from that diagram I can extract/open an
XML-file, called 'file.myeditor'. For a certain example, part of it looks
like this:

<states name="LOCKED"/>
<states xsi:type="Renegade:InitialState"/>
<states name="CLOSED"/>
<states name="OPENED"/>
<transitions source="//@states.1" target="//@states.0"/>
<transitions event="unlocks" source="//@states.0" target="//@states.2"/>
<transitions event="locks" source="//@states.2" target="//@states.0"/>
<transitions event="open" source="//@states.2" target="//@states.3"/>
<transitions event="close" source="//@states.3" target="//@states.2"/>

Now I want to create a way to transform this into SCXML. I think I have
figured out that part, or at least how I want to do it, but in order to do
that I need to have a way to map each statenumber to its name (like, in
the example above, the state mentioned as states.0 has the name "LOCKED").

Since I don't see any really easy way to do this when the XML-file looks
like this I think I would like to add an attribute (might not be the right
name, since I'm not quite sure what it is I want) to my node-type, which
should contain an ID-number. The number should be unique and assigned
automatically when a node is drawn in the editor (preferrably 0 for the
first node, 1 for the second and so on, so one of the tags in the code
snippet above should be "<states name="LOCKED" id="0"/>" or something
similar).

Is this possible? I'm guessing it's done in the ecore-model, but how is it
done?

Thanks,
Anna
Re: ID-number for states? [message #215890 is a reply to message #215872] Tue, 20 January 2009 14:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cayla_sha.gmx.net

Hello Anna!

I did something very simliar in my project. I`ll explain.

First: Yes, if you want, you can add you own attribute "ID". If you mark
it with 'isID="true"' (and I think 'unique="true"'), it will be used
automatically in the '*.myeditor' to reference the states. But then you
have to care yourself, that the ID stays unique. I had some experiences
with that, the title of the newsgroup-mail is "setID() causes
Connections to disappear".

BUT: You don`t need this. I`ll explain with an example:
<states name="LOCKED"/>
<states xsi:type="Renegade:InitialState"/>
<states name="CLOSED"/>
<states name="OPENED"/>
<transitions event="locks" source="//@states.2" target="//@states.0"/>
With "//@states.0" the reference means the first state from above:
<states name="LOCKED"/>
With "//@states.2" the third state from above is meant: <states
name="CLOSED"/>
You just count the states! (It took me some time, too, until I realized
that it`s that simple)

How do you want to transform it?
I made my own Export-Wizard. I read the file with a SAXParser and
created during parsing a new DOM-Tree. I can help you with that, if you
want :)

Best wishes
Julia
Re: ID-number for states? [message #215896 is a reply to message #215890] Tue, 20 January 2009 15:06 Go to previous messageGo to next message
Anna is currently offline AnnaFriend
Messages: 34
Registered: July 2009
Member
Cayla Sha wrote:

> Hello Anna!

> I did something very simliar in my project. I`ll explain.

> First: Yes, if you want, you can add you own attribute "ID". If you mark
> it with 'isID="true"' (and I think 'unique="true"'), it will be used
> automatically in the '*.myeditor' to reference the states. But then you
> have to care yourself, that the ID stays unique. I had some experiences
> with that, the title of the newsgroup-mail is "setID() causes
> Connections to disappear".

> BUT: You don`t need this. I`ll explain with an example:
> <states name="LOCKED"/>
> <states xsi:type="Renegade:InitialState"/>
> <states name="CLOSED"/>
> <states name="OPENED"/>
> <transitions event="locks" source="//@states.2" target="//@states.0"/>
> With "//@states.0" the reference means the first state from above:
> <states name="LOCKED"/>
> With "//@states.2" the third state from above is meant: <states
> name="CLOSED"/>
> You just count the states! (It took me some time, too, until I realized
> that it`s that simple)

Yes, I realized that this was the case, but still I wasn't sure how to
solve my problem in an (hopefully :)) easy way...I thought about creating
an XSLT to transform the XML-file to SCXML. I saw that it hade been done
between CCXML and SCXML, and since I'm at least a little familiar with
these things I thought that would be the best solution for me. But I don't
know how to express the id-part in the XSLT? I mean, so I can refer to the
state name on the first row when I encounter "states.0" and so on.

> How do you want to transform it?
> I made my own Export-Wizard. I read the file with a SAXParser and
> created during parsing a new DOM-Tree. I can help you with that, if you
> want :)

I answered the first part of the question in the piece above, I hope :)
Not sure what a SAXParser is...if possible I would like to solve the
problem in the way I explained above, with XSLT, but if not I would of
course appreciate some help to do it in another way.

/Anna
Re: ID-number for states? [message #215913 is a reply to message #215896] Tue, 20 January 2009 17:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cayla_sha.gmx.net

hm, I can`t imagine how a xslt can help transforming from one xml-file
to another...

I just can explain how I did it:
I used JAXP: http://en.wikipedia.org/wiki/Java_API_for_XML_Processing.
I parse my file with a SAXParser:
http://en.wikipedia.org/wiki/Simple_API_for_XML
This site helped me a lot:
http://www.torsten-horn.de/techdocs/java-xml.htm#Programmier beispiele-JAXP
Just ignore the german text, it says nothing helpful, and look at the
code :)

Each time the parser passes a node <states>, the method startElement()
is called. You just have to make a counter and increment it each time.
So you know at each node, where you are at the moment. Then you take the
name of <states> and build a new node out of it (the way, the scxml
likes states) and put it in a new DOMTree (of course you need to make an
empty DOM-Document at the beginning).
Then you put the counter into a Hashtable togehter with the name of the
state. So when later the method startElement() is called for a
transition, you can look up in the hashtable which name belongs to the
number. Because you just need the name to reference a state, when I
understand this article right: http://en.wikipedia.org/wiki/SCXML :)

I hope this helps!
Best wishes
Julia
Re: ID-number for states? [message #215990 is a reply to message #215913] Wed, 21 January 2009 09:01 Go to previous messageGo to next message
Anna is currently offline AnnaFriend
Messages: 34
Registered: July 2009
Member
Cayla Sha wrote:

> hm, I can`t imagine how a xslt can help transforming from one xml-file
> to another...

I just assumed that it would, since it was done here:
http://www.w3.org/TR/2005/WD-scxml-20050705/#CCXMLtoSCXML
I know it says that it's only a prototype, but I figured that they
wouldn't have tried to do it if they didn't think it was at all possible...

> I just can explain how I did it:
> I used JAXP: http://en.wikipedia.org/wiki/Java_API_for_XML_Processing.
> I parse my file with a SAXParser:
> http://en.wikipedia.org/wiki/Simple_API_for_XML
> This site helped me a lot:
> http://www.torsten-horn.de/techdocs/java-xml.htm#Programmier beispiele-JAXP
> Just ignore the german text, it says nothing helpful, and look at the
> code :)

I'll have a look at the links above...the problem is that I really don't
want to mess too much with java since it isn't really my thing :/ of
course I understand that java might be needed for this project, but we're
currently two persons working on it and it's the other one who deals with
most of the java-parts. I could let her do it, but that would divide the
work quite unevenly between us. Oh well, just trying to explain why I
would rather try to do it in some other way :P

However, I do appreciate that you're trying to help. Maybe there is no
better solution for my problem, but I thought I'll try and look some more.
If you (or someone else, of course) have any other idea, please let me
know!

Thanks,
Anna
Re: ID-number for states? [message #216262 is a reply to message #215872] Fri, 23 January 2009 11:33 Go to previous message
Seweryn Niemiec is currently offline Seweryn NiemiecFriend
Messages: 80
Registered: July 2009
Member
Anna S wrote:
[...]
> the code snippet above should be "<states name="LOCKED" id="0"/>" or
> something similar).
>
> Is this possible? I'm guessing it's done in the ecore-model, but how is
> it done?

Read this:
http://serdom.eu/ser/2008/07/02/eclipse-gmf-enabling-uuids-i n-semantic-model-the-simplest-way
and this:
http://serdom.eu/ser/2007/03/05/how-to-enable-uuid-in-emf-ge nerated-model-to-get-copypaste-working

--
Greetings,
Seweryn
Previous Topic:OffScreenEditPartFactory
Next Topic:Problem with link creation
Goto Forum:
  


Current Time: Thu Apr 25 12:00:16 GMT 2024

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

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

Back to the top