Package ch.fusun.baron.city.ui

Source Code of ch.fusun.baron.city.ui.CityTileChildrenProvider

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);
    }
  }

}
TOP

Related Classes of ch.fusun.baron.city.ui.CityTileChildrenProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.