private void makeDscanPanel() {
    dscanPP = new PrefPanel("dscan", null);
    int row = 0;
    dscanPP.addCheckBoxField(DSCAN_ADDSIZE, "Add File Size", false, 0, row++);
    // dscanPP.addCheckBoxField(DSCAN_ADDLATEST, "Add Latest", false, 0, row++);
    dscanPP.addTextField(DSCAN_PATH, "Path", "", 0, row++, null);
    dscanPP.addTextField(DSCAN_DIR, "Directory Location", "", 0, row++, null);
    // dscanPP.addTextField(DSCAN_FILTER, "Filter", "", 0, row++, null);

    dscanPP.addEmptyRow(row++, 2);
    dscanPP.addHeading("Time Coverage", row++);

    exampleButton = makeButton("Example filename");
    exampleButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            InvDataset leaf = findLeafDataset(dataset);
            exampleButton.setText((leaf == null) ? "ERR" : leaf.getName());
          }
        });
    dscanPP.addComponent(exampleButton, 0, row, null);

    // dscanPP.addTextField(DSCAN_TC_MATCH, "Dataset Name Match", "", 0, row++, null);
    // dscanPP.addTextField(DSCAN_TC_SUBS, "Substituton Pattern", "$1-$2-$3T$4:00:00", 0, row++,
    // null);
    // dscanPP.addTextField(DSCAN_TC_DURATOPN, "Duration", "", 0, row++, null);

    dscanPP.finish(false);

    IndependentWindow dscanWindow =
        new IndependentWindow("DatasetScan " + "options", BAMutil.getImage("thredds"), dscanPP);
    dscanWindow.setBounds(new Rectangle(150, 50, 700, 300));
  }
  public static void main(String args[]) {
    JFrame frame;
    final DatasetEditor editor = new DatasetEditor();

    frame = new JFrame("Test DatasetEditor");
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    JButton save = new JButton("Accept");
    save.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            editor.accept();
            editor.store2Dataset();
            try {
              cat.writeXML(System.out, true);
            } catch (IOException e1) {
              e1.printStackTrace();
            }
          }
        });
    JPanel main = new JPanel(new BorderLayout());
    main.add(editor, BorderLayout.CENTER);
    main.add(save, BorderLayout.NORTH);

    frame.getContentPane().add(main);
    frame.pack();
    frame.setLocation(150, 10);
    frame.setVisible(true);

    // LOOK-NOSAVE
    java.net.Authenticator.setDefault(new UrlAuthenticatorDialog(frame));

    // String url = "http://uni10.unidata.ucar.edu:8088/thredds/content/idd/models.xml";
    String url = "http://thredds.ucar.edu/thredds/content/idd/models.xml";
    InvCatalogFactory catFactory = InvCatalogFactory.getDefaultFactory(true);
    cat = catFactory.readXML(url);
    InvDatasetImpl ds = (InvDatasetImpl) cat.findDatasetByID("NCEP/NAM/V");

    editor.setDataset(ds);
  }
  private void setGCmode(int mode) {
    setMode(metadataPP.getField(LAT_START), mode);
    setMode(metadataPP.getField(LAT_EXTENT), mode);
    setMode(metadataPP.getField(LAT_RESOLUTION), mode);
    setMode(metadataPP.getField(LAT_UNITS), mode);
    setMode(metadataPP.getField(LON_START), mode);
    setMode(metadataPP.getField(LON_EXTENT), mode);
    setMode(metadataPP.getField(LON_RESOLUTION), mode);
    setMode(metadataPP.getField(LON_UNITS), mode);
    setMode(metadataPP.getField(HEIGHT_START), mode);
    setMode(metadataPP.getField(HEIGHT_EXTENT), mode);
    setMode(metadataPP.getField(HEIGHT_RESOLUTION), mode);
    setMode(metadataPP.getField(HEIGHT_UNITS), mode);
    setMode(metadataPP.getField(ZPOSITIVE_UP), mode);

    extractGCButton.setEnabled(mode != 2);
  }
  private JPanel makeVariablesPanel() {
    variablesFld =
        new Field.BeanTableField(
            VARIABLES, "Variables", null, ThreddsMetadata.Variable.class, null, null);

    extractVButton = makeButton("Extract Variables");
    extractVButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            extractVariables();
          }
        });

    JPanel buttPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
    buttPanel.add(extractVButton);

    JPanel vPanel = new JPanel(new BorderLayout());
    vPanel.add(buttPanel, BorderLayout.NORTH);
    vPanel.add(variablesFld.getEditComponent(), BorderLayout.CENTER);
    return vPanel;
  }
  private void setGC(ThreddsMetadata.GeospatialCoverage gc, int mode) {
    PersistentBean gcBean = (gc == null) ? null : new PersistentBean(gc);

    setEditValue(LAT_START, gcBean, mode);
    setEditValue(LAT_EXTENT, gcBean, mode);
    setEditValue(LAT_RESOLUTION, gcBean, mode);
    setEditValue(LAT_UNITS, gcBean, mode);

    setEditValue(LON_START, gcBean, mode);
    setEditValue(LON_EXTENT, gcBean, mode);
    setEditValue(LON_RESOLUTION, gcBean, mode);
    setEditValue(LON_UNITS, gcBean, mode);

    setEditValue(HEIGHT_START, gcBean, mode);
    setEditValue(HEIGHT_EXTENT, gcBean, mode);
    setEditValue(HEIGHT_RESOLUTION, gcBean, mode);
    setEditValue(HEIGHT_UNITS, gcBean, mode);

    setEditValue(ZPOSITIVE_UP, gcBean, mode);

    extractGCButton.setEnabled(mode != 2);
  }
  public boolean setDataset(InvDatasetImpl ds) {
    if (!accept()) return false;

    this.dataset = ds;
    this.leafDataset = null;
    exampleButton.setText("Example Dataset");

    //////////
    PersistentBean persBean = new PersistentBean(ds);

    setEditValue(NAME, persBean, 0);
    setEditValue(ID, persBean, 0);

    setEditValueWithInheritence(AUTHORITY, persBean);
    setEditValueWithInheritence(SERVICE_NAME, persBean);

    setEditValueWithInheritence(FORMAT_TYPE, persBean);
    setEditValueWithInheritence(DATA_TYPE, persBean);

    setEditValue(COLLECTION_TYPE, persBean, 0);
    setEditValue(HARVEST, persBean, 0);

    // gotta find which GeospatialCoverage to use.
    int mode = 0;
    ThreddsMetadata.GeospatialCoverage gc = ds.getLocalMetadata().getGeospatialCoverage();
    if ((gc == null) || gc.isEmpty()) {
      gc = ds.getLocalMetadataInheritable().getGeospatialCoverage();
      mode = 1;
    }
    if ((gc == null) || gc.isEmpty()) {
      gc = ds.getGeospatialCoverage();
      mode = 2; // inherited
    }
    metadataPP.setFieldValue(GC_TYPE, inherit_types.get(mode));
    setGC(gc, mode);

    // gotta find which TimeCoverage to use.
    mode = 0;
    CalendarDateRange tc = ds.getLocalMetadata().getCalendarDateCoverage();
    if (tc == null) {
      tc = ds.getLocalMetadataInheritable().getCalendarDateCoverage();
      mode = 1;
    }
    if (tc == null) {
      tc = ds.getCalendarDateCoverage();
      mode = 2; // inherited
    }
    metadataPP.setFieldValue(TC_TYPE, inherit_types.get(mode));
    if (tc != null) dateRangeSelector.setDateRange(tc.toDateRange());
    setTCmode(mode);

    setEditValueWithInheritence(SUMMARY, persBean);
    setEditValueWithInheritence(RIGHTS, persBean);
    setEditValueWithInheritence(HISTORY, persBean);
    setEditValueWithInheritence(PROCESSING, persBean);

    setVariables(variablesFld);
    setBeanList(creatorsFld, CREATORS, persBean);
    setBeanList(publishersFld, PUBLISHERS, persBean);
    setBeanList(projectsFld, PROJECTS, persBean);
    setBeanList(keywordsFld, KEYWORDS, persBean);
    setBeanList(datesFld, DATES, persBean);
    setBeanList(contributorsFld, CONTRIBUTORS, persBean);
    setBeanList(docsFld, DOCUMENTATION, persBean);

    if (ds instanceof InvDatasetScan) {
      dscanPP.setEnabled(true);
      setEditValue(dscanPP, DSCAN_PATH, persBean, 0);
      setEditValue(dscanPP, DSCAN_DIR, persBean, 0);
      // setEditValue( dscanPP, DSCAN_FILTER, persBean, 0);
      setEditValue(dscanPP, DSCAN_ADDSIZE, persBean, 0);
      // setEditValue( dscanPP, DSCAN_ADDLATEST, persBean, 0);
      // setEditValue( dscanPP, DSCAN_TC_MATCH, persBean, 0);
      // setEditValue( dscanPP, DSCAN_TC_SUBS, persBean, 0);
      // setEditValue( dscanPP, DSCAN_TC_DURATOPN, persBean, 0);
    } else dscanPP.setEnabled(false);

    return true;
  }
 private JButton makeButton(String name) {
   JButton b = new JButton(name);
   b.setForeground(actionColor);
   return b;
 }
  public DatasetEditor() {
    JTabbedPane tabs = new JTabbedPane();

    metadataPP = new PrefPanel("Edit Catalog Dataset", null, null);
    tabs.add("metadata", metadataPP);

    int row = 0;
    metadataPP.addHeading("Basic", row++);

    // row 0
    metadataPP.addTextField(NAME, "Name", "", 0, row++, "8,1");
    // row 1
    metadataPP.addTextField(ID, "ID", "", 0, row, null);
    addPopups(metadataPP.addTextField(AUTHORITY, "Authority", "", 2, row, null));
    addPopups(metadataPP.addTextField(SERVICE_NAME, "Service", "", 4, row, null));

    row++;
    // row 2
    addPopups(
        metadataPP.addEnumComboField(
            FORMAT_TYPE, "Data format", DataFormatType.getAllTypes(), true, 0, row, null));
    addPopups(
        metadataPP.addEnumComboField(
            DATA_TYPE, "Data type", Arrays.asList(FeatureType.values()), true, 2, row, null));
    metadataPP.addEnumComboField(
        COLLECTION_TYPE, "Collection type", CollectionType.getAllTypes(), true, 4, row++, null);

    ////////////
    metadataPP.addHeading("GeoSpatial Coverage", row++);

    // addCheckBoxField("localMetadata.geospatialCoverage.global", "Global", false, 0, row);
    gc_type = metadataPP.addEnumComboField(GC_TYPE, "type", inherit_types, false, 0, row, null);
    gc_type.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            String mode = (String) gc_type.getValue();
            setGCmode(getMode(mode));
          }
        });

    extractGCButton = makeButton("Extract Geospatial");
    extractGCButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            extractGeospatial();
          }
        });
    metadataPP.addComponent(extractGCButton, 2, row, "left, center");

    metadataPP.addCheckBoxField(ZPOSITIVE_UP, "Z positive up", false, 4, row);
    row++;

    /* JPanel geoPanel = new JPanel();
    Field.CheckBox global = new Field.CheckBox( "localMetadata.geospatialCoverage.global", "Global", false, persBean);
    geoPanel.add( new JLabel("Global: "));
    geoPanel.add( global.getEditComponent());
    geoPanel.add( new JButton("Read Dataset"));
    pp.addComponent(geoPanel, 0, row++, "left, center"); */

    // 4 columns in 3 rows
    metadataPP.addDoubleField(LAT_START, "Starting Latitude", 0.0, 5, 0, row, null);
    metadataPP.addDoubleField(LAT_EXTENT, "Size", 0.0, 5, 2, row, null);
    metadataPP.addDoubleField(LAT_RESOLUTION, "Resolution", 0.0, 5, 4, row, null);
    metadataPP.addTextField(LAT_UNITS, "Units", "", 6, row, null);
    metadataPP.addDoubleField(LON_START, "Starting Longitude", 0.0, 5, 0, row + 1, null);
    metadataPP.addDoubleField(LON_EXTENT, "Size", 0.0, 5, 2, row + 1, null);
    metadataPP.addDoubleField(LON_RESOLUTION, "Resolution", 0.0, 5, 4, row + 1, null);
    metadataPP.addTextField(LON_UNITS, "Units", "", 6, row + 1, null);
    metadataPP.addDoubleField(HEIGHT_START, "Starting Height", 0.0, 5, 0, row + 2, null);
    metadataPP.addDoubleField(HEIGHT_EXTENT, "Size", 0.0, 5, 2, row + 2, null);
    metadataPP.addDoubleField(HEIGHT_RESOLUTION, "Resolution", 0.0, 5, 4, row + 2, null);
    metadataPP.addTextField(HEIGHT_UNITS, "Units", "", 6, row + 2, null);
    // addTextField("localMetadata.geospatialCoverage.ZPositive", "Z is Positive", "up", 6, row+3,
    // null);
    row += 3;

    //////
    metadataPP.addHeading("Temporal Coverage", row++);
    tc_type = metadataPP.addEnumComboField(TC_TYPE, "type", inherit_types, false, 0, row++, null);
    tc_type.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            String mode = (String) tc_type.getValue();
            setTCmode(getMode(mode));
          }
        });

    DateRange range = null;
    try {
      range = new DateRange();
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
    dateRangeSelector = new RangeDateSelector("", range, false, false, null, false, false);
    DateField minDateField = dateRangeSelector.getMinDateField();
    DateField maxDateField = dateRangeSelector.getMaxDateField();
    DurationField durationField = dateRangeSelector.getDurationField();
    DurationField resolutionField = dateRangeSelector.getResolutionField();

    metadataPP.addField(minDateField, 0, row, null);
    metadataPP.addField(maxDateField, 2, row, null);
    metadataPP.addField(durationField, 4, row, null);
    metadataPP.addField(resolutionField, 6, row++, null);

    ////
    metadataPP.addHeading("Digital Library Info", row++);
    metadataPP.addCheckBoxField(HARVEST, "Harvest", false, 0, row++);

    addPopups(metadataPP.addTextAreaField(SUMMARY, "Summary", null, 7, 0, row, "3,1"));
    addPopups(metadataPP.addTextAreaField(RIGHTS, "Rights", null, 2, 0, row + 1, "3,1"));

    addPopups(metadataPP.addTextAreaField(HISTORY, "History", null, 7, 4, row, "3,1"));
    addPopups(metadataPP.addTextAreaField(PROCESSING, "Process", null, 2, 4, row + 1, "3,1"));
    row += 2;

    metadataPP.addEmptyRow(row++, 10);

    JTabbedPane tabPane = new JTabbedPane();
    metadataPP.addComponent(tabPane, 0, row, "8,1");

    ArrayList<Field.BeanTableField> tables = new ArrayList<>();

    tabPane.addTab("Variables", makeVariablesPanel());
    tables.add(variablesFld);

    creatorsFld =
        new Field.BeanTableField(
            CREATORS, "Creators", null, ThreddsMetadata.Source.class, null, null);
    tabPane.addTab("Creators", creatorsFld.getEditComponent());
    tables.add(creatorsFld);

    publishersFld =
        new Field.BeanTableField(
            PUBLISHERS, "Publishers", null, ThreddsMetadata.Source.class, null, null);
    tabPane.addTab("Publishers", publishersFld.getEditComponent());
    tables.add(publishersFld);

    projectsFld =
        new Field.BeanTableField(
            PROJECTS, "Projects", null, ThreddsMetadata.Vocab.class, null, null);
    tabPane.addTab("Projects", projectsFld.getEditComponent());
    tables.add(projectsFld);

    keywordsFld =
        new Field.BeanTableField(
            KEYWORDS, "Keywords", null, ThreddsMetadata.Vocab.class, null, null);
    tabPane.addTab("Keywords", keywordsFld.getEditComponent());
    tables.add(keywordsFld);

    datesFld = new Field.BeanTableField(DATES, "Dates", null, DateType.class, null, null);
    tabPane.addTab("Dates", datesFld.getEditComponent());
    tables.add(datesFld);

    contributorsFld =
        new Field.BeanTableField(
            CONTRIBUTORS, "Contributors", null, ThreddsMetadata.Contributor.class, null, null);
    tabPane.addTab("Contributors", contributorsFld.getEditComponent());
    tables.add(contributorsFld);

    docsFld =
        new Field.BeanTableField(
            DOCUMENTATION, "Documentation", null, InvDocumentation.class, null, null);
    tabPane.addTab("Documentation", docsFld.getEditComponent());
    tables.add(docsFld);

    for (Field.BeanTableField table : tables) addPopups(table);

    metadataPP.finish(false);

    makeDscanPanel();
    tabs.add("datasetScan", dscanPP);

    setLayout(new BorderLayout());
    add(tabs, BorderLayout.CENTER);
  }