【发布时间】:2016-04-02 00:50:17
【问题描述】:
我正在阅读一本 Eclipse 插件书。我之前有一个Simple SWT/JFace exercise fails to find handler 的问题。
我现在正在做一个弹出菜单练习。我有一个树形视图和一个表格视图,我试图在两个视图上呈现相同的弹出菜单(这全部来自书中的说明)。
在每个视图的createPartControl 方法中,我添加了如下代码:
MenuManager manager = new MenuManager("#PopupMenu");
Menu menu = manager.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(manager, viewer);
“查看者”是TableViewer 或TreeViewer。
我添加了以下menuContribution:
<menuContribution allPopups="false" locationURI="popup:org.eclipse.ui.popup.any">
<command commandId="com.packtpub.e4.clock.ui.command.showTheTime"
label="Show the Time" style="push">
<visibleWhen checkEnabled="false">
<with variable="selection">
<iterate ifEmpty="false">
<adapt type="java.util.TimeZone">
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
连同这个命令:
<command description="Shows the Time"
id="com.packtpub.e4.clock.ui.command.showTheTime"
name="Show the Time">
</command>
还有这个处理程序:
<handler class="com.packtpub.e4.clock.ui.handlers.ShowTheTime"
commandId="com.packtpub.e4.clock.ui.command.showTheTime">
</handler>
以下是处理程序类:
public class ShowTheTime extends AbstractHandler {
public Object execute(ExecutionEvent event) {
ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getSelectionService().getSelection();
if (sel instanceof IStructuredSelection && !sel.isEmpty()) {
Object value = ((IStructuredSelection)sel).getFirstElement();
if (value instanceof TimeZone) {
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.setTimeZone((TimeZone) value);
MessageDialog.openInformation(null, "The time is", sdf.format(new Date()));
}
}
return null;
}
}
当我运行实例并右键单击树或表时,我得到......什么都没有。什么都没有发生。
是否有可能带有“adapt”的“迭代”没有找到与该类型匹配的选择 (java.util.TimeZone)?
【问题讨论】:
标签: java eclipse eclipse-plugin