java - Conflict of "addSelectionChangedListener" and "addDoubleClickListener" for TableViewer -
all related
with jface tableviewer
, want select entry(e.g select file) single-click, , other operations(e.g go directory) double-click.
noticing addselectionchangedlistener()
, adddoubleclicklistener()
via webpage: http://javafact.com/2010/08/07/example-tableviewer-events/ , add selectionchangedlistener
, doubleclicklistener
tableviwer
, , find out: either of 2 listeners can work, can't work - it's doubleclicklistener
can't work.
what's problem? how should implement listeners single-click , double-clicks? comments appreciated.
about code: created tableviewer, , want show filesystem structure. expected behavior: user can double click directory entry , tableviewer show structure of selected directory; user select generic file single-click. other operations, warning message dialog shown.
the following code related event handlers.
tableview.addselectionchangedlistener( new iselectionchangedlistener() { public void selectionchanged(selectionchangedevent event) { istructuredselection sel = (istructuredselection) tableview.getselection(); file selfile = (file) sel.getfirstelement(); if(selfile != null){ if (selfile.isdirectory()) { messagedialog.openwarning(getshell(), "warning", "you select directory"); return; } system.out.println("selected : "+ selfile.getabsolutepath()); selectfilename = selfile.getabsolutepath(); } } }); tableview.adddoubleclicklistener( new idoubleclicklistener() { @override public void doubleclick(doubleclickevent arg0) { object selected; istructuredselection selection = (istructuredselection) tableview.getselection(); if (selection.size() != 1) return; selected = selection.getfirstelement(); file file = (file) selected; if (file.isfile()) { messagedialog.openinformation(getshell(),"warning", "you double-clicks generic file"); return; } if (file.isdirectory()) { system.out.println("clicked direcotry: " + file.getabsolutepath()); //applynewdirectory(file); } } });
regards & sunzen
(prolog: still working jface/swt here, might of interest someone)
the problem api allows this, not work (oh swt...). cannot have both listeners on tableview, selectionchangedlistener grab click , consume event.
the solution attach selectionchangedlistener underlying table, , doubleclicklistener tableviewer. way can have both, e.g.:
table.addselectionchangedlistener(new iselectionchangedlistener(...)); tableviewer.adddoubleclicklistener(new idoubleclicklistener(...));
Comments
Post a Comment