PDA

View Full Version : ReversedGridSelectionModel



Arno.Nyhm
24 Aug 2009, 5:43 AM
if you like your selection like always the ctrl key is pressed to select rows you can use this selection model:


package org.yournamehere.client.gui.components;

import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.GridView;
import java.util.Arrays;

/**
*
* @param <M> the model type contained within the store
* @author anonym
*/
public class ReversedGridSelectionModel<M extends ModelData> extends GridSelectionModel<M> {

@Override
protected void handleMouseDown(GridEvent<M> e) {
if (isLocked()) {
return;
}
if (e.isRightClick()) {
if (e.getRowIndex() != -1) {
if (isSelected(listStore.getAt(e.getRowIndex())) && selectionMode != SelectionMode.SINGLE) {
return;
}
select(e.getRowIndex(), false);
}
} else {
GridView view = grid.getView();
M sel = listStore.getAt(e.getRowIndex());

if (selectionMode == SelectionMode.SINGLE) {
if (isSelected(sel) && e.isControlKey()) {
deselect(sel);
} else if (!isSelected(sel)) {
select(sel, false);
view.focusCell(e.getRowIndex(), e.getColIndex(), true);
}
} else {
if (e.isShiftKey() && lastSelected != null) {
int last = listStore.indexOf(lastSelected);
int index = e.getRowIndex();
int a = (last > index) ? index : last;
int b = (last < index) ? index : last;
select(a, b, e.isControlKey());
lastSelected = listStore.getAt(last);
view.focusCell(index, e.getColIndex(), true);
} else if (isSelected(sel) && !e.isControlKey()) {
doDeselect(Arrays.asList(sel), false);
} else {
if (isSelected(sel) && e.isControlKey()) {
return;
}
doSelect(Arrays.asList(sel), !e.isControlKey(), false);
view.focusCell(e.getRowIndex(), e.getColIndex(), true);
}
}
}
}
}



see http://extjs.com/forum/showthread.php?p=374485#post374485

Arno.Nyhm
30 Sep 2009, 3:29 AM
something similar for CheckboxSelectionModel

ExtendedCheckBoxSelectionModel
http://www.extjs.com/forum/showthread.php?t=81701