Skip to main content



      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 08:53 Go to next message
Eclipse UserFriend
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 11:56 Go to previous messageGo to next message
Eclipse UserFriend
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");
> }
> }
> };
Re: Saving a file from the editor [message #723751 is a reply to message #723475] Fri, 09 September 2011 07:01 Go to previous messageGo to next message
Eclipse UserFriend
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 07:18] by Moderator

Re: Saving a file from the editor [message #723768 is a reply to message #723751] Fri, 09 September 2011 08:29 Go to previous message
Eclipse UserFriend
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?
> }
Previous Topic:Display second diagram with given resource
Next Topic:Semantics
Goto Forum:
  


Current Time: Thu Jul 17 12:17:52 EDT 2025

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

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

Back to the top