英文:
How to tell a FieldEditorPreferencePage to invalidate/redraw programatically?
问题
我定义了一个自定义的FieldEditorPreferencePage。在createFieldEditors方法中,我使用一个自定义的FieldEditor构建了一个简单的界面,其中包含一个按钮,用于加载文件。当用户加载文件时,界面区域(按钮所在的位置)需要更改并显示其他特定的GUI。如何使FieldEditorPreferencePage失效?我使用了父复合组件的layout()方法,但没有任何效果。我在这里做错了什么?
public class MyPage extends FieldEditorPreferencePage {
...
private Composite fieldEditorParent;
private boolean fileLoaded = false;
@Override
protected void createFieldEditors() {
fieldEditorParent = this.getFieldEditorParent();
MyFieldEditor compositeFieldEditor = new MyFieldEditor(fieldEditorParent) {
if(fileLoaded) {
//绘制文件内容
} else {
Button chooseButton = new Button(buttonsComposite, SWT.NONE);
chooseButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
//选择文件
fileLoaded = true;
//使页面失效 <— 这样做不起作用!
fieldEditorParent.layout(true, true);
}
}
}
}
}
英文:
I defined a custom FieldEditorPreferencePage. In createFieldEditors method I construct a simple interface with a custom FieldEditor that holds button that loads a file. When a user loads the file the interface region (where the button stands) need to change and show other specific gui. How to invalidate the FieldEditorPreferencePage? I used the layout() method of the parent composite but nothing happens. What am I doing wrong here?
public class MyPage extends FieldEditorPreferencePage {
...
private Composite fieldEditorParent;
private boolean fileLoaded = false;
@Override
protected void createFieldEditors() {
fieldEditorParent = this.getFieldEditorParent();
MyFieldEditor compositeFieldEditor = new MyFieldEditor(fieldEditorParent) {
if(fileLoaded) {
//draw file content
} else {
Button chooseButton = new Button(buttonsComposite, SWT.NONE);
chooseButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
//choose file
fileLoaded = true;
//invalidate page <-- THIS DOES NOT WORK!
fieldEditorParent.layout(true, true);
}
}
}
}
}
专注分享java语言的经验与见解,让所有开发者获益!
评论