|
Processing... Click on a header to sort.
Description & Source Code
demo.zul
<window id="win" title="Car List" border="normal" apply="demo.getting_started.listbox.ListboxController"> <listbox model="${win$composer.carsModel}" checkmark="true" mold="paging" pageSize="9"> <listhead> <listheader width="32px" /> <listheader label="Model" align="center" sort="auto(model)" /> <listheader label="Make" align="center" sort="auto(make)" /> <listheader label="Type" align="center" sort="auto(type)" /> <listheader label="Cost" align="center" sort="auto(cost)" image="/widgets/getting_started/img/dollar.png" /> <listheader label="Displacement" align="center" sort="auto(engineDisplacement)" /> <listheader label="Transmission" align="center" /> <listheader label="Country" align="center" sort="auto(country)" width="130px" /> </listhead> <template name="model"> <listitem> <listcell /> <listcell label="${each.model}" /> <listcell label="${each.make}" /> <listcell label="${each.type}" /> <listcell label="${each.cost}" style="text-align: right"/> <listcell label="${each.engineDisplacement} c.c." style="text-align: right"/> <listcell label="${each.autoTransmission ? 'AT' : 'MT'}" image="/widgets/getting_started/img/${each.autoTransmission ? 'at' : 'mt' }.png" /> <listcell style="text-align: left"> <image src="/widgets/getting_started/img/${each.country}.png" /> <label value="${each.country}" /> </listcell> </listitem> </template> </listbox> </window> ListboxController.java
package demo.getting_started.listbox; import java.util.Set; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.select.SelectorComposer; import org.zkoss.zk.ui.select.annotation.Listen; import org.zkoss.zk.ui.select.annotation.Wire; import org.zkoss.zk.ui.util.Clients; import org.zkoss.zul.ListModel; import org.zkoss.zul.ListModelList; import org.zkoss.zul.Window; import demo.getting_started.Car; import demo.getting_started.CarService; import demo.getting_started.CarServiceImpl; public class ListboxController extends SelectorComposer<Component> { private static final long serialVersionUID = 1L; private ListModel<Car> carsModel; @Wire private Window win; public ListboxController() { CarService carService = new CarServiceImpl(); carsModel = new ListModelList<Car>(carService.findAll()); ((ListModelList<Car>)carsModel).setMultiple(true); } public ListModel<Car> getCarsModel() { return carsModel; } @Listen("onSelect = listbox") public void updateMessage() { Set<Car> selectedCars = ((ListModelList<Car>)carsModel).getSelection(); int size = selectedCars.size(); showNotify(size > 0 ? size + " cars selected: " + selectedCars : "no car selected", win); } private void showNotify(String msg,Component ref){ Clients.showNotification(msg,"info",ref,"top_right",2000); } } Car.java
package demo.getting_started; import java.util.Set; public class Car { private String carId; private String model; private String picture; private String make; private String country; private String type; private double cost; private int engineDisplacement; private boolean autoTransmission; private Accessories accessories; private Set<String> salesmen; public Car() { } public String getCarId() { return carId; } public void setCarId(String carId) { this.carId = carId; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public String getPicture() { return picture; } public void setPicture(String picture) { this.picture = picture; } public String getMake() { return make; } public void setMake(String make) { this.make = make; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } public String getType() { return type; } public void setType(String type) { this.type = type; } public double getCost() { return cost; } public void setCost(double cost) { this.cost = cost; } public int getEngineDisplacement() { return engineDisplacement; } public void setEngineDisplacement(int engineDisplacement) { this.engineDisplacement = engineDisplacement; } public boolean isAutoTransmission() { return autoTransmission; } public void setAutoTransmission(boolean autoTransmission) { this.autoTransmission = autoTransmission; } public Accessories getAccessories() { return accessories; } public void setAccessories(Accessories accessories) { this.accessories = accessories; } public Set<String> getSalesmen() { return salesmen; } public void setSalesmen(Set<String> salesmen) { this.salesmen = salesmen; } public String toString() { return model; } } CarService.java
package demo.getting_started; import java.util.List; public interface CarService { /** * Retrieve all cars in the car store. * @return all cars. */ public List<Car> findAll(); /** * Store or modify a car in car store. */ void store(Car car); /** * Store or modify a inventory item in car store. */ void store(InventoryItem inventoryItem); /** * Order cars. */ void order(List<OrderItem> orderItems); /** * Retrieve the root of car categories. */ Category getCarCategoriesRoot(); /** * Count cars by filter. */ int countByFilter(String filter); /** * Query cars by filter. */ List<Car> queryByFilter(String filter); }
Copyright © 2005-2024 Potix Corporation All rights reserved.
|
Processing... |