1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.BorderLayout;
|
---|
7 | import java.awt.FlowLayout;
|
---|
8 | import java.awt.Frame;
|
---|
9 | import java.awt.event.ActionEvent;
|
---|
10 | import java.awt.event.ItemEvent;
|
---|
11 | import java.awt.event.ItemListener;
|
---|
12 | import java.awt.event.MouseAdapter;
|
---|
13 | import java.awt.event.MouseEvent;
|
---|
14 | import java.util.Collection;
|
---|
15 | import java.util.HashSet;
|
---|
16 | import java.util.List;
|
---|
17 | import java.util.Set;
|
---|
18 | import java.util.concurrent.ExecutionException;
|
---|
19 | import java.util.concurrent.Future;
|
---|
20 |
|
---|
21 | import javax.swing.AbstractAction;
|
---|
22 | import javax.swing.DefaultListSelectionModel;
|
---|
23 | import javax.swing.JCheckBox;
|
---|
24 | import javax.swing.JList;
|
---|
25 | import javax.swing.JPanel;
|
---|
26 | import javax.swing.JPopupMenu;
|
---|
27 | import javax.swing.JScrollPane;
|
---|
28 | import javax.swing.ListSelectionModel;
|
---|
29 | import javax.swing.SwingUtilities;
|
---|
30 | import javax.swing.event.ListSelectionEvent;
|
---|
31 | import javax.swing.event.ListSelectionListener;
|
---|
32 |
|
---|
33 | import org.openstreetmap.josm.Main;
|
---|
34 | import org.openstreetmap.josm.actions.AbstractInfoAction;
|
---|
35 | import org.openstreetmap.josm.data.osm.Changeset;
|
---|
36 | import org.openstreetmap.josm.data.osm.ChangesetCache;
|
---|
37 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
38 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
39 | import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
|
---|
40 | import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
|
---|
41 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
42 | import org.openstreetmap.josm.gui.MapView;
|
---|
43 | import org.openstreetmap.josm.gui.SideButton;
|
---|
44 | import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetCacheManager;
|
---|
45 | import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetHeaderDownloadTask;
|
---|
46 | import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetInSelectionListModel;
|
---|
47 | import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetListCellRenderer;
|
---|
48 | import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetListModel;
|
---|
49 | import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetsInActiveDataLayerListModel;
|
---|
50 | import org.openstreetmap.josm.gui.help.HelpUtil;
|
---|
51 | import org.openstreetmap.josm.gui.io.CloseChangesetTask;
|
---|
52 | import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
|
---|
53 | import org.openstreetmap.josm.tools.BugReportExceptionHandler;
|
---|
54 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
55 | import org.openstreetmap.josm.tools.OpenBrowser;
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * ChangesetDialog is a toggle dialog which displays the current list of changesets.
|
---|
59 | * It either displays
|
---|
60 | * <ul>
|
---|
61 | * <li>the list of changesets the currently selected objects are assigned to</li>
|
---|
62 | * <li>the list of changesets objects in the current data layer are assigend to</li>
|
---|
63 | * </ul>
|
---|
64 | *
|
---|
65 | * The dialog offers actions to download and to close changesets. It can also launch an external
|
---|
66 | * browser with information about a changeset. Furthermore, it can select all objects in
|
---|
67 | * the current data layer being assigned to a specific changeset.
|
---|
68 | *
|
---|
69 | */
|
---|
70 | public class ChangesetDialog extends ToggleDialog{
|
---|
71 | //static private final Logger logger = Logger.getLogger(ChangesetDialog.class.getName());
|
---|
72 |
|
---|
73 | private ChangesetInSelectionListModel inSelectionModel;
|
---|
74 | private ChangesetsInActiveDataLayerListModel inActiveDataLayerModel;
|
---|
75 | private JList lstInSelection;
|
---|
76 | private JList lstInActiveDataLayer;
|
---|
77 | private JCheckBox cbInSelectionOnly;
|
---|
78 | private JPanel pnlList;
|
---|
79 |
|
---|
80 | // the actions
|
---|
81 | private SelectObjectsAction selectObjectsAction;
|
---|
82 | private ReadChangesetsAction readChangesetAction;
|
---|
83 | private ShowChangesetInfoAction showChangsetInfoAction;
|
---|
84 | private CloseOpenChangesetsAction closeChangesetAction;
|
---|
85 | private LaunchChangesetManagerAction launchChangesetManagerAction;
|
---|
86 |
|
---|
87 | protected void buildChangesetsLists() {
|
---|
88 | DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
|
---|
89 | inSelectionModel = new ChangesetInSelectionListModel(selectionModel);
|
---|
90 |
|
---|
91 | lstInSelection = new JList(inSelectionModel);
|
---|
92 | lstInSelection.setSelectionModel(selectionModel);
|
---|
93 | lstInSelection.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
---|
94 | lstInSelection.setCellRenderer(new ChangesetListCellRenderer());
|
---|
95 |
|
---|
96 | selectionModel = new DefaultListSelectionModel();
|
---|
97 | inActiveDataLayerModel = new ChangesetsInActiveDataLayerListModel(selectionModel);
|
---|
98 | lstInActiveDataLayer = new JList(inActiveDataLayerModel);
|
---|
99 | lstInActiveDataLayer.setSelectionModel(selectionModel);
|
---|
100 | lstInActiveDataLayer.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
---|
101 | lstInActiveDataLayer.setCellRenderer(new ChangesetListCellRenderer());
|
---|
102 |
|
---|
103 | DblClickHandler dblClickHandler = new DblClickHandler();
|
---|
104 | lstInSelection.addMouseListener(dblClickHandler);
|
---|
105 | lstInActiveDataLayer.addMouseListener(dblClickHandler);
|
---|
106 |
|
---|
107 | ChangesetPopupMenuLauncher popupMenuLauncher = new ChangesetPopupMenuLauncher();
|
---|
108 | lstInSelection.addMouseListener(popupMenuLauncher);
|
---|
109 | lstInActiveDataLayer.addMouseListener(popupMenuLauncher);
|
---|
110 | }
|
---|
111 |
|
---|
112 | protected void registerAsListener() {
|
---|
113 | // let the model for changesets in the current selection listen to various
|
---|
114 | // events
|
---|
115 | ChangesetCache.getInstance().addChangesetCacheListener(inSelectionModel);
|
---|
116 | MapView.addEditLayerChangeListener(inSelectionModel);
|
---|
117 | DataSet.selListeners.add(inSelectionModel);
|
---|
118 |
|
---|
119 | // let the model for changesets in the current layer listen to various
|
---|
120 | // events and bootstrap it's content
|
---|
121 | ChangesetCache.getInstance().addChangesetCacheListener(inActiveDataLayerModel);
|
---|
122 | MapView.addEditLayerChangeListener(inActiveDataLayerModel);
|
---|
123 | if (Main.main.getEditLayer() != null) {
|
---|
124 | Main.main.getEditLayer().data.addDataSetListener(inActiveDataLayerModel);
|
---|
125 | inActiveDataLayerModel.initFromDataSet(Main.main.getEditLayer().data);
|
---|
126 | inSelectionModel.initFromPrimitives(Main.main.getEditLayer().data.getSelected());
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | protected void unregisterAsListener() {
|
---|
131 | // remove the list model for the current edit layer as listener
|
---|
132 | //
|
---|
133 | ChangesetCache.getInstance().removeChangesetCacheListener(inActiveDataLayerModel);
|
---|
134 | MapView.removeEditLayerChangeListener(inActiveDataLayerModel);
|
---|
135 | if (Main.main.getEditLayer() != null) {
|
---|
136 | Main.main.getEditLayer().data.removeDataSetListener(inActiveDataLayerModel);
|
---|
137 | }
|
---|
138 |
|
---|
139 | // remove the list model for the changesets in the current selection as
|
---|
140 | // listener
|
---|
141 | //
|
---|
142 | MapView.removeEditLayerChangeListener(inSelectionModel);
|
---|
143 | DataSet.selListeners.remove(inSelectionModel);
|
---|
144 | }
|
---|
145 |
|
---|
146 | @Override
|
---|
147 | public void showNotify() {
|
---|
148 | registerAsListener();
|
---|
149 | DatasetEventManager.getInstance().addDatasetListener(inActiveDataLayerModel, FireMode.IN_EDT);
|
---|
150 | }
|
---|
151 |
|
---|
152 | @Override
|
---|
153 | public void hideNotify() {
|
---|
154 | unregisterAsListener();
|
---|
155 | DatasetEventManager.getInstance().removeDatasetListener(inActiveDataLayerModel);
|
---|
156 | }
|
---|
157 |
|
---|
158 | protected JPanel buildFilterPanel() {
|
---|
159 | JPanel pnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
---|
160 | pnl.setBorder(null);
|
---|
161 | pnl.add(cbInSelectionOnly = new JCheckBox(tr("For selected objects only")));
|
---|
162 | cbInSelectionOnly.setToolTipText(tr("<html>Select to show changesets for the currently selected objects only.<br>"
|
---|
163 | + "Unselect to show all changesets for objects in the current data layer.</html>"));
|
---|
164 | cbInSelectionOnly.setSelected(Main.pref.getBoolean("changeset-dialog.for-selected-objects-only", false));
|
---|
165 | return pnl;
|
---|
166 | }
|
---|
167 |
|
---|
168 | protected JPanel buildListPanel() {
|
---|
169 | buildChangesetsLists();
|
---|
170 | JPanel pnl = new JPanel(new BorderLayout());
|
---|
171 | if (cbInSelectionOnly.isSelected()) {
|
---|
172 | pnl.add(new JScrollPane(lstInSelection));
|
---|
173 | } else {
|
---|
174 | pnl.add(new JScrollPane(lstInActiveDataLayer));
|
---|
175 | }
|
---|
176 | return pnl;
|
---|
177 | }
|
---|
178 |
|
---|
179 | protected JPanel buildButtonPanel() {
|
---|
180 | JPanel tp = getButtonPanel(5);
|
---|
181 |
|
---|
182 | // -- select objects action
|
---|
183 | selectObjectsAction = new SelectObjectsAction();
|
---|
184 | tp.add(new SideButton(selectObjectsAction, false));
|
---|
185 | cbInSelectionOnly.addItemListener(selectObjectsAction);
|
---|
186 | lstInActiveDataLayer.getSelectionModel().addListSelectionListener(selectObjectsAction);
|
---|
187 | lstInSelection.getSelectionModel().addListSelectionListener(selectObjectsAction);
|
---|
188 |
|
---|
189 | // -- read changesets action
|
---|
190 | readChangesetAction = new ReadChangesetsAction();
|
---|
191 | tp.add(new SideButton(readChangesetAction, false));
|
---|
192 | cbInSelectionOnly.addItemListener(readChangesetAction);
|
---|
193 | lstInActiveDataLayer.getSelectionModel().addListSelectionListener(readChangesetAction);
|
---|
194 | lstInSelection.getSelectionModel().addListSelectionListener(readChangesetAction);
|
---|
195 |
|
---|
196 | // -- close changesets action
|
---|
197 | closeChangesetAction = new CloseOpenChangesetsAction();
|
---|
198 | tp.add(new SideButton(closeChangesetAction, false));
|
---|
199 | cbInSelectionOnly.addItemListener(closeChangesetAction);
|
---|
200 | lstInActiveDataLayer.getSelectionModel().addListSelectionListener(closeChangesetAction);
|
---|
201 | lstInSelection.getSelectionModel().addListSelectionListener(closeChangesetAction);
|
---|
202 |
|
---|
203 | // -- show info action
|
---|
204 | showChangsetInfoAction = new ShowChangesetInfoAction();
|
---|
205 | tp.add(new SideButton(showChangsetInfoAction, false));
|
---|
206 | cbInSelectionOnly.addItemListener(showChangsetInfoAction);
|
---|
207 | lstInActiveDataLayer.getSelectionModel().addListSelectionListener(showChangsetInfoAction);
|
---|
208 | lstInSelection.getSelectionModel().addListSelectionListener(showChangsetInfoAction);
|
---|
209 |
|
---|
210 | // -- launch changeset manager action
|
---|
211 | launchChangesetManagerAction = new LaunchChangesetManagerAction();
|
---|
212 | tp.add(new SideButton(launchChangesetManagerAction, false));
|
---|
213 | cbInSelectionOnly.addItemListener(launchChangesetManagerAction);
|
---|
214 | lstInActiveDataLayer.getSelectionModel().addListSelectionListener(launchChangesetManagerAction);
|
---|
215 | lstInSelection.getSelectionModel().addListSelectionListener(launchChangesetManagerAction);
|
---|
216 |
|
---|
217 | return tp;
|
---|
218 | }
|
---|
219 |
|
---|
220 | protected void build() {
|
---|
221 | JPanel pnl = new JPanel(new BorderLayout());
|
---|
222 | pnl.add(buildFilterPanel(), BorderLayout.NORTH);
|
---|
223 | pnl.add(pnlList = buildListPanel(), BorderLayout.CENTER);
|
---|
224 | pnl.add(buildButtonPanel(), BorderLayout.SOUTH);
|
---|
225 | add(pnl, BorderLayout.CENTER);
|
---|
226 |
|
---|
227 | cbInSelectionOnly.addItemListener(new FilterChangeHandler());
|
---|
228 |
|
---|
229 | HelpUtil.setHelpContext(pnl, HelpUtil.ht("/Dialog/ChangesetListDialog"));
|
---|
230 | }
|
---|
231 |
|
---|
232 | protected JList getCurrentChangesetList() {
|
---|
233 | if (cbInSelectionOnly.isSelected())
|
---|
234 | return lstInSelection;
|
---|
235 | return lstInActiveDataLayer;
|
---|
236 | }
|
---|
237 |
|
---|
238 | protected ChangesetListModel getCurrentChangesetListModel() {
|
---|
239 | if (cbInSelectionOnly.isSelected())
|
---|
240 | return inSelectionModel;
|
---|
241 | return inActiveDataLayerModel;
|
---|
242 | }
|
---|
243 |
|
---|
244 | protected void initWithCurrentData() {
|
---|
245 | if (Main.main.getEditLayer() != null) {
|
---|
246 | inSelectionModel.initFromPrimitives(Main.main.getEditLayer().data.getSelected());
|
---|
247 | inActiveDataLayerModel.initFromDataSet(Main.main.getEditLayer().data);
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | public ChangesetDialog(MapFrame mapFrame) {
|
---|
252 | super(
|
---|
253 | tr("Changesets"),
|
---|
254 | "changesetdialog",
|
---|
255 | tr("Open the list of changesets in the current layer."),
|
---|
256 | null, /* no keyboard shortcut */
|
---|
257 | 200, /* the preferred height */
|
---|
258 | false /* don't show if there is no preference */
|
---|
259 | );
|
---|
260 | build();
|
---|
261 | initWithCurrentData();
|
---|
262 | }
|
---|
263 |
|
---|
264 | class DblClickHandler extends MouseAdapter {
|
---|
265 | @Override
|
---|
266 | public void mouseClicked(MouseEvent e) {
|
---|
267 | if (!SwingUtilities.isLeftMouseButton(e) || e.getClickCount() < 2)
|
---|
268 | return;
|
---|
269 | Set<Integer> sel = getCurrentChangesetListModel().getSelectedChangesetIds();
|
---|
270 | if (sel.isEmpty())
|
---|
271 | return;
|
---|
272 | if (Main.main.getCurrentDataSet() == null)
|
---|
273 | return;
|
---|
274 | new SelectObjectsAction().selectObjectsByChangesetIds(Main.main.getCurrentDataSet(), sel);
|
---|
275 | }
|
---|
276 |
|
---|
277 | }
|
---|
278 |
|
---|
279 | class FilterChangeHandler implements ItemListener {
|
---|
280 | public void itemStateChanged(ItemEvent e) {
|
---|
281 | Main.pref.put("changeset-dialog.for-selected-objects-only", cbInSelectionOnly.isSelected());
|
---|
282 | pnlList.removeAll();
|
---|
283 | if (cbInSelectionOnly.isSelected()) {
|
---|
284 | pnlList.add(new JScrollPane(lstInSelection), BorderLayout.CENTER);
|
---|
285 | } else {
|
---|
286 | pnlList.add(new JScrollPane(lstInActiveDataLayer), BorderLayout.CENTER);
|
---|
287 | }
|
---|
288 | validate();
|
---|
289 | repaint();
|
---|
290 | }
|
---|
291 | }
|
---|
292 |
|
---|
293 | /**
|
---|
294 | * Selects objects for the currently selected changesets.
|
---|
295 | */
|
---|
296 | class SelectObjectsAction extends AbstractAction implements ListSelectionListener, ItemListener{
|
---|
297 |
|
---|
298 | public SelectObjectsAction() {
|
---|
299 | putValue(NAME, tr("Select"));
|
---|
300 | putValue(SHORT_DESCRIPTION, tr("Select all objects assigned to the currently selected changesets"));
|
---|
301 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
|
---|
302 | updateEnabledState();
|
---|
303 | }
|
---|
304 |
|
---|
305 | public void selectObjectsByChangesetIds(DataSet ds, Set<Integer> ids) {
|
---|
306 | if (ds == null || ids == null)
|
---|
307 | return;
|
---|
308 | Set<OsmPrimitive> sel = new HashSet<OsmPrimitive>();
|
---|
309 | for (OsmPrimitive p: ds.getNodes()) {
|
---|
310 | if (ids.contains(p.getChangesetId())) {
|
---|
311 | sel.add(p);
|
---|
312 | }
|
---|
313 | }
|
---|
314 | for (OsmPrimitive p: ds.getWays()) {
|
---|
315 | if (ids.contains(p.getChangesetId())) {
|
---|
316 | sel.add(p);
|
---|
317 | }
|
---|
318 | }
|
---|
319 | for (OsmPrimitive p: ds.getRelations()) {
|
---|
320 | if (ids.contains(p.getChangesetId())) {
|
---|
321 | sel.add(p);
|
---|
322 | }
|
---|
323 | }
|
---|
324 | ds.setSelected(sel);
|
---|
325 | }
|
---|
326 |
|
---|
327 | public void actionPerformed(ActionEvent e) {
|
---|
328 | if (Main.main.getEditLayer() == null)
|
---|
329 | return;
|
---|
330 | ChangesetListModel model = getCurrentChangesetListModel();
|
---|
331 | Set<Integer> sel = model.getSelectedChangesetIds();
|
---|
332 | if (sel.isEmpty())
|
---|
333 | return;
|
---|
334 |
|
---|
335 | DataSet ds = Main.main.getEditLayer().data;
|
---|
336 | selectObjectsByChangesetIds(ds,sel);
|
---|
337 | }
|
---|
338 |
|
---|
339 | protected void updateEnabledState() {
|
---|
340 | setEnabled(getCurrentChangesetList().getSelectedIndices().length > 0);
|
---|
341 | }
|
---|
342 |
|
---|
343 | public void itemStateChanged(ItemEvent arg0) {
|
---|
344 | updateEnabledState();
|
---|
345 |
|
---|
346 | }
|
---|
347 |
|
---|
348 | public void valueChanged(ListSelectionEvent e) {
|
---|
349 | updateEnabledState();
|
---|
350 | }
|
---|
351 | }
|
---|
352 |
|
---|
353 | /**
|
---|
354 | * Downloads selected changesets
|
---|
355 | *
|
---|
356 | */
|
---|
357 | class ReadChangesetsAction extends AbstractAction implements ListSelectionListener, ItemListener{
|
---|
358 | public ReadChangesetsAction() {
|
---|
359 | putValue(NAME, tr("Download"));
|
---|
360 | putValue(SHORT_DESCRIPTION, tr("Download information about the selected changesets from the OSM server"));
|
---|
361 | putValue(SMALL_ICON, ImageProvider.get("download"));
|
---|
362 | updateEnabledState();
|
---|
363 | }
|
---|
364 |
|
---|
365 | public void actionPerformed(ActionEvent arg0) {
|
---|
366 | ChangesetListModel model = getCurrentChangesetListModel();
|
---|
367 | Set<Integer> sel = model.getSelectedChangesetIds();
|
---|
368 | if (sel.isEmpty())
|
---|
369 | return;
|
---|
370 | ChangesetHeaderDownloadTask task = new ChangesetHeaderDownloadTask(sel);
|
---|
371 | Main.worker.submit(task);
|
---|
372 | }
|
---|
373 |
|
---|
374 | protected void updateEnabledState() {
|
---|
375 | setEnabled(getCurrentChangesetList().getSelectedIndices().length > 0);
|
---|
376 | }
|
---|
377 |
|
---|
378 | public void itemStateChanged(ItemEvent arg0) {
|
---|
379 | updateEnabledState();
|
---|
380 |
|
---|
381 | }
|
---|
382 |
|
---|
383 | public void valueChanged(ListSelectionEvent e) {
|
---|
384 | updateEnabledState();
|
---|
385 | }
|
---|
386 | }
|
---|
387 |
|
---|
388 | /**
|
---|
389 | * Closes the currently selected changesets
|
---|
390 | *
|
---|
391 | */
|
---|
392 | class CloseOpenChangesetsAction extends AbstractAction implements ListSelectionListener, ItemListener {
|
---|
393 | public CloseOpenChangesetsAction() {
|
---|
394 | putValue(NAME, tr("Close open changesets"));
|
---|
395 | putValue(SHORT_DESCRIPTION, tr("Closes the selected open changesets"));
|
---|
396 | putValue(SMALL_ICON, ImageProvider.get("closechangeset"));
|
---|
397 | updateEnabledState();
|
---|
398 | }
|
---|
399 |
|
---|
400 | public void actionPerformed(ActionEvent arg0) {
|
---|
401 | List<Changeset> sel = getCurrentChangesetListModel().getSelectedOpenChangesets();
|
---|
402 | if (sel.isEmpty())
|
---|
403 | return;
|
---|
404 | Main.worker.submit(new CloseChangesetTask(sel));
|
---|
405 | }
|
---|
406 |
|
---|
407 | protected void updateEnabledState() {
|
---|
408 | setEnabled(getCurrentChangesetListModel().hasSelectedOpenChangesets());
|
---|
409 | }
|
---|
410 |
|
---|
411 | public void itemStateChanged(ItemEvent arg0) {
|
---|
412 | updateEnabledState();
|
---|
413 | }
|
---|
414 |
|
---|
415 | public void valueChanged(ListSelectionEvent e) {
|
---|
416 | updateEnabledState();
|
---|
417 | }
|
---|
418 | }
|
---|
419 |
|
---|
420 | /**
|
---|
421 | * Show information about the currently selected changesets
|
---|
422 | *
|
---|
423 | */
|
---|
424 | class ShowChangesetInfoAction extends AbstractAction implements ListSelectionListener, ItemListener {
|
---|
425 | public ShowChangesetInfoAction() {
|
---|
426 | putValue(NAME, tr("Show info"));
|
---|
427 | putValue(SHORT_DESCRIPTION, tr("Open a web page for each selected changeset"));
|
---|
428 | putValue(SMALL_ICON, ImageProvider.get("about"));
|
---|
429 | updateEnabledState();
|
---|
430 | }
|
---|
431 |
|
---|
432 | public void actionPerformed(ActionEvent arg0) {
|
---|
433 | Set<Changeset> sel = getCurrentChangesetListModel().getSelectedChangesets();
|
---|
434 | if (sel.isEmpty())
|
---|
435 | return;
|
---|
436 | if (sel.size() > 10 && ! AbstractInfoAction.confirmLaunchMultiple(sel.size()))
|
---|
437 | return;
|
---|
438 | String baseUrl = AbstractInfoAction.getBaseBrowseUrl();
|
---|
439 | for (Changeset cs: sel) {
|
---|
440 | String url = baseUrl + "/changeset/" + cs.getId();
|
---|
441 | OpenBrowser.displayUrl(
|
---|
442 | url
|
---|
443 | );
|
---|
444 | }
|
---|
445 | }
|
---|
446 |
|
---|
447 | protected void updateEnabledState() {
|
---|
448 | setEnabled(getCurrentChangesetList().getSelectedIndices().length > 0);
|
---|
449 | }
|
---|
450 |
|
---|
451 | public void itemStateChanged(ItemEvent arg0) {
|
---|
452 | updateEnabledState();
|
---|
453 | }
|
---|
454 |
|
---|
455 | public void valueChanged(ListSelectionEvent e) {
|
---|
456 | updateEnabledState();
|
---|
457 | }
|
---|
458 | }
|
---|
459 |
|
---|
460 | /**
|
---|
461 | * Show information about the currently selected changesets
|
---|
462 | *
|
---|
463 | */
|
---|
464 | class LaunchChangesetManagerAction extends AbstractAction implements ListSelectionListener, ItemListener {
|
---|
465 | public LaunchChangesetManagerAction() {
|
---|
466 | putValue(NAME, tr("Details"));
|
---|
467 | putValue(SHORT_DESCRIPTION, tr("Opens the Changeset Manager window for the selected changesets"));
|
---|
468 | putValue(SMALL_ICON, ImageProvider.get("dialogs/changeset", "changesetmanager"));
|
---|
469 | updateEnabledState();
|
---|
470 | }
|
---|
471 |
|
---|
472 | protected void launchChangesetManager(Collection<Integer> toSelect) {
|
---|
473 | ChangesetCacheManager cm = ChangesetCacheManager.getInstance();
|
---|
474 | if (cm.isVisible()) {
|
---|
475 | cm.setExtendedState(Frame.NORMAL);
|
---|
476 | cm.toFront();
|
---|
477 | cm.requestFocus();
|
---|
478 | } else {
|
---|
479 | cm.setVisible(true);
|
---|
480 | cm.toFront();
|
---|
481 | cm.requestFocus();
|
---|
482 | }
|
---|
483 | cm.setSelectedChangesetsById(toSelect);
|
---|
484 | }
|
---|
485 |
|
---|
486 | public void actionPerformed(ActionEvent arg0) {
|
---|
487 | ChangesetListModel model = getCurrentChangesetListModel();
|
---|
488 | Set<Integer> sel = model.getSelectedChangesetIds();
|
---|
489 | if (sel.isEmpty())
|
---|
490 | return;
|
---|
491 | final Set<Integer> toDownload = new HashSet<Integer>();
|
---|
492 | ChangesetCache cc = ChangesetCache.getInstance();
|
---|
493 | for (int id: sel) {
|
---|
494 | if (!cc.contains(id)) {
|
---|
495 | toDownload.add(id);
|
---|
496 | }
|
---|
497 | }
|
---|
498 |
|
---|
499 | final ChangesetHeaderDownloadTask task;
|
---|
500 | final Future<?> future;
|
---|
501 | if (toDownload.isEmpty()) {
|
---|
502 | task = null;
|
---|
503 | future = null;
|
---|
504 | } else {
|
---|
505 | task = new ChangesetHeaderDownloadTask(toDownload);
|
---|
506 | future = Main.worker.submit(task);
|
---|
507 | }
|
---|
508 |
|
---|
509 | Runnable r = new Runnable() {
|
---|
510 | public void run() {
|
---|
511 | // first, wait for the download task to finish, if a download
|
---|
512 | // task was launched
|
---|
513 | if (future != null) {
|
---|
514 | try {
|
---|
515 | future.get();
|
---|
516 | } catch(InterruptedException e) {
|
---|
517 | e.printStackTrace();
|
---|
518 | } catch(ExecutionException e){
|
---|
519 | e.printStackTrace();
|
---|
520 | BugReportExceptionHandler.handleException(e.getCause());
|
---|
521 | return;
|
---|
522 | }
|
---|
523 | }
|
---|
524 | if (task != null) {
|
---|
525 | if (task.isCanceled())
|
---|
526 | // don't launch the changeset manager if the download task
|
---|
527 | // was canceled
|
---|
528 | return;
|
---|
529 | if (task.isFailed()) {
|
---|
530 | toDownload.clear();
|
---|
531 | }
|
---|
532 | }
|
---|
533 | // launch the task
|
---|
534 | launchChangesetManager(toDownload);
|
---|
535 | }
|
---|
536 | };
|
---|
537 | Main.worker.submit(r);
|
---|
538 | }
|
---|
539 |
|
---|
540 | protected void updateEnabledState() {
|
---|
541 | setEnabled(getCurrentChangesetList().getSelectedIndices().length > 0);
|
---|
542 | }
|
---|
543 |
|
---|
544 | public void itemStateChanged(ItemEvent arg0) {
|
---|
545 | updateEnabledState();
|
---|
546 | }
|
---|
547 |
|
---|
548 | public void valueChanged(ListSelectionEvent e) {
|
---|
549 | updateEnabledState();
|
---|
550 | }
|
---|
551 | }
|
---|
552 |
|
---|
553 | class ChangesetPopupMenuLauncher extends PopupMenuLauncher {
|
---|
554 | @Override
|
---|
555 | public void launch(MouseEvent evt) {
|
---|
556 | JList lst = getCurrentChangesetList();
|
---|
557 | if (lst.getSelectedIndices().length == 0) {
|
---|
558 | int idx = lst.locationToIndex(evt.getPoint());
|
---|
559 | if (idx >=0) {
|
---|
560 | lst.getSelectionModel().addSelectionInterval(idx, idx);
|
---|
561 | }
|
---|
562 | }
|
---|
563 | ChangesetDialogPopup popup = new ChangesetDialogPopup();
|
---|
564 | popup.show(lst, evt.getX(), evt.getY());
|
---|
565 |
|
---|
566 | }
|
---|
567 | }
|
---|
568 |
|
---|
569 | class ChangesetDialogPopup extends JPopupMenu {
|
---|
570 | public ChangesetDialogPopup() {
|
---|
571 | add(selectObjectsAction);
|
---|
572 | addSeparator();
|
---|
573 | add(readChangesetAction);
|
---|
574 | add(closeChangesetAction);
|
---|
575 | addSeparator();
|
---|
576 | add(showChangsetInfoAction);
|
---|
577 | }
|
---|
578 | }
|
---|
579 | }
|
---|