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 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(); } }