Changeset 1845 in josm for trunk/src/org


Ignore:
Timestamp:
2009-07-25T19:20:23+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #2996: error, but no Message, if a relation is containing itself

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/relation
Files:
2 edited

Legend:

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

    r1840 r1845  
    2020import java.awt.event.WindowAdapter;
    2121import java.awt.event.WindowEvent;
    22 import java.beans.PropertyChangeEvent;
    23 import java.beans.PropertyChangeListener;
    2422import java.io.IOException;
    2523import java.util.ArrayList;
     
    4644import javax.swing.KeyStroke;
    4745import javax.swing.SwingUtilities;
    48 import javax.swing.event.AncestorEvent;
    49 import javax.swing.event.AncestorListener;
    5046import javax.swing.event.ChangeEvent;
    5147import javax.swing.event.ChangeListener;
     
    193189                    .toString()));
    194190        }
     191
     192        addWindowListener(
     193                new WindowAdapter() {
     194                    @Override
     195                    public void windowOpened(WindowEvent e) {
     196                        cleanSelfReferences();
     197                    }
     198                }
     199        );
     200
    195201    }
    196202
     
    626632        if (!b) {
    627633            dispose();
     634        }
     635    }
     636
     637    /**
     638     * checks whether the current relation has members referring to itself. If so,
     639     * warns the users and provides an option for removing these members.
     640     *
     641     */
     642    protected void cleanSelfReferences() {
     643        ArrayList<OsmPrimitive> toCheck = new ArrayList<OsmPrimitive>();
     644        toCheck.add(getRelation());
     645        if (memberTableModel.hasMembersReferringTo(toCheck)) {
     646            int ret = ConditionalOptionPaneUtil.showOptionDialog(
     647                    "clean_relation_self_references",
     648                    Main.parent,
     649                    tr("<html>There is at least one member in this relation referring<br>"
     650                            + "to the relation itself.<br>"
     651                            + "This creates circular dependencies and is dicuraged.<br>"
     652                            + "How do you want to proceed with circular dependencies?</html>"),
     653                            tr("Warning"),
     654                            JOptionPane.YES_NO_OPTION,
     655                            JOptionPane.WARNING_MESSAGE,
     656                            new String[]{tr("Remove them, clean up relation"), tr("Ignore them, leave relation as is")},
     657                            tr("Remove them, clean up relation")
     658            );
     659            switch(ret) {
     660            case ConditionalOptionPaneUtil.DIALOG_DISABLED_OPTION: return;
     661            case JOptionPane.CLOSED_OPTION: return;
     662            case JOptionPane.NO_OPTION: return;
     663            case JOptionPane.YES_OPTION:
     664                memberTableModel.removeMembersReferringTo(toCheck);
     665                break;
     666            }
    628667        }
    629668    }
     
    13161355        }
    13171356    }
     1357
     1358
    13181359}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r1839 r1845  
    395395    }
    396396
    397     public boolean isEditableRelation(int row) {
    398         if (row < 0 || row >= members.size())
    399             return false;
    400         RelationMember member = members.get(row);
     397    /**
     398     * Replies true if the index-th relation members referrs
     399     * to an editable relation, i.e. a relation which is not
     400     * incomplete.
     401     *
     402     * @param index the index
     403     * @return true, if the index-th relation members referrs
     404     * to an editable relation, i.e. a relation which is not
     405     * incomplete
     406     */
     407    public boolean isEditableRelation(int index) {
     408        if (index < 0 || index >= members.size())
     409            return false;
     410        RelationMember member = members.get(index);
    401411        if (!(member.member instanceof Relation))
    402412            return false;
     
    429439        return false;
    430440    }
    431 
    432441
    433442    void sort() {
Note: See TracChangeset for help on using the changeset viewer.