-
大师为您详解rcp视图之间使用监听传递参数
- 作者:李香主 分类:电脑技术 发布时间:2017-09-19 18:04:36
电脑现已成为我们工作、生活和娱乐必不可少的工具了,在使用电脑的过程中,可能会遇到rcp视图之间使用监听传递参数的问题,如果我们遇到了rcp视图之间使用监听传递参数的情况,该怎么处理怎么才能解决rcp视图之间使用监听传递参数带来的困扰呢,对于这样的问题其实我们只需要eclipse新建一个插件项目,项目的名称为jianting.在项目中新建2个视图view1,view2,打开Perspective.java这个文件,把视图打开。IFolderLayout left=layout.createFolder("left", IPageLayout.LEF...
电脑现已成为我们工作、生活和娱乐必不可少的工具了,在使用电脑的过程中,可能会遇到rcp视图之间使用监听传递参数的问题,如果我们遇到了rcp视图之间使用监听传递参数的情况,该怎么处理怎么才能解决rcp视图之间使用监听传递参数带来的困扰呢,对于这样的问题其实我们只需要eclipse新建一个插件项目,项目的名称为jianting.在项目中新建2个视图view1,view2,打开Perspective.java这个文件,把视图打开。IFolderLayout left=layout.createFolder("left", IPageLayout.LEFT, 0.5f, IPageLayout.ID_EDITOR_AREA);left.addView(view1.这样就解决了这样的问题,接下来给大家带来rcp视图之间使用监听传递参数的详细操作步骤。
工具/原料
eclipse
方法/步骤
新建一个插件项目,项目的名称为jianting.
在项目中新建2个视图view1,view2,打开Perspective.java这个文件,把视图打开。
IFolderLayout left=layout.createFolder("left", IPageLayout.LEFT, 0.5f, IPageLayout.ID_EDITOR_AREA);
left.addView(view1.ID);
IFolderLayout bottom=layout.createFolder("bottom", IPageLayout.BOTTOM, 0.5f, IPageLayout.ID_EDITOR_AREA);
bottom.addView(view2.ID);
在view1视图中建立一个发送类:
public class fasong implements ISelectionProvider{
List<ISelectionChangedListener> listeners = new ArrayList<ISelectionChangedListener>();
ISelection theselection = StructuredSelection.EMPTY;
@Override
public void addSelectionChangedListener(ISelectionChangedListener listener) {
listeners.add(listener);
}
@Override
public ISelection getSelection() {
return theselection;
}
@Override
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
listeners.remove(listener);
}
@Override
public void setSelection(ISelection selection) {
if(selection==null){
return;
}
theselection = selection;
final SelectionChangedEvent e = new SelectionChangedEvent(this, selection);
Object[] listenersArray = listeners.toArray();
for (int i = 0; i < listenersArray.length; i++) {
final ISelectionChangedListener l = (ISelectionChangedListener) listenersArray[0];
l.selectionChanged(e);
}
}
}
在view1视图初始化时,把发送类注册到视图中:
fasong fa=new fasong();
this.getSite().setSelectionProvider(fa);
编辑text key的事件,当有键按下时,把得到文本发送出去。
ISelection st=new StructuredSelection(((Text)e.getSource()).getText());
fa.setSelection(st);
在view2视图中写监听类,把监听的字符串显示在text中。
public class jieshou implements ISelectionListener{
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if(selection!=null ){
IStructuredSelection st = (IStructuredSelection)selection;
text.setText((String) st.getFirstElement());
}
}
}
在view2初始化时,增加监听类:
jieshou jie=new jieshou();
this.getViewSite().getWorkbenchWindow().getSelectionService().addSelectionListener(jie);
项目运行,在view1中输入字符串,同时view2视图的text框内一样显示。
猜您喜欢
- 麒麟9000S猛兽出笼:单核跑分测试揭秘..2024-03-19
- 快速安装高效插件,让你成为百家号大..2024-03-13
- 迈向成功! 详解win11系统添加打印机的..2024-02-22
- 拯救UEFI固件,重拾Win10系统,详解恢复..2023-12-31
- 告别卡顿!Windows 10彻底清除缓存文件..2023-12-30
- 360装机大师轻松安装Win7系统:简单易..2023-12-29
相关推荐
- 笔记本关不了机怎么办_解决笔记本突..2021-06-24
- 在ps中如何换背景图片..2017-08-27
- Win11如何取消固定图标?Win11取消固定..2022-07-18
- Win10怎么添加纯英文输入法 windows10如何..2023-01-20
- adobe reader无法安装怎么办_adobe reader无..2021-06-17
- 如何添加chrome迅雷扩展程序 添加chro..2021-04-26