Changeset 2095 in josm for trunk/src/org/openstreetmap/josm/gui/conflict
- Timestamp:
- 2009-09-12T06:21:30+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/conflict/tags
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java
r2084 r2095 26 26 import org.openstreetmap.josm.command.ChangePropertyCommand; 27 27 import org.openstreetmap.josm.command.Command; 28 import org.openstreetmap.josm.data.osm.Node; 28 29 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 30 import org.openstreetmap.josm.data.osm.TagCollection; … … 34 35 import org.openstreetmap.josm.tools.WindowGeometry; 35 36 36 public class CombineWaysConflictResolverDialog extends JDialog { 37 38 static private CombineWaysConflictResolverDialog instance; 39 40 public static CombineWaysConflictResolverDialog getInstance() { 37 /** 38 * This dialog helps to resolve conflicts occuring when combining or merging primitives. 39 * 40 * There is a singleton instance of this dialog which can be retrieved using 41 * {@see #getInstance()}. 42 * 43 * The dialog uses two model: one model for resolving tag conflicts, the other model 44 * for resolving conflicts in relation membership. For both models there are accessors, 45 * i.e {@see #getTagConflictResolverModel()} and {@see #getRelationMemberConflictResolverModel()}. 46 * 47 * Models have to be <strong>populated</strong> before the dialog is launched. Example: 48 * <pre> 49 * CombinePrimitiveResolverDialog dialog = CombinePrimitiveResolverDialog.getInstance(); 50 * dialog.getTagConflictResolverModel().populate(aTagCollection); 51 * dialog.getRelationMemberConflictResolverModel().populate(aRelationLinkCollection); 52 * dialog.prepareDefaultDecisions(); 53 * </pre> 54 * 55 * You should also set the target primitive which other primitives (ways or nodes) are 56 * merged to. Use {@see #setTargetPrimitive(OsmPrimitive)}. 57 * 58 * After the dialog closed use {@see #isCancelled()} to check whether the user cancelled 59 * the dialog. If it wasn't cancelled you may build a collection of {@see Command} objects 60 * which reflect the conflict resolution decisions the user made in the dialog: 61 * see {@see #buildResolutionCommands()} 62 * 63 * 64 */ 65 public class CombinePrimitiveResolverDialog extends JDialog { 66 67 static private CombinePrimitiveResolverDialog instance; 68 69 public static CombinePrimitiveResolverDialog getInstance() { 41 70 if (instance == null) { 42 instance = new Combine WaysConflictResolverDialog(Main.parent);71 instance = new CombinePrimitiveResolverDialog(Main.parent); 43 72 } 44 73 return instance; … … 50 79 private boolean cancelled; 51 80 private JPanel pnlButtons; 52 private Way targetWay;53 54 55 56 public Way getTargetWay() {57 return target Way;58 } 59 60 public void setTarget Way(Way targetWay) {61 this.target Way = targetWay;81 private OsmPrimitive targetPrimitive; 82 83 84 85 public OsmPrimitive getTargetPrimitmive() { 86 return targetPrimitive; 87 } 88 89 public void setTargetPrimitive(OsmPrimitive primitive) { 90 this.targetPrimitive = primitive; 62 91 updateTitle(); 63 92 } 64 93 65 94 protected void updateTitle() { 66 if (target Way== null) {67 setTitle(tr("Conflicts when combining ways"));95 if (targetPrimitive == null) { 96 setTitle(tr("Conflicts when combining primitives")); 68 97 return; 69 98 } 70 setTitle( 71 tr( 72 "Conflicts when combining ways - combined way is ''{0}''", 73 targetWay.getDisplayName(DefaultNameFormatter.getInstance()) 74 ) 75 ); 99 if (targetPrimitive instanceof Way) { 100 setTitle( 101 tr( 102 "Conflicts when combining ways - combined way is ''{0}''", 103 targetPrimitive.getDisplayName(DefaultNameFormatter.getInstance()) 104 ) 105 ); 106 } else if (targetPrimitive instanceof Node) { 107 setTitle( 108 tr( 109 "Conflicts when merging nodes - merged node is ''{0}''", 110 targetPrimitive.getDisplayName(DefaultNameFormatter.getInstance()) 111 ) 112 ); 113 } 76 114 } 77 115 … … 113 151 } 114 152 115 public Combine WaysConflictResolverDialog(Component owner) {153 public CombinePrimitiveResolverDialog(Component owner) { 116 154 super(JOptionPane.getFrameForComponent(owner),true /* modal */); 117 155 build(); … … 143 181 } 144 182 145 public List<Command> buildResolutionCommands( Way targetWay) {183 public List<Command> buildResolutionCommands() { 146 184 List<Command> cmds = new LinkedList<Command>(); 147 185 148 186 if (getTagConflictResolverModel().getNumDecisions() >0) { 149 187 TagCollection tc = getTagConflictResolverModel().getResolution(); 150 cmds.addAll(buildTagChangeCommand(target Way, tc));188 cmds.addAll(buildTagChangeCommand(targetPrimitive, tc)); 151 189 } 152 190 153 191 if (getRelationMemberConflictResolverModel().getNumDecisions() >0) { 154 cmds.addAll(getRelationMemberConflictResolverModel().buildResolutionCommands(target Way));192 cmds.addAll(getRelationMemberConflictResolverModel().buildResolutionCommands(targetPrimitive)); 155 193 } 156 194 157 195 Command cmd = pnlRelationMemberConflictResolver.buildTagApplyCommands( 158 getRelationMemberConflictResolverModel().getModifiedRelations(target Way)196 getRelationMemberConflictResolverModel().getModifiedRelations(targetPrimitive) 159 197 ); 160 198 if (cmd != null) { … … 242 280 ) 243 281 ).applySafe(this); 282 setCancelled(false); 244 283 } else { 245 284 new WindowGeometry(this).remember(getClass().getName() + ".geometry"); -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverModel.java
r2070 r2095 18 18 import org.openstreetmap.josm.data.osm.Relation; 19 19 import org.openstreetmap.josm.data.osm.RelationMember; 20 20 import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference; 21 22 /** 23 * This model manages a list of conflicting relation members. 24 * 25 * It can be used as {@see TableModel}. 26 * 27 * 28 */ 21 29 public class RelationMemberConflictResolverModel extends DefaultTableModel { 30 /** the property name for the number conflicts managed by this model */ 22 31 static public final String NUM_CONFLICTS_PROP = RelationMemberConflictResolverModel.class.getName() + ".numConflicts"; 23 32 33 /** the list of conflict decisions */ 24 34 private List<RelationMemberConflictDecision> decisions; 35 /** the collection of relations for which we manage conflicts */ 25 36 private Collection<Relation> relations; 37 /** the number of conflicts */ 26 38 private int numConflicts; 27 39 private PropertyChangeSupport support; 28 40 29 41 42 /** 43 * Replies the current number of conflicts 44 * 45 * @return the current number of conflicts 46 */ 30 47 public int getNumConflicts() { 31 48 return numConflicts; 32 49 } 33 50 51 /** 52 * Updates the current number of conflicts from list of decisions and emits 53 * a property change event if necessary. 54 * 55 */ 34 56 protected void updateNumConflicts() { 35 57 int count = 0; … … 71 93 RelationMemberConflictDecision d = decisions.get(row); 72 94 switch(column) { 73 74 75 76 77 95 case 0: /* relation */ return d.getRelation(); 96 case 1: /* pos */ return Integer.toString(d.getPos() + 1); // position in "user space" starting at 1 97 case 2: /* role */ return d.getRole(); 98 case 3: /* original */ return d.getOriginalPrimitive(); 99 case 4: /* decision */ return d.getDecision(); 78 100 } 79 101 return null; … … 84 106 RelationMemberConflictDecision d = decisions.get(row); 85 107 switch(column) { 86 87 88 89 90 91 92 108 case 2: /* role */ 109 d.setRole((String)value); 110 break; 111 case 4: /* decision */ 112 d.decide((RelationMemberConflictDecisionType)value); 113 refresh(); 114 break; 93 115 } 94 116 fireTableDataChanged(); 95 117 } 96 118 119 /** 120 * Populates the model with the members of the relation <code>relation</code> 121 * referring to <code>primitive</code>. 122 * 123 * @param relation the parent relation 124 * @param primitive the child primitive 125 */ 97 126 protected void populate(Relation relation, OsmPrimitive primitive) { 127 decisions.clear(); 98 128 for (int i =0; i<relation.getMembersCount();i++) { 99 129 if (relation.getMember(i).refersTo(primitive)) { … … 103 133 } 104 134 135 /** 136 * Populates the model with the relation members belonging to one of the relations in <code>relations</code> 137 * and referring to one of the primitives in <code>memberPrimitives</code>. 138 * 139 * @param relations the parent relations. Empty list assumed if null. 140 * @param memberPrimitives the child primitives. Empty list assumed if null. 141 */ 105 142 public void populate(Collection<Relation> relations, Collection<? extends OsmPrimitive> memberPrimitives) { 106 143 decisions.clear(); 144 relations = relations == null ? new LinkedList<Relation>() : relations; 145 memberPrimitives = memberPrimitives == null ? new LinkedList<OsmPrimitive>() : memberPrimitives; 107 146 for (Relation r : relations) { 108 147 for (OsmPrimitive p: memberPrimitives) { … … 114 153 } 115 154 155 /** 156 * Populates the model with the relation members represented as a collection of 157 * {@see RelationToChildReference}s. 158 * 159 * @param references the references. Empty list assumed if null. 160 */ 161 public void populate(Collection<RelationToChildReference> references) { 162 references = references == null ? new LinkedList<RelationToChildReference>() : references; 163 if (references.isEmpty()) { 164 this.relations = new HashSet<Relation>(references.size()); 165 return; 166 } 167 decisions.clear(); 168 this.relations = new HashSet<Relation>(references.size()); 169 for (RelationToChildReference reference: references) { 170 decisions.add(new RelationMemberConflictDecision(reference.getParent(), reference.getPosition())); 171 relations.add(reference.getParent()); 172 } 173 refresh(); 174 } 175 176 /** 177 * Replies the decision at position <code>row</code> 178 * 179 * @param row 180 * @return the decision at position <code>row</code> 181 */ 116 182 public RelationMemberConflictDecision getDecision(int row) { 117 183 return decisions.get(row); 118 184 } 119 185 186 /** 187 * Replies the number of decisions managed by this model 188 * 189 * @return the number of decisions managed by this model 190 */ 120 191 public int getNumDecisions() { 121 192 return getRowCount(); 122 193 } 123 194 195 /** 196 * Refreshes the model state. Invoke this method to trigger necessary change 197 * events after an update of the model data. 198 * 199 */ 124 200 public void refresh() { 125 201 updateNumConflicts(); … … 127 203 } 128 204 205 /** 206 * Apply a role to all member managed by this model. 207 * 208 * @param role the role. Empty string assumed if null. 209 */ 129 210 public void applyRole(String role) { 130 211 role = role == null ? "" : role; … … 154 235 } else { 155 236 switch(decision.getDecision()) { 156 157 158 159 160 161 162 163 164 165 166 167 237 case REPLACE: 238 rmNew = new RelationMember(decision.getRole(),newPrimitive); 239 modifiedRelation.addMember(rmNew); 240 isChanged |= ! rm.equals(rmNew); 241 break; 242 case REMOVE: 243 isChanged = true; 244 // do nothing 245 break; 246 case UNDECIDED: 247 // FIXME: this is an error 248 break; 168 249 } 169 250 } … … 174 255 } 175 256 257 /** 258 * Builds a collection of commands executing the decisions made in this model. 259 * 260 * @param newPrimitive the primitive which members shall refer to if the 261 * decision is {@see RelationMemberConflictDecisionType#REPLACE} 262 * @return a list of commands 263 */ 176 264 public List<Command> buildResolutionCommands(OsmPrimitive newPrimitive) { 177 265 List<Command> command = new LinkedList<Command>(); … … 192 280 } 193 281 switch(decision.getDecision()) { 194 195 196 197 198 199 200 201 282 case REMOVE: return true; 283 case REPLACE: 284 if (!relation.getMember(i).getRole().equals(decision.getRole())) 285 return true; 286 if (relation.getMember(i).getMember() != newPrimitive) 287 return true; 288 case UNDECIDED: 289 // FIXME: handle error 202 290 } 203 291 } … … 205 293 } 206 294 295 /** 296 * Replies the set of relations which have to be modified according 297 * to the decisions managed by this model. 298 * 299 * @param newPrimitive the primitive which members shall refer to if the 300 * decision is {@see RelationMemberConflictDecisionType#REPLACE} 301 * 302 * @return the set of relations which have to be modified according 303 * to the decisions managed by this model 304 */ 207 305 public Set<Relation> getModifiedRelations(OsmPrimitive newPrimitive) { 208 306 HashSet<Relation> ret = new HashSet<Relation>();
Note:
See TracChangeset
for help on using the changeset viewer.