}
}
}
});
ContentPanel main = new ContentPanel();
main.setBorders(true);
main.setBodyBorder(false);
main.setLayout(new FitLayout());
main.setHeaderVisible(false);
ToolBar bar = new ToolBar();
bar.add(new LabelToolItem("Filter:"));
StoreFilterField<BeanModel> field = new StoreFilterField<BeanModel>() {
@Override
protected boolean doSelect(Store<BeanModel> store, BeanModel parent, BeanModel record, String property,
String filter) {
Photo photo = record.getBean();
String name = photo.getName().toLowerCase();
if (name.indexOf(filter.toLowerCase()) != -1) {
return true;
}
return false;
}
@Override
protected void onFilter() {
super.onFilter();
view.getSelectionModel().select(0, false);
}
};
field.setWidth(100);
field.bind(store);
bar.add(field);
bar.add(new SeparatorToolItem());
bar.add(new LabelToolItem("Sort By:"));
sort = new SimpleComboBox<String>();
sort.setTriggerAction(TriggerAction.ALL);
sort.setEditable(false);
sort.setForceSelection(true);
sort.setWidth(90);
sort.add("Name");
sort.add("File Size");
sort.add("Last Modified");
sort.setSimpleValue("Name");
sort.addListener(Events.Select, new Listener<FieldEvent>() {
public void handleEvent(FieldEvent be) {
sort();
}
});
bar.add(sort);
main.setTopComponent(bar);
view = new ListView<BeanModel>() {
@Override
protected BeanModel prepareData(BeanModel model) {
Photo photo = model.getBean();
long size = photo.getSize() / 1000;
model.set("shortName", Format.ellipse(photo.getName(), 15));
model.set("sizeString", NumberFormat.getFormat("#0").format(size) + "k");
model.set("dateString", DateTimeFormat.getMediumDateTimeFormat().format(photo.getDate()));
model.set("modPath", GWT.getHostPageBaseURL() + photo.getPath());
return model;
}
};
view.setId("img-chooser-view");
view.setTemplate(getTemplate());
view.setBorders(false);
view.setStore(store);
view.setItemSelector("div.thumb-wrap");
view.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
view.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<BeanModel>>() {
public void handleEvent(SelectionChangedEvent<BeanModel> be) {
onSelectionChange(be);
}
});
main.add(view);
details = new LayoutContainer();
details.setBorders(true);
details.setStyleAttribute("backgroundColor", "white");