Eclipse RCP: Using property tester with menu [message #655034] |
Fri, 18 February 2011 06:09 |
|
I want to use property tester to display a command in toolbar only when a member variable in a class has a certain value. The problem is that untill I add one more dummy command in that menu, the required command is not visisble even on satisfying all the requirement. The code is as below:
View:
public class View extends ViewPart {
public static final String ID = "TestToolBar.view";
private String mTableName = "Account";
public String getTableName(){
return mTableName;
}
other methods....
}
Property Tester class:
public class TestPropertyTester extends PropertyTester{
private static final String TABLENAME = "tablename";
@Override
public boolean test(Object receiver, String property, Object[] args,
Object expectedValue) {
System.out.println("property " + property);
if(receiver instanceof View && property.equalsIgnoreCase(TABLENAME))
{
View view = (View) receiver;
System.out.println(view.getTableName());
if(view.getTableName().equalsIgnoreCase(expectedValue.toStri ng())){
System.out.println("if(view.getTableName().equalsIgnoreCase ");
return true;
}
}
return false;
}
}
Plugin.xml
Command:
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="testtoolbar.TestCommandHandler"
id="TestToolBar.TestCommand"
name="Test Command">
</command>
<command
defaultHandler="testtoolbar.TestCommandHandler"
id="TestToolBar.TestCommand1"
name="Test Command 1">
</command>
</extension>
Menu:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:TestToolBar.view">
<command
commandId="TestToolBar.TestCommand"
icon="icons/alt_window_16.gif"
label="Test Command"
style="push">
<visibleWhen>
<or>
<with
variable="activePart">
<test
forcePluginActivation="true"
property="TestToolBar.PropertyTester.tablename"
value="Account">
</test>
</with>
</or>
</visibleWhen>
</command>
<command
commandId="TestToolBar.TestCommand1"
icon="icons/alt_window_32.gif"
label="Test Command 1"
style="push">
</command>
</menuContribution>
</extension>
View:
<extension
point="org.eclipse.ui.views">
<view
name="View"
class="testtoolbar.View"
id="TestToolBar.view">
</view>
Property Tester
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="testtoolbar.TestPropertyTester"
id="TestToolBar.PropertyTester"
namespace="TestToolBar.PropertyTester"
properties="tablename"
type="java.lang.Object">
</propertyTester>
</extension>
All the print statements in the property tester class are executed even then the command TestCommand is not displayed till I add a dummy command TestCommand1.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03132 seconds