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 04:26 Go to next message
Sir Wayne is currently offline Sir Wayne
Messages: 206
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 06:47 Go to previous messageGo to next message
Christian is currently offline Christian
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 09:43 Go to previous messageGo to next message
Sir Wayne is currently offline Sir Wayne
Messages: 206
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 15:35 Go to previous messageGo to next message
Sir Wayne is currently offline Sir Wayne
Messages: 206
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 15:43 Go to previous message
Sir Wayne is currently offline Sir Wayne
Messages: 206
Registered: July 2009
Senior Member
*doppel post*

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

Report message to a moderator

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


Current Time: Fri Aug 22 15:41:45 EDT 2014

Powered by FUDForum. Page generated in 0.01855 seconds