Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Enabling and disabling pop-up actions
Enabling and disabling pop-up actions [message #296666] Thu, 29 December 2005 13:34 Go to next message
Eclipse UserFriend
Originally posted by: ilzogoiby.gmail.com

Hello.
I'm trying to enable and disable a pop-up action according to the state of
a static field of a class. I've defined an enablement, and associated it
to an action filter class. Unfortunately, the actions now always appear
disabled.
What am I doing wrong?

Thanks in advance,

Pedro

P.S.: Here's some code...


<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="false"
id="Syncronization"
nameFilter="*.java"
objectClass="org.eclipse.jdt.core.ICompilationUnit">
<action
class="com.les.les51.popup.actions.ActionLock"
enablesFor="1"
icon="icons/sample.gif"
id="IM.Lock"
label="Lock"
menubarPath="IM.Syncronization/Lock">
<enablement>
<objectClass
name="com.les.les51.popup.actions.SyncActionFilter"/>
</enablement>
</action>
<action
class="com.les.les51.popup.actions.ActionUnlock"
enablesFor="1"
icon="icons/sample.gif"
id="IM.Unlock"
label="Unlock"
menubarPath="IM.Syncronization/Unlock">
<enablement>
<objectClass
name="com.les.les51.popup.actions.SyncActionFilter"/>
</enablement>
</action>
<menu
id="IM.Syncronization"
label="Syncronization"
/>
</objectContribution>
</extension>


public class SyncActionFilter implements IActionFilter {

public boolean testAttribute(Object target, String name, String value) {
System.out.println("testing "+Messenger.username);

if (Messenger.username == null)
return false;
else
return true;
}

}
Re: Enabling and disabling pop-up actions [message #297020 is a reply to message #296666] Fri, 06 January 2006 11:48 Go to previous message
Eclipse UserFriend
Originally posted by: douglas.pollock.magma.ca

Pedro Ferreira wrote:
> I'm trying to enable and disable a pop-up action according to the state of
> a static field of a class. I've defined an enablement, and associated it
> to an action filter class. Unfortunately, the actions now always appear
> disabled.
> What am I doing wrong?
> <enablement>
> <objectClass
> name="com.les.les51.popup.actions.SyncActionFilter"/>
> </enablement>


I believe this is supposed to be objectState not objectClass. Then the
objects in the selection must implement IActionFilter.

The workbench will retrieve the filter from the selected object by
testing to see if it implements IActionFilter. If that fails, the
workbench will ask for a filter through through the IAdaptable
mechanism. If a filter is found the workbench will pass each name value
pair to the filter to determine if it matches the state of the selected
object. If so, or there is no filter, the action will be added to the
context menu for the object.


Please read the documentation on the org.eclipse.ui.popupMenus extension
point, and the org.eclipse.ui.IActionFilter class.



cheers,
d.
Previous Topic:creating an editor "scheme" for jVi
Next Topic:Add submenu to MenuManager?
Goto Forum:
  


Current Time: Sat May 10 23:22:58 EDT 2025

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

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

Back to the top