Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Add Object to the UI Programmatically (Add new object to the UI and to be seen)
icon9.gif  Add Object to the UI Programmatically [message #1637946] Fri, 27 February 2015 00:08 Go to next message
Tim Drake is currently offline Tim DrakeFriend
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;}


Re: Add Object to the UI Programmatically [message #1639227 is a reply to message #1637946] Fri, 27 February 2015 14:26 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1899
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Tim,

Graphiti uses EMF Transactions to execute all changes. That means that all
EMF object live inside a TransactionalEditingDomain and must use a
transaction to execute any changes. You will need to write something like
this:

TransactionalEditingDomain editingDomain =
diagramBehavior.getEditingDomain(); // or get the editing domain from the
EObject and cast it
editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain)
{

@Override
protected void doExecute() {
// Do you changes here
}
});

Michael
Previous Topic:BorderDecorator for Visible Rectangle instead of InvisibleRectangle
Next Topic:Set background color in text editor lines (PDE)
Goto Forum:
  


Current Time: Wed Nov 14 08:32:29 GMT 2018

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

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

Back to the top