问题描述
我有一个 eclipse插件,使用单个视图(如eclipse helloworld-view-plugin-project)。在视图文件中,当我想要更新视图时,我会收到一个事件。
I have an eclipse plug-in with a single view (like the eclipse helloworld-view-plugin-project). In the view-file I get an event when I want to update the view.
在此视图中,我有一个具有多个标签的组中的GridData。我有几个服务注册到程序,其状态应该在此GridData中显示。
In this view I have a GridData in a Group with multiple labels. I have several services which register to the programe and whose status should be shown in this GridData.
编辑:为了更好地显示我的问题我更新了这篇文章,并添加了整个代码:
In order to better show my problem I updated this post and added the whole code:
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)
}
不幸的是,我不知道正确的方式是更新/重置它。我尝试了以下内容:
Unfortunately, I don't know what the right way is to update/reset it. I tried the following:
监听器(应更新视图/服务列表):
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();
}
});
}
});
我还尝试了以下语句(单独);所有没有成功:
I also tried the following statements (individually); all without success:
parent.redraw();
parent.update();
parent.layout();
parent.layout(true);
parent.refresh();
在这个我阅读了以下内容:
Eclipse部件通常更新其内容作为对工作台内
更改选择的反应(例如,用户可能在调试视图中的另一个堆栈框架上单击
)。
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).
不幸的是,我不知道还有什么可以尝试,我没有找到任何有用的搜索... 感谢您的帮助和建议
Unfortunately, I don't know what to else I could try and I didn't find anything helpful with searches... thank's for your help and suggestions!
推荐答案
我终于找到答案(和AndreiC的帮助一起):
I finally found the answer (together with AndreiC's help!):
我的监听器现在看起来像这样:
my listener now looks like this:
r.addPropertyChangeListener(BindingNames.SERVICE_ADDED, new PropertyChangeListener() {
public void propertyChange(final PropertyChangeEvent evt) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
// remove grpYourStatus from parent
grpYourStatus.dispose();
// add grpYourStatus (with updated values) to parent
createStatusGroupBox();
// refresh view
parent.pack();
parent.layout(true);
}
});
}
});
其余的与上面的代码一样。
The rest is the same like the code above.
这篇关于如何在eclipse插件中更新/刷新视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!