Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » IEvaluationService
IEvaluationService [message #512245] Thu, 04 February 2010 08:53 Go to next message
Sir Wayne is currently offline Sir Wayne
Messages: 206
Registered: July 2009
Senior Member
Hello,

i have few questions about the IEvaluationService. I have still a problem to understand it.
I have some Views and a Interface
public interface IDeletable {

	public boolean isDeleteable();
	public void delete();
}

If the methode isDeleteable true the command should be enable.
So i have a PropertyTester
public class DeleteProperyTester extends PropertyTester {

	public static final String IS_DELETE = "delete";

	@Override
	public boolean test(Object receiver, String property, Object[] args,
			Object expectedValue) {
		if (property.equals(IS_DELETE))
			return ((IDeletable) receiver).isDeleteable();
		
		return false;
	}

}

And the Handler
public class DeleteHandler extends AbstractHandler{

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchPart edi = HandlerUtil.getActivePart(event);

		if (null != edi) {
			if (edi instanceof IDeletable) {
				IDeletable deletable = (IDeletable) edi;
				deletable.delete();
			}
		}
		return null;
	}

}

If i switch the view, the ProprtyTester checks the method isDeleteable again. Its the same like the Save Command, i switch a Edtior and it's calling the isDirty method. Ok that works.
But I need a Event which can be fire like the PROP_DIRTY... If I modify a Text the PropertyTester shoudl test the isDeleteable again. But I don't know how i can do this. I know i need a EvaluationService:

1. How can i register a EvaluationService and how can i unregister?
2. Do I need a AbstractSourceProvider?
3. Some example?

Thanks =)

[Updated on: Thu, 04 February 2010 10:00]

Report message to a moderator

Re: IEvaluationService [message #512577 is a reply to message #512245] Fri, 05 February 2010 09:30 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

SirWayne wrote:
>
> 1. How can i register a EvaluationService and how can i unregister?
> 2. Do I need a AbstractSourceProvider?
> 3. Some example?
> Thanks =)

What expression are you using your property tester in? You probably
want your handler activeWhen the activePart passes your property tester.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: IEvaluationService [message #513260 is a reply to message #512577] Tue, 09 February 2010 09:50 Go to previous messageGo to next message
Sir Wayne is currently offline Sir Wayne
Messages: 206
Registered: July 2009
Senior Member
Yes activeWhen the PropertyTester return true.
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="command.DeleteHandler"
            commandId="test">
         <activeWhen>
            <with
                  variable="activePart">
               <test
                     forcePluginActivation="true"
                     property="test.delete">
               </test>
            </with>
         </activeWhen>
      </handler>
   </extension>

It works, and now i want to use the properytester in my editor like PROP_DIRTY. And now i don't know how I fire a Event and register the service.

public class Editor2 extends EditorPart implements IDeletable{

	private Text text;

	
	@Override
	public void createPartControl(Composite parent) {
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 4;
		parent.setLayout(gridLayout);
		text = new Text(parent,SWT.BORDER);


		text.addModifyListener(new ModifyListener() {
			
			@Override
			public void modifyText(ModifyEvent e) {
				// fire Event which triggers the PropertyTester
				// to test the isDeletable again
				
			}
		});

	}
	@Override
	public void delete() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isDeleteable() {
		System.out.println("deletable");
		return !text.getText().isEmpty();
	}

}


Best regards and thanks =)
Re: IEvaluationService [message #513328 is a reply to message #513260] Tue, 09 February 2010 13:49 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

SirWayne wrote:

>
> @Override
> public void modifyText(ModifyEvent e) {
> // fire Event which triggers the PropertyTester
> // to test the isDeletable again
>
> }
> });

Here is where you want to use
org.eclipse.ui.services.IEvaluationService.requestEvaluation (String)

PW



--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: IEvaluationService [message #513440 is a reply to message #513328] Wed, 10 February 2010 04:06 Go to previous messageGo to next message
Sir Wayne is currently offline Sir Wayne
Messages: 206
Registered: July 2009
Senior Member
Paul Webster wrote on Tue, 09 February 2010 13:49
SirWayne wrote:

>
> @Override
> public void modifyText(ModifyEvent e) {
> // fire Event which triggers the PropertyTester
> // to test the isDeletable again
>
> }
> });

Here is where you want to use
org.eclipse.ui.services.IEvaluationService.requestEvaluation (String)

PW


Thank you very much!!!

So it works. Thats very nice =). I thought always i have to register the service. So its very easy =)...
		final IEvaluationService evaluationService = (IEvaluationService) getSite()
		.getWorkbenchWindow().getWorkbench().getService(
		IEvaluationService.class);
		evaluationService.requestEvaluation("test.delete");


[Updated on: Wed, 10 February 2010 07:24]

Report message to a moderator

Re: IEvaluationService [message #513569 is a reply to message #513440] Wed, 10 February 2010 05:28 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

SirWayne wrote:
> Ok by this way?
>
> final IEvaluationService evaluationService =
> (IEvaluationService) getSite()
> .getWorkbenchWindow().getWorkbench().getService(
> IEvaluationService.class);
> evaluationService.requestEvaluation("delete");

evaluationService.requestEvaluation("test.delete");

> Is it necessary to register/unregister the IEvaluationService and how?

no


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:Invoking the Workspace Launcher Dialog
Next Topic:ContainerSelectionGroup -- advice on reuse?
Goto Forum:
  


Current Time: Mon Jul 28 16:45:32 EDT 2014

Powered by FUDForum. Page generated in 0.02490 seconds