2012-03-16 2 views
1

WindowBuilder Pro를 사용하여 간단한 SWT Eclipse 플러그인을 만들고 있습니다. 사용자가 툴바 아이템을 클릭하면 아래에서 생성 한 대화 상자 클래스를 팝업 메뉴에 표시하고 싶은데, ViewPart를 중심으로합니다. 누구든지이 작업을 수행하는 방법을 알고 있습니까? 그것은 ... 당신은 대화 상자를 열 수있는 새로운 쉘을 만들 필요가 없습니다팝업창이있는 Eclipse RCP SWT 문제

public class MyApp extends ViewPart { 

    public void createPartControl(final Composite arg0) { 
     arg0.setLayout(new GridLayout(1, false)); 

     final ToolBar toolBar = new ToolBar(arg0, SWT.FLAT | SWT.RIGHT); 
     toolBar.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); 

     final ToolItem connectItem = new ToolItem(toolBar, SWT.NONE); 
     connectItem.addSelectionListener(new SelectionAdapter() { 
      @Override 
      public void widgetSelected(final SelectionEvent e) { 
       System.out.println("connect button clicked!"); 
       final Shell newShell = new Shell(); 
       newShell.setText("Connect to box"); 
       newShell.setLayout(new GridLayout(2, false)); 
       newShell.setSize(400, 400); 
       newShell.pack(); 
       newShell.open(); 
       final ConnectSUVDialog dialog = new ConnectBoxDialog(newShell); 
      } 
     }); 
     . 
     . 
     . 
    } 
} 


public class ConnectSUVDialog 
    extends Dialog { 
    private Text txtHostName; 
    private Text txtUserName; 
    private Text txtPassword; 

    public ConnectSUVDialog(final Shell parentShell) { 
     super(parentShell); 
    } 

    @Override 
    protected Control createDialogArea(final Composite parent) { 
     final Composite container = (Composite) super.createDialogArea(parent); 
     container.setLayout(new GridLayout(2, false)); 


     this.txtHostName = new Text(container, SWT.BORDER); 
     this.txtHostName.setText("host name"); 
     this.txtHostName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); 

     this.txtUserName = new Text(container, SWT.BORDER); 
     this.txtUserName.setText("user name"); 
     this.txtUserName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); 

     this.txtPassword = new Text(container, SWT.BORDER); 
     this.txtPassword.setText("password"); 
     this.txtPassword.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); 

     return container; 
    } 

    /** 
    * Create contents of the button bar. 
    * @param parent 
    */ 
    @Override 
    protected void createButtonsForButtonBar(final Composite parent) { 
     createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 
     createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); 
    } 

    /** 
    * Return the initial size of the dialog. 
    */ 
    @Override 
    protected Point getInitialSize() { 
     return new Point(450, 300); 
    } 

} 

답변

2

훨씬 더 직관적 인 스윙에서입니다.

ConnectSUVDialog dialog = new ConnectSUVDialog(arg0.getShell()); 
dialog.open();