2013-03-08 46 views
1

我有一個問題,我現在無法解決我自己。在部分展開後避免樹大小調整

我有一個RCP ViewPage包含兩個部分。這些部分位於SashForm中,以便用戶能夠調整擴展部分的大小。在底部有一個樹,初始化後它是空的。通過用戶交互(即刪除過濾器),樹會被填充並且其中包含大量數據。如果用戶現在摺疊底部視圖並再次展開,則樹會重新調整大小,從而導致我的窗體中出現滾動條。我想要的是樹形視圖中的滾動條。

下面是這個視圖是如何打造:

- ScrolledForm 
    - Form Body 
    - Sash 
     - Section 1 
     - Composite 
      - Some View 
     - Section 2 
     - Composite 
      - Tree 

我希望你明白我想要的目的。

更新:這裏有一些源代碼來玩。它使用表而不是樹,但產生相同的問題。

public class MyPersonPageEditor extends FormPage { 

    public static final String ID = "some.ID"; 

    TableViewer tableViewer; 

    public MyPersonPageEditor(FormEditor editor) { 
     super(editor, ID, "Some Title"); 
    } 

    @Override 
    protected void createFormContent(IManagedForm managedForm) { 
     FormToolkit toolkit = managedForm.getToolkit(); 
     ScrolledForm form = managedForm.getForm(); 
     Composite formBody = form.getBody(); 
     formBody.setLayout(new GridLayout()); 

     form.setText("Some Title"); 
     toolkit.decorateFormHeading(form.getForm()); 

     SashForm sfForm = new SashForm(formBody, SWT.VERTICAL); 
     sfForm.setLayout(new GridLayout()); 
     sfForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

     Section topSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE); 
     topSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
     topSection.setText("Section 1 Title"); 
     Composite topSectionComposite = toolkit.createComposite(topSection); 
     topSectionComposite.setLayout(new GridLayout()); 
     toolkit.createLabel(topSectionComposite, "Just some content. Doesn't need to be much"); 
     Button btn = toolkit.createButton(topSectionComposite, "Create Table Content", SWT.PUSH); 
     btn.addSelectionListener(new SelectionListener() { 
      @Override 
      public void widgetSelected(SelectionEvent e) { 
       for (int i = 0 ; i < 10 ; i++) { 
        tableViewer.add("Element " + i); 
       } 
      } 

      @Override 
      public void widgetDefaultSelected(SelectionEvent e) { 

      } 
     }); 
     topSection.setClient(topSectionComposite); 

     Section bottomSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE); 
     bottomSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
     bottomSection.setText("Section 2 Title"); 
     Composite bottomSectionComposite = toolkit.createComposite(bottomSection); 
     bottomSectionComposite.setLayout(new GridLayout()); 
     bottomSectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
     bottomSection.setClient(bottomSectionComposite); 
     Table table = toolkit.createTable(bottomSectionComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | 
       SWT.V_SCROLL | SWT.H_SCROLL | SWT.RESIZE); 
     table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
     table.setHeaderVisible(true); 

     tableViewer = new TableViewer(table); 
     tableViewer.add("New Element"); 
     new TableColumn(table, SWT.LEFT).setText("Spalte 1"); 

     TableLayout layoutDefault = new TableLayout(); 
     layoutDefault.addColumnData(new ColumnWeightData(1)); 
     table.setLayout(layoutDefault); 

     form.reflow(true); 
    } 
} 

如果您在開始後單擊按鈕,該表看起來就像左圖。在摺疊並展開第二部分後,它看起來像是正確的。

enter image description here

回答

0

- 確保該樹具有SWT.H_SCROLL風格(如果我沒記錯),使得其具有最小尺寸(例如使用網格佈局和的GridData設置到了minHeight X或與TableWrapLayout和資料表身高提示爲X) - 如果您無法使其正常工作,請告訴我,我會嘗試製作代碼;此外,在佈局的畫面將是巨大的

+0

我編輯了我的問題,並提供了一些源代碼來玩和一些截圖 – 2013-03-13 15:39:45

1

這裏是工作的代碼:你只需要調整的樹/表的大小,並確保它不會跨越的垂直空間跨度:

public void createPartControl(Composite parent) { 

    FormToolkit toolkit = new FormToolkit(parent.getDisplay()); 
    final ScrolledForm form = toolkit.createScrolledForm(parent); 
    Composite formBody = form.getBody(); 
    formBody.setLayout(new GridLayout()); 
    form.setText("Some Title"); 
    toolkit.decorateFormHeading(form.getForm()); 

    SashForm sfForm = new SashForm(formBody, SWT.VERTICAL); 
    sfForm.setLayout(new GridLayout()); 
    sfForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

    //top section 
    Section topSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE); 
    topSection.setLayout(new GridLayout()); 
    topSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
    topSection.setText("Section 1 Title"); 
    Composite topSectionComposite = toolkit.createComposite(topSection); 
    topSectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
    topSectionComposite.setLayout(new TableWrapLayout()); 

    toolkit.createLabel(topSectionComposite, "Just some content. Doesn't need to be much"); 
    Button btn = toolkit.createButton(topSectionComposite, "Create Table Content", SWT.PUSH); 
    btn.addSelectionListener(new SelectionListener() { 

     @Override 
     public void widgetSelected(SelectionEvent e) { 
      for (int i = 0 ; i < 10 ; i++) { 
       tableViewer.add("Element " + i); 
      } 
      form.reflow(true); 
     } 

     @Override 
     public void widgetDefaultSelected(SelectionEvent e) { 

     } 
    }); 
    topSection.setClient(topSectionComposite); 

    //bottom section 
    Section bottomSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE); 
    bottomSection.setLayout(new GridLayout()); 
    bottomSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
    bottomSection.setText("Section 2 Title"); 
    Composite bottomSectionComposite = toolkit.createComposite(bottomSection); 
    bottomSectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
    bottomSectionComposite.setLayout(new TableWrapLayout()); 

    Table table = toolkit.createTable(bottomSectionComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | 
      SWT.V_SCROLL | SWT.H_SCROLL | SWT.RESIZE); 

    TableWrapData ttd222 = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB); 
    ttd222.maxHeight =200; 
    table.setLayoutData(ttd222); 
    table.setHeaderVisible(true); 

    tableViewer = new TableViewer(table); 
    tableViewer.add("New Element"); 
    new TableColumn(table, SWT.LEFT).setText("Spalte 1"); 

    TableLayout layoutDefault = new TableLayout(); 
    layoutDefault.addColumnData(new ColumnWeightData(1)); 
    table.setLayout(layoutDefault); 

    bottomSection.setClient(bottomSectionComposite); 
    form.reflow(true); 
} 
相關問題