0

I have created a array list and when the list item is selected using mouse down event a listener has to be added for it so how can this be done .The code for which i have created the array list ia as follows

final java.util.List<Object> listSort = new ArrayList<>();
for(String key: descriptionMappernewer.keySet())
    listSort.add(key);

final MyFilter filter = new MyFilter();

final ListViewer viewer = new ListViewer(this);
//viewer.getList();
viewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
//viewer.getList();
viewer.setContentProvider(new ArrayContentProvider());
viewer.setInput(listSort); 

and now I need to add mouse down event listener for it. Earlier I had written the mouse event listener of SWT but that has to changed now. The earlier SWT listener looks like this

list.addListener(SWT.Selection, new Listener(){
      public void handleEvent(Event e) {
          int index =  list.getSelectionIndex();
          txtMethodDescription.setText(descriptionMappernewer.get( list.getItem(index)));
      }
});

So please help me how can we add the listener to array list of java.util.List

1 Answer 1

3

java.util.List is not a user interface object and does not support listeners.

The user interface object in your code is the ListViewer. Since this is a JFace object it uses addSelectionListener for selections:

viewer.addSelectionChangedListener(new ISelectionChangedListener()
  {
    @Override
    public void selectionChanged(final SelectionChangedEvent event)
    {
      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();

      txtMethodDescription.setText(descriptionMappernewer.get(selection.getFirstElement())));
    }
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.