Is it possible in Tapestry 5.3.6 display tooltip (title) in palette component if the option text is too long to be displayed? I am interested in cases where option texts are almost identical, but they differ in last characters which are not visible.
You just need to add custom attribute(title
) to select model options. To do this you need to add your own OptionModel
implementation:
public class CustomOptionModel implements OptionModel {
private final String label;
private final Object value;
private final Map<String, String> attributes;
public CustomOptionModel(final String label,
final Object value,
final String tooltip) {
this.label = label;
this.value = value;
if (tooltip != null) {
attributes = new HashMap<String, String>();
attributes.put("title", tooltip);
} else {
attributes = null;
}
}
public String getLabel() {
return label;
}
public boolean isDisabled() {
return false;
}
public Map<String, String> getAttributes() {
return attributes;
}
public Object getValue() {
return value;
}
}
And the last thing is to attach select model to palette:
public SelectModel getMySelectModel() {
final List<OptionModel> options = new ArrayList<OptionModel>();
options.add(new CustomOptionModel("First", 1, "First Item"));
options.add(new CustomOptionModel("Second", 2, "Second Item"));
options.add(new CustomOptionModel("Third", 3, "Third Item"));
return new SelectModelImpl(null, options);
}