Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Properties and Listeners(HELP ! (please!!!))
Properties and Listeners [message #556319] Tue, 31 August 2010 18:32 Go to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi guys,

May I ask your help to understand if I am properly implementing the listeners for two fields in the property section?

My questions are:

Q1: is it correct to have a different listener for each field/attribute?
Q2: is it correct the way I am implementing the refresh method? is there a way to understand which element changed in order to just refresh the element which is changed?

Q2: if I have another businessObject, namely "IntentionSpec", which:

- is a specialization of the businessObject "Intention"

- has the two attributes inherited from "Intention" plus another attribute called "newAttribute"

and I want that in the property section when:

i) an "Intention" diagram element is selected --> two attributes are visualized in the panel and if I edit them the "Intention" business object is changed (similar to the actual code)

ii) an "IntentsionSpec" is selected ---> three attributes are visualized in the panel and if I edit them the "IntentionSpec" business object is changed.

Do you have some suggestions how to do that?
For example, should I put everything it the same:

public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage)

and add some lines such as:

Object bo= Graphiti.getLinkService().getBusinessObjectForLinkedPictogra mElement(pe);

if (bo == Intention) then
<actual code>

else
<code to visualize the previous two fields + the newAttribute, and in this case I use the same listeners plus a new one>

Is this correct?

Thank you very much for any help or suggestions Smile







---------------
...
public class IntentionSection extends GFPropertySection implements ITabbedPropertyConstants {

private Text nameText;
private Text descriptionText;


private ModifyListener listenerIntentionName = new ModifyListener(){

public void modifyText (ModifyEvent arg0){

PictogramElement pe = getSelectedPictogramElement();
Intention bimElement = (Intention) Graphiti.getLinkService().getBusinessObjectForLinkedPictogra mElement(pe);

bimElement.setName(nameText.getText());
bimElement.setDescription(descriptionText.getText());
System.out.print("\Name setted: "+bimElement.getName());

}
};
private ModifyListener listenerIntentionDescription = new ModifyListener(){

public void modifyText (ModifyEvent arg0){

PictogramElement pe = getSelectedPictogramElement();
Intention bimElement = (Intention) Graphiti.getLinkService().getBusinessObjectForLinkedPictogra mElement(pe);
bimElement.setDescription(descriptionText.getText());
System.out.print("\nDescription setted: "+bimElement.getDescription());


}
};



@Override
public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
super.createControls(parent, tabbedPropertySheetPage);

TabbedPropertySheetWidgetFactory factory = getWidgetFactory();
Composite composite = factory.createFlatFormComposite(parent);
FormData data;

// nameText
nameText = factory.createText(composite, ""); //$NON-NLS-1$

data = new FormData();
//data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);
data.left = new FormAttachment(0, 100);

data.right = new FormAttachment(100, 0);
data.top = new FormAttachment(0, VSPACE);
nameText.setLayoutData(data);
//Daniele: I am adding the listener here
nameText.addModifyListener(listenerIntentionName);

CLabel valueLabel = factory.createCLabel(composite, "Name:"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(nameText, -HSPACE);
data.top = new FormAttachment(nameText, 0, SWT.CENTER);
valueLabel.setLayoutData(data);

// descriptionText

descriptionText = factory.createText(composite, "", SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); //$NON-NLS-1$

data = new FormData();
data.left = new FormAttachment(0, 100);
data.right = new FormAttachment(100, 0);
//TODO: try to modify the layout for property
data.top = new FormAttachment(nameText, VSPACE);
descriptionText.setLayoutData(data);
descriptionText.addModifyListener(listenerIntentionDescripti on);

CLabel valueLabelDescription = factory.createCLabel(composite, "Description:"); //$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, 0);
//-HSPACE
data.right = new FormAttachment(descriptionText, -HSPACE);
data.top = new FormAttachment(descriptionText, 0, SWT.CENTER);
valueLabelDescription.setLayoutData(data);


}

@Override
public void refresh() {
PictogramElement pe = getSelectedPictogramElement();
if (pe != null) {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogra mElement(pe);
// the filter assured, that it is a Intention
if (bo == null)
return;
// Remove listener
nameText.removeModifyListener(listenerIntentionName);


// Modify values of the properties
String name = ((Intention) bo).getName();
System.out.print("\nSet Name property: "+name);
nameText.setText(name == null ? "" : name); //$NON-NLS-1$

// (RE)Add listener
nameText.addModifyListener(listenerIntentionName);


// Remove listener

descriptionText.removeModifyListener(listenerIntentionDescri ption);
String description = ((Intention) bo).getDescription();
System.out.print("\nSet Description property: "+description);
descriptionText.setText(description == null ? "" : description); //$NON-NLS-1$

// (RE)Add listener
descriptionText.addModifyListener(listenerIntentionName);


}
} Crying or Very Sad

[Updated on: Fri, 03 September 2010 18:57]

Report message to a moderator

Re: Properties and Listeners [message #556855 is a reply to message #556319] Thu, 02 September 2010 19:44 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi guys,

with the above code I have the problem reported below Sad Sad Sad

Do you have any suggestions?

Please Smile, I am stuck

Thank you very much!!!
Daniele

------------------------------
eclipse.buildId=I20100608-0911
java.version=1.6.0_18
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=en_CA
Framework arguments: -product org.eclipse.platform.ide
Command-line arguments: -product org.eclipse.platform.ide -data /home/daniele/workspace/../runtime-EclipseApplication -dev file:/home/daniele/workspace/.metadata/.plugins/org.eclipse. pde.core/Eclipse Application/dev.properties -os linux -ws gtk -arch x86


Error
Thu Sep 02 15:38:22 EDT 2010
Unhandled event loop exception

java.lang.IllegalStateException: Cannot modify resource set without a write transaction
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ssertWriting(TransactionChangeRecorder.java:348)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ppendNotification(TransactionChangeRecorder.java:302)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.p rocessObjectNotification(TransactionChangeRecorder.java:284)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.n otifyChanged(TransactionChangeRecorder.java:240)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:280)
at BIM.impl.ThingImpl.setName(ThingImpl.java:210)
at org.eclipse.graphiti.bim.property.IntentionSection$1.modifyT ext(IntentionSection.java:58)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:173)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3552)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3171)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:24 27)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)

