- Timestamp:
- 2016-01-27T22:18:36+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r9588 r9657 77 77 import org.openstreetmap.josm.gui.dialogs.relation.actions.OKAction; 78 78 import org.openstreetmap.josm.gui.dialogs.relation.actions.PasteMembersAction; 79 import org.openstreetmap.josm.gui.dialogs.relation.actions.RefreshAction; 79 80 import org.openstreetmap.josm.gui.dialogs.relation.actions.RemoveAction; 80 81 import org.openstreetmap.josm.gui.dialogs.relation.actions.RemoveSelectedAction; … … 128 129 private JButton sortBelowButton; 129 130 /** 131 * Action for performing the {@link RefreshAction} 132 */ 133 private RefreshAction refreshAction; 134 /** 135 * Action for performing the {@link ApplyAction} 136 */ 137 private ApplyAction applyAction; 138 /** 130 139 * Action for performing the {@link CancelAction} 131 140 */ … … 172 181 173 182 tagEditorPanel = new TagEditorPanel(relation, presetHandler); 174 175 // populate the models 176 // 177 if (relation != null) { 178 tagEditorPanel.getModel().initFromPrimitive(relation); 179 this.memberTableModel.populate(relation); 180 if (!getLayer().data.getRelations().contains(relation)) { 181 // treat it as a new relation if it doesn't exist in the 182 // data set yet. 183 setRelation(null); 184 } 185 } else { 186 tagEditorPanel.getModel().clear(); 187 this.memberTableModel.populate(null); 188 } 183 populateModels(relation); 189 184 tagEditorPanel.getModel().ensureOneTag(); 190 185 … … 259 254 } 260 255 261 protected void cancel() { 256 /** 257 * Reloads data from relation. 258 */ 259 public void reloadDataFromRelation() { 260 setRelation(getRelation()); 261 populateModels(getRelation()); 262 refreshAction.updateEnabledState(); 263 } 264 265 private void populateModels(Relation relation) { 266 if (relation != null) { 267 tagEditorPanel.getModel().initFromPrimitive(relation); 268 memberTableModel.populate(relation); 269 if (!getLayer().data.getRelations().contains(relation)) { 270 // treat it as a new relation if it doesn't exist in the data set yet. 271 setRelation(null); 272 } 273 } else { 274 tagEditorPanel.getModel().clear(); 275 memberTableModel.populate(null); 276 } 277 } 278 279 /** 280 * Apply changes. 281 * @see ApplyAction 282 */ 283 public void apply() { 284 applyAction.actionPerformed(null); 285 } 286 287 /** 288 * Cancel changes. 289 * @see CancelAction 290 */ 291 public void cancel() { 262 292 cancelAction.actionPerformed(null); 263 293 } … … 269 299 */ 270 300 protected JToolBar buildToolBar() { 271 JToolBar tb 301 JToolBar tb = new JToolBar(); 272 302 tb.setFloatable(false); 273 tb.add(new ApplyAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this)); 303 refreshAction = new RefreshAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this); 304 applyAction = new ApplyAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this); 305 tb.add(refreshAction); 306 tb.add(applyAction); 274 307 tb.add(new DuplicateRelationAction(memberTableModel, tagEditorPanel.getModel(), getLayer())); 275 308 DeleteCurrentRelationAction deleteAction = new DeleteCurrentRelationAction(getLayer(), this); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r9632 r9657 235 235 } 236 236 RelationMember member = members.get(rowIndex); 237 RelationMember newMember = new RelationMember(value.toString(), member.getMember()); 237 String role = value.toString(); 238 if (member.hasRole(role)) 239 return; 240 RelationMember newMember = new RelationMember(role, member.getMember()); 238 241 members.remove(rowIndex); 239 242 members.add(rowIndex, newMember); 243 fireTableDataChanged(); 240 244 } 241 245 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/ApplyAction.java
r9496 r9657 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component;7 6 import java.awt.event.ActionEvent; 8 7 8 import java.beans.PropertyChangeEvent; 9 import java.beans.PropertyChangeListener; 10 11 import javax.swing.event.TableModelEvent; 12 import javax.swing.event.TableModelListener; 13 14 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 9 15 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable; 10 16 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel; … … 18 24 * @since 9496 19 25 */ 20 public class ApplyAction extends SavingAction {26 public class ApplyAction extends SavingAction implements PropertyChangeListener, TableModelListener { 21 27 22 28 /** … … 34 40 putValue(SMALL_ICON, ImageProvider.get("save")); 35 41 putValue(NAME, tr("Apply")); 36 setEnabled(true); 42 updateEnabledState(); 43 memberTableModel.addTableModelListener(this); 44 tagModel.addPropertyChangeListener(this); 37 45 } 38 46 39 47 @Override 40 48 public void actionPerformed(ActionEvent e) { 41 if (editor.getRelation() == null) { 42 applyNewRelation(tagModel); 43 } else if (!memberTableModel.hasSameMembersAs(editor.getRelationSnapshot()) || tagModel.isDirty()) { 44 if (editor.isDirtyRelation()) { 45 if (confirmClosingBecauseOfDirtyState()) { 46 if (layer.getConflicts().hasConflictForMy(editor.getRelation())) { 47 warnDoubleConflict(); 48 return; 49 } 50 applyExistingConflictingRelation(tagModel); 51 if (editor instanceof Component) { 52 ((Component) editor).setVisible(false); 53 } 54 } 55 } else { 56 applyExistingNonConflictingRelation(tagModel); 57 } 49 if (applyChanges()) { 50 ((GenericRelationEditor) editor).reloadDataFromRelation(); 58 51 } 59 52 } 53 54 @Override 55 protected void updateEnabledState() { 56 setEnabled(isEditorDirty()); 57 } 58 59 @Override 60 public void propertyChange(PropertyChangeEvent evt) { 61 updateEnabledState(); 62 } 63 64 @Override 65 public void tableChanged(TableModelEvent e) { 66 updateEnabledState(); 67 } 60 68 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java
r9512 r9657 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component;7 6 import java.awt.event.ActionEvent; 8 7 … … 66 65 //copied from OKAction.run() 67 66 Main.pref.put("relation.editor.generic.lastrole", tfRole.getText()); 68 if (editor.getRelation() == null) { 69 applyNewRelation(tagModel); 70 } else if (!memberTableModel.hasSameMembersAs(snapshot) || tagModel.isDirty()) { 71 if (editor.isDirtyRelation()) { 72 if (confirmClosingBecauseOfDirtyState()) { 73 if (layer.getConflicts().hasConflictForMy(editor.getRelation())) { 74 warnDoubleConflict(); 75 return; 76 } 77 applyExistingConflictingRelation(tagModel); 78 } else 79 return; 80 } else { 81 applyExistingNonConflictingRelation(tagModel); 82 } 83 } 67 if (!applyChanges()) 68 return; 84 69 } else if (ret == 2 || ret == JOptionPane.CLOSED_OPTION) //Cancel, continue editing 85 70 return; 86 71 //in case of "No, discard", there is no extra action to be performed here. 87 72 } 88 if (editor instanceof Component) { 89 ((Component) editor).setVisible(false); 90 } 73 hideEditor(); 91 74 } 92 75 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/OKAction.java
r9496 r9657 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component;7 6 import java.awt.event.ActionEvent; 8 7 … … 43 42 Main.pref.put("relation.editor.generic.lastrole", tfRole.getText()); 44 43 memberTable.stopHighlighting(); 45 if (editor.getRelation() == null) { 46 applyNewRelation(tagModel); 47 } else if (!memberTableModel.hasSameMembersAs(editor.getRelationSnapshot()) || tagModel.isDirty()) { 48 if (editor.isDirtyRelation()) { 49 if (confirmClosingBecauseOfDirtyState()) { 50 if (layer.getConflicts().hasConflictForMy(editor.getRelation())) { 51 warnDoubleConflict(); 52 return; 53 } 54 applyExistingConflictingRelation(tagModel); 55 } else 56 return; 57 } else { 58 applyExistingNonConflictingRelation(tagModel); 59 } 60 } 61 if (editor instanceof Component) { 62 ((Component) editor).setVisible(false); 63 } 44 if (!applyChanges()) 45 return; 46 hideEditor(); 64 47 } 65 48 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java
r9496 r9657 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component; 6 7 import java.util.ArrayList; 7 8 import java.util.List; … … 111 112 Main.main.undoRedo.add(new ChangeCommand(editor.getRelation(), editedRelation)); 112 113 layer.data.fireSelectionChanged(); 113 // this will refresh the snapshot and update the dialog title114 //115 editor.setRelation(editor.getRelation());116 114 } 117 115 … … 166 164 // Do nothing 167 165 } 166 167 protected boolean applyChanges() { 168 if (editor.getRelation() == null) { 169 applyNewRelation(tagModel); 170 } else if (isEditorDirty()) { 171 if (editor.isDirtyRelation()) { 172 if (confirmClosingBecauseOfDirtyState()) { 173 if (layer.getConflicts().hasConflictForMy(editor.getRelation())) { 174 warnDoubleConflict(); 175 return false; 176 } 177 applyExistingConflictingRelation(tagModel); 178 hideEditor(); 179 } else 180 return false; 181 } else { 182 applyExistingNonConflictingRelation(tagModel); 183 } 184 } 185 editor.setRelation(editor.getRelation()); 186 return true; 187 } 188 189 protected void hideEditor() { 190 if (editor instanceof Component) { 191 ((Component) editor).setVisible(false); 192 } 193 } 194 195 protected boolean isEditorDirty() { 196 Relation snapshot = editor.getRelationSnapshot(); 197 return (snapshot != null && !memberTableModel.hasSameMembersAs(snapshot)) || tagModel.isDirty(); 198 } 168 199 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java
r9623 r9657 166 166 */ 167 167 public void clear() { 168 boolean wasEmpty = tags.isEmpty(); 168 169 tags.clear(); 169 setDirty(true); 170 fireTableDataChanged(); 170 if (!wasEmpty) { 171 setDirty(true); 172 fireTableDataChanged(); 173 } 171 174 } 172 175 … … 335 338 tags.add(tag); 336 339 fireTableDataChanged(); 337 setDirty(true);338 340 } 339 341
Note:
See TracChangeset
for help on using the changeset viewer.