Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Saving a file from the editor
Saving a file from the editor [message #723387] Thu, 08 September 2011 12:53 Go to next message
amalia.msanusiFriend
Messages: 6
Registered: March 2011
Junior Member
Hello,

I've created a statechart editor and I did some customization similar to the GMF Mindmap Tutorial 3.

Basically when I right click the diagram, a model transformation is done, which is executed using Command. This seems to work except that I can't save the transformed diagram into another file. I've got an error: java.net.UnknownServiceException: protocol doesn't support output.

Any idea how to do this?

Here;s the code for Command:
protected Command createUnitApplicationCommand(final UnitApplication unitApplication, final EObject statechart) {
		
		return new AbstractCommand() {
			@Override
			public void execute() {
				boolean result = unitApplication.execute();
				if (result) {
					System.out.println("Successful");
					
					if (statechart == null) {
						System.err.println("statechart is null");
						return;
					} 

					Bundle bundle = Platform.getBundle("tue.examples.statechart");
					String path = bundle.getEntry("model/default2.sm").toExternalForm();
					URI modelUri = URI.createURI(path);
					statechart.eResource().setURI(modelUri);
					
					try {
						statechart.eResource().save(null);
					} catch (IOException e) {
						e.printStackTrace();
					}
				} else {
					System.err.println("Not successful");
				}
			}
		};
Re: Saving a file from the editor [message #723475 is a reply to message #723387] Thu, 08 September 2011 15:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Amalia,

It looks like you're trying to save into contents of an installed
bundle, which of course isn't supported. What are you trying to
accomplish with the code you show below? An application that modifies
its own installation is a very bad idea. Shouldn't you be trying to
save to the workspace with a platform:/resource/<project>/<path> URI?


On 08/09/2011 5:53 AM, amalia.msanusi wrote:
> Hello,
>
> I've created a statechart editor and I did some customization similar
> to the GMF Mindmap Tutorial 3.
> Basically when I right click the diagram, a model transformation is
> done, which is executed using Command. This seems to work except that
> I can't save the transformed diagram into another file. I've got an
> error: java.net.UnknownServiceException: protocol doesn't support output.
>
> Any idea how to do this?
>
> Here;s the code for Command:
>
> protected Command createUnitApplicationCommand(final UnitApplication
> unitApplication, final EObject statechart) {
>
> return new AbstractCommand() {
> @Override
> public void execute() {
> boolean result = unitApplication.execute();
> if (result) {
> System.out.println("Successful");
>
> if (statechart == null) {
> System.err.println("statechart is null");
> return;
> }
> Bundle bundle =
> Platform.getBundle("tue.examples.statechart");
> String path =
> bundle.getEntry("model/default2.sm").toExternalForm();
> URI modelUri = URI.createURI(path);
> statechart.eResource().setURI(modelUri);
>
> try {
> statechart.eResource().save(null);
> } catch (IOException e) {
> e.printStackTrace();
> }
> } else {
> System.err.println("Not successful");
> }
> }
> };


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Saving a file from the editor [message #723751 is a reply to message #723475] Fri, 09 September 2011 11:01 Go to previous messageGo to next message
amalia.msanusiFriend
Messages: 6
Registered: March 2011
Junior Member
Hi Ed,

What I am trying to achieve is to save the result of model transformation into a file. I've tried the following, but it didn't save the file at all. Do you know how to save it into a file?

URI modelUri = URI.createFileURI(new File("D:/Documents/Eclipse/tue.examples.statechart.diagram.custom/model" + "statechart.henshin")
						.getAbsolutePath());
					Resource res = resourceSet.createResource(modelUri, "henshin");
					
					try {
						res.getContents().add(tsResult);
						res.save(null);
					} catch (IOException e) {
						e.printStackTrace();
					}

[Updated on: Fri, 09 September 2011 11:18]

Report message to a moderator

Re: Saving a file from the editor [message #723768 is a reply to message #723751] Fri, 09 September 2011 12:29 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
Amalia,

Comments below.

On 09/09/2011 4:01 AM, amalia.msanusi wrote:
> Hi Ed,
>
> What I am trying to achieve is to save the result of model
> transformation into a file. I've tried the following, but it didn't
> save the file at all. Do you know how to save it into a file?
> URI modelUri = URI.createFileURI(new File("PATH_TO" +
> "statechart.henshin")
> .getAbsolutePath());
You've used the debugger to look at the value this produces. I.e.,
where are you looking to see if it's saved?
> Resource res =
> resourceSet.createResource(modelUri, "henshin");
>
> try {
> res.getContents().add(tsResult);
> res.save(null);
> } catch (IOException e) {
> e.printStackTrace();
Does it thrown an exception? If so, what does it tell you?
> }


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Display second diagram with given resource
Next Topic:Semantics
Goto Forum:
  


Current Time: Tue Apr 23 07:44:10 GMT 2024

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

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

Back to the top