Changeset 12496 in josm for trunk


Ignore:
Timestamp:
2017-07-23T14:36:03+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #15055 - add synchronization to conflict dialog

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r12353 r12496  
    123123        model = new ConflictListModel();
    124124
    125         lstConflicts = new JList<>(model);
    126         lstConflicts.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    127         lstConflicts.setCellRenderer(new OsmPrimitivRenderer());
    128         lstConflicts.addMouseListener(new MouseEventHandler());
     125        synchronized (this) {
     126            lstConflicts = new JList<>(model);
     127            lstConflicts.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     128            lstConflicts.setCellRenderer(new OsmPrimitivRenderer());
     129            lstConflicts.addMouseListener(new MouseEventHandler());
     130        }
    129131        addListSelectionListener(e -> Main.map.mapView.repaint());
    130132
     
    165167     * @since 5958
    166168     */
    167     public void addListSelectionListener(ListSelectionListener listener) {
     169    public synchronized void addListSelectionListener(ListSelectionListener listener) {
    168170        lstConflicts.getSelectionModel().addListSelectionListener(listener);
    169171    }
     
    174176     * @since 5958
    175177     */
    176     public void removeListSelectionListener(ListSelectionListener listener) {
     178    public synchronized void removeListSelectionListener(ListSelectionListener listener) {
    177179        lstConflicts.getSelectionModel().removeListSelectionListener(listener);
    178180    }
     
    191193     */
    192194    private void resolve() {
    193         if (conflicts == null || model.getSize() == 0)
    194             return;
    195 
    196         int index = lstConflicts.getSelectedIndex();
    197         if (index < 0) {
    198             index = 0;
    199         }
    200 
    201         Conflict<? extends OsmPrimitive> c = conflicts.get(index);
    202         ConflictResolutionDialog dialog = new ConflictResolutionDialog(Main.parent);
    203         dialog.getConflictResolver().populate(c);
    204         dialog.showDialog();
    205 
    206         lstConflicts.setSelectedIndex(index);
    207 
     195        synchronized (this) {
     196            if (conflicts == null || model.getSize() == 0)
     197                return;
     198
     199            int index = lstConflicts.getSelectedIndex();
     200            if (index < 0) {
     201                index = 0;
     202            }
     203
     204            Conflict<? extends OsmPrimitive> c = conflicts.get(index);
     205            ConflictResolutionDialog dialog = new ConflictResolutionDialog(Main.parent);
     206            dialog.getConflictResolver().populate(c);
     207            dialog.showDialog();
     208
     209            lstConflicts.setSelectedIndex(index);
     210        }
    208211        Main.map.mapView.repaint();
    209212    }
     
    214217    public void refreshView() {
    215218        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
    216         conflicts = editLayer == null ? new ConflictCollection() : editLayer.getConflicts();
     219        synchronized (this) {
     220            conflicts = editLayer == null ? new ConflictCollection() : editLayer.getConflicts();
     221        }
    217222        GuiHelper.runInEDT(() -> {
    218223            model.fireContentChanged();
     
    221226    }
    222227
    223     private void updateTitle() {
     228    private synchronized void updateTitle() {
    224229        int conflictsCount = conflicts.size();
    225230        if (conflictsCount > 0) {
     
    247252        g.setColor(preferencesColor);
    248253        Visitor conflictPainter = new ConflictPainter(nc, g);
    249         for (OsmPrimitive o : lstConflicts.getSelectedValuesList()) {
    250             if (conflicts == null || !conflicts.hasConflictForMy(o)) {
    251                 continue;
    252             }
    253             conflicts.getConflictForMy(o).getTheir().accept(conflictPainter);
     254        synchronized (this) {
     255            for (OsmPrimitive o : lstConflicts.getSelectedValuesList()) {
     256                if (conflicts == null || !conflicts.hasConflictForMy(o)) {
     257                    continue;
     258                }
     259                conflicts.getConflictForMy(o).getTheir().accept(conflictPainter);
     260            }
    254261        }
    255262    }
     
    281288     * @return the conflict collection currently held by this dialog; may be null
    282289     */
    283     public ConflictCollection getConflicts() {
     290    public synchronized ConflictCollection getConflicts() {
    284291        return conflicts;
    285292    }
     
    290297     * @return Conflict
    291298     */
    292     public Conflict<? extends OsmPrimitive> getSelectedConflict() {
     299    public synchronized Conflict<? extends OsmPrimitive> getSelectedConflict() {
    293300        if (conflicts == null || model.getSize() == 0)
    294301            return null;
     
    299306    }
    300307
    301     private boolean isConflictSelected() {
     308    private synchronized boolean isConflictSelected() {
    302309        final ListSelectionModel selModel = lstConflicts.getSelectionModel();
    303310        return selModel.getMinSelectionIndex() >= 0 && selModel.getMaxSelectionIndex() >= selModel.getMinSelectionIndex();
     
    316323
    317324    @Override
    318     public void selectionChanged(SelectionChangeEvent event) {
     325    public synchronized void selectionChanged(SelectionChangeEvent event) {
    319326        lstConflicts.setValueIsAdjusting(true);
    320327        lstConflicts.clearSelection();
     
    416423
    417424        @Override
    418         public OsmPrimitive getElementAt(int index) {
     425        public synchronized OsmPrimitive getElementAt(int index) {
    419426            if (index < 0 || index >= getSize())
    420427                return null;
     
    423430
    424431        @Override
    425         public int getSize() {
     432        public synchronized int getSize() {
    426433            return conflicts != null ? conflicts.size() : 0;
    427434        }
    428435
    429         public int indexOf(OsmPrimitive my) {
     436        public synchronized int indexOf(OsmPrimitive my) {
    430437            if (conflicts != null) {
    431438                for (int i = 0; i < conflicts.size(); i++) {
     
    437444        }
    438445
    439         public OsmPrimitive get(int idx) {
     446        public synchronized OsmPrimitive get(int idx) {
    440447            return conflicts != null ? conflicts.get(idx).getMy() : null;
    441448        }
     
    469476        public void actionPerformed(ActionEvent e) {
    470477            Collection<OsmPrimitive> sel = new LinkedList<>();
    471             for (OsmPrimitive o : lstConflicts.getSelectedValuesList()) {
    472                 sel.add(o);
     478            synchronized (this) {
     479                for (OsmPrimitive o : lstConflicts.getSelectedValuesList()) {
     480                    sel.add(o);
     481                }
    473482            }
    474483            DataSet ds = Main.getLayerManager().getEditDataSet();
     
    499508            final ConflictResolver resolver = new ConflictResolver();
    500509            final List<Command> commands = new ArrayList<>();
    501             for (OsmPrimitive osmPrimitive : lstConflicts.getSelectedValuesList()) {
    502                 Conflict<? extends OsmPrimitive> c = conflicts.getConflictForMy(osmPrimitive);
    503                 if (c != null) {
    504                     resolver.populate(c);
    505                     resolver.decideRemaining(type);
    506                     commands.add(resolver.buildResolveCommand());
     510            synchronized (this) {
     511                for (OsmPrimitive osmPrimitive : lstConflicts.getSelectedValuesList()) {
     512                    Conflict<? extends OsmPrimitive> c = conflicts.getConflictForMy(osmPrimitive);
     513                    if (c != null) {
     514                        resolver.populate(c);
     515                        resolver.decideRemaining(type);
     516                        commands.add(resolver.buildResolveCommand());
     517                    }
    507518                }
    508519            }
Note: See TracChangeset for help on using the changeset viewer.