001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.dialogs.changeset;
003
004import java.awt.BorderLayout;
005import java.beans.PropertyChangeEvent;
006import java.beans.PropertyChangeListener;
007
008import javax.swing.BorderFactory;
009import javax.swing.JPanel;
010import javax.swing.JScrollPane;
011
012import org.openstreetmap.josm.data.osm.Changeset;
013import org.openstreetmap.josm.gui.tagging.TagEditorModel;
014import org.openstreetmap.josm.gui.tagging.TagTable;
015
016/**
017 * This panel displays the tags of the currently selected changeset in the {@link ChangesetCacheManager}
018 *
019 */
020public class ChangesetTagsPanel extends JPanel implements PropertyChangeListener{
021
022    private TagEditorModel model;
023
024    protected void build() {
025        setLayout(new BorderLayout());
026        setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
027        model = new TagEditorModel();
028        TagTable tblTags = new TagTable(model);
029        tblTags.setEnabled(false);
030        add(new JScrollPane(tblTags), BorderLayout.CENTER);
031    }
032
033    /**
034     * Constructs a new {@code ChangesetTagsPanel}.
035     */
036    public ChangesetTagsPanel() {
037        build();
038    }
039
040    protected void init(Changeset cs) {
041        if (cs == null) {
042            model.clear();
043            return;
044        }
045        model.initFromTags(cs.getKeys());
046    }
047
048    /* ---------------------------------------------------------------------------- */
049    /* interface PropertyChangeListener                                             */
050    /* ---------------------------------------------------------------------------- */
051    @Override
052    public void propertyChange(PropertyChangeEvent evt) {
053        if (!evt.getPropertyName().equals(ChangesetCacheManagerModel.CHANGESET_IN_DETAIL_VIEW_PROP))
054            return;
055        Changeset cs = (Changeset)evt.getNewValue();
056        if (cs == null) {
057            model.clear();
058        } else {
059            model.initFromPrimitive(cs);
060        }
061    }
062}