Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Create Element and Link
Create Element and Link [message #693160] Tue, 05 July 2011 23:17 Go to next message
Elvis  is currently offline Elvis Friend
Messages: 15
Registered: May 2011
Junior Member
Hi people,

I have the following metamodel:


@namespace(uri="example", prefix="example")
package example;

@gmf.diagram(foo="bar")
class Schema {
val Entity[*] entity_schema;
val Attribute[*] attribute_schema;
val LinkAttribute[*] linkAttribute_schema;
}

@gmf.node(label="name", label.icon="false", figure="rectangle", size="100,50")
class Entity {
id attr String identity;
attr String name;
}

@gmf.node(label="name", label.icon="false", figure="ellipse", size="100,50")
class Attribute {
id attr String identity;
attr String name;
}

@gmf.link(source="source", target="target")
class LinkAttribute {
ref Entity[1] source;
ref Attribute[1] target;
}


And I'm trying to implement it as follows: After creating an Entity, I want to select the Attribute on the objects palette, click on the Entity
created to create a new Attribute with a new LinkAttribute connected in the selected Entity.

Would anyone have any suggestions for how to do this?

Thanks for the help and sorry my English!

Best regards,

Elvis
Re: Create Element and Link [message #693309 is a reply to message #693160] Wed, 06 July 2011 08:46 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

Hi Elvis,

I think you will need to manually customise the code generated by GMF to do that. Eugenia is focused on helping create the GMF models, and does not customize the code generated by GMF beyond what is possible with those GMF models. I would recommend you ask this questions over the GMF forum: I'm sure they will be able to help you more there Smile.

If you don't share Attributes between several Entities, another option would be storing the Attributes inside a compartment in Entity. Please check this example:

http://eclipse.org/gmt/epsilon/doc/eugenia/

Best regards,
Antonio
Re: Create Element and Link [message #693453 is a reply to message #693309] Wed, 06 July 2011 14:01 Go to previous messageGo to next message
Elvis  is currently offline Elvis Friend
Messages: 15
Registered: May 2011
Junior Member
Hi Antonio,

Thanks for the reply and suggestion, it really would be simpler to implement using compartment, but would like to learn how to do this customization via GMF, once again thanks for the help.

Elvis
Re: Create Element and Link [message #695298 is a reply to message #693453] Mon, 11 July 2011 13:10 Go to previous messageGo to next message
Giovanni De Sossi is currently offline Giovanni De SossiFriend
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

Hi Elvis,

you have to manually modify your (generated) [XYZ]CreateCommand; you'll find them in your [xyz].diagram.edit.commands package. There you can replace the code of, say, AttributeCreateCommand with custom code operating at EMF level.

HTH, bye

Giovanni
Re: Create Element and Link [message #695521 is a reply to message #695298] Mon, 11 July 2011 23:05 Go to previous messageGo to next message
Elvis  is currently offline Elvis Friend
Messages: 15
Registered: May 2011
Junior Member
Hi Giovanni,

Thanks for the help, I will work in this direction and still this weeks I'll put the result here.

Thank you very much

Elvis
Re: Create Element and Link [message #697500 is a reply to message #695521] Sun, 17 July 2011 01:31 Go to previous messageGo to next message
Elvis  is currently offline Elvis Friend
Messages: 15
Registered: May 2011
Junior Member
Hi Giovanni,

I modified the DoExecuteWithResult of the class AttributeCreateCommand to create the LinkAttribute automatically, the code bellow:

	/**
	 * @generated NOT
	 */
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
			IAdaptable info) throws ExecutionException {

		Attribute newElement = ErcaseFactory.eINSTANCE.createAttribute();
		LinkAttribute newLink = ErcaseFactory.eINSTANCE.createLinkAttribute();
		
		Schema owner = (Schema) getElementToEdit();
		owner.getElement_schema().add(newElement);
		owner.getLinkAttribute_schema().add(newLink);

		newLink.setSource( ? );
		newLink.setTarget(newElement);

		doConfigure(newElement, monitor, info);
		doConfigureLink(newLink, monitor, info);
		
		((CreateElementRequest) getRequest()).setNewElement(newElement);
		
		((CreateElementRequest) getRequest()).setNewElement(newLink);
		CommandResult.newOKCommandResult(newLink);	
		
		return CommandResult.newOKCommandResult(newElement);
		
	}


But I'm not getting set the source property of the LinkAttribute with the Entity element that was clicked in the creation of Attribute. I know that I will have to change the policies to creating the elements, but first I need to know how to get the Entity element in the constructor of AttributeCreateCommand. Do you know what other changes I have to do to be able to implement such recourse?

Thank you very much

Elvis
Re: Create Element and Link [message #697841 is a reply to message #697500] Mon, 18 July 2011 07:45 Go to previous messageGo to next message
Giovanni De Sossi is currently offline Giovanni De SossiFriend
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

Hi Elvis,

you have two ways to do this:

- you can intercept the current selection in your DiagramItemSemanticEditPolicy, or
- you can find the current selection directly in your Command (not recommended)

In both cases, the code is about the same:

IStructuredSelection sel = (IStructuredSelection) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();

Then you have to check if sel.getFirstElement is an instance of EntityEditPart, and retrieve the (inner) semantic element: this is your source element.

Bye,

Giovanni
Re: Create Element and Link [message #698144 is a reply to message #697841] Mon, 18 July 2011 21:36 Go to previous messageGo to next message
Elvis  is currently offline Elvis Friend
Messages: 15
Registered: May 2011
Junior Member
Hi Giovanni,

Thanks for the reply again, I'll keep working on it and then put the code here so that others can learn too.

His directions are helping me a lot

Elvis
Re: Create Element and Link [message #698668 is a reply to message #698144] Tue, 19 July 2011 23:29 Go to previous messageGo to next message
Elvis  is currently offline Elvis Friend
Messages: 15
Registered: May 2011
Junior Member
Hi Giovanni,

I made the interception of source element in SchemaItemSemanticEditPolicy as the code below:
	/**
	 * @generated NOT
	 */
	protected Command getCreateCommand(CreateElementRequest req) {
		if (ExampleElementTypes.Entity_2001 == req.getElementType()) {
			return getGEFWrapper(new EntityCreateCommand(req));
		}
		if (ExampleElementTypes.Attribute_2002 == req.getElementType()) {
			EObject source = getEntityFromSelection();
			if (source != null) {
				return getGEFWrapper(new AttributeCreateCommand(req, source, null));
			}
		}
		return super.getCreateCommand(req);
	}

	/**
	 * @generated NOT
	 */
    public static EObject getEntityFromSelection() {
        if (PlatformUI.getWorkbench() != null
                && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
                && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService() != null) {
        	IStructuredSelection sel = (IStructuredSelection) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
        	if (((IStructuredSelection) sel).getFirstElement() instanceof EntityEditPart) {
            	EntityEditPart entity = (EntityEditPart) ((IStructuredSelection) sel).getFirstElement();
            	Object model = entity.getModel();
                if (model instanceof View && ((View) model).getElement() != null) {
                    return ((View) model).getElement();
                }
            }
        }
        return null;
    }

Now I am not able to adjust the policies to allow the creation of the attribute with just one click on the entity. Do You know what classes or methods I have to adjust?

Thank you more one time and excuse the mishap

Elvis
Re: Create Element and Link [message #698687 is a reply to message #693160] Wed, 20 July 2011 00:58 Go to previous messageGo to next message
Silvia  is currently offline Silvia Friend
Messages: 12
Registered: March 2011
Junior Member
Hi Elvis,

I'm not sure to understand your initial question. Nevertheless, the following variation of your emf script can be an alternative solution, which doesn't involve modifications to generated code.

@namespace(uri="example", prefix="example")
package example;

@gmf.diagram(foo="bar")
class Schema {
val Entity[*] entity_schema;
val Attribute[*] attribute_schema;
}

@gmf.node(label="name", label.icon="false", figure="rectangle", size="100,50")
class Entity {
id attr String identity;
attr String name;
@gmf.link(target.decoration="arrow")
ref Attribute [*] attribues;
}

@gmf.node(label="name", label.icon="false", figure="ellipse", size="100,50")
class Attribute {
id attr String identity;
attr String name;
}
Re: Create Element and Link [message #698784 is a reply to message #698668] Wed, 20 July 2011 08:20 Go to previous messageGo to next message
Giovanni De Sossi is currently offline Giovanni De SossiFriend
Messages: 161
Registered: October 2009
Location: Rome, Italy
Senior Member

Hi Elvis,

the "create node" commands are called by [Diagram]ItemSemanticEditPolicy; in your own code, I think this is the SchemaItemSemanticEditPolicy class. There you need to modify your getCreateCommand method, intercepting the element type from the CreateElementRequest...but I don't know how to react to single mouse click, not yet. I have the same requirement, when I solve the problem I post back the solution.

Bye,

Giovanni
Re: Create Element and Link [message #698970 is a reply to message #698784] Wed, 20 July 2011 15:08 Go to previous message
Elvis  is currently offline Elvis Friend
Messages: 15
Registered: May 2011
Junior Member
Hi Giovanni and Silvia,

First thanks for your reply.

Silvia the usability of emf scripts mentioned are exactly the same: to create the Entity, to create the Attribute and then create the LinkAttribute connecting both. We are trying the following usability: create the Entity, select the Attribute and click on the Entity created to be automatically created Attribute and LinkAttribute already with both connected.

Giovanni maybe be easier to implement modifing the LinkAttribute instead of the Attribute, I will try to create automatically a new Attribute after select the LinkAttribute and click on the Entity created. Thank you for your help and we will continue interacting to implement this feature.

Elvis
Previous Topic:Phantom nodes that are not targeted by a link mapping representing containment reference present in
Next Topic:[Epsilon] Not F.A.Q.
Goto Forum:
  


Current Time: Fri Mar 29 01:34:41 GMT 2024

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

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

Back to the top