単一のビューを持つ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();
この投稿では、次のことを読みました。
createPartControls は、含まれているウィジェットが作成されるビューのライフサイクルの時間です (ビューが最初に表示されるとき)。このコードは、ビューのライフ サイクル中に 1 回だけ実行されるため、ここに何かを直接追加してビューを更新することはできません。
Eclipse パーツは通常、ワークベンチ内の変更された選択への反応としてコンテンツを更新します (たとえば、ユーザーはデバッグ ビューで別のスタック フレームをクリックする可能性があります)。
残念ながら、他に何を試せばよいかわかりません。また、検索に役立つものも見つかりませんでした。ご協力とご提案をありがとうございます。