Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to run Xtend2 from toolbar bottom?
How to run Xtend2 from toolbar bottom? [message #894184] Sat, 07 July 2012 12:58 Go to next message
Andrea Margheri is currently offline Andrea MargheriFriend
Messages: 20
Registered: July 2012
Junior Member
Hi,

I have an Xtext project fro my DSL and the code generator made with Xtend2. Usually code generation starts at the saving event, instead I want a toolbar bottom in my plugin from which I start the generation.

I made the bottom, but I don't know how get the Resource from active editor to start doGenerate(Resource, IFileSystemAccess).

Thanks,

Andrea
Re: How to run Xtend2 from toolbar bottom? [message #894185 is a reply to message #894184] Sat, 07 July 2012 13:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13423
Registered: July 2009
Senior Member
Hi,

let you inspire by http://christiandietrich.wordpress.com/2011/10/15/xtext-calling-the-generator-from-a-context-menu/

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to run Xtend2 from toolbar bottom? [message #894186 is a reply to message #894185] Sat, 07 July 2012 13:16 Go to previous messageGo to next message
Andrea Margheri is currently offline Andrea MargheriFriend
Messages: 20
Registered: July 2012
Junior Member
I try it but don't work the
@inject Provider<EclipseResourceFileSystemAccess> fileAccessProvider

other way?

[Updated on: Sat, 07 July 2012 13:16]

Report message to a moderator

Re: How to run Xtend2 from toolbar bottom? [message #894187 is a reply to message #894186] Sat, 07 July 2012 13:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13423
Registered: July 2009
Senior Member
Hi,

how do you create your toolbar button?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to run Xtend2 from toolbar bottom? [message #894190 is a reply to message #894187] Sat, 07 July 2012 13:29 Go to previous messageGo to next message
Andrea Margheri is currently offline Andrea MargheriFriend
Messages: 20
Registered: July 2012
Junior Member
I create a new extension in plugin.xml, with menuContribution and toolbar.
The handler for command is this

@Inject
	private AxacmlGenerator generator;

	@Inject
	IResourceDescriptions resourceDescriptions;

	@Inject
	IResourceSetProvider resourceSetProvider;

	@Inject 
	private JavaIoFileSystemAccess fileAccess;

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {

		ISelection selection = HandlerUtil.getCurrentSelection(event);
		IStructuredSelection structuredSelection = (IStructuredSelection) selection;
		Object firstElement = structuredSelection.getFirstElement();
		if (firstElement instanceof IFile) {

			IFile file = (IFile) firstElement;
			IProject project = file.getProject();
			//IFolder srcGenFolder = project.getFolder("src");

			URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
			ResourceSet rs = resourceSetProvider.get(project);
			Resource r = rs.getResource(uri, true);

			generator.doGenerate(r, fileAccess);
		}
		return null;
	}



I get the selected file but resourceSetProvider doesn't run.
Re: How to run Xtend2 from toolbar bottom? [message #894194 is a reply to message #894190] Sat, 07 July 2012 13:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13423
Registered: July 2009
Senior Member
Make sure you use the executableextensionfactory in the plugin.xml!

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to run Xtend2 from toolbar bottom? [message #894206 is a reply to message #894194] Sat, 07 July 2012 16:26 Go to previous messageGo to next message
Andrea Margheri is currently offline Andrea MargheriFriend
Messages: 20
Registered: July 2012
Junior Member
Ok, now Resource is got by ResourceProvider, I'm quite new of Xtext and Giuce so I don't understand before.

I change also EclipseResourceFileSystemAccess with EclipseResourceFileSystemAccess2 because is deprecated, and to avoid nullpointException I add the following code
fsa.setMonitor(new NullProgressMonitor());
fsa.setProject(project);

but even if there aren't any exception no genereted files are in my project. I check with debug and all xtend instructions is executed.
Why the files aren't created?

Thanks a lot!

Andrea
Re: How to run Xtend2 from toolbar bottom? [message #894210 is a reply to message #894206] Sat, 07 July 2012 17:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13423
Registered: July 2009
Senior Member
Hi,

i cannot say - you have to debug the code yourself

p.s: in Xtext 2.3 and with EclipseResourceFileSystemAccess2 you have to do somehting like
fsa.setOutputPath("src-gen");


~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to run Xtend2 from toolbar bottom? [message #894322 is a reply to message #894210] Sun, 08 July 2012 07:15 Go to previous messageGo to next message
Andrea Margheri is currently offline Andrea MargheriFriend
Messages: 20
Registered: July 2012
Junior Member
OK thanks,

Andrea
Re: How to run Xtend2 from toolbar bottom? [message #894327 is a reply to message #894322] Sun, 08 July 2012 08:48 Go to previous messageGo to next message
Andrea Margheri is currently offline Andrea MargheriFriend
Messages: 20
Registered: July 2012
Junior Member
I fix the problem, I have to redefine OutputConfiguration with the permission for create new folder.

Andrea
Re: How to run Xtend2 from toolbar bottom? [message #894621 is a reply to message #894327] Mon, 09 July 2012 20:22 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13423
Registered: July 2009
Senior Member
can you post what you have done?

On 2012-07-08 08:48:41 +0000, Andrea Margheri said:

> I fix the problem, I have to redefine OutputConfiguration with the
> permission for create new folder.
>
> Andrea


--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to mailto:xtext@xxxxxxxx


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Giving the lexer a different stream
Next Topic:using format effector character in a terminal rule
Goto Forum:
  


Current Time: Sat Apr 04 16:30:51 GMT 2020

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

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

Back to the top