我正在編寫一個Eclipse插件,並且爲了響應某些操作,我在啓動一系列操作(在單獨的作業中)時感興趣。其中一個操作是請求用戶提供一個文件名,我正在嘗試使用JFace JDialog。如何在Eclipse插件中以無模式方式使用JFace FileDialog?
但是,我不清楚如何以無模式的方式做到這一點;例如,我在哪裏獲得顯示和shell?如何確保用戶界面繼續工作,同時開發人員可以編輯對話框中的內容?
我正在編寫一個Eclipse插件,並且爲了響應某些操作,我在啓動一系列操作(在單獨的作業中)時感興趣。其中一個操作是請求用戶提供一個文件名,我正在嘗試使用JFace JDialog。如何在Eclipse插件中以無模式方式使用JFace FileDialog?
但是,我不清楚如何以無模式的方式做到這一點;例如,我在哪裏獲得顯示和shell?如何確保用戶界面繼續工作,同時開發人員可以編輯對話框中的內容?
可能是你能看到的Eclipse本身是怎麼做的:
/**
* Creates a new dialog with the given shell as parent.
* @param parentShell the parent shell
*/
public FindReplaceDialog(Shell parentShell) {
super(parentShell);
fParentShell= null;
[...]
readConfiguration();
setShellStyle(SWT.CLOSE | SWT.MODELESS | SWT.BORDER | SWT.TITLE | SWT.RESIZE);
setBlockOnOpen(false);
}
/**
* Returns this dialog's parent shell.
* @return the dialog's parent shell
*/
public Shell getParentShell() {
return super.getParentShell();
}
/**
* Sets the parent shell of this dialog to be the given shell.
*
* @param shell the new parent shell
*/
public void setParentShell(Shell shell) {
if (shell != fParentShell) {
if (fParentShell != null)
fParentShell.removeShellListener(fActivationListener);
fParentShell= shell;
fParentShell.addShellListener(fActivationListener);
}
fActiveShell= shell;
}
它確實取決於對話的重點管理它的父shell。
/**
* Updates the find replace dialog on activation changes.
*/
class ActivationListener extends ShellAdapter {
/*
* @see ShellListener#shellActivated(ShellEvent)
*/
public void shellActivated(ShellEvent e) {
fActiveShell= (Shell)e.widget;
updateButtonState();
if (fGiveFocusToFindField && getShell() == fActiveShell &&
okToUse(fFindField))
fFindField.setFocus();
}
/*
* @see ShellListener#shellDeactivated(ShellEvent)
*/
public void shellDeactivated(ShellEvent e) {
fGiveFocusToFindField= false;
storeSettings();
[...]
fActiveShell= null;
updateButtonState();
}
}
甲ShellAdapter
是提供了通過ShellListener
接口,它提供了具有在Shell
狀態變化處理的方法中描述的方法的默認實現。
重要的是,樣式值應該包含SWT.MODELESS。
風格是SWT中最重要的事情之一,你應該看看,因爲你可以僅僅因爲styel值而控制和初始化很多東西。