source: josm/trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java@ 1750

Last change on this file since 1750 was 1750, checked in by Gubaer, 15 years ago

new: replaced global conflict list by conflict list per layer, similar to datasets

File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.util.Collection;
9import java.util.HashSet;
10import java.util.Set;
11
12import javax.swing.JOptionPane;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.command.PurgePrimitivesCommand;
16import org.openstreetmap.josm.data.osm.DataSet;
17import org.openstreetmap.josm.data.osm.OsmPrimitive;
18import org.openstreetmap.josm.io.MultiFetchServerObjectReader;
19import org.openstreetmap.josm.tools.Shortcut;
20
21/**
22 * This action synchronizes a set of primitives with their state on the server.
23 *
24 *
25 */
26public class UpdateSelectionAction extends JosmAction {
27
28 static public int DEFAULT_MAX_SIZE_UPDATE_SELECTION = 50;
29
30 /**
31 * handle an exception thrown because a primitive was deleted on the server
32 *
33 * @param id the primitive id
34 */
35 protected void handlePrimitiveGoneException(long id) {
36 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader();
37 reader.append(Main.main.createOrGetEditLayer().data,id);
38 DataSet ds = null;
39 try {
40 ds = reader.parseOsm();
41 } catch(Exception e) {
42 handleUpdateException(e);
43 return;
44 }
45 Main.main.createOrGetEditLayer().mergeFrom(ds);
46 }
47
48 /**
49 * handle an exception thrown during updating a primitive
50 *
51 * @param id the id of the primitive
52 * @param e the exception
53 */
54 protected void handleUpdateException(Exception e) {
55 e.printStackTrace();
56 JOptionPane.showMessageDialog(
57 Main.parent,
58 tr("Failed to update the selected primitives."),
59 tr("Update failed"),
60 JOptionPane.ERROR_MESSAGE
61 );
62 }
63
64 /**
65 *
66 * @param id
67 */
68 protected void handleMissingPrimitive(long id) {
69 JOptionPane.showMessageDialog(
70 Main.parent,
71 tr("Could not find primitive with id {0} in the current dataset", new Long(id).toString()),
72 tr("Missing primitive"),
73 JOptionPane.ERROR_MESSAGE
74 );
75 }
76
77 /**
78 *
79 *
80 *
81 */
82 public void updatePrimitives(Collection<OsmPrimitive> selection) {
83 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader();
84 reader.append(selection);
85 DataSet ds = null;
86 try {
87 ds = reader.parseOsm();
88 } catch(Exception e) {
89 handleUpdateException(e);
90 return;
91 }
92 Main.main.createOrGetEditLayer().mergeFrom(ds);
93 }
94
95 public void updatePrimitive(long id) {
96 OsmPrimitive primitive = Main.main.createOrGetEditLayer().data.getPrimitiveById(id);
97 Set<OsmPrimitive> s = new HashSet<OsmPrimitive>();
98 s.add(primitive);
99 updatePrimitives(s);
100 }
101
102 public UpdateSelectionAction() {
103 super(tr("Update Selection"),
104 "updateselection",
105 tr("Updates the currently selected primitives from the server"),
106 Shortcut.registerShortcut("file:updateselection",
107 tr("Update Selection"),
108 KeyEvent.VK_U,
109 Shortcut.GROUP_HOTKEY + Shortcut.GROUPS_ALT2),
110 true);
111 }
112
113
114 public void actionPerformed(ActionEvent e) {
115 Collection<OsmPrimitive> selection = Main.ds.getSelected();
116 if (selection.size() == 0) {
117 JOptionPane.showMessageDialog(
118 Main.parent,
119 tr("There are no selected primitives to update."),
120 tr("Selection empty"),
121 JOptionPane.INFORMATION_MESSAGE
122 );
123 return;
124 }
125 updatePrimitives(selection);
126 }
127}
Note: See TracBrowser for help on using the repository browser.