Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » MHandledToolItem visibleWhen not working?
MHandledToolItem visibleWhen not working? [message #946625] Tue, 16 October 2012 06:59
François POYER is currently offline François POYER
Messages: 6
Registered: December 2009
Junior Member
I'm trying to have a part's toolbar content change dynamically.
What I've done so far is:
MPart myPart;

MRenderedToolBar toolbar = MMenuFactory.INSTANCE.createRenderedToolBar();
toolbar.setVisible(true);
toolbar.setToBeRendered(true);

MHandledToolItem item = MMenuFactory.INSTANCE.createHandledToolItem();
item.setEnabled(true);
item.setToBeRendered(true);
item.setVisible(true);

Expression visWhen = new CoreExpression() {
    public EvaluationResult evaluate(IEvaluationContext context) {
        // some code evaluating whether this item of the toolbar should be visible or not.
    }
};
MCoreExpression isVisibleWhenExpression = MUiFactory.INSTANCE.createCoreExpression();
isVisibleWhenExpression.setCoreExpressionId("programmatic.value");
isVisibleWhenExpression.setCoreExpression(visWhen);

item.setVisibleWhen(isVisibleWhenExpression); 

toolbar.getChldren().add(item);

myPart.setToolbar(toolbar);     


I've been doing this with a MPopupMenu and some MHandledMenuItem somewhere else in my code and this works like a charm (the menu items show or not in the popup menu depending on the return of the CoreExpression's evaluate, as expected).

But here, the evaluate method of my CoreExpression seems to be never called. Am I doing something wrong or is this a bug or intended feature?

Right now I'm working around that with a selection listener changing the MHandledToolItem's visible and toBeRendered attributes but that's far from perfect...

Also I've tried creating and using a MToolBar instead of the MRenderedToolBar but that doesn't seem to change anything... what's the difference between the two by the way?
Previous Topic:Questions regarding @Creatable
Next Topic:How to find DirectMenuItem programmatically
Goto Forum:
  


Current Time: Wed Aug 20 07:01:37 EDT 2014

Powered by FUDForum. Page generated in 0.01931 seconds