有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java SWT继承父对话框外壳?

我真的需要理解父母/孩子对话是如何工作的

我的用户使用一个名为Teamcenter的OTB应用程序。我正在编写一个从Teamcenter应用程序的菜单选择中调用的附加应用程序

当他们单击菜单项时,它会执行一个处理程序类,并为我的应用程序创建基本对话框

public class AplotDialogHandler extends AbstractHandler {
  private static AplotBaseDialog dlg = null;

  public AplotDialogHandler() {

  }// end Constructor

  //////////////////////////////////////////////////////////////////////////
  //                            execute()                                 //
  //////////////////////////////////////////////////////////////////////////
  @Override 
  public Object execute(final ExecutionEvent event) throws ExecutionException {
     if (dlg == null) {
        try {
           AbstractAIFApplication app = AIFDesktop.getActiveDesktop().getCurrentApplication();
        TCSession session = (TCSession) app.getSession();
        TCUserService userService = session.getUserService();

        AplotVersion.negotiateVersion(userService);
        AplotQueryCapabilities.initialize(userService);

        dlg = new AplotBaseDialog(null, session);
     }
     catch (Exception ex) {
        MessageBox.post(HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(), ex, true);
     }
  }

  dlg.create();
  dlg.getShell().setSize(700, 400);
  dlg.open();

  return null;
 }// end execute()
}// end EdiDialogHandler()

问题1。我的应用程序似乎与Teamcenter应用程序无关。这意味着我可以关闭Teamcenter,我的应用程序保持打开状态

问题2。我应该获取工作区shell并在基本对话框中传递它吗? 但即使我的应用程序处于打开状态,用户仍需要能够使用Teamcenter应用程序选择要发送到我的应用程序的数据

问题3。从基本对话框打开对话框时,我是否应该始终将基本对话框外壳传递给这些对话框

问题4。有没有一种标准的方法可以在用户完成后关闭对话框


共 (1) 个答案

  1. # 1 楼答案

    您需要将父Shell传递给对话框,以便在关闭父Shell时,子Shell也将被关闭

    你应该使你的对话框无模式(使用SWT.MODELSS作为样式。注意:它是提示),这样它就不会阻塞你的父shell

    以下是示例代码:

     public static void main(String[] args) {
    
        Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(1, false));
        shell.setSize(200, 200);
        Button b = new Button(shell, SWT.NONE);
        b.setText("Click");
        b.addSelectionListener(new SelectionListener() {
    
          @Override
          public void widgetSelected(SelectionEvent e) {
    
    
             CDialog dialog = new CDialog(shell);
    
             dialog.open();
          }
    
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
    
            // TODO Auto-generated method stub
    
          }
        });
    
        shell.open();
    
    
    
        while (!shell.isDisposed()) {
          if (!display.readAndDispatch())
            display.sleep();
        }
        display.dispose();
      }  
    
    
      private static class CDialog extends Dialog
      {
    
        /**
         * @param parentShell
         */
        protected CDialog(Shell parentShell) {
    
          super(parentShell);
        }
    
        /* (non-Javadoc)
         * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
         */
        @Override
        protected Control createDialogArea(Composite parent) {
    
          Composite comp =  (Composite) super.createDialogArea(parent);
    
          Label lbl = new Label(comp, SWT.NONE);
          lbl.setText("Test modeless dialog");
    
          return comp;
        }
        /* (non-Javadoc)
         * @see org.eclipse.jface.window.Window#getShellStyle()
         */
        @Override
        protected int getShellStyle() {
          return SWT.DIALOG_TRIM|SWT.MODELESS;
        }
    
      }