/** "Constructor." */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_production_site);

    findViews();
    setupClickListeners();

    productionSiteDB = new ProductionSiteDB(this);
    productionSiteDB.open();

    // find out if it as new ProductionSite or update of existing.
    if (getIntent().hasExtra(EXTRA_PRODUCTION_SITE)) {
      setupUpdate();
    }
    // try to set focus, no effect if updating
    etPpnr.requestFocus();
    // disable direct entry of coordinates
    Utils.disableEntry(etCoord);

    // TODO Enable location buttons if we get the services working
    if (hasLocationService) {
      ibHere.setEnabled(true);
      ibMap.setEnabled(true);
    }
  }
  /** Fill fields with intent-extras, disable input on ProductionSiteNr. */
  private void setupUpdate() {
    updating = true;
    Intent intent = getIntent();

    String siteNrStr = intent.getStringExtra(EXTRA_PRODUCTION_SITE);
    ProductionSiteNr siteNr = new ProductionSiteNr(siteNrStr);

    if (siteNr != null) {
      site = productionSiteDB.getProductionSite(siteNr);
    }

    if (site == null) {
      String text = getString(R.string.toast_could_not_fetch) + " " + siteNrStr;
      Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
      return;
    }

    Log.d(TAG, "site id: " + site.get_id());
    etOrg.setText(site.getSiteNr().getOrg());
    etPpnr.setText(site.getSiteNr().getPpnr());
    // disable input
    Utils.disableEntry(etOrg);
    Utils.disableEntry(etPpnr);

    if (site.hasName()) etName.setText(site.getName());
    if (site.hasAddress()) etAddress.setText(site.getAddress());
    if (site.hasPostnr()) etPostnr.setText(site.getPostnr());
    if (site.hasPostaddress()) etPostaddress.setText(site.getPostaddress());
    if (site.hasCoordinates()) etCoord.setText(site.getCoordinates());
    if (site.hasImageUriStr()) {
      imageUri = Uri.parse(site.getImageUriStr());
      Log.d(TAG, "loaded URI: " + imageUri);
      setThumbnail();
    } else {
      Log.d(TAG, "no loaded URI");
    }
  }