Thomas,

Thanks again for pointing me in the right direction.  It ended up
being a bit more involved than I expected, but it seems to be working
ok.  Here's the code for anyone else who might be interested:

    private final CellList<String> m_cellList =
        new CellList<String>(new TextCell());

    private DefaultSelectionEventManager<String>
m_selectionEventManager;

    private HandlerRegistration m_selectionChangeHandler;

    private boolean m_multiple;

    private void setEnabled(boolean p_enabled)
    {
        if (p_enabled)
            m_selectionEventManager =
                DefaultSelectionEventManager.createDefaultManager();
        else
            m_selectionEventManager =
 
DefaultSelectionEventManager.createBlacklistManager(0);
        setMultipleSelect(m_multiple);
    }

    public void setMultipleSelect(boolean p_multiple)
    {
        Set<String> selectedItems = getSelectedItems();
        AbstractSelectionModel<String> selectionModel;
        if (p_multiple)
        {
            selectionModel = new MultiSelectionModel<String>();
            m_cellList.setKeyboardSelectionPolicy(ENABLED);
        }
        else
        {
            selectionModel = new SingleSelectionModel<String>();
            m_cellList.setKeyboardSelectionPolicy(BOUND_TO_SELECTION);
        }
        m_cellList.setSelectionModel(selectionModel,
m_selectionEventManager);
        if (selectedItems != null)
        {
            Iterator<String> iter = selectedItems.iterator();
            while (iter.hasNext())
                selectionModel.setSelected(iter.next(), true);
        }
        if (m_selectionChangeHandler != null)
            m_selectionChangeHandler.removeHandler();
        m_selectionChangeHandler =
            selectionModel.addSelectionChangeHandler(this);
        m_multiple = p_multiple;
    }

    @SuppressWarnings("unchecked")
    public Set<String> getSelectedItems()
    {
        Set<String> set = new HashSet<String>();
        if (m_cellList.getSelectionModel() == null)
        {
            return set;
        }
        else if (m_multiple)
        {
            MultiSelectionModel<String> model =
 
(MultiSelectionModel<String>)m_cellList.getSelectionModel();
            set = model.getSelectedSet();
        }
        else
        {
            SingleSelectionModel<String> model =
 
(SingleSelectionModel<String>)m_cellList.getSelectionModel();
            String item = model.getSelectedObject();
            if (item != null)
                set.add(item);
        }
        return set;
    }

On Jun 16, 3:01 pm, Thomas Broyer <[email protected]> wrote:
> On Thursday, June 16, 2011 11:44:56 PM UTC+2, Jim Douglas wrote:
>
> > I'm getting slightly overwhelmed by the infrastructure required to
> > manage a CellList, so I might be missing something really simple.  How
> > do I set a CellList so that users can't change the selection with the
> > keyboard or mouse, while leaving programmatic selection in place
> > (which might be either MultiSelectionModel or SingleSelectionModel)?
>
> You can use setCellEventPreviewHandler to control how selection is handled;
> notably by passing a DefaultSelectionEventManager, for instance a custom one
> (createCustomManager) whose 
> EventTranslator<http://google-web-toolkit.googlecode.com/svn/javadoc/2.3/com/google/g...>
>  always
> returns false from clearSelection and IGNORE from translateSelectionEvent.
> (not tested, but I guess it should work)
>
> > And a marginally related subject -- is there no default UI for
> > managing multi-selection?  If I define an HTML select widget (GWT
> > ListBox) for multiple selection, there's a standard UI (hold down a
> > modifier key while clicking the mouse).
>
> The default behavior should allow it (provided you use a
> MultiSelectionModel, of course): Ctrl+Click to toggle an item to add/remove
> from the current selection, Shift+Click for the whole range between the
> current "anchor" (last place clicked without "shift" pressed) and the
> clicked row. It should also work with the keyboard: up/down to move, space
> to change selection (with Ctrl or Shift to add/remove a single item or range
> of items)
> This is the behavior of DefaultSelectionEventManager.createDefaultManager(),
> which is the default behavior of any AbstractHasData.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to