Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » enabledWhen for handlers and editors
enabledWhen for handlers and editors [message #334498] Thu, 12 February 2009 14:27 Go to next message
Eclipse UserFriend
I am having a heck of a time trying to get a the main toolbar state to
change when state in an editor changes. I have the same handler being
used in the editor's context menu and it works fine (probably because
the enabledWhen expression is evaluated every time the context menu is
displayed.

This is the fragment from the plugin.xml for this particular menu/handler:

<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions ">
<toolbar
id="org.kdr.portfolio.toolbar">
<command
commandId="org.kdr.risk.command.portfolio.save"
icon="icons/save.gif"
id="org.kdr.risk.toolbar.main.portfolio.save"
mnemonic="%action.save.mnemonic"
style="push"
tooltip="%portfolio.save.tooltip">
<visibleWhen
checkEnabled="false">
<and>
<reference
definitionId="org.kdr.risk.definition.portfolio.editor">
</reference>
</and>
</visibleWhen>
</command>
</toolbar>
</menuContribution>

------------------------------------------------------------ ----------------

<handler
class="org.kdr.ui.handler.SaveHandler"
commandId="org.kdr.risk.command.portfolio.save">
<activeWhen>
<or>
<reference
definitionId="org.kdr.risk.definition.portfolio.view">
</reference>
<reference

definitionId="org.kdr.risk.definition.portfolio.editor">
</reference>
</or>
</activeWhen>
<enabledWhen>
<and>
<reference

definitionId="org.kdr.risk.definition.portfolio.security.delete ">
</reference>
<reference
definitionId="org.kdr.risk.definition.portfolio.editor">
</reference>
<reference
definitionId="org.kdr.risk.definition.portfolio.dirty">
</reference>
</and>
</enabledWhen>
</handler>

All conditions used referenced expressions so the can (and are) reused.
All of the expressions are firing correctly (i.e. initial state of the
toolbar button is correct for the possible state scenarios). However,
when the state of the editor changes, it appears that the handler
expressions are not being re-evaluated. All controls on the editor (an
RCP form) have listeners registered to invoke comparison of the control
state vs. the model's state. No state is saved to the model until the
"Save" button is pressed. Hence the need for the toolbar button. If a
difference between the model and control is found a property change
event is fired (i.e.
firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY)). Is there some
other notification mechanism I should be using to cause the handler's
enabledWhen expression to re-evaluate?

Any and all help would be appreciated.

