Menu contribution problem in project Explorer [message #1213816] |
Wed, 27 November 2013 12:03 |
|
Dear all,
I have developed an Acceleo generator plugin able to generate WordML documentation from UML models. My UML editor is papyrus 0.10.0.
I would like to execute a command from a popup menu (right click) when I select the UML file of the Papyrus model. I have tested the commands and they work fine.
However, in the project explorer of papyrus, my popup doesn't appear. When I'm a regular project with an classic UML file, I see my popup. Here is my plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
<menu
icon="icons/document.gif"
id="doc_generators"
label="Generate documents"
tooltip="Utilities able to generate documentation">
</menu>
</menuContribution>
<menuContribution
locationURI="popup:doc_generators?after=additions">
<command
commandId="com.spacebel.acceleo.uml.to.wordml.ui.generateADD"
label="Generate ADD (WordML)"
mode="FORCE_TEXT"
style="push"
tooltip="Generation of the ADD document in WordML">
<visibleWhen>
<with
variable="selection">
<iterate
ifEmpty="false">
<instanceof
value="org.eclipse.core.resources.IResource">
</instanceof>
<test
property="org.eclipse.core.resources.name"
value="*.uml">
</test>
</iterate>
</with>
</visibleWhen>
</command>
<command
commandId="com.spacebel.acceleo.uml.to.wordml.ui.generateSRD"
label="Generate SRD (WordML)"
mode="FORCE_TEXT"
style="push"
tooltip="Generation of the SRD document in WordML">
<visibleWhen>
<with
variable="selection">
<iterate
ifEmpty="false">
<test
property="org.eclipse.core.resources.name"
value="*.uml">
</test>
<instanceof
value="org.eclipse.core.resources.IResource">
</instanceof>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="com.spacebel.acceleo.uml.to.wordml.ui.generateADD"
name="Generate ADD (WordML)">
</command>
<command
id="com.spacebel.acceleo.uml.to.wordml.ui.generateSRD"
name="Generate SRD (WordML)">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="com.spacebel.acceleo.uml.to.wordml.ui.GenerateSRDHandler"
commandId="com.spacebel.acceleo.uml.to.wordml.ui.generateSRD">
</handler>
<handler
class="com.spacebel.acceleo.uml.to.wordml.ui.GenerateADDHandler"
commandId="com.spacebel.acceleo.uml.to.wordml.ui.generateADD">
</handler>
</extension>
</plugin>
Does anyone have an idea ? I guess that the instanceOf in my test or the URI is not correct ...
In advance, thanks for your help.
Regards;
|
|
|
|
Re: Menu contribution problem in project Explorer [message #1216030 is a reply to message #1215992] |
Thu, 28 November 2013 09:45 |
|
Camille,
Thank you for your proposition. Actually, I have already tried this solution. However, it is not possible to adapt the SubResourceFile into an IFile. If I use your piece of code, I have an exception:
!ENTRY org.eclipse.ui 4 0 2013-11-28 10:39:07.115
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.ClassCastException: org.eclipse.papyrus.infra.onefile.model.impl.SubResourceFile cannot be cast to org.eclipse.core.resources.IFile
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:243)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:224)
etc ...
Best regards;
Johan
[Updated on: Thu, 28 November 2013 09:46] Report message to a moderator
|
|
|
Re: Menu contribution problem in project Explorer [message #1216485 is a reply to message #1216030] |
Thu, 28 November 2013 13:53 |
Camille Letavernier Messages: 952 Registered: February 2011 |
Senior Member |
|
|
Hi Johan,
I'm using this piece of code right now, so, it definitely works. There should not be a "ClassCastException", because "Adapt" is not a Cast (Unless there is another piece of code/extension, elsewhere, which tries to cast the SubResourceFile to an IFile instead of Adapting it).
You should try to define your menu first, and, once it appears correctly, add the command/handler, and see at which point it actually fails.
Regards,
Camille
Camille Letavernier
|
|
|
Re: Menu contribution problem in project Explorer [message #1216586 is a reply to message #1216485] |
Thu, 28 November 2013 14:48 |
|
Hi Camille,
Your are right, it is indeed a problem in my handler:
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
if (selection != null & selection instanceof IStructuredSelection) {
model = (IFile)((IStructuredSelection) selection).getFirstElement();
etc ...
The casting from Object to IFile with the IStructuredSelection doesn't work anymore.
Is there any generic adaptable to have the IFile from IStructuredSelection ?
Thanks for your help;
Johan
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02654 seconds