- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经实现了一个 View ,它将自身注册为 XText 编辑器和相关大纲中更改的监听器。为此,我添加了这一行
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().addSelectionListener(this);
在 View 的createPartControl方法中(它实现了ISelectionListener接口(interface))。因此,在 SelectionChanged 方法中,我检查选择是否是 ITextSelection(它来自 XTextEditor)或 IStructuredSelection(它来自 Outline)。
问题是,这样做时,当我启动 Eclipse 时,大纲被称为“不可用”。如果我单击大纲,它会刷新,显示内容并正确更新收听 View 。我做错了什么以及我应该做什么来避免大纲最初的“不可用”?
最佳答案
我最近遇到了这个问题,并通过在扩展 ViewPart 的类中实现 IPartListener2 来解决它,然后在 createPartcontrol 方法中添加一个部件监听器,如下所示:
getSite().getWorkbenchWindow().getPartService().addPartListener(this);
现在,通过在您的partOpened方法中使用类似的方法(必须在您实际使用部件监听器之前实现该方法,您将首先获得可用的 View 内容:
public void partOpened(IWorkbenchPartReference partRef) {
if(partRef.getPage().getActiveEditor() instanceof XtextEditor) {
somepart=partRef.getPage().getActiveEditor();
final XtextEditor editor = (XtextEditor)somepart;
final IXtextDocument document = editor.getDocument();
document.readOnly(new IUnitOfWork.Void<XtextResource>(){
public void process (XtextResource resource) throws Exception {
IParseResult parseResult = resource.getParseResult();
if(parseResult ==null)
return;
CompositeNode rootNode=(CompositeNode) parseResult.getRootNode();
LeafNode node = (LeafNode)NodeModelUtils.findLeafNodeAtOffset(rootNode, 0);
EObject object =NodeModelUtils.findActualSemanticObjectFor(node);
view.setInput(object);
}
});
}
}
这将使您正在实现的 View 在您激活 XtextEditor(特定于您的 DSL)时获取其内容。为了使 View 在编辑器中更改 Activity 文件中的任何内容时实时更改内容,您应该实现 IDocumentListener 并重写 DocumentChanged 方法。如果您这样做,您将不再依赖 SelectionListener,因为当文档中发生更改时 View 应该自动更新
希望这有帮助!
关于java - Eclipse (XText) SelectionListener 注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16858699/
我在 oracle adf (jdeveloper) 中有一个融合 Web 应用程序。 其中我有一个带有内联编辑的表格。如果用户离开当前行,我想在其中允许自动提交。因此,如果用户导航到另一行,则必须自
我正在尝试在 RadioButton 上实现一个事件: radio_Email.addSelectionListener( new org.eclipse.swt.events.Selecti
我找不到这个接口(interface)或其他相关信息: ok.addSelectionListener(new SelectionAdapter() { public void w
如何关闭 SelectionListener 中的Dialog?目前我的 SelectionListener 看起来像这样: public void widgetSelected(SelectionE
我有一个向 SWT shell 添加四个复选框按钮的代码,我已向复选框按钮添加了选择监听器,我想在单击 SWT Shell 的“确定”、“取消”和“关闭”按钮时将其删除,我该如何处理此类按钮事件,这是
我有一个带有 GUI 线程和 SQL 线程的应用程序。 GUI 中显示一棵树,单击树中的某个项目将启动一个单独的线程,该线程将启动 SQL 查询。查询完成后,树就会更新。 问题是,如果用户在获取线程完
我已经实现了一个 View ,它将自身注册为 XText 编辑器和相关大纲中更改的监听器。为此,我添加了这一行 PlatformUI.getWorkbench().getActiveWorkbench
嗨,强大的程序员们,作为 n00b 初学者,我再次请求你们的帮助...... 问题如下,我有一个子窗口,包含一些标签、按钮和两个下拉菜单。我想在一个名为“name”的组合框上有一个 Selection
我有一个名为“radio”的顶级菜单,其中包含两个 radio MenuItem。我为两者都添加了 SelectionListener。 MenuItem radio = new MenuIt
我正在我的 RAP 应用程序 (1.5M7) 中实现广告部分。为了展示广告,我使用了 SWT Browser 。如何检测用户对浏览器(广告)的点击,以便能够将其转发到链接页面? 最佳答案 如果您从外部
PostSelectionListener 已添加到当前工作台窗口: getWorkbenchWindow().getSelectionService().addPostSelectionListen
我正在努力检测绑定(bind)到 bean 的 CheckBoxGroup 中项目的取消选择。这是一个简化的示例: 我有一个类(class)人: package com.vaadin.test; im
为什么退出按钮不通知我选择已更改? (未选中) 我对 SelectionListener 进行了一些验证,按转义键跳过了我的验证。 这绝对不是正常的行为。当从表中按退出按钮以按隐藏按钮捕获该事件时,我
我无法理解 SWT SelectionListener 中两种方法之间的区别。 javadoc如下: void org.eclipse.swt.events.SelectionListener.wid
我是一名优秀的程序员,十分优秀!