2014-12-23 2 views
0

Я создал папку вкладок и создал некоторые вкладки, а на вкладках у меня есть композит, который содержит список. Так что у меня есть текстовое поле, поэтому, когда строка набирается в текстовом поле, и кнопка поиска нажата, чтобы отобразить список shoul, содержащий строку, как это можно сделать.Как искать строку в списке при нажатии кнопки в swt

Код для создания текстового поля и найти кнопку следующего

public void postConstruct (Composite parentComposite) { 
     parentComposite.setLayout(new GridLayout(1, true)); 

     Composite topComposite = new Composite(parentComposite, SWT.NONE); 
     topComposite.setLayout(new GridLayout(2, false)); 
     topComposite.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, true)); 

     Composite bottomComposite = new Composite(parentComposite, SWT.NONE); 
     GridData bottomCompositeGD = new GridData(SWT.FILL, SWT.BOTTOM, true, false); 
     bottomCompositeGD.heightHint = 100; 
     bottomComposite.setLayout(new GridLayout(2, false)); 
     bottomComposite.setLayoutData(bottomCompositeGD); 

     Composite topLeftComposite = new Composite(topComposite, SWT.NONE); 
     topLeftComposite.setLayout(new GridLayout(1, false)); 
     topLeftComposite.setLayoutData(new GridData(SWT.FILL, GridData.FILL, false, true)); 

     Composite topRightComposite = new Composite(topComposite, SWT.NONE); 
     topRightComposite.setLayout(new GridLayout(1, false)); 
     topRightComposite.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, true)); 

       Composite findTCComposite = new Composite(topRightComposite, SWT.NONE); 
     findTCComposite.setLayout(new GridLayout(2, true)); 
     findTCComposite.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, false)); 

     txtFindTC = new Text(findTCComposite, SWT.BORDER | SWT.WRAP | SWT.SINGLE); 
     txtFindTC.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, false)); 


Button btnFindTC = new Button(findTCComposite, SWT.NONE); 
     btnFindTC.setLayoutData(new GridData(SWT.BEGINNING, GridData.BEGINNING, false, false)); 
     btnFindTC.setText("Find TC"); 

TabFolder tabFolder = new TabFolder(topRightComposite, SWT.NONE); 
     tabFolder.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, true)); 

     TabItem itemBasicTC = new TabItem(tabFolder, SWT.NONE); 
     itemBasicTC.setText("Basic TCs"); 

     createListViewBasicTc(tabFolder,itemBasicTC); 


} 



the the tab is created is below 
private void createListViewBasicTc(Composite composite,TabItem itemBasicTC){ 
     final List list = new List(composite, SWT.BORDER); 
     itemBasicTC.setControl(list); 

     creatingDragSource(list); 
     //final java.util.List<String> listSort = new ArrayList<String>(); 
     //for(int i = 1; i <=10 ; i++) 
      list.add("TestCase   
      list.add("Test_)"); 
      list.add("something"); 


    } 

так что теперь, когда пользователь «некоторые» в текстовом поле и нажмите кнопку поиска в закладке должны отображаться на вкладке только «что-то» . Как это можно сделать.

ответ

0

Try что-то вроде этого

button.addListener (SWT.Selection, new Listener() 
{ 


    public void handleEvent(Event e) { 
     //This depends on your search criteria 
     String search = "A"; 
     Boolean found = false; 
     for (String str : list) { 
      if (str.trim().contains(search)) { 
       return true; 
      } 
     } 
     if (!found) { 
      return false; 
     } 
    } 

}); 
Смежные вопросы