2013-03-08 96 views
1

我的用戶從主應用程序工作區中選擇數據。數據存儲在可寫列表中。用戶然後繼續打開一個對話框以在表格中顯示選定的數據。 當我的用戶第一次打開對話框時。一切都很好,事情按計劃進行。但是當他們關閉對話框然後重新打開它時。我收到以下錯誤。org.eclipse.swt.SWTExecption:控件已處理

enter image description here

他們被允許關閉該對話框,並選擇更多的數據。然後再次打開對話框查看舊數據和新數據。

代碼正在使用的步驟順序錯誤。

protected Control createDialogArea(Composite parent) { 
    Composite composite = (Composite) super.createDialogArea(parent); 
    Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); 
    line.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true)); 
    final GridLayout gridLayout = new GridLayout(); 

    gridLayout.marginWidth = 15; 
    gridLayout.marginHeight = 10; 
    composite.setLayout(gridLayout); 

    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); 
    composite.setLayoutData(gridData); 
    createTopButtons(composite); 
    createTableViewer(composite); 
    createRemoveButtons(composite); 
    updateTableViewer(); 
    return composite; 
} 

在錯誤中,我們可以看到它從updateTableViewer

public void updateTableViewer() { 
    setRemoveButtonVisibility(); 
    setRemoveAllButtonVisibility(); 
    setPlotButtonVisibility(); 
    setPDFButtonVisibility(); 
} 

未來在錯誤中,我們看到它從setRemoveButtonVisibility未來();

public void setRemoveButtonVisibility() { 
    if (AplotDataModel.getInstance().getSize() > 0) { 
    removeButton.setVisible(true); 
    } 
    else { 
    removeButton.setVisible(false); 
    } 
} 

這是它指向行:

removeButton.setVisible(true); 

if條件正在檢查存儲用戶選擇數據可寫目錄。如果列表爲空,則按鈕不顯示,如果有數據,按鈕確實顯示。

下面是對話按鈕收盤代碼:

protected void createButtonsForButtonBar(Composite parent) { 
    Button okButton = createButton(parent, OK, "Close Aplot", true); 
    okButton.addSelectionListener(new SelectionAdapter() { 
    public void widgetSelected(SelectionEvent e) { 
     viewer = null; 
     close(); 
    } 
    }); 
} 

有什麼想法?

回答

5

而不是使用close(),使用getShell().setVisible(false)來隱藏對話框。因爲你正在重新使用同一個對話框,所以你不應該關閉它。如果您關閉對話框,然後將其關閉,您應該在每次需要打開對話框時創建一個新對話框。

0

確保在關閉shell之後並未嘗試讀取任何信息。 例子:

System.out.println(combo.getText()) 
shlUpload.close(); 
ImportGroup window = new ImportGroup(); 
window.open(combo.getText()); 

一旦關閉shlUpload不再看到對象「二合一」這是行不通的。 奧斯汀