Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Eclipse RCP: Using property tester with menu(Problem while using property tester with menu toolbar)
Eclipse RCP: Using property tester with menu [message #655034] Fri, 18 February 2011 01:09 Go to next message
Rohan is currently offline Rohan
Messages: 1
Registered: February 2011
Location: Pune
Junior Member
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.
Re: Eclipse RCP: Using property tester with menu [message #655137 is a reply to message #655034] Fri, 18 February 2011 08:20 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6850
Registered: July 2009
Location: Ottawa
Senior Member

So you have nothing else in the toolbar at all?

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:Adding an existing menu to a context menu
Next Topic:Icons in separate bundle
Goto Forum:
  


Current Time: Fri Apr 18 01:44:07 EDT 2014

Powered by FUDForum. Page generated in 0.07087 seconds