0

我有在应用程序启动时加载的表。此表是在复合中创建的。现在我有另一个功能搜索按钮,它将根据搜索输入填充同一个表。我无法用搜索结果填充表格。是否可以根据使用 SWT/Jface 的功能(在应用程序启动/搜索结果时加载)在同一个表中进行切换。例如应用程序启动时的表值显示

 m_workplaceViewer = new TableViewer(table);


               String[] workplace_titles= new String[]{"Code","Plant","Compy Reg Num","Num Of Employees","Type of industry","Type of products/service", "Representative","Main Phone","Phone 1","Phone 2","Fax", "Zip Code",
                        "Address 1","Address 2","Email","HomePage","Note 1","Note 2","Note 3","Note 4","Note 5"};


                for (int i = 0; i < 21; i++){

                 TableViewerColumn column_workplace = new TableViewerColumn(m_workplaceViewer,
                         SWT.NONE);                     
                column_workplace.getColumn().setWidth(75);
                column_workplace.getColumn().setText(workplace_titles[i]);              

               }   

                try {
                    workplaceDetailList= workplaceDaoImpl.getWorkplaceDetails();
                } catch (SQLException e3) {
                    // TODO Auto-generated catch block
                    e3.printStackTrace();
                }

对于搜索按钮

btnSearch.addListener(SWT.Selection, new Listener() {
                    public void handleEvent(Event event) {

                        String plant=text_workplace.getText();
                        System.out.println("Select Me : " + plant);

                        IStructuredSelection selection = (IStructuredSelection) m_workplaceViewer
                                .getSelection();
                        if (selection.getFirstElement() instanceof WorkplaceDetail) {
                         workplaceDetail = (WorkplaceDetail) selection.getFirstElement();
                        }
                         System.out.println("Start Search--2");

                        if (plant!=""){ 
                             table.removeAll();
                            workplaceDetailList=workplaceDaoImpl.getWorkplaceDetailsSearchByPlant(plant);

m_workplaceViewer.setInput(workplaceDetailList)

                            }           

数据绑定:

 ObservableListContentProvider m_personViewerContentProviderList1 = new ObservableListContentProvider();
             m_workplaceViewer.setContentProvider(m_personViewerContentProviderList1);

             IObservableList input = 
                       Properties.selfList(WorkplaceDetail.class).observe(workplaceDetailList);
            m_workplaceViewer.setInput(input);  

             ViewerSupport.bind(m_workplaceViewer,
                     input,
                    BeanProperties.values(new String[] {"code","plant","compRegNum","numOfEmps","typeIndst",
                            "typeProd","employee.empName","address.mainPhone","address.phone1","address.phone2",
                            "address.fax", "address.zip", "address.add1", "address.add2","address.empEmail",
                            "address.homepage","note1", "note2", "note3", "note4", "note5"}));

请不要说我只有一张桌子。

4

1 回答 1

2

通常的解决方案是

  • view.setInput(...)每当您有要显示的新结果时调用
  • 使用 anIObservableList作为两种情况的中间结果列表 - 然后您可以在需要时通过简单地操作列表来替换列表的内容
  • 使用 a ViewFilteron the TableViewer- 虽然只有当搜索结果是初始内容的适当子集时才能使用此方法

我通常使用后一种方法,主要是因为我可以将 UI 与业务逻辑完全分离,这可以使应用程序更容易测试:-)

于 2013-04-08T06:19:38.680 回答