Class EditTransaction


  • public class EditTransaction
    extends Object
    Takes care of "rollback" (if any geometries are invalid) and undo, for PlugIns and CursorTools that modify geometries.

    Also:

    • warns the user if invalid geometries are found
    • invalidates the layer envelope cache
    • invalidates the geometry envelope caches
    • (undoably) removes features from the layer when their geometries are made empty
    • (undoably) adds features to the layer when they start with empty geometries

    • Field Detail

      • ROLLING_BACK_INVALID_EDITS_KEY

        public static final String ROLLING_BACK_INVALID_EDITS_KEY
    • Constructor Detail

      • EditTransaction

        public EditTransaction​(Collection features,
                               String name,
                               Layer layer,
                               boolean rollingBackInvalidEdits,
                               boolean allowAddingAndRemovingFeatures,
                               LayerViewPanel layerViewPanel)
      • EditTransaction

        public EditTransaction​(Collection features,
                               String name,
                               Layer layer,
                               boolean rollingBackInvalidEdits,
                               boolean allowAddingAndRemovingFeatures,
                               LayerViewPanelContext layerViewPanelContext)
        If you want to delete a feature, you can either (1) include the feature in the features parameter, set allowAddingAndRemovingFeatures to true, then call #setGeometry(feature, empty geometry); or (2) not include the feature in the features parameter, instead using #deleteFeature
        Parameters:
        name - Display name for undo. Use PlugIn#getName or CursorTool#getName.
        layer - the layer to which the features belong
        allowAddingAndRemovingFeatures - whether to treat empty geometries as indications to add/remove features or as in fact empty geometries
    • Method Detail

      • getGeometry

        public org.locationtech.jts.geom.Geometry getGeometry​(int i)
      • getGeometry

        public org.locationtech.jts.geom.Geometry getGeometry​(Feature feature)
      • setGeometry

        public void setGeometry​(Feature feature,
                                org.locationtech.jts.geom.Geometry geometry)
      • setGeometries

        public void setGeometries​(Map featureToGeometryMap)
      • setGeometry

        public void setGeometry​(int i,
                                org.locationtech.jts.geom.Geometry geometry)
      • commit

        public boolean commit()
      • commit

        public static boolean commit​(Collection editTransactions)
      • commit

        public static boolean commit​(Collection editTransactions,
                                     EditTransaction.SuccessAction successAction)
        Commits several EditTransactions if their proposed geometries are all valid. Useful for committing changes to several layers because an EditTransaction handles one layer only. Gets the undo name and the UndoManager from the first EditTransaction.
        Parameters:
        successAction - run after the first execution (i.e. not after redos) if all proposed geometries are valid (or rollingBackInvalidEdits is false)
      • commit

        public boolean commit​(EditTransaction.SuccessAction successAction)
        Parameters:
        successAction - will be run if the geometries are valid (or OptionsPlugIn#isRollingBackInvalidEdits returns false), before the layer-change events are fired. Useful for animations and other visual indicators which would be slowed down if the layer-change events were fired first.
        Returns:
        true if all the proposed geometries are valid
      • clearEnvelopeCaches

        public void clearEnvelopeCaches()
      • proposedGeometriesValid

        public boolean proposedGeometriesValid()
      • size

        public int size()
      • getFeature

        public Feature getFeature​(int i)
      • createFeature

        public void createFeature​(Feature feature)
      • deleteFeature

        public void deleteFeature​(Feature feature)
        Parameters:
        feature - must not have been passed into the constructor
      • getLayer

        public Layer getLayer()
      • emptyGeometryCount

        public static int emptyGeometryCount​(Collection transactions)