public void rollback(IProgressMonitor monitor) throws Exception {
   if (noChange) return;
   monitor.beginTask(Messages.WriteFeatureChangesCommand_rollbackTask, IProgressMonitor.UNKNOWN);
   if (added) {
     store.removeFeatures(filter);
   } else {
     FeatureType featureType = this.editFeature.getFeatureType();
     store.modifyFeatures(
         featureType.getAttributeTypes(),
         this.editFeature.getAttributes(new Object[featureType.getAttributeCount()]),
         filter);
   }
 }
    /** @see Transfer#nativeToJava */
    @SuppressWarnings("deprecation")
    public Object nativeToJava(TransferData transferData) {
      String string = (String) TextTransfer.getInstance().nativeToJava(transferData);

      WKTReader reader = new WKTReader();
      try {
        Geometry read = reader.read(string);
        FeatureType ft =
            DataUtilities.createType(
                "Temp Type", "*geom:" + read.getClass().getName()); // $NON-NLS-1$ //$NON-NLS-2$
        return ft.create(new Object[] {read});
      } catch (Exception e) {
        UiPlugin.log("", e); // $NON-NLS-1$
      }
      return null;
    }
Beispiel #3
0
  private void save() throws Exception {
    FeatureStore fs = (FeatureStore) ds.getFeatureSource("poly_county");
    FeatureType ft = fs.getSchema();

    MemoryDataStore memorystore = new MemoryDataStore();

    ArrayList polys = new ArrayList(resultPolygon);

    Geometry gfinal = null;
    if (polys.size() == 1) {
      gfinal = (Polygon) polys.get(0); // POLYGON
    } else {
      GeometryFactory gf = ((Polygon) polys.get(0)).getFactory();
      gfinal = new MultiPolygon((Polygon[]) polys.toArray(new Polygon[polys.size()]), gf);
    }

    gfinal = gfinal.buffer(0); // for topologic problems.

    Object[] values = new Object[5];
    values[ft.find("module")] = MODULE;
    values[ft.find("gen_full")] = gfinal;

    values[ft.find("gen_1")] = generalize(gfinal, tolerance1);
    ;
    values[ft.find("gen_2")] = generalize(gfinal, tolerance1);
    ;
    values[ft.find("gen_3")] = generalize(gfinal, tolerance1);
    ;

    Feature f = ft.create(values);
    memorystore.addFeature(f);

    fs.addFeatures(memorystore.getFeatureReader("poly_county"));
  }
  /** @see net.refractions.udig.project.internal.command.MapCommand#run() */
  @SuppressWarnings("deprecation")
  public void run(IProgressMonitor monitor) throws Exception {
    monitor.beginTask(Messages.WriteFeatureChangesCommand_runTask, 3);
    SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 1);
    editFeature = featureProvider.get(subProgressMonitor);
    subProgressMonitor.done();
    store = storeProvider.get(subProgressMonitor);
    if (editFeature == null || store == null) {
      noChange = true;
      return;
    }

    FeatureType featureType = editFeature.getFeatureType();
    FilterFactory factory = FilterFactoryFinder.createFilterFactory();
    subProgressMonitor = new SubProgressMonitor(monitor, 1);
    subProgressMonitor.done();
    filter = factory.createFidFilter(editFeature.getID());
    FeatureCollection results = store.getFeatures(filter);

    FeatureIterator reader = results.features();
    try {
      if (reader.hasNext()) {
        try {
          store.modifyFeatures(
              featureType.getAttributeTypes(),
              editFeature.getAttributes(new Object[featureType.getAttributeCount()]),
              filter);
        } catch (Exception e) {
          ProjectPlugin.log("", e); // $NON-NLS-1$
          noChange = true;
        }

      } else {
        added = true;
        store.addFeatures(
            new StaticFeatureCollection(Collections.singleton(editFeature), featureType));
      }
    } finally {
      if (reader != null) reader.close();
    }
  }