袁咏琳为什么不火:在rcp中获得父Shell的几种方法 .

来源:百度文库 编辑:中财网 时间:2024/05/10 05:44:35

在实现了IWorkbenchWindowActionDelegate接口的类中:

private IWorkbenchWindow window;

public void init(IWorkbenchWindow window) {
   this.window = window;
}
public void run(IAction action) {
   Shell parentShell = window.getShell();
   MyDialog dialog = new MyDialog(parentShell, );
    etc 
}

在实现了IObjectActionDelegate 接口的类中:
private IWorkbenchPart targetPart;

public void setActivePart(IAction action, IWorkbenchPart targetPart)
{
   this.targetPart = targetPart;
}

public void run(IAction action) {
   IWorkbenchPartSite site = targetPart.getSite();
   MyDialog dialog = new MyDialog(site, );
    etc 
}

IViewPart 或者IEditorPartIShellProvider shellProvider = viewOrEditor.getSite();PlatformUI:
Shell parentShell =
   PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
Display :
Shell parentShell = Display.getDefault().getActiveShell();

以上各种方法对于获取其它的一些rcp中的重要对象也都有借鉴意义。