java rcp listview,在Eclipse RCP中显示视图时传递参数

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.

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!!!

UPDATE 1:

Approach mentioned in Passing parameters to the view

Interface:

public interface ICommunicationView extends IViewPart{

public void accept(Object parameter);

}

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:

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());

}

It prints Student Id as null.

Am I missing something obvious?

Thanks!

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值