Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Transaction use in Graphiti(Need to use a transaction when modifying by the property sheet)
Transaction use in Graphiti [message #1153109] Thu, 24 October 2013 11:37 Go to next message
Victor Lopez is currently offline Victor LopezFriend
Messages: 21
Registered: August 2013
Junior Member
Hello everyboy,

I started using the property sheets everything looked fine. I created the fields and I could show the values of the clicked business object.

The thing is that I want to modify the business object using the property sheet. So i added a listener to one field:

nameText.addModifyListener(new ModifyListener(){

    @Override
        public void modifyText(ModifyEvent e) {
            Text text = (Text) e.widget;
            bo.setName(text.getText());				
        }
			
    });


It crashes because I need to use a transaction (cannot modify the business object there). The thing is that I do not know which kind of transaction I do need.

Any help will be so "thanked" =)

Best regards,

Víctor.


Re: Transaction use in Graphiti [message #1153121 is a reply to message #1153109] Thu, 24 October 2013 11:50 Go to previous messageGo to next message
Vladimir D is currently offline Vladimir DFriend
Messages: 22
Registered: January 2013
Junior Member
Hi Victor,

I had a similar problem several days ago, and I found a solution at this link. Hope this helps you.

Kind regards,
Vladimir
Re: Transaction use in Graphiti [message #1153280 is a reply to message #1153121] Thu, 24 October 2013 14:00 Go to previous messageGo to next message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
You can get :

TransactionalEditingDomain editingDomain = getDiagramContainer().getDiagramBehavior().getEditingDomain();


and you can edit your bo inside :

editingDomain.getCommandStack().execute(
    new RecordingCommand(editingDomain, label) {
        protected void doExecute() {
            // here
        }
});


Marek
Re: Transaction use in Graphiti [message #1159217 is a reply to message #1153280] Mon, 28 October 2013 11:25 Go to previous messageGo to next message
Victor Lopez is currently offline Victor LopezFriend
Messages: 21
Registered: August 2013
Junior Member
Thank you two. Finally I did what Marek said and it worked. But there is one problem with it. This is what I have in my Section class:

//OBJECT NAME
		nameText = factory.createText(composite, "");
		data = new FormData();
		data.left = new FormAttachment(0, 100);
		data.right = new FormAttachment(100, 0);
		data.top = new FormAttachment(0, VSPACE);
		nameText.setLayoutData(data);
		nameText.addModifyListener(new ModifyListener(){

			@Override
			public void modifyText(ModifyEvent event) {
				
				e = event;
				
				TransactionalEditingDomain editingDomain = getDiagramContainer().getDiagramBehavior().getEditingDomain();
				
				editingDomain.getCommandStack().execute(
					new RecordingCommand(editingDomain, "") {
						protected void doExecute() {
					    	Text text = (Text) e.widget;
					        if(bo!=null){
								bo.setName(text.getText());

								org.eclipse.graphiti.mm.algorithms.Text t = (org.eclipse.graphiti.mm.algorithms.Text) cs
										.getGraphicsAlgorithm();
								t.setValue(bo.getName());
					        }
					        	
					    }
				});
		        			
			}
			
		});


When the pictogram object is already created everything is ok. But when I create the object for the first time, as it is selected when you create it, this code is executed and this time it crashes (when bo.setName(text.getText()); is executed).

It tells me to use it inside a write transaction (BUT THIS IS WHAT I AM DOING! =) )

Any idea? thanks again,

Víctor.


Re: Transaction use in Graphiti [message #1160803 is a reply to message #1159217] Tue, 29 October 2013 11:06 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Victor,

not sure, could it be that the write transaction for the creation is still
open? In that case another write transaction would not be allowed.

Michael
Re: Transaction use in Graphiti [message #1161034 is a reply to message #1160803] Tue, 29 October 2013 14:33 Go to previous messageGo to next message
Felix Velasco is currently offline Felix VelascoFriend
Messages: 43
Registered: July 2009
Member
Victor,

If this happens only on fresh created element, there's a chance you're creating it in a different EditionDomain. A quick test would be to reorder the code. Try this:
	org.eclipse.graphiti.mm.algorithms.Text t = (org.eclipse.graphiti.mm.algorithms.Text) cs.getGraphicsAlgorithm();
	t.setValue(text.getText());
	bo.setName(text.getText());
.

If it fails in the bo.setName, but not in the t.setValue, bo is inside a different EditingDomain. If that's the case, review how do you read or update the object to make sure you use the same Editing Domain
Re: Transaction use in Graphiti [message #1216486 is a reply to message #1161034] Thu, 28 November 2013 13:54 Go to previous message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
In my project I rather avoid setting initial values in property sheets. For me this task fits much more to CreateFeature.
Previous Topic:Multiple textfields in AddFeature
Next Topic:Drag and drop support
Goto Forum:
  


Current Time: Thu Apr 25 17:15:56 GMT 2024

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

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

Back to the top