在Eclipse RCP中显示视图时传递参数 [英] Passing parameters while showing a view in Eclipse RCP

查看:510
本文介绍了在Eclipse RCP中显示视图时传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建eclipse RCP应用程序,并且在显示视图时我遇到了传递参数。
作为第一种方法,我尝试在View2中的View2中设置一个静态变量,并打开该视图(如下所示)。有用。

I am creating eclipse RCP application and I am stuck with passing parameter while showing a view. As the first approach, I tried setting a static variable in View2 from View1 and opened that view (as below). It works.

IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();               
String viewIdToClose = studentListView.ID;
IViewPart viewToClose = activePage.findView(viewIdToClose);
TableItem item = studentTable.getItem(studentTable.getSelectionIndex());
String text = item.getText(ListViewConstants.TABLE_COLUMN_ONE);
activePage.hideView(viewToClose);
try {
    String viewIdToOpen = StudentReview.ID;
    StudentReview.userId = text;
     activePage.showView(viewIdToOpen);                 
} catch (PartInitException e) {...}

由于这似乎不做一个很好的做法,我按照以下链接(接受的答案)中提到的建议进行尝试。
将参数传递给视图
。在这种方法中,我们只能在显示视图后传递参数。

As this doesn't seem to be a good approach, I tried as per the suggestion mentioned in the below link(accepted answer). Passing parameters to the view . In this approach, we can pass parameters only after showing the view.

但是我遇到的问题是,打开的视图应该在调用时选择行的值showView()ie,我想根据View 1的选择填充View 2中的参数。
有什么办法可以实现吗?使用PULL而不是PUSH方法好吗?
任何建议是赞赏。
谢谢!!!

But the issue I have is, the view to be opened should have the value from selected row while calling showView() i.e, I want to populate the parameters in View 2 based on View 1's selection. Is there any way to achieve this? Is it good to use PULL instead of PUSH approach? Any suggestion is appreciated. Thanks!!!

更新1:
将参数传递给视图
接口:

UPDATE 1: Approach mentioned in Passing parameters to the view Interface:

public interface ICommunicationView extends IViewPart{
   public void accept(Object parameter);
}

调用accept():

Calling accept():

IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
String viewIdToClose = StudentListView.ID;
IViewPart viewToClose = activePage.findView(viewIdToClose);
TableItem item = studentTable.getItem(studentTable.getSelectionIndex());
String text = item.getText(ListViewConstants.TABLE_COLUMN_ONE);
activePage.hideView(viewToClose);
try {
   String viewIdToOpen = StudentReview.ID;
   ICommunicationView viewToOpen = (ICommunicationView) activePage.showView(viewIdToOpen);
   viewToOpen.accept(text);//Sending userId to Review view
} catch (PartInitException e) { ... }

StudentReviewView:

StudentReviewView:

private String studentId;
//getters and setters
@Override
public void accept(Object parameter) {
  setStudentId(parameter.toString());
}

public void createPartControl(final Composite parent) {
   ...
  System.out.println("Student Id" + this.getStudentId());    
}

将Student Id打印为null。

It prints Student Id as null.

我缺少一些明显的东西?

Am I missing something obvious?

谢谢!

推荐答案

activePage.showView(viewIdToOpen)打开视图时,平台调用 createPartControl C $ C>。所以不要在 createPartControl 上填充你的字段。在 setStudentId 被调用时执行。

Platform calls createPartControl when the view is opened by activePage.showView(viewIdToOpen). So don't populate your fields on createPartControl. Do it when setStudentId is called.

这篇关于在Eclipse RCP中显示视图时传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