| Putting it all together [message #667732] | 
Sun, 01 May 2011 15:57   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
I'd like to use Graphiti to create an editor which ultimately outputs an XML file.  
 
I've followed the tutorial and I think I understand the basic concepts but I'm having a little trouble figuring out how to use Graphiti to create a functional editor 
 
-I've created an EMF model from the schema for the XML format I want to deal with. From the tutorial I can see I need to use this as the Graphiti diagram is created and edited 
 
-More of a problem is how to provide the functionality of saving the XML file. Does this go in Graphiti or elsewhere? In the tutorial there's no export or indication the model is output is accessible outside of the diagram. 
 
-A little like the save issue, how do I import existing XML files? I've seen the dark processing feature and understand I could run through the file, construct the model and then display the diagram for it but again I don't see where this functionality goes. 
 
Apologies if this is all completely outside Graphiti's scope! Some pointers for where to look would be appreciated.
 |  
 |  
  | 
| Re: Putting it all together [message #667736 is a reply to message #667732] | 
Sun, 01 May 2011 17:10    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Am 01.05.11 21:57, schrieb Stuart Harper: 
> I'd like to use Graphiti to create an editor which ultimately outputs an 
> XML file. 
 
Just to clarify - the default file format used to store your EMF Ecore  
model is XML-based. I assume that you need to create a different kind of  
output file. 
 
I'd recommed to keep the Ecore-based model because it's much easier to  
simply generate the "target XML file" when saving the editor. 
 
> -More of a problem is how to provide the functionality of saving the XML 
> file. Does this go in Graphiti or elsewhere? 
 
It should be possible to override the method doSave of the DiagramEditor  
and add your own XML output to the editor. What method you choose to  
create the XML file is up to you. If you use a "complete" workbench  
instead of a RCP application, you could also use a builder - in this  
case, you don't need to modify the editor at all because the logic to  
create your XML file from the diagram file is encapsulated in the builder. 
 
> -A little like the save issue, how do I import existing XML files? 
 
I'd recommend an import wizard that creates the model file from your  
existing XML files. How you read these files is again up to you (SAX,  
DOM, whatever). You then create the corresponding EMF object (the  
"business object", add it to the model file, then create an AddContext  
and/or an AddConnectionContext to add the business object to the  
diagram. You then pass this context to the feature provider method  
addIfPossible (you can get the FP using  
 GraphitiUI.getExtensionManager().createFeatureProvider(diagr am)). 
 
It's a bit complex, but I'd recommend starting with a simple import  
wizard (see  
 http://wiki.eclipse.org/FAQ_How_do_I_add_my_wizard_to_the_Ne w,_Import,_or_Export_menu_categories%3F  
and related sources), add some XML reading of your choice and dump the  
contents to stderr / stdout. Then add the EMF model objects and use the  
reflective editor to check whether that works. If you've got the  
non-diagram stuff running, it's much easier to add the diagram creation. 
 
HTH 
   Volker 
 
--  
* Volker Wegert * http://www.volker-wegert.de/contact *
 |  
 |  
  | 
 | 
 | 
 | 
 | 
| Re: Putting it all together [message #715710 is a reply to message #715552] | 
Mon, 15 August 2011 05:21   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Hi Matt, 
 
as Volker mentioned you might override 
the doSave method in the DiagramEditor 
class. There, you can inspect the saved resources, validate them etc. 
 
You might also query a business/graphiti object from the diagram anytime 
and use EMF's eResource() method on the object to retrieve its resource. 
For how a mapping between EMF Resources/EObjects and Files can be done  
you can have a look at Graphiti's EMFService. 
 
Best, Tim
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.05849 seconds