[Updated on: Thu, 02 September 2010 19:45]

Report message to a moderator

Re: Properties and Listeners [message #557284 is a reply to message #556319] Mon, 06 September 2010 12:53 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim KaiserFriend
Messages: 118
Registered: July 2009
Senior Member
Hi,

you can not modify an EObject directly if it is controlled
by an EditingDomain.

See EMF Model Transaction Developer Guide
in the eclipse help for an explanation of the concepts.

In general, you can access the EditingDomain of an EObject
via
org.eclipse.emf.transaction.util.TransactionUtil.getEditingD omain(...)

Also you can use the method
public void execute(IFeature feature, IContext context)
of the GFPropertySection to have your model modification executed
inside a feature. Then the framework takes care of using the editingdomain of the diagram editor.


Best, Tim

Re: Properties and Listeners [message #557512 is a reply to message #557284] Tue, 07 September 2010 22:07 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Thank you very much Tim!!!

I much appreciated your help. Actually, I am trying to understand how this work looking at the guide you suggested.

Daniele
p.s.
I was wondering if you have also an example within the graphiti tutorial which I can use to better undestand the editingDomain or the execute method.


Re: Properties and Listeners [message #557522 is a reply to message #557512] Tue, 07 September 2010 23:47 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi Tim,

what about this solution (w.r.t. the above code)?

it seems to work but I am not sure if this is the correct way to do that.

Thanks in advance for any suggestions
Daniele
------------------------------



private ModifyListener listenerIntentionName = new ModifyListener(){

public void modifyText (ModifyEvent arg0){



// set the new name for the Intention
PictogramElement pe = getSelectedPictogramElement();
final Intention bimElement = (Intention) Graphiti.getLinkService().getBusinessObjectForLinkedPictogra mElement(pe);

TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(bimElement);

editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
protected void doExecute() {
bimElement.setName(nameText.getText());
}
});

}
};

[Updated on: Tue, 07 September 2010 23:48]

Report message to a moderator

Re: Properties and Listeners [message #557717 is a reply to message #556319] Wed, 08 September 2010 15:19 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim KaiserFriend
Messages: 118
Registered: July 2009
Senior Member
Looks good for me...
Best, Tim
Re: Properties and Listeners [message #557738 is a reply to message #557717] Wed, 08 September 2010 16:03 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Thank you Tim for your support!!
Daniele
Re: Properties and Listeners [message #558034 is a reply to message #557738] Thu, 09 September 2010 20:59 Go to previous messageGo to next message
Rhett Hudson is currently offline Rhett HudsonFriend
Messages: 43
Registered: September 2010
Member
I've been looking at this issue as well. I tried to implement an update to my domain model from a PropertySheet change using a feature, since that seemed like the preferred method. However, my attempt to set an attribute in the domain model failed because there was no active transaction.

I noticed that the implementation of execute() in GFPropertySection performs its command execution without a domain editor. When I changed it to look more like the command executions in AbstractFeatureProvider, it worked. Specifically, I substituted:


public void execute(final IFeature feature, final IContext context)
{
final TransactionalEditingDomain editingDomain =
this.getDiagramTypeProvider().getDiagramEditor().getEditingD omain();
CommandExec.getSingleton().executeCommand(
new GenericFeatureCommandWithContext(feature, context),
editingDomain);
}

That fixed my property originated update of the domain model.

Am I missing something in my process which would make the existing implementation of execute in GFPropertySection work?
Re: Properties and Listeners [message #558841 is a reply to message #556319] Tue, 14 September 2010 15:18 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim KaiserFriend
Messages: 118
Registered: July 2009
Senior Member
Hi,

probably you missed the last fix.
I checked in the fix to make it work on 6th of september.
If you update graphiti it should work
out of the box.

Best, Tim
Re: Properties and Listeners [message #558843 is a reply to message #558034] Tue, 14 September 2010 15:23 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi Rhett,

If you have a minute can you post how " to implement an update to my domain model from a PropertySheet change using a feature, since that seemed like the preferred method."

What I did work perfectly but since, as you said, using feature is the preferred method can you provide an example in this thread? (and maybe say why is the preffered one and why I should use that Smile?)

I will much appreciate that.
Thanks
Daniele

[Updated on: Tue, 14 September 2010 15:25]

Report message to a moderator

Re: Properties and Listeners [message #568087 is a reply to message #557717] Wed, 08 September 2010 16:03 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Thank you Tim for your support!!
Daniele
Re: Properties and Listeners [message #568109 is a reply to message #568087] Thu, 09 September 2010 20:59 Go to previous messageGo to next message
Rhett Hudson is currently offline Rhett HudsonFriend
Messages: 43
Registered: September 2010
Member
I've been looking at this issue as well. I tried to implement an update to my domain model from a PropertySheet change using a feature, since that seemed like the preferred method. However, my attempt to set an attribute in the domain model failed because there was no active transaction.

I noticed that the implementation of execute() in GFPropertySection performs its command execution without a domain editor. When I changed it to look more like the command executions in AbstractFeatureProvider, it worked. Specifically, I substituted:


public void execute(final IFeature feature, final IContext context)
{
final TransactionalEditingDomain editingDomain =
this.getDiagramTypeProvider().getDiagramEditor().getEditingD omain();
CommandExec.getSingleton().executeCommand(
new GenericFeatureCommandWithContext(feature, context),
editingDomain);
}

That fixed my property originated update of the domain model.

Am I missing something in my process which would make the existing implementation of execute in GFPropertySection work?
Re: Properties and Listeners [message #568279 is a reply to message #568109] Tue, 14 September 2010 15:23 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi Rhett,

If you have a minute can you post how " to implement an update to my domain model from a PropertySheet change using a feature, since that seemed like the preferred method."

What I did work perfectly but since, as you said, using feature is the preferred method can you provide an example in this thread?

I will much appreciate that.
Thanks
Daniele
Re: Properties and Listeners [message #692071 is a reply to message #568279] Sun, 03 July 2011 12:07 Go to previous messageGo to next message
Kalle  is currently offline Kalle Friend
Messages: 3
Registered: June 2011
Junior Member
I'm asking myself the same question, if it is a common way, to have a different focusListener for each field/combo/attribute etc.. I don't know how to assure, that only the textField, of which I was changing the value, is updated in my model. Currently I'm resetting all attributes of my model, when the focus of an element is lost, to make sure, the new value is updated.

Thanks
Re: Properties and Listeners [message #714808 is a reply to message #568279] Thu, 11 August 2011 14:41 Go to previous message
Christian B is currently offline Christian BFriend
Messages: 68
Registered: August 2011
Member
Daniele wrote on Tue, 14 September 2010 11:23
Hi Rhett,
If you have a minute can you post how " to implement an update to my domain model from a PropertySheet change using a feature, since that seemed like the preferred method."


I would also be very interested in an example for the method GFPropertySection.execute(IFeature feature, IContext context)

Anyone Wink

thanks in advance!

EDIT:
found an example!

http://www.eclipse.org/graphiti/developers/resources/ModifyListener.txt

[Updated on: Thu, 11 August 2011 15:27]

Report message to a moderator

Previous Topic:Validation for DirectEditFeatures
Next Topic:Bug with Undo after RenameEClassFeature
Goto Forum:
  


Current Time: Mon Nov 24 22:56:24 GMT 2014

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

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