gpt4 book ai didi

java - 使用 SWT/Jface 进行 SWT 表切换

转载 作者:行者123 更新时间:2023-12-02 07:07:58 25 4
gpt4 key购买 nike

我有一个在应用程序启动时加载的表。该表是在复合中创建的。现在我有另一个功能搜索按钮,它将根据搜索输入填充同一个表。我无法使用搜索结果填充表。是否可以使用 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)

                            }           

数据绑定(bind):

 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"}));

请注意,我只有一张 table 。

最佳答案

通常的解决方案是

  • 只要您想要显示新结果,就调用 view.setInput(...)
  • 使用 IObservableList 作为这两种情况的中间结果列表 - 然后您可以在需要时通过简单地操作列表来替换列表的内容
  • TableViewer 上使用 ViewFilter - 尽管只有当搜索结果是初始内容的正确子集时才能使用此方法

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

关于java - 使用 SWT/Jface 进行 SWT 表切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15872003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com