メインの GUI アプリケーションには、別のダイアログを開くボタンがあります。新しいダイアログには、プリンターのリストを含むテーブルがあります。これを機能させることはできません。私はそれがテーブルにデータを入力することであると確信しています。以下は、これを機能させるために使用しているコードです。
Button plotButton = new Button(composite, SWT.PUSH);
plotButton.setText("Select Plotter");
plotButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
startPrinterListOperation();
showFooBarDialog();
}
});
ここに showFooBarDialog() メソッドがあります
private void showFooBarDialog() {
apd = new FooDialog(null);
apd.create();
apd.getShell().setSize(700, 400);
apd.open();
}
FooDialog で、サーバー側の呼び出しから蓄積されたプリンターをテーブルに入力しようとしています。
private void startPrinterListOperation() {
listOp = new AplotPrinterListOperation(appReg.getString("aplot.message.GETPRINTERLIST"), session);
listOp.addOperationListener(new MyOperationListener(this) {
public void endOperationImpl() {
try {
printers = (ArrayList<PrinterProfile>) listOp.getPrinters();
}
finally {
listOp.removeOperationListener(this);
listOp = null;
}
}
});
session.queueOperation(listOp);
}
このメソッドは基本的に、サーバーにアクセスして使用可能なプリンターを収集し、それらを ArrayList に格納する操作を開始します。このプロセスには 1 ~ 2 秒かかる場合があります。
したがって、FooDialog がテーブルを開いてデータを入力しようとすると、この行ですぐに null ポインター エラーが発生します。
viewer.setInput(parentDialog.getPrintersArray());
が完了していないところだと思いますArrayList
のでNullを返しています。
startPrinterListOperation()
ボタンのクリックの代わりに呼び出す必要がある場所はありますか?showFooBarDialog();
特定のオフタイムまで実行しないようにする方法はありますか?私がこれをどのようにやろうとしているのか、私は完全にオフになっているかもしれません。
startPrinterListOperation()
メソッドFooDialog
は Main Gui ではなく にあるべきですか?SWT プログラマーとして、この問題にどのように対処しますか?
編集 テーブルコードの追加
private TableViewer createPlotterTable(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
createColumns(parent, viewer);
Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setInput(parentDialog.getPrintersArray());
// Layout the viewer
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
viewer.getControl().setLayoutData(gridData);
return viewer;
}
編集
テーブル コードは、メインの GUI クラスではなく別のクラスにあります。
public class AplotPlotterDialog extends TitleAreaDialog {
private AplotBaseDialog parentDialog = null;