Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Help on how to hook a RetargetAction to a running Action or Action Delegate
Help on how to hook a RetargetAction to a running Action or Action Delegate [message #146019] Fri, 17 October 2003 16:49
Eclipse UserFriend
Originally posted by: johncook.us.ibm.com

I am programming against Eclipse 2.0.2 (since the products I am targeting still
use Eclipse 2.0.2).

I am trying to add some semi-dynamic menu support, by extending the "Project"
menu with a RetargetAction that I programmatically will link to the right action
as the state of the plugin changes.

I am building a plugin that desires to use a LabelRetargetAction. I cannot seem
to get the action to work, and I cannot find an example of the right linkage.

One of my questions deals with the interplay between plugin.xml stanzas and my
code. I have an action definition, and I have an actionset. The actionset has
a single retarget action, so I do not specify a class.

In my code, I register as a WindowListener, and in the windowActivated method I
attempt to add the action to the partService as shown in the code snippet below
labeled "ADD ACTION".

However, my entry on the Project menu stays grayed out. It also has the label
from the plugin.xml, not from my resource string as defined in the add action code.

Something is missing, but I cannot find an example of how to do this.

A second question deals with global key bindings, and how to hook up to them.
It appears that global key bindings are not available for public access in
2.0.2, since it seems that I have to cast my IWorkbenchWindow to something much
more heinous in order to get access to a KeyService.

Help!

John Cook


## PLUGIN.XML #################################################
<?xml version="1.0" encoding="UTF-8"?>
<plugin
id="myplugin.PLUGIN"
name="%PLUGIN_NAME"
version="0.1.0"
provider-name="%PLUGIN_PROVIDER"
class="myplugin.EouPlugin">

<runtime>
<library name="%PLUGIN_RUNTIME">
<export name="*"/>
</library>
</runtime>
<requires>
<import plugin="org.eclipse.core.resources"/>
<import plugin="org.eclipse.ui"/>
<import plugin="org.eclipse.pde"/>
<import plugin="org.eclipse.pde.core"/>
<import plugin="org.eclipse.core.runtime"/>
<import plugin="org.eclipse.jdt"/>
<import plugin="org.eclipse.jdt.core"/>
<import plugin="org.eclipse.jdt.ui"/>
</requires>

<extension
point="org.eclipse.ui.actionDefinitions">
<actionDefinition
id="myplugin.RUN">
</actionDefinition>
</extension>

<extension
point="org.eclipse.ui.acceleratorSets">
<acceleratorSet
scopeId="org.eclipse.ui.globalScope"
configurationId="myplugin.MY_ACCELERATORSET">
<accelerator
key="CTRL+R CTRL+A 1"
id="myplugin.ACCELERATOR1">
</accelerator>
</acceleratorSet>
</extension>

<extension
point="org.eclipse.ui.actionSets">
<actionSet
label="%ACTIONSET1.LABEL"
visible="true"
id="myplugin.MY_ACTIONSET">
<action
label="%RETARGET1.LABEL"
tooltip="%RETARGET1.TOOLTIP"
icon="icons/sample.gif"
retarget="true"
menubarPath="project/additions"
allowLabelUpdate="true"
toolbarPath="project"
id="myplugin.RETARGET_ACTION_1">
</action>
</actionSet>
</extension>

</plugin>


## ADD ACTION ############################################################ #


/**
* @see org.eclipse.ui.IWindowListener#windowActivated(IWorkbenchWin dow)
*/
public void windowActivated(IWorkbenchWindow window)
{
ArrayList actionList = null ;
Hashtable actionsByWindow = this.itsActionsByWindow ;

if ( actionsByWindow.containsKey( window ) )
{
actionList = (ArrayList) itsActionsByWindow.get( window );
}
else
{
actionList = new ArrayList();
}

if ( actionList.isEmpty() )
{
LabelRetargetAction action1 = null ;
String actionID = itsPlugin.getResourceString( "ACTION1.ID" );
String actionLabel = itsPlugin.getResourceString( "ACTION1.LABEL" );
String actionTooltip = itsPlugin.getResourceString( "ACTION1.TOOLTIP" );
String actionDefinitionID = itsPlugin.getResourceString(
"ACTION1.DEFINITION_ID" );

action1 = new LabelRetargetAction( actionID, actionLabel );
action1.setToolTipText( actionTooltip );
action1.setAccelerator( SWT.CTRL | SWT.SHIFT | 'e' );
window.getPartService().addPartListener( action1 );
action1.setActionDefinitionId(actionDefinitionID ) ;

WWinKeyBindingService ks = (WorkbenchWindow)window).getKeyBindingService() ;
if ( ks != null )
{
ks.registerGlobalAction( action1 );
}
actionList.add( action1);
actionsByWindow.put( window, actionList );
}

}
Previous Topic:asyncExec() - what's wrong?
Next Topic:Migrating 2.1.1 project to 3.0 M4
Goto Forum:
  


Current Time: Sun Jun 22 06:50:25 EDT 2025

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

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

Back to the top