Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » how to reorder FeatureMap?
how to reorder FeatureMap? [message #487387] Wed, 23 September 2009 01:36 Go to next message
No real name is currently offline No real nameFriend
Messages: 31
Registered: September 2009
Member
Hi there,

I have model that uses a feature map to group various features which represent a large choice group and are collected and grouped by a single
feature map:
	<xsd:group name="activity">
		<xsd:choice>
			<xsd:element ref="activity"/>
			<xsd:element ref="assign"/>
            <xsd:element name="clone" type="tRequires"/>
            <xsd:element name="copy" type="tRequires"/>
			<xsd:element ref="exit"/>
			<xsd:element ref="flow"/>
			<xsd:element ref="if"/>
			<xsd:element ref="invoke"/>
            <xsd:element name="move" type="tRequires"/>
			<xsd:element ref="receive"/>
			<xsd:element ref="repeatUntil"/>
			<xsd:element ref="reply"/>
			<xsd:element ref="requires"/>
			<xsd:element ref="scope"/>
			<xsd:element ref="sequence"/>
			<xsd:element ref="wait"/>
			<xsd:element ref="while"/>
		</xsd:choice>
	</xsd:group>



Some of those elements are actually container for other elements. For example a sequence is defined as:

	<xsd:element name="sequence" type="tSequence"/>
	<xsd:complexType name="tSequence">
		<xsd:complexContent>
			<xsd:extension base="tExtensibleElements">
				<xsd:sequence>
					<xsd:group ref="activity" minOccurs="1" maxOccurs="unbounded"/>
				</xsd:sequence>
			</xsd:extension>
		</xsd:complexContent>
	</xsd:complexType>



Now I'm running into a situation where I need to programmatically reorder a sequence (in order to implement drag and drop behaviour for a graphical editor). An example would be:

sequence before reordering = "Requires > Invoke(A) > Wait > Invoke(B)"
sequence after reordering = "Invoke(A) > Wait > Requires > Invoke(B)"

But I don't have a glue how to reorder those elements since
(1.) I'm not quite sure how the elements are actually stored in the map and
(2.) (especially) I don't understand how a serial order is achieved.

Any hint is greatly appreciated,

sas

[Updated on: Wed, 23 September 2009 09:32]

Report message to a moderator

Re: reordering element container derived from xsd [message #487495 is a reply to message #487387] Wed, 23 September 2009 12:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Sas,

Comments below.

news.sascha.gessler@googlemail.com wrote:
> Hi there,
>
> I'm pretty new to EMF but I'm currently developing a graphical editor
> for a process modeling language. The editor is based on GMF and I'm
> using a EMF data-model that is derived from an xml schema definition.
> For example a sequence is a container for activities:
>
>
> <xsd:element name="sequence" type="tSequence"/>
> <xsd:complexType name="tSequence">
> <xsd:complexContent>
> <xsd:extension base="tExtensibleElements">
> <xsd:sequence>
> <xsd:group ref="activity" minOccurs="1"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> <xsd:group name="activity">
> <xsd:choice>
> <xsd:element ref="activity"/>
> <xsd:element ref="assign"/>
> <xsd:element name="clone" type="tRequires"/>
> <xsd:element name="copy" type="tRequires"/>
> <xsd:element ref="exit"/>
> <xsd:element ref="flow"/>
> <xsd:element ref="if"/>
> <xsd:element ref="invoke"/>
> <xsd:element name="move" type="tRequires"/>
> <xsd:element ref="receive"/>
> <xsd:element ref="repeatUntil"/>
> <xsd:element ref="reply"/>
> <xsd:element ref="requires"/>
> <xsd:element ref="scope"/>
> <xsd:element ref="sequence"/>
> <xsd:element ref="wait"/>
> <xsd:element ref="while"/>
> </xsd:choice>
> </xsd:group>
>
>
>
> This results in the following EClass:
>
>
> public interface Sequence extends ExtensibleElements {
> FeatureMap getActivity();
> EList<GenericActivity> getActivity1();
> EList<Assign> getAssign();
> EList<Requires> getClone();
> EList<Requires> getCopy();
> EList<Exit> getExit();
> EList<Flow> getFlow();
> EList<If> getIf();
> EList<Invoke> getInvoke();
> EList<Requires> getMove();
> EList<Receive> getReceive();
> EList<RepeatUntil> getRepeatUntil();
> EList<Reply> getReply();
> EList<Requires> getRequires();
> EList<Scope> getScope();
> EList<Sequence> getSequence();
> EList<Wait> getWait();
> EList<While> getWhile();
>
> } // Sequence
>
>
> Since I need to implement DnD behaviour I have some questions about
> the usage of a MoveCommand.
>
>
> 1. In my understanding the Sequence EClass provides me with an
> EFeatureMap which represents the group of activities. Is it save to
> assume that this EFeatureMap can be used as EStructuralFeature for a
> MoveCommand?
Yes, you'd want to be moving the entries of that feature map.
> 2. If not which feature should be used?
>
>
> So far I'm using the following command:
>
> public class CompartmentRepositionElementCommand extends
> AbstractTransactionalCommand {
>
> /**
> * the visual representation of the model element we work on
> */
> private EditPart mChildPart;
>
> /**
> * the model element we work on
> */
> private EObject mChild;
>
> /**
> * the visual representation of the model container we work on
> */
> private EditPart mContainerPart;
>
> /**
> * the container we work on
> */
> private EObject mContainer;
>
> /**
> * the containing feature
> */
> private EStructuralFeature mContainingFeature;
>
> /**
> * the new index
> */
> private int mNewIndex;
>
>
>
> /**
> * Constructs a runtime instance of
> <code>CompartmentRepositionElementCommand</code>.
> */
> public
> CompartmentRepositionElementCommand(TransactionalEditingDoma in
> editingDomain,
> EditPart containerPart, EObject container,
> EditPart childPart, EObject child, EStructuralFeature
> containingFeature, int newIndex) {
> super(editingDomain, "", getWorkspaceFiles(child));
>
> this.mContainerPart = containerPart;
> this.mContainer = container;
> this.mChildPart = childPart;
> this.mChild = child;
> this.mContainer = container;
> this.mContainingFeature = containingFeature;
> this.mNewIndex = newIndex;
> }
>
> @Override
> protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
> IAdaptable info) throws ExecutionException {
> CommandResult commandResult = null;
> try {
> // reposition model element
> // new MoveCommand(getEditingDomain(), mContainer,
> // mContainingFeature, mChild, mNewIndex).execute();
> new MoveCommand(getEditingDomain(), (EList<?>)
> mContainer.eGet(mContainingFeature, true), mChild, mNewIndex).execute();
>
> // reposition visual representation of model element
> ViewUtil.repositionChildAt(
> (View)mContainerPart.getModel(),
> (View)mChildPart.getModel(), mNewIndex);
> mContainerPart.refresh();
> } catch (RuntimeException exp){
> commandResult = CommandResult.newErrorCommandResult(exp);
> }
> return (commandResult == null) ?
> CommandResult.newOKCommandResult()
> : commandResult;
>
> }
>
> }
>
>
> For example passing in an Requires activity as child, the sequence as
> container and Sequence.getActivity() as structural feature doesn't do
> the trick. (Debugging shows me that the command fails since the
> element cann't be found in the FeatureMap.)
>
> The way I see it the FeatureMap holds some kind of proxy element. The
> question is, how do I get the command to work, i.e. how do I properly
> resolve the element?
Doesn't move (and drag and drop reordering) already work well in the
basic generated EMF editor?
>
>
> Thanks in advance,
> sas


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: reordering element container derived from xsd [message #487694 is a reply to message #487495] Thu, 24 September 2009 07:47 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 31
Registered: September 2009
Member
Hi Ed,

Quote:

Doesn't move (and drag and drop reordering) already work well in the
basic generated EMF editor?




Yes it does. But since I'm implementing drag&drop support for a GMF diagram editor
I need to programatically invoke similar code as the EMF tree editor does. Sadly I couldn't find the actual peace of code that is used by the EMF editor to create the according commands.

Maybe someone can point it out for me. (Likely this would solve the questions below).


Quote:

Yes, you'd want to be moving the entries of that feature map.



Thanks a lot for your reply. But still I'm not sure how to reorder a multi element feature map such as the "Sequence" element described in my original request:

(1.) I'm just missing how a FeatureMap stores lists of features and
(2.) how the actual linear order is mapped.

Given the following example:

Sequence = Assign(1), Requires, Assign(2)

I assume the FeatureMap stores something like:

FeatureMap = list(
Entry(key = Sequence__Assign, value = list(Assign(1), Assign(2))),
Entry(key = Sequence__Requires, value = list(Requires))
)

But given this kind of data structure how do we know that "Assign(1)" is the first element in the sequence, "Requires" the second and "Assign(2)" is the third element?


Thanks in advance,

sas

[Updated on: Thu, 24 September 2009 07:48]

Report message to a moderator

Re: reordering element container derived from xsd [message #487737 is a reply to message #487694] Thu, 24 September 2009 09:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Sas,

Comments below.

news.sascha.gessler@googlemail.com wrote:
> Hi Ed,
>
> Quote:
>> Doesn't move (and drag and drop reordering) already work well in the
>> basic generated EMF editor?
>
>
>
> Yes it does. But since I'm implementing drag&drop support for a GMF
> diagram editor I need to programatically invoke similar code as the
> EMF tree editor does. Sadly I couldn't find the actual peace of code
> that is used by the EMF editor to create the according commands.
>
> Maybe someone can point it out for me. (Likely this would solve the
> questions below).
You need to work with the actual FeatureMap.Entry instances in the list
using things like MoveCommand, AddCommand, and RemoveCommand.
>
>
> Quote:
>> Yes, you'd want to be moving the entries of that feature map.
>
>
> Thanks a lot for your reply. But still I'm not sure how to reorder a
> multi element feature map such as the "Sequence" element described in
> my original request:
> (1.) I'm just missing how a FeatureMap stores lists of features and
> (2.) how the actual linear order is mapped.
>
> Given the following example:
>
> Sequence = Assign(1), Requires, Assign(2)
>
> I assume the FeatureMap stores something like:
>
> FeatureMap = list(
> Entry(key = Sequence__Assign, value = Assign(1), Assign(2)),
No, it's just key/value pairs; single values.
> Entry(key = Sequence__Requires, value = Requires)
> )
>
> But given this kind of data structure how do we know that "Assign(1)"
> is the first element in the sequence, "Requires" the second and
> "Assign(2)" is the third element?
Instead of assuming, look at the actual structures.
>
>
> Thanks in advance,
>
> sas


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: reordering element container derived from xsd [message #487865 is a reply to message #487737] Thu, 24 September 2009 15:28 Go to previous message
No real name is currently offline No real nameFriend
Messages: 31
Registered: September 2009
Member
Thanks you very much.
Previous Topic:Merge of TransactionalEditingDomains
Next Topic:EMF Databinding to Inherited Attribute
Goto Forum:
  


Current Time: Thu Apr 18 10:47:20 GMT 2024

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

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

Back to the top