Add Object to the UI Programmatically [message #1637946] |
Fri, 27 February 2015 00:08 |
Tim Drake Messages: 1 Registered: February 2015 |
Junior Member |
|
|
Hi, Every one
I am new to Graphiti, today i ran into a problem, and i don't know how to solve it, search the google several hours now, maybe someone here can offer a little help.
Here is the problem, i can add objects just fine using the palette. But i want to add a new feature,that is when i use the direct editing feature to change the name of a object, if a certain string is typed in, a new object will be added into the diagram just like i drag a new object using palette.
i plan to do this at the checkValueValid, if a "=" is typed in, a new object should be added.
i managed to get the targetContainer, and i can create the object with the model code, but i always get the exception
java.lang.IllegalStateException: Cannot modify resource set without a write transaction
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processObjectNotification(TransactionChangeRecorder.java:284)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:240)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
How can I solve this problem?
Thanks for the help
@Override
public String checkValueValid(String value, IDirectEditingContext context) {
if (value.length() < 1)
return "Please enter any text as class name.";
if (value.contains("=")){
Object p = getBusinessObjectForPictogramElement(context.getPictogramElement());
Object a = Factory.eINSTANCE.createObject();
a.setName(value);
p.getObject().add(a);
return "not a valid name";
}
return null;}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03859 seconds