|
|
Re: Xtext plugin and context menu handler issue [message #1336006 is a reply to message #1334020] |
Tue, 06 May 2014 07:30 |
Davide G Messages: 36 Registered: October 2013 |
Member |
|
|
this is what've done: i disabled the extension point org.eclipse.xtext.builder.participant , then i added the command
and the handler in this way:
<extension point="org.eclipse.ui.commands">
<command
name="Generate Documentation"
id="org.xtext.passi.DocGen.ui.GenerationCommand">
</command>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
class="org.xtext.passi.ui.DocGenExecutableExtensionFactory:org.xtext.passi.DocGen.ui.GenerationHandler"
commandId="org.xtext.passi.DocGen.ui.GenerationCommand">
</handler>
</extension>
then i added the context menu voice, but for all the types of files:
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="org.xtext.passi.DocGen.ui.GenerationCommand"
style="push">
</command>
</menuContribution>
</extension>
The class GenerationHandler extends AbstractHandler and implements the interface IHandler, as shown below.
public class GenerationHandler extends AbstractHandler implements IHandler
{
@Inject
private IGenerator generator;
@Inject
private Provider<EclipseResourceFileSystemAccess2> fileAccessProvider;
@Inject
IResourceDescriptions resourceDescriptions;
@Inject
IResourceSetProvider resourceSetProvider;
/**
* Used to call manual documentation generation from the context menu
*/
public Object execute(ExecutionEvent event) throws ExecutionException
{
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection)
{
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IFile)
{
IFile file = (IFile) firstElement;
IProject project = file.getProject();
final EclipseResourceFileSystemAccess2 fsa = fileAccessProvider.get();
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
ResourceSet rs = resourceSetProvider.get(project);
Resource r = rs.getResource(uri, true);
generator.doGenerate(r, fsa);
}
}
return null;
}
@Override
public boolean isEnabled()
{
return true;
}
}
edit: In plugin.xml_gen were missing the command and handler definition so I added there, but nothing changed.
[Updated on: Tue, 06 May 2014 07:59] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04469 seconds