简体   繁体   中英

A dialog that allows a single selection in eclipse plugin

I would like to create a list dialog that will only allowed a single selection from a list of options ListSelectionDialog seems like a good option, but I could not find a way to restrict it to a single option, or change it to radio buttons.

I read the followings, and could not find any indication on how to do so: https://dzone.com/articles/discover-eclipses-jface-dialog

http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fui%2Fdialogs%2Fpackage-summary.html

If you write a class derived from ListSelectionDialog you can call the getViewer() method to get the CheckboxTableViewer the dialog uses.

You could then add a check state listener to force a single selection:

CheckboxTableViewer viewer = getViewer();
viewer.addCheckStateListener(new ICheckStateListener() {
  @Override
  public void checkStateChanged(final CheckStateChangedEvent event) {
    viewer.setCheckedElements(new Object[] { event.getElement() });
  }
});

Although I think this might confuse users expecting a checkbox list to support multiple selection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM