gpt4 book ai didi

popup - 尽管有 forcePluginActivation,但属性测试器不会加载。用于弹出菜单启用

转载 作者:行者123 更新时间:2023-12-04 04:51:08 26 4
gpt4 key购买 nike

我负责重构我公司的 Eclipse 插件中的弹出菜单以使用新的命令/处理程序/菜单扩展点方案。我们有一些关于何时应该启用或不启用某些菜单项的业务逻辑,这是通过它们应用于操作的 SelectionListener 的 onSelectionChanged 方法来处理的。我现在正在尝试使用自定义 PropertyTester 来控制启用,但似乎我的自定义 PropertyTester 没有被加载。我遵循了 Eclipse 的文档以及我可以在网上找到的任何教程,但出于某种原因,它只是不想工作。即使我只是将“测试”方法设置为返回 true,它也不起作用,因为测试器甚至从未加载过(我放入了一些断点,但它们从未被击中)。我已经尝试在 xml 的测试中设置“forcePluginActivation='true'”标志,但这也不能解决这种情况。这是一些代码,公司名称替换​​为“公司”,产品替换为“产品”...

命令 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 to product Android Project"
description="The resources, jars and native library to begin developing an product for Android project application will be added to the Android project">
</command>
<category
id="com.company.product.android.core.category2"
name="Product Tools">
</category>
</extension>

处理程序 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>

定义 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>

菜单 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 to Product Android Project"
tooltip="The resources, jars and native library to begin developing an product for Android project application will be added to the Android project.">
</command>
</menu>
</menuContribution>
</extension>

属性测试器 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>

性能测试器 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 AM PRODUCT PROJECT TESTER, AND I 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 the test method");
boolean enabled = false;

System.out.println("The receiver is a " + 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;
}

}

对于 java 代码,我尝试了当前的实现和注释掉的内容。我尝试了很多不同的变体,我在教程中看到的这些变体对其他人有用,但对我却没有。消息永远不会打印到控制台,如果我在构造函数或测试方法中设置断点,它们永远不会被命中。请让我知道其他信息是否有用...

最佳答案

我为我的项目使用了 PropertyTester,它工作正常

在您的定义 XML 中
您没有正确引用您的 PropertyTester 定义:

<definition
id="com.company.product.android.core.expressions.productProject">
<with variable="selection">
<iterate ifEmpty="false">
<test
property="com.company.product.android.**core**.expressions.productProjectProperty"
forcePluginActivation="true">
</test>
</iterate>
</with>
</definition>

然后在你的 MENU.XML
您应该引用正确的定义(productProject 而不是 androidProjectNature)
    <menu
icon="icons/wht_ws.gif"
id="com.company.product.android.core.tools"
label="Product Tools">

<visibleWhen>
<with variable="activeMenuSelection">
<iterate ifEmpty="false">
<reference
definitionId="com.company.product.android.core.expressions.productProject"/>
</iterate>
</with>
</visibleWhen>

<command
commandId="com.company.product.android.core.commands.convertToProduct"
label="Convert to Product Android Project"
tooltip="The resources, jars and native library to begin developing an product for Android project application will be added to the Android project.">
</command>
</menu>

最后,您不需要 HANDLER.XML 中的 EnableWhen 标签

我希望这会有所帮助

关于popup - 尽管有 forcePluginActivation,但属性测试器不会加载。用于弹出菜单启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17458972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com