private void extractVariables() {
    if (leafDataset == null) leafDataset = findLeafDataset(dataset);
    if (leafDataset == null) return;

    ThreddsMetadata.Variables vars;
    try {
      vars = MetadataExtractor.extractVariables(leafDataset);
    } catch (IOException e) {
      return;
    }

    if (vars != null) {
      ThreddsMetadata tm = dataset.getLocalMetadataInheritable();
      List<ThreddsMetadata.Variables> varsList = tm.getVariables();
      boolean replaced = false;
      for (int i = 0; i < varsList.size(); i++) {
        ThreddsMetadata.Variables vs = varsList.get(i);
        if (vs.getVocabulary().equals(vars.getVocabulary())) {
          varsList.set(i, vars); // replace
          replaced = true;
          break;
        }
      }
      if (!replaced) tm.addVariables(vars);

      variablesFld.setValue(vars.getVariableList());
      setMode(variablesFld, 1);
    }
  }
  private void setVariables(Field.BeanTable beanTable) {
    List variableLists = dataset.getLocalMetadata().getVariables();
    if ((variableLists != null) && (variableLists.size() > 0)) {
      ThreddsMetadata.Variables vars = (ThreddsMetadata.Variables) variableLists.get(0);
      beanTable.setValue(vars.getVariableList());
      setMode(beanTable, 0);
      return;
    }

    variableLists = dataset.getLocalMetadataInheritable().getVariables();
    if ((variableLists != null) && (variableLists.size() > 0)) {
      ThreddsMetadata.Variables vars = (ThreddsMetadata.Variables) variableLists.get(0);
      beanTable.setValue(vars.getVariableList());
      setMode(beanTable, 1);
      return;
    }

    variableLists = dataset.getVariables();
    if ((variableLists != null) && (variableLists.size() > 0)) {
      ThreddsMetadata.Variables vars = (ThreddsMetadata.Variables) variableLists.get(0);
      beanTable.setValue(vars.getVariableList());
      setMode(beanTable, (vars == null || vars.getVariableList().size() == 0) ? 1 : 2);
      return;
    }

    // clear out the table
    beanTable.setValue(new ArrayList());
  }