Changeset 2979 in josm for trunk


Ignore:
Timestamp:
2010-02-14T13:07:03+01:00 (10 years ago)
Author:
Gubaer
Message:

fixed #4386: "There are unsolved conflicts in layer X" holds up any uploading from the layer

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r2598 r2979  
    1818import org.openstreetmap.josm.data.APIDataSet;
    1919import org.openstreetmap.josm.data.conflict.ConflictCollection;
     20import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     21import org.openstreetmap.josm.gui.help.HelpUtil;
    2022import org.openstreetmap.josm.gui.io.UploadDialog;
    2123import org.openstreetmap.josm.gui.io.UploadPrimitivesTask;
     
    101103    }
    102104
     105    protected void alertUnresolvedConflicts(OsmDataLayer layer) {
     106        HelpAwareOptionPane.showOptionDialog(
     107                Main.parent,
     108                tr("<html>The data to be uploaded participates in unresolved conflicts of layer ''{0}''.<br>"
     109                        + "You have to resolve them first.</html>", layer.getName()
     110                ),
     111                tr("Warning"),
     112                JOptionPane.WARNING_MESSAGE,
     113                HelpUtil.ht("/Action/Upload#PrimitivesParticipateInConflicts")
     114        );
     115    }
     116
     117    /**
     118     * Check whether the preconditions are met to upload data in <code>apiData</code>.
     119     * Makes sure primitives in <code>apiData</code> don't participate in conflicts and
     120     * runs the installed {@see UploadHook}s.
     121     *
     122     * @param layer the source layer of the data to be uploaded
     123     * @param apiData the data to be uploaded
     124     * @return true, if the preconditions are met; false, otherwise
     125     */
    103126    public boolean checkPreUploadConditions(OsmDataLayer layer, APIDataSet apiData) {
    104127        ConflictCollection conflicts = layer.getConflicts();
    105         if (conflicts !=null && !conflicts.isEmpty()) {
    106             JOptionPane.showMessageDialog(
    107                     Main.parent,
    108                     tr("<html>There are unresolved conflicts in layer ''{0}''.<br>"
    109                             + "You have to resolve them first.</html>", layer.getName()),
    110                             tr("Warning"),
    111                             JOptionPane.WARNING_MESSAGE
    112             );
     128        if (apiData.participatesInConflict(conflicts)) {
     129            alertUnresolvedConflicts(layer);
    113130            return false;
    114131        }
    115         // Call all upload hooks in sequence. The upload confirmation dialog
    116         // is one of these.
     132        // Call all upload hooks in sequence.
     133        // FIXME: this should become an asynchronous task
     134        //
    117135        for(UploadHook hook : uploadHooks)
    118136            if(!hook.checkUpload(apiData))
     
    122140    }
    123141
     142    /**
     143     * Uploads data to the OSM API.
     144     *
     145     * @param layer the source layer for the data to upload
     146     * @param apiData the primitives to be added, updated, or deleted
     147     */
    124148    public void uploadData(OsmDataLayer layer, APIDataSet apiData) {
    125149        if (apiData.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java

    r2842 r2979  
    133133    }
    134134
     135    /**
     136     * Replies true if there is at least one non-new, deleted primitive in
     137     * <code>primitives</code>
     138     *
     139     * @param primitives the primitives to scan
     140     * @return true if there is at least one non-new, deleted primitive in
     141     * <code>primitives</code>
     142     */
    135143    protected boolean hasPrimitivesToDelete(Collection<OsmPrimitive> primitives) {
    136144        for (OsmPrimitive p: primitives)
     
    139147        return false;
    140148    }
     149
    141150    /**
    142151     * Uploads the primitives in <code>toUpload</code> to the server. Only
  • trunk/src/org/openstreetmap/josm/data/APIDataSet.java

    r2915 r2979  
    1515
    1616import org.openstreetmap.josm.actions.upload.CyclicUploadDependencyException;
     17import org.openstreetmap.josm.data.conflict.Conflict;
     18import org.openstreetmap.josm.data.conflict.ConflictCollection;
    1719import org.openstreetmap.josm.data.osm.DataSet;
    1820import org.openstreetmap.josm.data.osm.Node;
    1921import org.openstreetmap.josm.data.osm.OsmPrimitive;
     22import org.openstreetmap.josm.data.osm.PrimitiveId;
    2023import org.openstreetmap.josm.data.osm.Relation;
    2124import org.openstreetmap.josm.data.osm.RelationMember;
     
    137140        this();
    138141        init(ds);
     142    }
     143
     144    /**
     145     * Replies true if one of the primitives to be updated or to be deleted
     146     * participates in the conflict <code>conflict</code>
     147     *
     148     * @param conflict the conflict
     149     * @return true if one of the primitives to be updated or to be deleted
     150     * participates in the conflict <code>conflict</code>
     151     */
     152    public boolean participatesInConflict(Conflict<?> conflict) {
     153        if (conflict == null) return false;
     154        for (OsmPrimitive p: toUpdate) {
     155            if (conflict.isParticipating(p)) return true;
     156        }
     157        for (OsmPrimitive p: toDelete) {
     158            if (conflict.isParticipating(p)) return true;
     159        }
     160        return false;
     161    }
     162
     163    /**
     164     * Replies true if one of the primitives to be updated or to be deleted
     165     * participates in at least one conflict in <code>conflicts</code>
     166     *
     167     * @param conflicts the collection of conflicts
     168     * @return true if one of the primitives to be updated or to be deleted
     169     * participates in at least one conflict in <code>conflicts</code>
     170     */
     171    public boolean participatesInConflict(ConflictCollection conflicts) {
     172        if (conflicts == null || conflicts.isEmpty()) return false;
     173        Set<PrimitiveId> idsParticipatingInConflicts = new HashSet<PrimitiveId>();
     174        for (OsmPrimitive p: conflicts.getMyConflictParties()) {
     175            idsParticipatingInConflicts.add(p.getPrimitiveId());
     176        }
     177        for (OsmPrimitive p: conflicts.getTheirConflictParties()) {
     178            idsParticipatingInConflicts.add(p.getPrimitiveId());
     179        }
     180        for (OsmPrimitive p: toUpdate) {
     181            if (idsParticipatingInConflicts.contains(p.getPrimitiveId())) return true;
     182        }
     183        for (OsmPrimitive p: toDelete) {
     184            if (idsParticipatingInConflicts.contains(p.getPrimitiveId())) return true;
     185        }
     186        return false;
    139187    }
    140188
  • trunk/src/org/openstreetmap/josm/data/conflict/Conflict.java

    r2881 r2979  
    33
    44import org.openstreetmap.josm.data.osm.OsmPrimitive;
     5import org.openstreetmap.josm.data.osm.PrimitiveId;
    56
    67/**
     
    4243    }
    4344
     45    /**
     46     * Replies true if the primitive <code>primitive</code> is participating
     47     * in this conflict
     48     *
     49     * @param primitive the primitive
     50     * @return true if the primitive <code>primitive</code> is participating
     51     * in this conflict
     52     */
     53    public boolean isParticipating(OsmPrimitive primitive) {
     54        if (primitive == null) return false;
     55        return primitive.getPrimitiveId().equals(my.getPrimitiveId())
     56        || primitive.getPrimitiveId().equals(their.getPrimitiveId());
     57    }
     58
     59    /**
     60     * Replies true if the primitive with id <code>id</code> is participating
     61     * in this conflict
     62     *
     63     * @param id the primitive id
     64     * @return true if the primitive <code>primitive</code> is participating
     65     * in this conflict
     66     */
     67    public boolean isParticipating(PrimitiveId id) {
     68        if (id == null) return false;
     69        return id.equals(my.getPrimitiveId())
     70        || id.equals(their.getPrimitiveId());
     71    }
     72
    4473    @Override
    4574    public int hashCode() {
Note: See TracChangeset for help on using the changeset viewer.