Results 1 to 3 of 3

Thread: [FIXED] selected is null in MultiTreeSelectionModel

  1. #1
    Ext User
    Join Date
    Apr 2008
    Posts
    18
    Vote Rating
    0
      0  

    Default [FIXED] selected is null in MultiTreeSelectionModel

    A NullPointerException is thrown when you try to select an item in a Tree or TreeTable that is using a MultiTreeSelectionModel. It appears that the "selected" List has not been initialized in the doSelect method. (Line 69 in beta 2.)

  2. #2
    Ext User
    Join Date
    May 2008
    Posts
    1
    Vote Rating
    0
      0  

    Default Workaround

    You may override MultiTreeSelectionModel in your eclipse project, waiting for an official fix from ExtJS team.

    /*
    * Ext GWT - Ext for GWT
    * Copyright(c) 2007, 2008, Ext JS, LLC.
    * licensing@extjs.com
    *
    * http://extjs.com/license
    */
    package com.extjs.gxt.ui.client.widget.tree;

    import java.util.ArrayList;
    import java.util.List;

    import com.extjs.gxt.ui.client.Events;
    import com.extjs.gxt.ui.client.event.TreeEvent;
    import com.extjs.gxt.ui.client.widget.Items;

    /**
    * Multi-select tree selection model.
    */
    public class MultiTreeSelectionModel extends SingleTreeSelectionModel {

    protected List<TreeItem> selected = new ArrayList<TreeItem>(); // fix1

    /**
    * Returns the selected items.
    *
    * @return the items
    */
    public List<TreeItem> getSelectedItems() {
    return new ArrayList<TreeItem>(selected);
    }

    /**
    * Selects the item(s).
    *
    * @param items the item(s)
    */
    public void select(List<TreeItem> items) {
    doSelect(new Items(items), false, true);
    }

    @Override
    public void selectAll() {
    doSelect(new Items(tree.getAllItems()), false, false);
    }

    protected void doDeselectAll(boolean supressEvent) {
    boolean change = selected.size() > 0;
    for (TreeItem item : selected) {
    onSelectChange(item, false);
    }
    selected.clear();
    if (change && !supressEvent) {
    tree.fireEvent(Events.SelectionChange, new TreeEvent(tree));
    }
    }

    @Override
    protected void onRemove(TreeItem item) {
    if (selected.contains(item)) {
    deselect(item);
    }
    }

    protected void doSelect(Items<TreeItem> items, boolean keepExisting,
    boolean supressEvent) {
    boolean change = false;
    if (!keepExisting) {
    if (selected.size() > 0) {
    change = true;
    }
    doDeselectAll(false);
    }
    for (TreeItem item : items.getItems(tree)) { // fix2
    TreeEvent e = new TreeEvent(tree, item);
    if (item.fireEvent(Events.BeforeSelect, e)) {
    change = true;
    onSelectChange(item, true);
    selected.add(item);
    lastSelected = item;
    item.fireEvent(Events.Select, e);
    }

    }
    if (change && !supressEvent) {
    TreeEvent e = new TreeEvent(tree);
    e.selected = selected;
    tree.fireEvent(Events.SelectionChange, e);
    }
    }
    }

  3. #3
    Sencha User darrellmeyer's Avatar
    Join Date
    May 2007
    Location
    Washington, DC
    Posts
    2,242
    Vote Rating
    2
      0  

    Default

    Fix is in SVN.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •