PDA

View Full Version : ExtendedCheckBoxSelectionModel



Arno.Nyhm
30 Sep 2009, 3:28 AM
a little bit like this but also for GridSelectionModel

ReversedGridSelectionModel
http://www.extjs.com/forum/showthread.php?t=78522


its a drop in replacement for CheckBoxSelectionModel

new parameters
setCheckBoxOnly(true) - only checkboxes are trigger a selection change
setCheckBoxSynchronized(true) - let clicks in the list act the same like click the checkbox


PS:
i dont like my new names so very much. there are some better suggestions for naming?



/*
*
* @author anonym
*/
package com.mycompany.myapplication.client.gui.components;

import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.google.gwt.user.client.Event;
import java.util.Arrays;

/**
* A grid selection model and component plugin. To use, add the column config to
* the column model using {@link #getColumn()} and add this object to the grids
* plugin.
* added more settings
*
* @param <M> the model data type
*/
public class ExtendedCheckBoxSelectionModel<M extends ModelData> extends CheckBoxSelectionModel<M> {

private boolean checkBoxOnly = false;
private boolean checkBoxSynchronized = false;

public ExtendedCheckBoxSelectionModel() {
super();
}

@Override
protected void handleMouseDown(GridEvent e) {
if (checkBoxOnly || checkBoxSynchronized) {
if (e.getEvent().getButton() == Event.BUTTON_LEFT && ((checkBoxSynchronized && !checkBoxOnly) || e.getTarget().getClassName().equals("x-grid3-row-checker"))) {
M m = listStore.getAt(e.getRowIndex());
if (m != null) {
if (isSelected(m)) {
doDeselect(Arrays.asList(m), false);
} else {
doSelect(Arrays.asList(m), true, false);
}
}
}
} else {
super.handleMouseDown(e);
}
}

/**
* this is true if only the CheckBox can be clicked to toggle a Selection
* @return checkBoxOnly
*/
public boolean isCheckBoxOnly() {
return checkBoxOnly;
}

/**
* Set this to true if only the CheckBox can be clicked to toggle a Selection
* default: false
* @param checkBoxOnly
*/
public void setCheckBoxOnly(boolean checkBoxOnly) {
this.checkBoxOnly = checkBoxOnly;
}

/**
* this is true if clicking in the list is the same as clicking on the checkbox
* @return checkBoxSynchronized
*/
public boolean isCheckBoxSynchronized() {
return checkBoxSynchronized;
}

/**
* Set this to true to act with clicking in the list the same as clicking on the checkbox
* default: false
* @param checkBoxSynchronized
*/
public void setCheckBoxSynchronized(boolean checkBoxSynchronized) {
this.checkBoxSynchronized = checkBoxSynchronized;
}
}

kolli
4 Dec 2009, 11:35 AM
Thanks a lot buddy..
This was really helpful..