Software Technology Tips

Problem:

Sometimes it’s necessary to customize the behavior of the existing i.e. the eclipse provided commands according to the business logic of the rcp application.

Example:

Let’s say in general “Paste” command pastes the text from the clipboard. Now I want the paste command should paste text from clipboard with a prefix of “Hello”.

Solution:

The solution is to override the default handler with a custom one. But the problem with that is you can not declare a custom handler for existing command directly. It will raise a conflict.

So what we will do is we will activate the custom handler by activating a context.

Now, declare the custom handler like shown below:

<handler

    class="<custom handler>"

    commandId="<standard / existing command id>">

 <activeWhen>

    <with

       variable="activeContexts">

       <iterate

          ifEmpty="false"

          operator="or">

       <equals

           value="<custom context name>">

       </equals>

       </iterate>

    </with>

 </activeWhen>

</handler>

The above declaration will activate the custom handler when the declared context will be activated.

Now at the start –up of the application you can activate the context by using following code.

IContextService contextService = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class);

contextService.activateContext( <custom context name> );

So now the above declared command will use the custom handler.


Related Tags:

Eclipse, EclipseRCP, Custom Handler, Standard Command

Author: Debabrata Pati

Eclipse

Let us Connect!

iso 9001 QA25 Red Herring STPI D&B Fastest Growing SME 2013 Award zinnov Nasscom

This site uses cookies. We respect your privacy.copyright (c) Mindfire Solutions 2007-2015. Login