我有一个eclipse插件与一个单一的查看(如eclipse helloworld-view-plugin-project)。在视图文件中,当我想更新视图时,我得到一个事件。如何在eclipse插件中更新/刷新视图?
在这个视图中,我有一个具有多个标签的组中的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的是,时间(当视图首先变得可见 )。此代码仅在视图生命周期 期间执行一次,因此您无法直接在此添加任何内容以刷新您的 视图。
Eclipse部件通常会更新其内容,作为对工作台内部改变的选择的反应(例如,用户可能在调试视图中的另一个堆栈帧上单击 )。
不幸的是,我不知道什么东西我可以尝试,我没有找到任何与搜索有帮助...... 感谢对您的帮助和建议!
谢谢安德烈您的回答。是的,我也尝试过(添加到我的文章)。你有什么其他的建议?谢谢 – casaout
你有没有尝试过只使用layout(),没有重绘()? – acostache
不幸的是,parent.layout()没有改变任何东西... – casaout