Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Commandframework
Commandframework [message #488332] Mon, 28 September 2009 08:26 Go to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
Registered: July 2009
Senior Member
Hello,

I have a own command and a handler. This handler is enable when the activeEditor implement my own interface IClearable.
This works:
   <handler
            class="ui.command.MaskDeleteHandler"
            commandId="MaskDelete">
         <enabledWhen>
            <with
                  variable="activeEditor">
               <instanceof
                     value=IClerable>
               </instanceof>
            </with>
         </enabledWhen>
      </handler>


public interface IClearable
{
public boolean isClear();
...
}


But now I want a 2nd condition. The command should only be enabled, if the activeEditor implements IClearable and the isClear methode returns true.

How could I do this?

Thx a lot Smile
Re: Commandframework [message #488345 is a reply to message #488332] Mon, 28 September 2009 10:47 Go to previous messageGo to next message
Christian is currently offline ChristianFriend
Messages: 72
Registered: July 2009
Member
SirWayne schrieb:
> Hello,
>
> I have a own command and a handler. This handler is enable when the
> activeEditor implement my own interface IClearable.
> This works:
>
> <handler
> class="ui.command.MaskDeleteHandler"
> commandId="MaskDelete">
> <enabledWhen>
> <with
> variable="activeEditor">
> <instanceof
> value=IClerable>
> </instanceof>
> </with>
> </enabledWhen>
> </handler>
>
>
>
> public interface IClearable
> {
> public boolean isClear();
> ..
> }
>
>
> But now I want a 2nd condition. The command should only be enabled, if
> the activeEditor implements IClearable and the isClear methode returns
> true.
>
> How could I do this?
>
> Thx a lot :)
use a PropertyTester for this:
http://wiki.eclipse.org/Command_Core_Expressions#Property_Te sters
Re: Commandframework [message #488380 is a reply to message #488345] Mon, 28 September 2009 13:43 Go to previous messageGo to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
Registered: July 2009
Senior Member
Do you have an example?

Do I need a own ProprtyTester

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;

public class ClearPropertyTester extends PropertyTester {


	public boolean test(Object receiver, String property, Object[] args,
			Object expectedValue) {
		if (receiver instanceof IWorkbench ) {
			final IWorkbench window = (IWorkbench) receiver;
				IWorkbenchPart part = window.getActiveWorkbenchWindow().getActivePage().getActivePart();
				if (part != null && part instanceof IClearable) {
					return ((IClearable)part).isClear();
				}
			
		}
		return false;
	}

}



or how i have to use?
Re: Commandframework [message #488466 is a reply to message #488380] Mon, 28 September 2009 19:35 Go to previous messageGo to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
Registered: July 2009
Senior Member
Ok got it thx =)
Solution:
      <handler
            class="ui.command.MaskDeleteHandler"
            commandId="MaskDelete">
            <enabledWhen>
               <with
                     variable="activePart">
                  <test
                        forcePluginActivation="true"
                        property="ui.command.interfaces.isClearable">
                  </test>
               </with>
            </enabledWhen>

      </handler>



<propertyTester
            class="ui.command.propertytester.ClearProperyTester"
            id="ClearProperyTester"
            namespace="ui.command.interfaces"
            properties="isClearable"
            type="ui.command.interfaces.IClearable">
      </propertyTester>


import org.eclipse.core.expressions.PropertyTester;

import ui.command.interfaces.IClearable;

public class ClearProperyTester extends PropertyTester {

    @Override
    public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
        return ((IClearable) receiver).isClearable();
    }

}

Re: Commandframework [message #488470 is a reply to message #488380] Mon, 28 September 2009 19:43 Go to previous message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
Registered: July 2009
Senior Member
*doppel post*

[Updated on: Tue, 29 September 2009 05:53]

Report message to a moderator

Previous Topic:New Wizards
Next Topic:[DataBinding] Does there exist a BufferedObservable?
Goto Forum:
  


Current Time: Fri Mar 29 11:18:50 GMT 2024

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

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

Back to the top