eclipse plugin - Property Testers do not load despite forcePluginActivation. For popup menu enablement -
i in charge of refactoring popup menus in company's eclipse plugin use new commands/handler/menu extension point scheme. had business logic when menu items should enabled or not, , handled through onselectionchanged method of selectionlistener applied action. trying control enablement using custom propertytester, seems custom propertytesters not being loaded. i've followed eclipse's doc tutorials find online , reason not want work. if set "test" method return true, doesn't work because tester never loaded (i threw break points in , never hit). i've tried setting "forcepluginactivation='true'" flag in test in xml, not remedy situation. here code, company name replaced "company" , product replaced "product"...
command xml
<extension point="org.eclipse.ui.commands"> <command categoryid="com.company.product.android.core.category2" id="com.company.product.android.core.commands.converttoproduct" name="convert product android project" description="the resources, jars , native library begin developing product android project application added android project"> </command> <category id="com.company.product.android.core.category2" name="product tools"> </category> </extension>
handler xml
<extension point="org.eclipse.ui.handlers"> <handler class="com.company.product.android.core.commands.converttoproduct" commandid="com.company.product.android.core.commands.converttoproduct"> <enabledwhen> <reference definitionid="com.company.product.android.core.expressions.productproject"> </reference> </enabledwhen> </handler> </extension>
definitions xml
<extension> point="org.eclipse.core.expressions.definitions"> <definition id="com.company.product.android.core.expressions.androidprojectnature"> <with variable="selection"> <iterate ifempty="false"> <test property="org.eclipse.core.resources.projectnature" value="com.android.ide.eclipse.adt.androidnature"> </test> </iterate> </with> </definition> <definition id="com.company.product.android.core.expressions.productproject"> <with variable="selection"> <iterate ifempty="false"> <test property="com.company.product.android.expressions.productprojectproperty" forcepluginactivation="true"> </test> </iterate> </with> </definition> </extension>
menu xml
<extension point="org.eclipse.ui.menus"> <menucontribution locationuri="popup:org.eclipse.ui.navigator.projectexplorer#popupmenu?after=additions"> <menu icon="icons/wht_ws.gif" id="com.company.product.android.core.tools" label="product tools"> <visiblewhen> <reference definitionid="com.company.product.android.core.expressions.androidprojectnature"> </reference> </visiblewhen> <command commandid="com.company.product.android.core.commands.converttoproduct" label="convert product android project" tooltip="the resources, jars , native library begin developing product android project application added android project."> </command> </menu> </menucontribution> </extension>
property tester xml
<extension point="org.eclipse.core.expressions.propertytesters"> <propertytester class="com.company.product.android.core.expressions.productprojecttester" id="com.company.product.android.core.expressions.productprojecttester" namespace="com.company.product.android.core.expressions" properties="productprojectproperty" type="java.lang.object"> </propertytester> </extension>
property tester java
package com.company.product.android.core.expressions; import org.eclipse.core.expressions.propertytester; import org.eclipse.jdt.core.ijavaproject; import org.eclipse.jface.viewers.iselection; import org.eclipse.jface.viewers.structuredselection; import org.eclipse.ui.iselectionservice; import org.eclipse.ui.platformui; import com.company.product.android.core.projectutils; public class productprojecttester extends propertytester { public productprojecttester() { system.out.println("i product project tester, , have been created"); } @override public boolean test(object receiver, string property, object[] args, object expectedvalue) { //ijavaproject project = null; //iselectionservice selectionservice = // platformui.getworkbench().getactiveworkbenchwindow().getselectionservice(); //iselection selection = selectionservice.getselection(); //boolean enabled = projectutils.issingleprojectselected(selection); system.out.println("i entered test method"); boolean enabled = false; system.out.println("the receiver " + receiver.getclass().tostring()); ijavaproject project = (ijavaproject)receiver; //if (enabled && selection instanceof structuredselection) { //project = projectutils.getjavaproject(); if (project != null) { enabled = projectutils.hasneedversion(project) && (!projectutils.isproductandroidproject(project.getproject())); } //} return enabled; } }
for java code, tried both current implementation , commented out well. have tried lot of different variations saw in tutorials worked others not me. messages never printed console, , if set breakpoints in constructor or test method, never hit. please let me know if additional information useful...
alright after 2 days of fighting this, not able work way. followed @ least 10 different tutorials on how custom property testers work, no avail. went far using startup extension point force plugin load early. used selectionchangedlistener request updates evaluation server anytime project explorer selection changed. nothing seemed going make custom property tester work. not load property testers... never called anything, despite saying set fine, , mirror tutorials followed.
eventually got tired of trying make work , looked alternative. ended finding this: http://blog.eclipse-tips.com/2009/02/commands-part-5-authentication-in-rcp.html
i implemented sourceprovider have variable values corresponding different project states. use , , check of possible values is. finally, when plugin loads, hook selectionchangedlistener packageexplorer's viewer, time selection change occurs, logic reevaluated , variable changed if needed. although it's not ideal way wanted it, works, , it's not deprecated. couldn't waste more time trying property testers work...
hope helped someone!
Comments
Post a Comment