@Override
  public Number[] getScope(int dimension) throws DriverException {
    if (cachedScope == null) {
      boolean open = isOpen();
      if (!open) {
        open();
      }
      for (int i = 0; i < getRowCount(); i++) {
        Metadata m = getMetadata();
        for (int j = 0; j < m.getFieldCount(); j++) {
          int typeCode = m.getFieldType(j).getTypeCode();
          Envelope r = null;
          if ((typeCode & Type.GEOMETRY) != 0) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsGeometry().getEnvelopeInternal();
            }
          } else if (typeCode == Type.RASTER) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsRaster().getMetadata().getEnvelope();
            }
          } else if (typeCode == Type.STREAM) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsStream().getEnvelope();
            }
          }
          if (r != null) {
            if (cachedScope == null) {
              cachedScope = new Envelope(r);
            } else {
              cachedScope.expandToInclude(r);
            }
          }
        }
      }
      if (!open) {
        close();
      }
    }

    if (cachedScope == null) {
      return new Number[] {0, 0};
    } else {
      if (dimension == DataSet.X) {
        return new Number[] {cachedScope.getMinX(), cachedScope.getMaxX()};
      } else if (dimension == DataSet.Y) {
        return new Number[] {cachedScope.getMinY(), cachedScope.getMaxY()};
      } else {
        throw new UnsupportedOperationException("Not yet implemented");
      }
    }
  }
  private void initializeEdition() throws DriverException {
    if (!initialized) {
      long rowCount = getDataSource().getRowCount();

      // build alpha indexes on unique fields
      Metadata m = getMetadata();
      for (int i = 0; i < m.getFieldCount(); i++) {
        Type type = m.getFieldType(i);
        if (type.getBooleanConstraint(Constraint.UNIQUE)
            || type.getBooleanConstraint(Constraint.PK)) {
          IndexManager indexManager = getDataSourceFactory().getIndexManager();
          try {
            if (!indexManager.isIndexed(getName(), m.getFieldName(i))) {
              indexManager.buildIndex(getName(), m.getFieldName(i), new NullProgressMonitor());
            }
          } catch (NoSuchTableException e) {
            throw new DriverException("table not found: " + getName(), e);
          } catch (IndexException e) {
            throw new DriverException("Cannot create index on unique fields", e);
          }
        }
      }

      // initialize directions
      rowsAddresses = new ArrayList<PhysicalRowAddress>();
      for (int i = 0; i < rowCount; i++) {
        PhysicalRowAddress dir = new OriginalRowAddress(getDataSource(), i);
        rowsAddresses.add(dir);
        editionActions.add(new NoEditionInfo(getPK(i), i));
      }

      Number[] xScope = getDataSource().getScope(DataSet.X);
      Number[] yScope = getDataSource().getScope(DataSet.Y);
      if ((xScope != null) && (yScope != null)) {
        cachedScope =
            new Envelope(
                new Coordinate(xScope[0].doubleValue(), yScope[0].doubleValue()),
                new Coordinate(xScope[1].doubleValue(), yScope[1].doubleValue()));
      } else {
        cachedScope = null;
      }

      initialized = true;
    }
  }
 /**
  * Adds the symbol panel attached to the given {@link Symbolizer} and returns the panel.
  *
  * @param symb Symbolizer
  * @return The newly generated symbol panel
  */
 private ILegendPanel addSymbolPanel(Symbolizer symb) {
   // Get the legend corresponding to this symbolizer.
   Legend legend = LegendFactory.getLegend(symb);
   if (legend instanceof AbstractRecodedLegend) {
     DataSource dataSource = layer.getDataSource();
     AbstractRecodedLegend leg = (AbstractRecodedLegend) legend;
     try {
       Metadata metadata = dataSource.getMetadata();
       String f = leg.getLookupFieldName();
       int in = metadata.getFieldIndex(f);
       leg.setComparator(AbstractRecodedLegend.getComparator(metadata.getFieldType(in)));
     } catch (DriverException e) {
       LOGGER.warn("Can't retrieve an accurate Comparator for this classification");
     }
   }
   // Initialize a panel for this legend.
   ILegendPanel panel = ILegendPanelFactory.getILegendPanel(this, legend);
   // Give it a new id.
   panel.setId(createNewID());
   // Add the symbol panel to the container after putting it in a
   // new JScrollPane.
   dialogContainer.add(panel.getId(), getJScrollPane(panel));
   return panel;
 }