Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to ad commands to views with specific secondary view id
How to ad commands to views with specific secondary view id [message #894025] Fri, 06 July 2012 12:31 Go to next message
Tankut Koray is currently offline Tankut KorayFriend
Messages: 49
Registered: July 2009
Member

I am adding commands to views using commands framework. I want to know how to add commands to menus/toolbars for specific views with a specific secondary id?
Re: How to ad commands to views with specific secondary view id [message #894150 is a reply to message #894025] Fri, 06 July 2012 23:38 Go to previous message
Simon Scholz is currently offline Simon ScholzFriend
Messages: 73
Registered: April 2012
Location: Germany
Member
Hi Tankut,

a command itself is always independend from the UI(menus/toolbars).
It just defines certain command/action in an abstract way.

The thing you really can add to a View is a menu extension.
On that menuContribution in the plugin.xml you can add a visibleWhen flag, where you can define the conditions for showing the menuContribution.

          <visibleWhen
                checkEnabled="false">
            <with
                  variable="activePart">
               <test
                     property="link to your PropertyTester, which checks the secondary id of the activePart" args="specialSecondaryId1,specialSecondaryId2,specialSecondaryId3">
               </test>
            </with>
          </visibleWhen>


Your PropertyTester could be something like this:

public class SecondaryIdTester extends PropertyTester {

    
    @Override
    public boolean test(Object receiver, String property, Object[] args,
            Object expectedValue) {
        boolean testSucceeds = false;
        
        if(receiver instanceof YourView){
              String secondaryId = ((YourView)receiver).getViewSite().getSecondaryId();

            for(Object arg : args){
                 if(secondaryId.equals(arg)){
                      testSucceeds = true;
                 }
            } 
        }


        return testSucceeds;
    }
}


A good overview concerning the usage of PropertyTesters can be found here:
http://wiki.eclipse.org/Command_Core_Expressions#Expressions_and_the_Command_Framework

I hope this helps you and do not hesitate to ask again, if anything is unclear or you need further information.

Best regards,

Simon

[Updated on: Fri, 06 July 2012 23:47]

Report message to a moderator

Previous Topic:org.eclipse.ui issue
Next Topic:RCP-App asTest-Tool for a third-party-library ...
Goto Forum:
  


Current Time: Wed Feb 28 20:35:21 GMT 2024

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

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

Back to the top