Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Enabling Toolbar Button when any editor is open(Enabling Toolbar Button when any editor is open)
Enabling Toolbar Button when any editor is open [message #849410] Thu, 19 April 2012 05:49 Go to next message
jogendra chouhan is currently offline jogendra chouhan
Messages: 31
Registered: January 2012
Member
Hi ,

I am developing a plugin in which i need to enable a toolbar button when any editor is open and one of my propert in propertytest class is true.So i have to enable that icon when any resource is selected from explorer or if any editor is active then also i have to enable it.

Can anybody tell me how to do that ?

Thanks in adv.
Re: Enabling Toolbar Button when any editor is open [message #849477 is a reply to message #849410] Thu, 19 April 2012 07:24 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten Schlathölter
Messages: 208
Registered: February 2012
Location: Düsseldorf
Senior Member
You should implement an org.eclipse.ui.menus extension together with a command and a respective handler. Then enable the handler using expressions that express your conditions.

For example:

<plugin>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
         <toolbar
               id="testSpringWsToolbar">
            <command
                  commandId="testWsCall"
                  icon="test.gif"
                  id="testWsCall"
                  label="testWsCall"
                  style="push">
               <visibleWhen
                     checkEnabled="true">
               </visibleWhen>
            </command>
         </toolbar>
      </menuContribution>
   </extension>
   <extension
         point="org.eclipse.ui.commands">
      <command
            id="testWsCall"
            name="testWsCall">
      </command>
   </extension>
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="testspringws.TestWsCallHandler"
            commandId="testWsCall">
         <enabledWhen>
            <or>
               <with
                     variable="activePart">
                  <instanceof
                        value="org.eclipse.ui.IEditorPart">
                  </instanceof>
               </with>
               <with
                     variable="selection">
                  <iterate
                        ifEmpty="false"
                        operator="or">
                     <instanceof
                           value="java.lang.Object">
                     </instanceof>
                  </iterate>
               </with>
            </or>
         </enabledWhen>      
       </handler>
   </extension>

</plugin>


Re: Enabling Toolbar Button when any editor is open [message #849531 is a reply to message #849477] Thu, 19 April 2012 08:26 Go to previous messageGo to next message
jogendra chouhan is currently offline jogendra chouhan
Messages: 31
Registered: January 2012
Member
Thanks a lot Thorsten.. It worked !
Re: Enabling Toolbar Button when any editor is open [message #850504 is a reply to message #849531] Fri, 20 April 2012 05:01 Go to previous messageGo to next message
jogendra chouhan is currently offline jogendra chouhan
Messages: 31
Registered: January 2012
Member
Hi Thorsten,
While testing the suggestion given by you I found that if the file on which i want to enable the button is already open(during my last eclipse close eclipse have saved the state of my active windows). The button is not get enabled automatically though the file is opnened in editor. I need to re-open the file to get that button enabled.

Could you please tell me how can i achieve that as well.
thanks in adv.

Re: Enabling Toolbar Button when any editor is open [message #850508 is a reply to message #849531] Fri, 20 April 2012 05:04 Go to previous messageGo to next message
jogendra chouhan is currently offline jogendra chouhan
Messages: 31
Registered: January 2012
Member
Hi Thorsten,
While testing the suggestion given by you I found that if the file on which i want to enable the button is already open(during my last eclipse close eclipse have saved the state of my active windows). The button is not get enabled automatically though the file is opnened in editor. I need to re-open the file to get that button enabled.

Could you please tell me how can i achieve that as well.
thanks in adv.

Re: Enabling Toolbar Button when any editor is open [message #850586 is a reply to message #850508] Fri, 20 April 2012 06:42 Go to previous message
Thorsten Schlathölter is currently offline Thorsten Schlathölter
Messages: 208
Registered: February 2012
Location: Düsseldorf
Senior Member
Hi,
sorry but I don't have a solution for you. Actually what you want to achieve should happen by default. And in my testcase it does. I have tried the following:
Start the eclipse platform with a launch configuration from within eclipse. In addition to the target platform add the test plugin that contributes the action. Create a project, add a file, open the file. -> Action is enabled. Close launch configuration and restart launch configuration. As a result the file is open and the action is enabled. In other words I cannot reproduce your problem. Maybe you have changed the expressions in a way that now causes the problem. If so, you may want to try with simple expressions.

Regards
Thorsten
Previous Topic:I'm trying to make a Template for a Fragment Project
Next Topic:Product Export in Eclipse
Goto Forum:
  


Current Time: Thu Sep 18 17:54:03 GMT 2014

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

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