Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Automatic father creation
Automatic father creation [message #194864] Sun, 29 June 2008 15:15 Go to next message
Nicola Salvo is currently offline Nicola SalvoFriend
Messages: 42
Registered: July 2009
Member
Hello everybody!

I'm quite new to GMF, and I'm trying to model an xsd file with EMF/GMF. I
need to implement something like:

WorkflowType
-Sequence
--WorkflowType
-Parallel
--WorkflowType
-Pipeline

where workflowType is just a container for 3 kind workflows. I'd like to
automatically add the element when one of the 3 workflows is added to the
diagram. I found here
http://wiki.eclipse.org/index.php/GMF_MapModel_Hints#Endless .2Frecursive_hierarchies
how to create recursive hierarchies, but I don't know how to avoid to
create the WorkflowType container everytime. What I want to do is to let
the user adding the workflow type, creating automatically the container
element. Something like:

Sequence
-Parallel
--Sequence
-Parallel
-Pipeline

I understand that the explanation is not clear, but I don't know how to
explain better the problem. Please any advice is welcome, I've been stuck
on this problem for days.
Cheers

Nicola
Re: Automatic father creation [message #195070 is a reply to message #194864] Tue, 01 July 2008 11:49 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Nicola,

> -Parallel
> --Sequence
> -Parallel
> -Pipeline
You can make it working by creating mapping for this diagram structure +
then modifying generated CreateParallel/SequenceCommand to create Workflow
element in addition.
As a result you'll be able to create disared diagram structure, but will
not be able to initialize diagram using existing model - additional modification
will be required in this place.

-----------------
Alex Shatalin
Re: Automatic father creation [message #195078 is a reply to message #195070] Tue, 01 July 2008 11:51 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Alex,

just one more option - you can create derived feature for Parallel referencing
Sequence and implement corresponding EMF-generated operation to create Workflow
if necessary. In this case you should not modify GMF-generated code, but
have to modify EMF-generated.

-----------------
Alex Shatalin
Re: Automatic father creation [message #195764 is a reply to message #195070] Fri, 04 July 2008 09:09 Go to previous messageGo to next message
Nicola Salvo is currently offline Nicola SalvoFriend
Messages: 42
Registered: July 2009
Member
Hello Alex,

sorry for the late reply. First of all thank you for helping. I tried to
follow your advice and I dive a bit in the newsgroup. What I did so far is:

public class ParallelTypeCreateCommand extends CreateElementCommand {
..
..
@Override
protected EObject doDefaultElementCreation() {
ParallelType obj = (ParallelType) super.doDefaultElementCreation();
WorkflowType wt = ModelFactory.eINSTANCE.createWorkflowType();
obj.getWorkflow().add(wt);

return obj;
}

then I defined a new policy:
public class ParallelTypeEditPart extends ShapeNodeEditPart {
class MyCreationEditPolicy extends CreationEditPolicy {
/* (non-Javadoc)
* @see
org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEdit Policy#getCreateCommand(org.eclipse.gmf.runtime.diagram.ui.r equests.CreateViewRequest)
*/
@Override
protected Command getCreateCommand(CreateViewRequest request) {

IElementType wt = RequestElementTypes.WorkflowType_2011;
//IElementType wt2 = RequestElementTypes.WorkflowType_2008;

ICommand createElementViewCommand = ((ICommandProxy) super
.getCreateCommand(request)).getICommand();

TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)
getHost())
.getEditingDomain();
CompositeTransactionalCommand cc = new CompositeTransactionalCommand(
editingDomain, DiagramUIMessages.AddCommand_Label);
cc.compose(createElementViewCommand);

PreferencesHint preferencesHint = getDiagramPreferencesHint();

CreateViewAndElementRequest req = new CreateViewAndElementRequest(
wt, preferencesHint);
Iterator descriptors = req.getViewDescriptors().iterator();

while (descriptors.hasNext()) {
CreateViewRequest.ViewDescriptor descriptor =
(CreateViewRequest.ViewDescriptor) descriptors
.next();

CreateCommand createCommand = new CreateCommand(editingDomain,
descriptor, ((View) (getHost().getModel()))
.getDiagram());

cc.compose(createCommand);
}

return new ICommandProxy(cc.reduce());
}
}

and installed it:

protected void createDefaultEditPolicies() {
installEditPolicy(EditPolicyRoles.CREATION_ROLE,
new MyCreationEditPolicy());

Using the debugger I can notice that the funtion is called and the
doDefaultElementCreation() correctly update the Domain, but the
workflowType node is not added on the diagram. Any idea?
Cheers

Nicola
Alex Shatalin wrote:

> Hello Nicola,

>> -Parallel
>> --Sequence
>> -Parallel
>> -Pipeline
> You can make it working by creating mapping for this diagram structure +
> then modifying generated CreateParallel/SequenceCommand to create Workflow
> element in addition.
> As a result you'll be able to create disared diagram structure, but will
> not be able to initialize diagram using existing model - additional
modification
> will be required in this place.

> -----------------
> Alex Shatalin
Re: Automatic father creation [message #195936 is a reply to message #195764] Mon, 07 July 2008 09:57 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Nicola,

> doDefaultElementCreation() correctly update the Domain, but the
> workflowType node is not added on the diagram. Any idea? Cheers
Can you see this node on diagram after reopenning (or pressing F5 on its
container)?

-----------------
Alex Shatalin
Re: Automatic father creation [message #195989 is a reply to message #195936] Mon, 07 July 2008 16:09 Go to previous messageGo to next message
Nicola Salvo is currently offline Nicola SalvoFriend
Messages: 42
Registered: July 2009
Member
Hello Alex,

I tried to close reopen the diagram, but the child element is not there.
I used a little bit the debugger, but I got no clue, so I tried a
different way:

public class ParallelTypeEditHelper extends RequestBaseEditHelper {
@Override
protected ICommand getConfigureCommand(final ConfigureRequest req) {
return new ConfigureElementCommand(req) {
protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
EObject element = req.getElementToConfigure();

doConfiguration(element, monitor);
return CommandResult.newOKCommandResult(element);
}
};
}

/**
*
* @param element
* @param monitor
*/
protected void doConfiguration(EObject element, IProgressMonitor
monitor) {
ParallelType pt = (ParallelType) element;

EReference parallelContainer = ModelPackage.eINSTANCE
..getParallelType_Workflow();
WorkflowType wtObj = ModelFactory.eINSTANCE.createWorkflowType();
EClass workflowClass = wtObj.eClass();
EObject condition = EMFCoreUtil.create(pt, parallelContainer,
workflowClass);

}

and now it's working. Is there any difference with the other way? I'd
like to learn better GMF, so it can be cool to understand why the other
way it's not working.

Moreover, the original title of the post was related with father, thus
inner element, creation. I have an input element and I'd like to be able
to create all the inner elements: I will try to follow to modify the
helper class, but probably it will be not enough because when I select
the tool and I move the mouse on the diagram, I got a "white cross"
probably because the command it not executable. Any suggestion?
Thank you very much for your help

Nicola


On Mon, 2008-07-07 at 09:57 +0000, Alex Shatalin wrote:
> Hello Nicola,
>
> > doDefaultElementCreation() correctly update the Domain, but the
> > workflowType node is not added on the diagram. Any idea? Cheers
> Can you see this node on diagram after reopenning (or pressing F5 on its
> container)?
>
> -----------------
> Alex Shatalin
>
>
Re: Automatic father creation [message #196036 is a reply to message #195989] Tue, 08 July 2008 09:08 Go to previous message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Nicola,

I'm still thinking that there can be a way to generate most of the things....
I suggest you to stay with first approach (modify CreateCommand for an element)
and try to debug element creation to see the reason for this error. If an
element was created successfully then you should be able to see it in domain
model file on saving the diagram - this is a first check i suggest to perform.
Then if an element was saved you can try to see why corresponding view instance
was not created. To fix F5 you can debug ???DiagramUpdater.

-----------------
Alex Shatalin
Previous Topic:figure visibility change
Next Topic:Replacing DiagramContributionItemProvider
Goto Forum:
  


Current Time: Fri Apr 19 20:33:20 GMT 2024

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

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

Back to the top