E3: Add a button to an EditorPart tool bar under some conditions [message #1758305] |
Mon, 27 March 2017 12:52 |
Djak Mising name Messages: 16 Registered: November 2010 |
Junior Member |
|
|
Hi,
I can't manage to add (or dsiplay) a tool bar button to an EditorPart tool bar under some conditions. The test I need to do is an instance of a member of a class ChartEditorPart that extends EditorPart.
If the following test is true:
editor.getComposite() instanceof JFCComposite
the button must be added to the tool bar otherwise the button must be hidden.
I'm tried to use org.eclipse.core.expressions.propertyTesters but I didn't manage to do that. Here is my menu contribution:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:AdvancedChartEditorToolBar">
<command
commandId="OpenJFCChartPropertiesEditor"
icon="icons/silk_chart_edit.png"
style="push">
<visibleWhen
checkEnabled="false">
<or>
<reference
definitionId="IsJFCComposite">
</reference>
</or>
</visibleWhen>
</command>
</menuContribution>
</extension>
And some tests to use a property tester but I can't manage to access the EditorPart in the class of the tester:
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="org.txm.chartsengine.jfreechart.rcp.testers.IsJFCComposite"
id="org.txm.chartsengine.jfreechart.rcp.testers.IsJFCComposite"
namespace="org.txm.chartsengine.jfreechart.rcp.testers"
properties="IsJFCComposite"
type="java.lang.Object">
</propertyTester>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="IsJFCComposite">
<test
forcePluginActivation="true"
property="org.txm.chartsengine.jfreechart.rcp.testers.IsJFCComposite">
</test>
</definition>
</extension>
Do you think it is the most simple approach?
Any help would be very appreciated
[Updated on: Mon, 27 March 2017 12:55] Report message to a moderator
|
|
|
|
Re: E3: Add a button to an EditorPart tool bar under some conditions [message #1758480 is a reply to message #1758413] |
Wed, 29 March 2017 07:04 |
Djak Mising name Messages: 16 Registered: November 2010 |
Junior Member |
|
|
Hi,
thank you for your reply. The problem I have with this solution is the EditorPart class and ID are the same in both cases.
Actually I don't understand well at what time the testers are called. When my editor becomes active I can see the tester is called because my test code is well executed:
public class IsJFCComposite extends PropertyTester {
public static final String PROPERTY_NAMESPACE = "org.txm.chartsengine.jfreechart.rcp.testers"; //$NON-NLS-1$
public static final String PROPERTY_EXPERT_ENABLED = "IsJFCComposite";
@Override
public boolean test(Object receiver, String property, Object[] args,
Object expectedValue) {
System.out.println("IsJFCComposite.test() recevier = " + receiver.getClass().getSimpleName());
System.out.println("IsJFCComposite.test() property = " + property);
System.out.println("IsJFCComposite.test() args = " + args);
System.out.println("IsJFCComposite.test() expectedValue = " + expectedValue);
return true;
}
}
but I can't access the editor in the test method (none of the arguments is the editor).
Writing makes me think that I could get the active editor here and maybe change the type of the property tester?
<propertyTester
class="org.txm.chartsengine.jfreechart.rcp.testers.IsJFCComposite"
id="org.txm.chartsengine.jfreechart.rcp.testers.IsJFCComposite"
namespace="org.txm.chartsengine.jfreechart.rcp.testers"
properties="IsJFCComposite"
type="org.txm.chartsengine.rcp.editors.ChartEditorPartt">
</propertyTester>
I'll try that.
Edit: Actually it can't work because I need to display the button for all visible editors and also even if they are not active. With the test above, the button disappears when the editor becomes inactive
Also, to be more precise, we don't use the main tool bar but a custom tool bar added to the editor and registered in the menu service, so more than one tool bar can be visible at same time.
[Updated on: Thu, 30 March 2017 09:49] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03530 seconds