Changeset 2979 in josm
- Timestamp:
- 2010-02-14T13:07:03+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r2598 r2979 18 18 import org.openstreetmap.josm.data.APIDataSet; 19 19 import org.openstreetmap.josm.data.conflict.ConflictCollection; 20 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 21 import org.openstreetmap.josm.gui.help.HelpUtil; 20 22 import org.openstreetmap.josm.gui.io.UploadDialog; 21 23 import org.openstreetmap.josm.gui.io.UploadPrimitivesTask; … … 101 103 } 102 104 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 */ 103 126 public boolean checkPreUploadConditions(OsmDataLayer layer, APIDataSet apiData) { 104 127 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); 113 130 return false; 114 131 } 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 // 117 135 for(UploadHook hook : uploadHooks) 118 136 if(!hook.checkUpload(apiData)) … … 122 140 } 123 141 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 */ 124 148 public void uploadData(OsmDataLayer layer, APIDataSet apiData) { 125 149 if (apiData.isEmpty()) { -
trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java
r2842 r2979 133 133 } 134 134 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 */ 135 143 protected boolean hasPrimitivesToDelete(Collection<OsmPrimitive> primitives) { 136 144 for (OsmPrimitive p: primitives) … … 139 147 return false; 140 148 } 149 141 150 /** 142 151 * Uploads the primitives in <code>toUpload</code> to the server. Only -
trunk/src/org/openstreetmap/josm/data/APIDataSet.java
r2915 r2979 15 15 16 16 import org.openstreetmap.josm.actions.upload.CyclicUploadDependencyException; 17 import org.openstreetmap.josm.data.conflict.Conflict; 18 import org.openstreetmap.josm.data.conflict.ConflictCollection; 17 19 import org.openstreetmap.josm.data.osm.DataSet; 18 20 import org.openstreetmap.josm.data.osm.Node; 19 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.data.osm.PrimitiveId; 20 23 import org.openstreetmap.josm.data.osm.Relation; 21 24 import org.openstreetmap.josm.data.osm.RelationMember; … … 137 140 this(); 138 141 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; 139 187 } 140 188 -
trunk/src/org/openstreetmap/josm/data/conflict/Conflict.java
r2881 r2979 3 3 4 4 import org.openstreetmap.josm.data.osm.OsmPrimitive; 5 import org.openstreetmap.josm.data.osm.PrimitiveId; 5 6 6 7 /** … … 42 43 } 43 44 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 44 73 @Override 45 74 public int hashCode() {
Note:
See TracChangeset
for help on using the changeset viewer.