Eclipse RCP:View 与 Editor 交互
来源:互联网 发布:饿了么研发待遇 知乎 编辑:程序博客网 时间:2024/05/13 02:37
parts 之间有三种交互方式:
(1)使用 selection
IWorkbenchSite 允许 view 和 editor 调用其 setSelectionProvider 方法发布其 selection,其他 view 和 editor 可以通过 ISelectionService.addSelectionListener(ISelectionListener) 注册监听 selection,然后做出交互。
例如,ContactView 将 TreeViewer 发布为 SelectionProvider,AddContactAction将自己注册为 SelectionListener,当 TreeViewer 发生 selection 事件时通知AddContactAction 进行处理。
org.eclipsercp.hyperbola/ContactsView
treeViewer = new TreeViewer(parent, SWT.BORDER | SWT.MULTI
| SWT.V_SCROLL);
getSite().setSelectionProvider(treeViewer);
……
}
this.window = window;
setId(ID);
setActionDefinitionId(ID);
setText("&Add Contact...");
setToolTipText("Add a contact to your contacts list.");
setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
Application.PLUGIN_ID, IImageKeys.ADD_CONTACT));
window.getSelectionService().addSelectionListener(this);
}
public void dispose() {
window.getSelectionService().removeSelectionListener(this);
}
public void selectionChanged(IWorkbenchPart part, ISelection incoming) {
// Selection containing elements
if (incoming instanceof IStructuredSelection) {
selection = (IStructuredSelection) incoming;
setEnabled(selection.size() == 1
&& selection.getFirstElement() instanceof RosterGroup);
} else {
// Other selections, for example containing text or of other kinds.
setEnabled(false);
}
}
(2)Part listeners
使用 IPartService 注册 IPartListener,当 part 发生打开、关闭和隐藏等事件时通知 IPartListener。
例如,当打开一个 chat editor 后,高亮选中 contact view 中的相应联系人,就可以使用此种方式。
创建 IPartListener
private IPartListener partListener = new IPartListener() {
public void partOpened(IWorkbenchPart part) {
trackOpenChatEditors(part);
}
public void partClosed(IWorkbenchPart part) {
trackOpenChatEditors(part);
}
private void trackOpenChatEditors(IWorkbenchPart part) {
if (! (part instanceof ChatEditor))
return;
ChatEditor editor = (ChatEditor) part;
ChatEditorInput input = (ChatEditorInput) editor.getEditorInput();
String participant = input.getParticipant();
if (openEditors.contains(participant)) {
openEditors.remove(participant);
} else {
openEditors.add(participant);
}
treeViewer.refresh(true);
}
...
};
注册 IPartListener
public void createPartControl(Composite parent) {
...
getSite().getWorkbenchWindow().
getPartService().addPartListener(partListener);
}
public void dispose() {
getSite().getWorkbenchWindow().
getPartService().removePartListener(partListener);
}
ContactView 的 LabelProvider 根据 openEditors 来修改联系人的字体或者颜色:
private class ContactsDecorator implements ILabelDecorator, IFontDecorator {
...
public Font decorateFont(Object element) {
if(element instanceof RosterEntry) {
RosterEntry entry = (RosterEntry)element;
if(ContactsView.this.openEditors.contains(entry.getUser()))
return JFaceResources.getFontRegistry().
getBold(JFaceResources.DEFAULT_FONT);
}
return null;
}
}
public void createPartControl(Composite parent) {
treeViewer = new TreeViewer(parent, SWT.BORDER | SWT.MULTI
| SWT.V_SCROLL);
getSite().setSelectionProvider(treeViewer);
HyperbolaLabelProvider hyperbolaLabelProvider = new
HyperbolaLabelProvider();
DecoratingLabelProvider decorator = new
DecoratingLabelProvider(hyperbolaLabelProvider,
new ContactsDecorator());
treeViewer.setLabelProvider(decorator);
...
}
}
(3)直接交互
可以在 view 或者 editor 中调用其他 view、editor 的引用,也可以使用 IWorkbenchPage 来打开关闭其他 view 或 editor 。但这种做法增加了 view、editor 的耦合。
参考:
《Eclipse Rich Client Platform Designing, Coding, and Packaging Java Applications》:chapter16
- Eclipse RCP:View 与 Editor 交互
- Eclipse RCP:View 与 Editor 交互
- RCP开发中Editor与View的选择
- Eclipse RCP 从菜单打开Editor
- Eclipse RCP 从菜单打开Editor
- RCP中获得其他view或editor引用的方法
- Eclipse RCP中Viewer交互的三种方式/Make your Eclipse applications richer with view linking
- 6. Eclipse RCP中的用户交互元素
- Eclipse RCP中控制Editor不重复打开的方法
- Eclipse RCP中控制Editor不重复打开的方法
- Eclipse RCP Console View 相关操作
- Eclipse RCP Console View 相关操作
- Eclipse RCP之视图—view
- Eclipse RCP之视图—view
- eclipse rcp显示/隐藏视图(view)
- RCP Editor 修改状态
- ECLIPSE用VE进行RCP开发2:使用Eclipse的VE(Visual Editor)
- Eclipse rcp : How to save a dirty view
- 待机界面 运营商名称 获取过程
- 可不可以有一个人
- 安装Linux系统时的ACPI和APIC问题
- >
- January 22th Friday 2010
- Eclipse RCP:View 与 Editor 交互
- qa和测试是不一样的。
- 配置spring日志记录
- Sql Server 常用函数
- SWT图片显示,支持JPEG,GIF(动画),BMP,ICO,PNG和TIFF
- 使用Dotnetbar做出office07风格的窗体
- sqlplus 汉字乱码问题的解决
- 无法实现接口成员,因为它不是公共的-----------interface
- 七个让人顿悟的人生哲理寓言