YList does not currently support multiple selections.
Anyway, you may set the list model (possible values of the list) by calling setListModel method. Data may be any JavaBeans. The selected row object is mapped to YModel. Let's say your list data is Collection of Dogs, then you should have "private Dog selectedDog" in your YModel. Or you may use YList.setModelField to map only certain field of Dog to YModel. For example, setModelField("name") would map Dog.getName() to YModel field "private String name". Also, set the list MVC_NAME to "selectedDog" or "name"
Hope you will get the idea. Anyway, multiple selections is currently supported in YDualList, which works in similar way as YList.
Tomi
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The suggestion given by you does not really fulfil my requirement. My requirement is to be able to select multiple values.
Can you suggest me what is the data structure that can be used for the "YDualList"? and how can I write a method in the controller which gets invoked when any selection is made in that list e.g. buttonNamePressed() for button with name "buttonName" and comboBoxChanged() for comboBox with name "comboBox".
Ashish.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
YDualList is a component that has similar list model as YList and YComboBox. Selections are linked to another YModel Collection. YDualList is combination of two YPlainLists. You can listen to list changes to overriding viewChanged in YController or by implementing method public void myDualListChanged() (where myDualList is components MVC_NAME).
Alternatively, if you don't like the YDualList layout, you could try cloods version of YList (looks quite interesting, I'm now sure how it works but I will to check it out). Or then create your own implementation of YList listening to multiple selections. I could add this support to the next version of TikeSwing, but that will take some time.
Tomi
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
in my opinion:
if you use YList, your Model can be a Collection of pojo and it rapresents the selection in the list.
if you use YPlainList your Model can be a Collection of pojo, and it rapresents the elements of list.
If you are interested in List with two models, one for selection and one for elements, I have developed this:
public class YExtendedList extends YList implements
YIExtendedModelComponent {
/**
* Sets internal model for this list.
*
* @param data
* the collection of POJOs
* @param formatter
* defines how a list item is showed to user
* @param sort
* if items will be sorted according to the interface String
* presentation
*/
public void setListModel(Collection data, YFormatter formatter, boolean sort) {
originalListModel = data;
this.formatter = formatter;
this.sort = sort;
super.setListModel(data, formatter, sort);
}
public String getListModelField() {
return listModelField;
}
public void setListModelField(String listModelField) {
this.listModelField = listModelField;
}
public YFormatter getFormatter() {
return formatter;
}
public void setFormatter(YFormatter formatter) {
this.formatter = formatter;
}
public boolean isSort() {
return sort;
}
public void setSort(boolean sort) {
this.sort = sort;
}
}
Bye
clood
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I wanted to use multiple selection box and I guess the obvious choice was "YList".
But I am not sure, what datatype to use in order to map it in the Model.
e.g. for YComboBox -> String
YTable -> Collection
I could not find mapping datatype for the "YList"
Please help me with this. This is very urgent.
Ashish.
YList does not currently support multiple selections.
Anyway, you may set the list model (possible values of the list) by calling setListModel method. Data may be any JavaBeans. The selected row object is mapped to YModel. Let's say your list data is Collection of Dogs, then you should have "private Dog selectedDog" in your YModel. Or you may use YList.setModelField to map only certain field of Dog to YModel. For example, setModelField("name") would map Dog.getName() to YModel field "private String name". Also, set the list MVC_NAME to "selectedDog" or "name"
Hope you will get the idea. Anyway, multiple selections is currently supported in YDualList, which works in similar way as YList.
Tomi
Hi Tomi,
The suggestion given by you does not really fulfil my requirement. My requirement is to be able to select multiple values.
Can you suggest me what is the data structure that can be used for the "YDualList"? and how can I write a method in the controller which gets invoked when any selection is made in that list e.g. buttonNamePressed() for button with name "buttonName" and comboBoxChanged() for comboBox with name "comboBox".
Ashish.
YDualList is a component that has similar list model as YList and YComboBox. Selections are linked to another YModel Collection. YDualList is combination of two YPlainLists. You can listen to list changes to overriding viewChanged in YController or by implementing method public void myDualListChanged() (where myDualList is components MVC_NAME).
Alternatively, if you don't like the YDualList layout, you could try cloods version of YList (looks quite interesting, I'm now sure how it works but I will to check it out). Or then create your own implementation of YList listening to multiple selections. I could add this support to the next version of TikeSwing, but that will take some time.
Tomi
Hi,
in my opinion:
if you use YList, your Model can be a Collection of pojo and it rapresents the selection in the list.
if you use YPlainList your Model can be a Collection of pojo, and it rapresents the elements of list.
If you are interested in List with two models, one for selection and one for elements, I have developed this:
public class YExtendedList extends YList implements
YIExtendedModelComponent {
private String listModelField;
private Collection originalListModel;
private YFormatter formatter;
private boolean sort;
public String[] getExtendedFields() {
if (listModelField == null)
return new String[0];
return new String[] { listModelField };
}
public Object getModelValue(String field) throws Exception {
if (field.equals(listModelField)) {
return originalListModel;
}
return null;
}
public void setModelValue(String field, Object value) throws Exception {
if (field.equals(listModelField)) {
Object obj = getModelValue();//returns selected values
setListModel((Collection) value,this.formatter,this.sort);
setModelValue(obj);
}
}
/**
* Sets internal model for this list.
*
* @param data
* the collection of POJOs
* @param formatter
* defines how a list item is showed to user
* @param sort
* if items will be sorted according to the interface String
* presentation
*/
public void setListModel(Collection data, YFormatter formatter, boolean sort) {
originalListModel = data;
this.formatter = formatter;
this.sort = sort;
super.setListModel(data, formatter, sort);
}
public String getListModelField() {
return listModelField;
}
public void setListModelField(String listModelField) {
this.listModelField = listModelField;
}
public YFormatter getFormatter() {
return formatter;
}
public void setFormatter(YFormatter formatter) {
this.formatter = formatter;
}
public boolean isSort() {
return sort;
}
public void setSort(boolean sort) {
this.sort = sort;
}
}
Bye
clood