开发者

Whats the difference between Command Parameters and Menu Contribution Parameters

开发者 https://www.devze.com 2023-01-31 20:13 出处:网络
I can see that parameters can be defined for Comma开发者_开发知识库nds defined using the Commands extension point. I can not define a value for these command parameters.

I can see that parameters can be defined for Comma开发者_开发知识库nds defined using the Commands extension point. I can not define a value for these command parameters.

I can also define parameters under the Command element in the menus extension point when defining menu contributions. I can define a value for the parameter here.

Are the command parameters in Command different from parameters in menu contributions? If they are different how are they different?


The plugin org.eclipse.ui.command, Let you declare parameters for your commands. When you add parameter to your command, you have to set and id, type and a list of possible values for your parameter implementing IParameterValues.

After that, you can add this command to a menu item with parameters and its values.

For example, Imagine you have a command with id org.rcp.commands.new. And It's defined a parameter with name "type" and posible values (file, project and folder). You'll be able to add three menu item with commandId = "org.rcp.commands.new" for each parameter

Sample of plugin.xml

...

Find more info in this link: http://blog.eclipse-tips.com/2008/12/commands-part-3-parameters-for-commands.html


The difference is basically the same as the declaration of a function argument - func(int a) and the specification of a named argument in a function call - e.g. func(a=1).

Here is a small example that illustrates the difference between the two. The following declaration specifies a new command with with a single parameter. The parameter has both an id and a name. The id is used later, whereas the name is only used in a few views and can be disregarded here. So this is really just showName(String header).

<extension
    point="org.eclipse.ui.commands">
<command
    categoryId="com.rcpcompany.training.demo33.providers.ui.category.demoCommands"
    description="Shows the name of the current resource"
    id="com.rcpcompany.training.demo33.providers.ui.commands.showName"
    name="&amp;Show Name">
    <commandParameter
        id="header"
        name=”Header“ />
</command>
</extension>

Here we have a use of the same command with a value for the header argument. So this is showName(header="The selected resource is....").

<menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar id="com.rcpcompany.training.demo33.providers.ui.toolbar1">
    <command
        commandId="com.rcpcompany.training.demo33.providers.ui.commands.showName">
    <parameter
        name="header"
        value="The selected resource is...." />
    </command>
</toolbar>
</menuContribution>

Note that it is the id attribute of the parameter declaration that is the name attribute of the parameter use... So it is header and not Header.

0

精彩评论

暂无评论...
验证码 换一张
取 消