On Sunday, December 22, 2013 1:32:17 AM UTC+11, Donald Mteka wrote:
Glad you fixed it!!The model would use .equals method to compare the keys returned by the ProvidesKey to determine whether an object is contained in its selected set.That's correct.That was same thing as creating CompoundKey class if you insisted on maintaining that picture of a key..
infact your 'notion' of the key is the only thing that changed, from 'combination of id&no' to the array Object itself!
It works because by returning the key as the array object itself, not only should obj1.equals(obj2) return true, but obj1 == obj2 alse.
On Sat, Dec 21, 2013 at 5:20 PM, Tom <Henr...@gmail.com> wrote:
hi, i haven't try ur method but i fixed,first, just use item[]
public Object getKey(String[] item) {return item == null ? null : item;}& thenpublic Boolean getValue(String[] object) {return selectionModel.isSelected(object); }thenb usecellTable.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:this.no=no;this.id=id;private String id;public class CompoundKey{Ok, the following changes should fix your problem:1) Crate a class CompoundKey, or similarly, overriding the equals method as follows
private String no;public CombinedKey(String id, String 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 columnso how to fix?
On Sunday, December 22, 2013 12:43:04 AM UTC+11, Donald Mteka wrote:And as a side note, your null check in ProvidesKey implementation is insignificant as the NullPointerException would have been already thrown at line: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.
RegardsString[] itemArr={item[0],item[1]};
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 - cool3Now, 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, the
selectionModel
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(obje ctArr); } }; cellTable.setSelectionModel(se lectionModel); CheckboxHeader selectAllCheckBoxHeader = new CheckboxHeader(); selectAllCheckBoxHeader.addVal ueChangeHandler(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(it em)) { System.out.println(Arrays.toSt ring(item)); selectionModel.setSelected(ite m, true); } } } }); cellTable.addColumn(checkColum n, selectAllCheckBoxHeader); When I clikced the selectAll, then non of visible checkBoxes got check, but when printout
Set<String[]> selSet=selectionModel.getSelec
tedSet(); 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 selectedNote: I also tried
cellTable.setSelectionMo
but not working.del(selectionModel, DefaultSelectionEventManager.< String[]> createCheckboxManager()); To post to this group, send email to google-we...@googlegroups.com.--
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 .
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-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-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