Thanks,
Karl
Re: enabledWhen for handlers and editors [message #334511 is a reply to message #334498] Fri, 13 February 2009 09:00 Go to previous messageGo to next message
Eclipse UserFriend
What do the expression definitions look like? The variables used in the
definition (in <with/> elements) will determine when the expressions get
re-evaluated.

are you using property testers?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: enabledWhen for handlers and editors [message #334513 is a reply to message #334511] Fri, 13 February 2009 09:44 Go to previous messageGo to next message
Eclipse UserFriend
This is the contents of the expression definitions extension point:

There are property testers for the properties org.kdr.isNew,
org.kdr.isDirty, and org.kdr.isAllowed.

The org.kdr.isDirty simply examines the isDirty method of the
IEditorPart. org.kdr.isNew examines the model contained by the
associated IEditorPart.getEditorInput() which all have the method
isNew(). org.kdr.isAllowed checks permissions for the specific operation
(the first parameter) for the given object (the object contained in the
<with> tag or the class evaluated from the second parameter). If the
<with> tag is an ISelection or a collection and does not have an
<iterate> tag, it is iterated by the property tester and every object's
permission is checked. If not object is supplied by <with> the second
parameter is used to determine the class of the object and used to check
permissions (e.g. used for an add operation).


<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="org.kdr.risk.definition.portfolio.view">
<and>
<with
variable="activeContexts">
<iterate
ifEmpty="false"
operator="or">
<or>
<equals
value="org.kdr.risk.context.portfolio">
</equals>
</or>
</iterate>
</with>
<with
variable="activePartId">
<equals
value="view.portfolio">
</equals>
</with>
</and>
</definition>
<definition
id="org.kdr.risk.definition.portfolio.editor">
<and>
<with
variable="activeContexts">
<iterate
ifEmpty="false"
operator="or">
<or>
<equals
value="org.kdr.risk.context.portfolio">
</equals>
</or>
</iterate>
</with>
<with
variable="activeEditorId">
<equals
value="editor.portfolio">
</equals>
</with>
</and>
</definition>
<definition
id="org.kdr.risk.definition.portfolio.editor.focus">
<and>
<with
variable="activeContexts">
<iterate
ifEmpty="false"
operator="or">
<or>
<equals
value="org.kdr.risk.context.portfolio">
</equals>
</or>
</iterate>
</with>
<with
variable="activePartId">
<equals
value="editor.portfolio">
</equals>
</with>
</and>
</definition>
<definition
id="org.kdr.risk.definition.portfolio.not.new">
<with
variable="activeEditor">
<test
property="org.kdr.isNew"
value="false">
</test>
</with>
</definition>
<definition
id="org.kdr.risk.definition.portfolio.dirty">
<with
variable="activeEditor">
<test
property="org.kdr.isDirty"
value="true">
</test>
</with>
</definition>
<definition
id="org.kdr.risk.definition.portfolio.selected">
<with
variable="selection">
<and>
<count
value="+">
</count>
<iterate>
<or>
<instanceof
value="org.kdr.portfolio.Portfolio">
</instanceof>
</or>
</it0erate>
</and>
</with>
</definition>
<definition
id="org.kdr.risk.definition.portfolio.security.add">
<with
variable="selection">
<and>
<test
args="add,org.kdr.portfolio.Portfolio"
property="org.kdr.isAllowed"
value="true">
</test>
</and>
</with>
</definition>
<definition
id="org.kdr.risk.definition.portfolio.security.change">
<with
variable="selection">
<iterate>
<and>
<test
args="change"
property="org.kdr.isAllowed"
value="true">
</test>
</and>
</iterate>
</with>
</definition>
<definition
id="org.kdr.risk.definition.portfolio.security.delete">
<or>
<with
variable="selection">
<iterate>
<and>
<test
args="remove"
property="org.kdr.isAllowed"
value="true">
</test>
</and>
</iterate>
</with>
<and>
<reference

definitionId="org.kdr.risk.definition.portfolio.editor">
</reference>
<with
variable="activeEditor">
<test
args="remove,org.kdr.portfolio.Portfolio"
property="org.kdr.isAllowed"
value="true">
</test>
</with>
</and>
</or>
</definition>
</extension>

Paul Webster wrote:
> What do the expression definitions look like? The variables used in the
> definition (in <with/> elements) will determine when the expressions get
> re-evaluated.
>
> are you using property testers?
>
> PW
> >
Re: enabledWhen for handlers and editors [message #334518 is a reply to message #334513] Fri, 13 February 2009 12:41 Go to previous messageGo to next message
Eclipse UserFriend
Karl Koster wrote:
> This is the contents of the expression definitions extension point:
>
> There are property testers for the properties org.kdr.isNew,
> org.kdr.isDirty, and org.kdr.isAllowed.
>

An expression containing the segment below will be re-evaluated when the
variable changes ... so when a new active editor is selected.
<with
variable="activeEditor">
<test
property="org.kdr.isDirty"
value="true">
</test>
</with>

This will not get re-evaluated if the current active editor simply goes
dirty. You would have to use
org.eclipse.ui.services.IEvaluationService.requestEvaluation (String) at
the appropriate time to request a re-evaluation of expressions
containing your property.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: enabledWhen for handlers and editors [message #334522 is a reply to message #334518] Fri, 13 February 2009 18:15 Go to previous message
Eclipse UserFriend
Paul,

Thank you very much for this information. It was exactly what I was
looking for.

Karl

Paul Webster wrote:
> Karl Koster wrote:
>> This is the contents of the expression definitions extension point:
>>
>> There are property testers for the properties org.kdr.isNew,
>> org.kdr.isDirty, and org.kdr.isAllowed.
>>
>
> An expression containing the segment below will be re-evaluated when the
> variable changes ... so when a new active editor is selected.
> <with
> variable="activeEditor">
> <test
> property="org.kdr.isDirty"
> value="true">
> </test>
> </with>
>
> This will not get re-evaluated if the current active editor simply goes
> dirty. You would have to use
> org.eclipse.ui.services.IEvaluationService.requestEvaluation (String) at
> the appropriate time to request a re-evaluation of expressions
> containing your property.
>
> PW
>
>
Previous Topic:Plugin loading fails in 3.3/3.4
Next Topic:JRE Refresh on the Mac
Goto Forum:
  


Current Time: Sat Mar 15 11:07:41 EDT 2025

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

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

Back to the top