Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » delete an element from model(how to delete an element from .uml file)
delete an element from model [message #1015896] Mon, 04 March 2013 08:27 Go to next message
Joshua Yang is currently offline Joshua YangFriend
Messages: 11
Registered: October 2012
Junior Member
Hi,
I'm quiet new to GFM and I have some problems
How could I delete an element from the data model?
I get the element by the way below:

URI fileUri = URI.createFileURI(modelFilePath); 
ResourceSet resourceSet  = new ResourceSetImpl(); 
			
Resource resource = resourceSet.getResource(fileUri, true);
EList<EObject> eList = resource.getContents();
EObject eObject = eList.get(0);
Model fmToolModel = (Model)eObject;
xxElement x = fmToolModel.get...


what is the best way to delete the element and the links with it?
Deleting only the x while not deleting the links may cause errors that the file could not open.

Giving me the code is what i expected...

Thanks~
Re: delete an element from model [message #1015914 is a reply to message #1015896] Mon, 04 March 2013 09:19 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
Hi Joshua,

when do you want to delete the semantic model element? Is there some user interaction involved? Basically, you should delete the model element via the Editingdomain using commands to support undo / redo, for example the DestroyElementCommand.

To delete the links, it is important how your model is structured. If the links eContainer is the element you deleted, it will be deleted automatically. If not, there are some hooks like GMFs EditHelper#getDestroyDependentsCommand you could use.

Maybe you can explain your use case in more detail?

Best regards,

Andreas



Re: delete an element from model [message #1015918 is a reply to message #1015914] Mon, 04 March 2013 09:28 Go to previous messageGo to next message
Joshua Yang is currently offline Joshua YangFriend
Messages: 11
Registered: October 2012
Junior Member
maybe it could be another question since I find that right click pop menu contains
the command to delete selected element("DestroyElementCommand" as you mentoned).

The problem may be is this:

how to call the command in a pop menu?

Thank you for the quick reply~^_^
Re: delete an element from model [message #1015920 is a reply to message #1015918] Mon, 04 March 2013 09:32 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
IOperationHistory history = OperationHistoryFactory.getOperationHistory();
history.execute(new DestroyElementCommand(new DestroyElementRequest(toDelete, false)), new NullProgressMonitor(), null);
Re: delete an element from model [message #1015922 is a reply to message #1015920] Mon, 04 March 2013 09:39 Go to previous messageGo to next message
Joshua Yang is currently offline Joshua YangFriend
Messages: 11
Registered: October 2012
Junior Member
is DestroyElementCommand a generated class or ...

it looks as if that not fits my situation well...
Re: delete an element from model [message #1015925 is a reply to message #1015922] Mon, 04 March 2013 09:42 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
No, it is a runtime class.
Add a plugin dependency to org.eclipse.gmf.runtime.emf.type.core.



Re: delete an element from model [message #1015937 is a reply to message #1015925] Mon, 04 March 2013 10:32 Go to previous messageGo to next message
Joshua Yang is currently offline Joshua YangFriend
Messages: 11
Registered: October 2012
Junior Member
sorry to reply so late
but the code throws exception...

Could you please give a helping hand?
org.eclipse.core.commands.ExecutionException: While executing the operation, an exception occurred
at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:521)
	at edu.fudan.fdsplc.feature.configuration.model.feature.configuration.presentation.ConfigurationEditor.generateAppModel(ConfigurationEditor.java:469)
	at edu.fudan.fdsplc.feature.configuration.model.feature.configuration.presentation.ConfigurationEditor.access$6(ConfigurationEditor.java:403)
	at edu.fudan.fdsplc.feature.configuration.model.feature.configuration.presentation.ConfigurationEditor$4.widgetSelected(ConfigurationEditor.java:197)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
...
Caused by: java.lang.NullPointerException
	at org.eclipse.emf.workspace.AbstractEMFOperation.inheritedOptions(AbstractEMFOperation.java:252)

Re: delete an element from model [message #1015954 is a reply to message #1015937] Mon, 04 March 2013 11:58 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
In GMF, it is very important to change the model only via the Editingdomain.
Do not load the model element that you want to delete with a new resourceset.
Instead, load it via your EditingDomain. You can receive it from your active editor,
DiagramDocumentEditor#getEditingDomain() or even better from the selected object TransactionUtil.getEditingdomain(selectedelement);

From your Editing domain you can get the resource set via getResourceSet().


Re: delete an element from model [message #1015955 is a reply to message #1015954] Mon, 04 March 2013 12:05 Go to previous messageGo to next message
Joshua Yang is currently offline Joshua YangFriend
Messages: 11
Registered: October 2012
Junior Member
the problem here is
the model i want to change is not the one opened in the editor...

what i want to do is actually like this:
load a model , change the content ,and save it to another file,
while the file my current editor opened is with no relationship with what i did

[Updated on: Mon, 04 March 2013 12:26]

Report message to a moderator

Re: delete an element from model [message #1015962 is a reply to message #1015954] Mon, 04 March 2013 12:30 Go to previous message
Joshua Yang is currently offline Joshua YangFriend
Messages: 11
Registered: October 2012
Junior Member
Hi,Andreas

The code finally executed wihout any error.However it does not gose as i wished.

Here gose my code:
ResourceSet resourceSet  = new ResourceSetImpl();
TransactionalEditingDomain domainx = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(resourceSet);
Resource res = domainx.loadResource(fileUri.path());
xxxImpl toDelete = (xxxImpl)((xxxModelImpl)res.getContents().get(0)).getXXX().get(0);

IOperationHistory history = OperationHistoryFactory.getOperationHistory();
DestroyElementRequest desRequest = new DestroyElementRequest(toDelete, true);
history.execute(new DestroyElementCommand(desRequest), new NullProgressMonitor(), null);

The code delete the element indeed,while the edgs goes still. it causes the problem that i can not open the file any more.

What should I do ,Could you please give a helping hand?

[Updated on: Mon, 04 March 2013 15:40]

Report message to a moderator

Previous Topic:GMF examples sources
Next Topic:How to delete ae element programmly?
Goto Forum:
  


Current Time: Sun Mar 29 19:49:03 GMT 2020

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

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

Back to the top