Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Properties and Listeners
Properties and Listeners [message #565867] 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: 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 :)







---------------
...
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
nameText.removeModifyListener(listenerIntentionName);
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);


}
}
Re: Properties and Listeners [message #567773 is a reply to message #565867] 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 following error :(

Have someone some suggestions?
Please :)
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)
Re: Properties and Listeners [message #567918 is a reply to message #565867] 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 #567991 is a reply to message #567918] 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 #568015 is a reply to message #567991] 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 work but I am not sure if there is a better way.
Thanks in advance for any suggstions
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());
}
});

}
};
Re: Properties and Listeners [message #568065 is a reply to message #565867] 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 #568264 is a reply to message #565867] Tue, 14 September 2010 15:18 Go to previous 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
Previous Topic:Graphiti 0.7.0 RC1 available
Next Topic:Font Size In Pixels
Goto Forum:
  


Current Time: Sat Nov 29 07:48:15 GMT 2014

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

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