java插件更新_java-如何在Eclipse插件中更新/刷新视图?

我有一个具有单个视图的eclipse插件(例如eclipse helloworld-view-plugin-project).当我想更新视图时,在视图文件中得到一个事件.

在此视图中,我在一个具有多个标签的组中有一个GridData.我有几个注册到程序的服务,其状态应在此GridData中显示.

编辑:为了更好地显示我的问题,我更新了这篇文章,并添加了整个代码:

CreatePartControl():

public void createPartControl(Composite _parent) {

parent = _parent;

createContents();

addBindings();

makeActions();

contributeToActionBars();

}

CreateContents():

protected void createContents() {

// fixed

checkIcon = //...

errorIcon = //...

smallFont = SWTResourceManager.getFont("Segoe UI", 7, SWT.NORMAL);

// content

gl_shell = new GridLayout(1, false);

//margins, etc. for gl_shell

parent.setLayout(gl_shell);

final Label lblGreeting = new Label(parent, SWT.NONE);

lblGreeting.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));

lblGreeting.setText("Hi " + Preferences.getPreName());

// -- GROUP YOUR STATS (show all services)

createStatusGroupBox();

}

createStatusGroupBox():

private Group grpYourStatus = null; // outside the method for access in listener (below)

private void createStatusGroupBox() {

grpYourStatus = new Group(parent, SWT.NONE);

grpYourStatus.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

grpYourStatus.setText("Your upload status");

grpYourStatus.setLayout(new GridLayout(3, false));

// add message if no service is registered

if ( r.getServiceList().size() == 0 ) {

Label status = new Label(grpYourStatus, SWT.NONE);

status.setText("No service registered.");

new Label(grpYourStatus, SWT.NONE); //empty

new Label(grpYourStatus, SWT.NONE); //empty

}

// add labels (status, message, name) for each registered service

for ( IRecorderObject service : r.getServiceList() ) {

Label name = new Label(grpYourStatus, SWT.NONE);

Label status = new Label(grpYourStatus, SWT.NONE);

Label message = new Label(grpYourStatus, SWT.NONE);

message.setFont(smallFont);

message.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));

service.getServiceViewItem().setLabelsAndIcons(name, status, message, checkIcon, errorIcon); //this also sets the values of the labels (label.setText(...) via data binding)

}

不幸的是,我不知道更新/重置它的正确方法是什么.我尝试了以下方法:

侦听器(应更新视图/服务列表):

r.addPropertyChangeListener(BindingNames.SERVICE_ADDED, new PropertyChangeListener() {

public void propertyChange(final PropertyChangeEvent evt) {

Display.getDefault().asyncExec(new Runnable() {

public void run() {

// This "redraws" the view, but just places the whole content (generated in createStatusGroupBox()) above the other parts.

//Display.getCurrent().update();

//createStatusGroupBox();

//parent.layout(true);

//parent.redraw();

// disposes grpYourStatus-Group but doesn't show anything then

grpYourStatus.dispose();

createStatusGroupBox();

grpYourStatus.layout();

grpYourStatus.redraw();

}

});

}

});

我还尝试了以下语句(分别);都没有成功:

parent.redraw();

parent.update();

parent.layout();

parent.layout(true);

parent.refresh();

在此post中,我阅读以下内容:

createPartControls is that time of the life cycle of a view, where its

contained widgets are created (when the view becomes visible

initially). This code is only executed once during the view life

cycle, therefore you cannot add anything here directly to refresh your

view.

Eclipse parts typically update their content as a reaction to a

changed selection inside of the workbench (e.g. the user might click

on another stack frame in the debug view).

不幸的是,我不知道该怎么办,搜索没有任何帮助…感谢您的帮助和建议!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值