- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试在 Eclipse 中创建一个插件,当右键单击包资源管理器中的文件或文件夹时,它会添加一个菜单项。该菜单项包含某些必须动态加载的命令(因此我不能在 plugin.xml 中对它们进行硬编码)。这些命令实际上位于另一个扩展中,它通过我提供的扩展点将自身附加到我的插件。
我现在正在做的是创建菜单项,用附加到我的扩展点的所有命令填充它,并向所有这些命令添加一个 ButtonListener。一切都是这样,但有一个问题。我需要获取有关用户在包资源管理器中右键单击了哪个项目的信息(它是 IFile 还是 IFolder 项目?),根据我的研究,我需要在处理程序中执行此操作,如下所示:
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
TreeSelection treeSelection = (TreeSelection) currentSelection;
Object firstElement = treeSelection.getFirstElement();
ActionMenu.setNode(firstElement);
return null;
}
其中 Action menu 是表示菜单项的实际类,负责填充它。不幸的是,我的插件中现在从未调用过该代码。
我的问题是:
我如何为每个命令动态创建一个处理程序以便调用 execute() 函数?或者在我的 ActionMenu 类中是否有更好的方法来获取用户右键单击的选择(以了解它是 IFolder 还是 IFile)?
这是我的 ActionMenu 类中的相关代码(将每个命令添加为子菜单项的 fill() 函数和 ButtonListener 嵌套类)。 ICommand 是命令必须在其他扩展中实现的接口(interface):
...
public final void fill(final Menu menu, final int index) {
// Here you could get selection and decide what to do
// You can also simply return if you do not want to show a menu
List<ICommand> commands = new ArrayList<ICommand>();
IConfigurationElement[] contributions = Platform.getExtensionRegistry().getConfigurationElementsFor(Extension_Point_ID);
try {
for (IConfigurationElement e : contributions) {
final Object o =
e.createExecutableExtension("class");
commands.add((ICommand) o);
}
} catch (CoreException ex) {
System.out.println(ex.getMessage());
}
for (ICommand command : commands)
{
MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
menuItem.setText(command.getName());
menuItem.addSelectionListener(new ButtonListener(command));
}
}
public class ButtonListener extends SelectionAdapter {
ICommand command_;
public ButtonListener(ICommand command) {
command_ = command;
}
@Override
public final void widgetSelected(final SelectionEvent e) {
if (node_ instanceof org.eclipse.core.resources.IFile) {
command_.executeFile(node_);
}
else if (node_ instanceof org.eclipse.core.resources.IFolder) {
command_.executeFolder(node_);
}
}
}
这是我的 plugin.xml 文件的内容:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="ca.polymtl.log8430.Command" name="Command" schema="schema/ca.polymtl.log8430.Command.exsd"/>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
<menu
id="apply_command"
label="ApplyCommand">
</menu>
</menuContribution>
<menuContribution locationURI="popup:apply_command?after=additions">
<dynamic
class="ca.polymtl.log8430.popup.ActionMenu"
id="ca.polymtl.log8430.popup.actionMenu">
</dynamic>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="ca.polymtl.log8430.Handler"
commandId="ca.polymtl.log8430.Command1">
</handler>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="ca.polymtl.log8430.Command1"
name="Command_1">
</command>
</extension>
</plugin>
感谢您的帮助,如果您需要更多详细信息,请随时询问。
最佳答案
鉴于您设置菜单的方式,您不需要使用处理程序。您可以简单地在监听器的 widgetSelected
方法中获取当前选择:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IStructuredSelection selection = (IStructuredSelection)page.getSelection();
注意:实际选择可能不会直接实现IFile
或IFolder
,所以你应该使用平台适配管理器看它们是否适配
到资源:
Object selObject = selection.getFirstElement();
IResource resource = (IResource)Platform.getAdapterManager().getAdapter(selObject, IResource.class);
然后测试resource
看它是IFile
还是IFolder
。
关于java - Eclipse 插件 : Populating dynamically a menu with commands and corresponding handlers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22256387/
如何将多个json对象添加/映射到dart对象 import 'dart:async'; import 'dart:convert'; import 'package:flutter/foundati
我正在研究将产品集成到 Dynamics Great Plains 中。我之前使用过 Dynamics CRM,但没有使用过 Great Plains。我听说 GP 与 CRM 是不同的动物,即使它们
System.Linq.Dynamic.Core 和 System.Linq.Dynamic 有什么区别?我目前正在使用 System.Linq.Dynamic 并且它不包含对 的支持选择 和 多选
我正在尝试通过Firebase存储将图像上传到Firebase,然后在Firestore中创建一个文档,其中包含上述上传图像的网址。为此,我使用此功能 void uploadImageAndCr
我一直在尝试整理一些东西,使我可以从 ListPlot 中提取点,以便在进一步的计算中使用它们。我目前的方法是使用 Locator[] 选择点。这适用于显示点,但我无法弄清楚如何从带有 head Dy
只要我在与 Program 类相同的程序集中有类 ClassSameAssembly ,下面的代码就可以正常工作。但是,当我将类 ClassSameAssembly 移动到单独的程序集时,会引发 Ru
我只是尝试从Firebase实时数据库解析数据。 但在转换为模型时有问题 我正在尝试从Flutter上解析Firebase数据库中的数据。 但是一个错误说 MY Complete QUIZ: {-M5
我创建了一个方法,当我构建它时,出现了这个错误: type '_InternalLinkedHashMap' is not a subtype of type 'List' in type cast
我对这个 flutter 的简单图表代码有疑问。在我尝试运行代码时显示此错误。请任何人都可以帮助我在这.... The argument type 'List>' can't be assigned
我尝试在我的 flutter 应用程序中解析来自 Firestore 的文档。 Firestore 文档: 我创建了两个类来解析这个文档。 类产品: class Produkt{ String n
我有一个2d-List,其中包含一个字符串和一个Map,如下所示: List> content = [ [ "String", { "one": 23,
我使用 Dart“json_serializable”包在 Flutter 应用程序中的 Firestore 数据结构下反序列化。 { googleBookId: jjl4BgAAQBAJ, prov
我注册了 Dynamic CRM 在线试用版(30 天)并创建了一个非托管自定义解决方案(新字段、一些自定义实体等)。现在,我想导出非托管解决方案并将其导入到我的服务器中的 Dynamic CRM O
当我尝试从 StreamTransform 获取一些数据时遇到一些问题 我不明白什么是正确的数据类型 未捕获的异常:类型错误:“_StreamHandlerTransformer”的实例:“_Stre
我正在尝试获取用户数据,但在这样做时出现以下错误: Exception: type '_InternalLinkedHashMap' is not a subtype of type 'Map 我查看
我正在尝试在 sqflite 数据库中保存一些带有 flutter 的数据,但我仍然收到一条错误消息: [ERROR:flutter/shell/common/shell.cc(181)] Dart
我有一个JSON响应,结构如下:。在这个JSON响应中,有各种动态键,如“Owner”和“Master”,每个键都包含一个JSON对象或一个JSON对象数组。我需要创建一个gson数据类来解析这个动态
在 Dynamics 2012 ax 中编译 CIL 时,我看到以下错误 - 名称为“Dynamics.Ax.application”的重复类型。在程序集中“Dynamics.Ax.applicati
我有一个带有 LinkedHashMap 成员的 StatefulWidget 小部件,如下所示: LinkedHashMap _items = new LinkedHashMap>(); 现在我需要
我正在尝试按照此处所述实现搜索资源功能:https://cloudblogs.microsoft.com/dynamics365/it/2019/05/21/retrieve-resource-ava
我是一名优秀的程序员,十分优秀!