PDA

View Full Version : [FIXED] selected is null in MultiTreeSelectionModel



kcaseye
7 May 2008, 9:52 AM
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.)

Golinelli
15 May 2008, 1:13 AM
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);
}
}
}

darrellmeyer
19 May 2008, 8:07 AM
Fix is in SVN.