2013-03-11 79 views
0

我的應用程序被編寫爲在OOTB應用程序中運行。用戶可以從OOTB應用程序中選擇數據並將其存儲在我的應用程序的WritableList中。用戶然後可以點擊OOTB工具欄中的按鈕,打開我的應用程序的基礎對話框。該對話框向用戶顯示他們已經選擇的數據表。從基本對話框中,他們可以對錶格中的數據執行不同的任務。這包括刪除數據以及從OOTB應用程序中選擇更多數據。我的應用程序將保存數據,直到用戶關閉OOTB應用程序關閉。但是我必須給用戶一個基本對話框上的按鈕來從他們的視圖中刪除對話框。所以當他們使用OOTB應用程序時,這個對話框並不適用。我的基礎對話框是由TitleAreaDialog構建的。我的第一個嘗試是關閉createButtonForButtonBar方法中的dailog。不關閉用戶隱藏對話框

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(); 
     } 
    }); 
    } 

但是close();正在處理我所有的SWT Widget並導致運行時錯誤。 SWT_Widget在嘗試打開對話框備份時已經放置。所以有了一些建議,我試圖隱藏shell。所以我刪除了close()並放在getShell()中。

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

}

現在我正在逐漸線運行空指針異常:getShell()調用setVisible(假)。

如果我刪除了「OK」並將其替換爲SWT_PUSH。它似乎沒有錯誤的工作。

protected void createButtonsForButtonBar(Composite parent) { 
    Button okButton = createButton(parent, SWT.PUSH, "Close Aplot", true); 
    okButton.setEnabled(true); 
    okButton.addSelectionListener(new SelectionAdapter() { 
    public void widgetSelected(SelectionEvent e) { 
     viewer = null; 
     getShell().setVisible(false); 
    } 
    }); 

}

前一個問題,我意識到這不是好的做法。

那麼我該如何隱藏我的dailog而不關閉它呢?我假設我必須保留createButtonsForButtonBar方法。那麼,我該如何改變我必須妥善照顧貝殼隱藏?

感謝

編輯

這是否看起來是正確的?

@Override 
protected void createButtonsForButtonBar(final Composite parent) { 
    createButton(parent, IDialogConstants.OK_ID, "Close Aplot", 
     true); 
} 

@Override 
protected void okPressed() { 
    viewer = null; 
    getShell().setVisible(false); 
} 
+0

你只需要隱藏對話框的外殼。我看到你做了什麼。 – 2013-03-12 14:49:54

回答

0

您可以嘗試org.eclipse.swt.widgets.Decorations.setMinimized(boolean)以最小化用戶單擊按鈕時的對話框?這是更好的解決方案嗎?