Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » E3: Add a button to an EditorPart tool bar under some conditions
E3: Add a button to an EditorPart tool bar under some conditions [message #1758305] Mon, 27 March 2017 12:52 Go to next message
Djak Mising name is currently offline Djak Mising nameFriend
Messages: 14
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 Smile

[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 #1758413 is a reply to message #1758305] Tue, 28 March 2017 13:31 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 788
Registered: January 2012
Senior Member

The easier way is to make a contribution to the main toolbar and add a `visibleWhen` test for when `activeEditor` or `activeEditorId` is your editor.

Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
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 Go to previous message
Djak Mising name is currently offline Djak Mising nameFriend
Messages: 14
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 Smile

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

Previous Topic:Debugging hang on splash screen
Next Topic:Bundling and Codesigning for macOS
Goto Forum:
  


Current Time: Sat Nov 17 02:28:35 GMT 2018

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

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

Back to the top