Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Creating a new resource from within a plugin
Creating a new resource from within a plugin [message #721482] Thu, 01 September 2011 21:30 Go to next message
Leonardo Kenji Shikida is currently offline Leonardo Kenji ShikidaFriend
Messages: 37
Registered: July 2009
Member
Hi

I am pretty confused here

using JDT, I can create a new file just like this

http://wiki.eclipse.org/FAQ_How_are_resources_created%3F

but from EMF example, I can create a new model file like this

http://www.vogella.de/articles/EclipseEMFPersistence/article.html (see example 2.1)

following the second procedure, I have a plugin project running in a new workspace and I try to create the file. No exception raised, nothing happened. Just silently ignored.

at the same time, if I run the same code as a standalone java app, it creates the new model file (actually a XML file) in the same project directory.

so, how should I create this model from within a plugin project?

TIA

Kenji
Re: Creating a new resource from within a plugin [message #721525 is a reply to message #721482] Fri, 02 September 2011 01:43 Go to previous message
Leonardo Kenji Shikida is currently offline Leonardo Kenji ShikidaFriend
Messages: 37
Registered: July 2009
Member
now I see...

it´s creating the file at the working directory defined in the "arguments" tab of the "eclipse application" run configuration...

resolved just like this
			Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
			Map<String, Object> m = reg.getExtensionToFactoryMap();
			m.put("xxx", new XMIResourceFactoryImpl());

			// Obtain a new resource set
			ResourceSet resSet = new ResourceSetImpl();

			// Create a resource
			Resource resource = resSet.createResource(URI
					.createURI(cdu.getNome()+".xxx"));
			// Get the first model element and cast it to the right type, in my
			// example everything is hierarchical included in this first node
			resource.getContents().add(cdu);

			ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
			
			// Now save the content.
			try {
				resource.save(baos, Collections.EMPTY_MAP);
				//resource.save(Collections.EMPTY_MAP);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			IFolder folder = targetFolder;
			IFile file = folder.getFile(cdu.getNome()+".xxx");
			InputStream source = new ByteArrayInputStream(baos.toByteArray());
			file.create(source, IResource.NONE, null);
Previous Topic:Library problem
Next Topic:Javaw.exe terminated
Goto Forum:
  


Current Time: Fri Apr 26 17:37:45 GMT 2024

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

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

Back to the top