Changeset 2246 in josm for trunk/src/org


Ignore:
Timestamp:
2009-10-04T14:43:54+02:00 (15 years ago)
Author:
Gubaer
Message:

Improved user feedback when deleting a relation failed because it was still referred to by another relation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r2240 r2246  
    1010import java.net.URL;
    1111import java.net.UnknownHostException;
     12import java.util.regex.Matcher;
     13import java.util.regex.Pattern;
    1214
    1315import org.openstreetmap.josm.Main;
     16import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1417import org.openstreetmap.josm.io.OsmApi;
    1518import org.openstreetmap.josm.io.OsmApiException;
     
    5154    }
    5255
     56    /**
     57     * Explains a precondition exception when a child relation could not be deleted because
     58     * it is still referred to by an undeleted parent relation.
     59     *
     60     * @param e the exception
     61     * @param childRelation the child relation
     62     * @param parentRelation the parent relation
     63     * @return
     64     */
     65    public static String explainDeletedRelationStillInUse(OsmApiException e, long childRelation, long parentRelation) {
     66        String msg = tr(
     67                "<html><strong>Failed</strong> to delete <strong>relation {0}</strong>."
     68                + " It is still referred to by relation {1}.<br>"
     69                + "Please load relation {1}, remove the reference to relation {0}, and upload again.</html>",
     70                childRelation,parentRelation
     71        );
     72        return msg;
     73    }
    5374
    5475    /**
     
    5980    public static String explainPreconditionFailed(OsmApiException e) {
    6081        e.printStackTrace();
    61         String msg = tr(
     82        String msg = e.getErrorHeader();
     83        if (msg != null) {
     84            String pattern = "Precondition failed: The relation (\\d+) is used in relation (\\d+)\\.";
     85            Pattern p = Pattern.compile(pattern);
     86            Matcher m = p.matcher(msg);
     87            if (m.matches()) {
     88                long childRelation = Long.parseLong(m.group(1));
     89                long parentRelation = Long.parseLong(m.group(2));
     90                return explainDeletedRelationStillInUse(e, childRelation, parentRelation);
     91            }
     92        }
     93        msg = tr(
    6294                "<html>Uploading to the server <strong>failed</strong> because your current<br>"
    6395                + "dataset violates a precondition.<br>" + "The error message is:<br>" + "{0}" + "</html>", e
Note: See TracChangeset for help on using the changeset viewer.