Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to add menuListener
How to add menuListener [message #1780349] Sat, 20 January 2018 21:16 Go to next message
Muhammad Umar is currently offline Muhammad UmarFriend
Messages: 1
Registered: January 2018
Junior Member
My menu is defined in xml like following.
How can I add menuListener to menu so that I can do something when the focus is on specific menu.


<extension
point="org.eclipse.ui.editorActions">
<editorContribution
targetID="net.sourceforge.texlipse.TexEditor"
id="net.sourceforge.texlipse.editor.editorContribution">
<menu
label="&amp;TTS Settings"
id="net.sourceforge.texlipse.menus.tts">
<separator name="sourceGroup"/>
<separator name="latexGroup"/>
<separator name="commentGroup"/>
<separator name="spellGroup"/>
</menu>

<action
class="net.sourceforge.texlipse.actions.TTSPdfModeAction"
icon="icons/start.png"
id="net.sourceforge.texlipse.actions.TTSPdfModeAction"
definitionId="net.sourceforge.texlipse.commands.PDF"
label="&amp;PDF"
menubarPath="net.sourceforge.texlipse.menus.tts/sourceGroup"
style="push"
toolbarPath="latexGroup"
tooltip="PDF"/>
<action
class="net.sourceforge.texlipse.actions.TTSStopAction"
icon="icons/stop.png"
id="net.sourceforge.texlipse.actions.TTSStopAction"
definitionId="net.sourceforge.texlipse.commands.TTSStop"
label="&amp;Stop"
menubarPath="net.sourceforge.texlipse.menus.tts/sourceGroup"
style="push"
toolbarPath="latexGroup"
tooltip="Stop"/>

<action
class="net.sourceforge.texlipse.actions.TTSResumeAction"
icon="icons/resume.png"
id="net.sourceforge.texlipse.actions.TTSResumeAction"
definitionId="net.sourceforge.texlipse.commands.TTSResume"
label="&amp;Resume"
menubarPath="net.sourceforge.texlipse.menus.tts/sourceGroup"
style="push"
toolbarPath="latexGroup"
tooltip="Resume"/>

<action
class="net.sourceforge.texlipse.editor.TexEditor"
id="net.sourceforge.texlipse.editor.TexEditor"
definitionId="net.sourceforge.texlipse.editor.commands.TexEditor"
label="&amp;TexEditor"
/>

<action
class="net.sourceforge.texlipse.actions.TTSPauseAction"
icon="icons/pause.png"
id="net.sourceforge.texlipse.actions.TTSPauseAction"
definitionId="net.sourceforge.texlipse.commands.TTSPause"
label="&amp;Pause"
menubarPath="net.sourceforge.texlipse.menus.tts/sourceGroup"
style="push"
toolbarPath="latexGroup"
tooltip="Pause"/>
<action
class="net.sourceforge.texlipse.actions.TTSStartAction"
icon="icons/start.png"
id="net.sourceforge.texlipse.actions.TTSStartAction"
definitionId="net.sourceforge.texlipse.commands.TTSStart"
label="&amp;Start"
menubarPath="net.sourceforge.texlipse.menus.tts/sourceGroup"
style="push"
toolbarPath="latexGroup"
tooltip="Start"/>

<action
class="net.sourceforge.texlipse.actions.TTSOFFAction"
icon="icons/off.png"
id="net.sourceforge.texlipse.actions.TTSOFFAction"
definitionId="net.sourceforge.texlipse.commands.TTSOff"
label="&amp;OFF"
menubarPath="net.sourceforge.texlipse.menus.tts/sourceGroup"
style="push"
toolbarPath="latexGroup"
tooltip="OFF"
/>
<action
class="net.sourceforge.texlipse.actions.VbstWordAction"
icon="icons/word.png"
id="net.sourceforge.texlipse.actions.VbstWordAction"
definitionId="net.sourceforge.texlipse.commands.VbstWordAction"
label="&amp;By Word"
menubarPath="net.sourceforge.texlipse.menus.tts/latexGroup"
style="push"
toolbarPath="latexGroup"
tooltip="By Word"/>
<action
class="net.sourceforge.texlipse.actions.VbstCharAction"
icon="icons/char.png"
id="net.sourceforge.texlipse.actions.VbstCharAction"
definitionId="net.sourceforge.texlipse.commands.VbstCharAction"
label="&amp;By char"
menubarPath="net.sourceforge.texlipse.menus.tts/latexGroup"
style="push"
toolbarPath="latexGroup"
tooltip="By Char"/>


</editorContribution>
</extension>
Re: How to add menuListener [message #1780640 is a reply to message #1780349] Thu, 25 January 2018 08:19 Go to previous message
Priya Arrora is currently offline Priya ArroraFriend
Messages: 3
Registered: November 2017
Junior Member
you can also add separate listeners to both menus as anonymous class.

public void menuSelected(MenuEvent e) {
//Make sure jMenu1 and jMenu2 are accessible in here.
if(e.getSource()==jMenu1)
operationForMenu1();
else if(e.getSource()==jMenu2)
operationForMenu2();
}
Previous Topic:NoClassDefFoundError/ClassNotFoundException >>> ObjectMapper
Next Topic:Can I use JDT to parse Java project strictly using command-line?
Goto Forum:
  


Current Time: Tue Oct 16 20:18:25 GMT 2018

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

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

Back to the top