Saturday, December 21, 2013

Re: binding MultiSelectionModel to checkBoxColumn in CellTable, but why checkBoxs in column were not AUTO-selected CORRESPONDINGLY to SelectionModel?

hi, i haven't try ur method but i fixed,
first, just use item[]
public Object getKey(String[] item) {
     return item == null ? null : item;
}


& then 
public Boolean getValue(String[] object) {
     return selectionModel.isSelected(object);
}

thenb use 
cellTable.setSelectionModel(selectionModel, DefaultSelectionEventManager.<String[]> createCheckboxManager());

Finally, it work as i expected

On Sunday, December 22, 2013 1:13:30 AM UTC+11, Donald Mteka wrote:
Ok, the following changes should fix your problem:
1) Crate a class CompoundKey, or similarly, overriding the equals method as follows
public class CompoundKey{
    private String id;
   private String no;
    public CombinedKey(String id, String no){
     this.id=id;
     this.no=no;
    }

  public boolean equals(Object other){
    if(!(other instanceof CompoundKey))return false;

   CompoundKey otherCK=(CompoundKey)other;
  return this.id.equals(otherCK.id) && this.no.equals(otherCK.no);
  }
 
 }

2)Implement ProvidesKey's getKey method as:
 public Object getKey(String[] object){
  return new CompoundKey(object[0],object[1]);
 }

3)Implement CheckBox column's getValues method as:
  public Object getValue(String[] object){
  return model.isSelected(object);
}
 
HTH,


On Sat, Dec 21, 2013 at 4:57 PM, Tom <Henr...@gmail.com> wrote:
The unique key is the combination of ID and No column
so how to fix?


On Sunday, December 22, 2013 12:43:04 AM UTC+11, Donald Mteka wrote:
Hello Tom,
 your problem stems from the use of newly created array objects in your ProvidesKey and checkbox Column implementations. These array objects returned for getKey(..)  and getValue(...) would never equal any other! Hence model.isSelected(..) will always return false.

 And as a side note, your null check in ProvidesKey implementation is insignificant as the NullPointerException would have been already thrown at line:
 
String[] itemArr={item[0],item[1]};
Regards



On Sat, Dec 21, 2013 at 4:08 PM, Tom <Henr...@gmail.com> wrote:

Here is my problem. I have simple table with 3 columns (Id, no, text) Id and no combination creates a unique key for each row.

Id - no - text  12 - 1 - my text1  12 - 2 - my text2  13 - 1 - cool  13 - 2 - cool2  13 - 3 - cool3  

Now, i want to load these data into a CellTable with 4 columns (the 1st column is checkBoxColumn, the other 3 columns are ID/No/Text textcolum. I also want to put a SelectAllCheckBox on the Header of checkBoxColumn so that when user click on selectAllCheckBox then all the current visible checkBoxes got selected (of cause celltable could have many page but it will select only the visible ones).

Here is the code, i finished all the requirements except 1, that is "when i clicked the selectAllCheckBox, theselectionModel got selected but the correspondingly checkBoxes were not selected.

Here is the Code.

public static final ProvidesKey<String[]> KEY_PROVIDER = new ProvidesKey<String[]>() {        @Override        public Object getKey(String[] item) {          String[] itemArr={item[0],item[1]};          return item == null ? null : itemArr;          }  };  

Here is the main CrllTable code:

final MultiSelectionModel<String[]> selectionModel = new MultiSelectionModel<String[]>(KEY_PROVIDER);    final CellTable<String[]> cellTable = new CellTable<String[]>();    Column<String[], Boolean> checkColumn = new Column<String[], Boolean>(                  new CheckboxCell(true, false)) {          @Override          public Boolean getValue(String[] object) {                  // Get the value from the selection model.                   String[] objectArr={object[0],object[1]};                     return selectionModel.isSelected(objectArr);                 }   };     cellTable.setSelectionModel(selectionModel);   CheckboxHeader selectAllCheckBoxHeader = new CheckboxHeader();   selectAllCheckBoxHeader.addValueChangeHandler(new ValueChangeHandler(){                @Override              public void onValueChange(ValueChangeEvent event) {                  // TODO Auto-generated method stub                  System.out.println("test");                  for (String[] item : cellTable.getVisibleItems()) {                          if (!selectionModel.isSelected(item)) {                          System.out.println(Arrays.toString(item));                        selectionModel.setSelected(item, true);                        }                  }              }      });    cellTable.addColumn(checkColumn, selectAllCheckBoxHeader);  

When I clikced the selectAll, then non of visible checkBoxes got check, but when printout

Set<String[]> selSet=selectionModel.getSelectedSet();  for(String[] s : selSet){    System.out.println("Mine: "+Arrays.toString(s));  }  

it showed the currect selected items

Suppose pageSize is 3, then Output :

Mine: [12,1,my text1]  Mine: [12,2,my text2]  Mine: [13,1,cool]  

So how to make visible checkBoxes got selected automatically EXACTLY and CORESPONDINGLY /In TANDEM as the selectionModel got selected

Note: I also tried cellTable.setSelectionModel(selectionModel, DefaultSelectionEventManager.<String[]> createCheckboxManager()); but not working.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.



--
Donald Mteka
+255653105004

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.



--
Donald Mteka
+255653105004

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment