package ch.fusun.baron.city.ui;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import ch.fusun.baron.city.City;
import ch.fusun.baron.city.api.CityService;
import ch.fusun.baron.core.injection.Inject;
import ch.fusun.baron.data.DataListener;
import ch.fusun.baron.data.DataUpdate;
import ch.fusun.baron.map.Tile;
import ch.fusun.baron.map.ui.gef.editpart.TileChild;
import ch.fusun.baron.map.ui.gef.editpart.TileChildrenProvider;
/**
* Tile provider for cities
*/
public class CityTileChildrenProvider implements TileChildrenProvider {
private final List<DataListener> listeners = new LinkedList<DataListener>();
private transient CityService cityService;
/**
* Injection constructor
*/
public CityTileChildrenProvider() {
}
/**
* @param cityService
* The injected service
*/
@Inject
public void setCityService(CityService cityService) {
this.cityService = cityService;
this.cityService.addDataListener(this);
}
@SuppressWarnings("rawtypes")
@Override
public Collection<TileChild> getChildren(Tile model) {
City city = cityService.getCity(model);
Collection<TileChild> children = new ArrayList<TileChild>();
if (city != null) {
children.add(new CityTileChild(city));
}
return children;
}
@Override
public void addListener(DataListener listener) {
this.listeners.add(listener);
}
@Override
public void dataChanged(DataUpdate update) {
for (DataListener listener : listeners) {
listener.dataChanged(update);
}
}
}