Changeset 2156 in josm


Ignore:
Timestamp:
2009-09-17T21:52:20+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3533: auto-completion in relation editor broken

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
4 edited

Legend:

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

    r2048 r2156  
    7070import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    7171import org.openstreetmap.josm.gui.tagging.AutoCompletingTextField;
    72 import org.openstreetmap.josm.gui.tagging.TagCellEditor;
    73 import org.openstreetmap.josm.gui.tagging.TagEditorModel;
    74 import org.openstreetmap.josm.gui.tagging.TagTable;
     72import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
    7573import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache;
    7674import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
     
    9290
    9391    /** the tag table and its model */
    94     private TagEditorModel tagEditorModel;
    95     private TagTable tagTable;
    96     private AutoCompletionCache acCache;
    97     private AutoCompletionList acList;
     92    private TagEditorPanel tagEditorPanel;
    9893    private ReferringRelationsBrowser referrerBrowser;
    9994    private ReferringRelationsBrowserModel referrerModel;
     
    124119        // initialize the autocompletion infrastructure
    125120        //
    126         acCache = AutoCompletionCache.getCacheForLayer(getLayer());
    127         acCache.initFromDataSet();
    128         acList = new AutoCompletionList();
     121        AutoCompletionCache.getCacheForLayer(getLayer()).initFromDataSet();
    129122
    130123        // init the various models
    131124        //
    132         tagEditorModel = new TagEditorModel();
    133125        memberTableModel = new MemberTableModel(getLayer());
    134126        selectionTableModel = new SelectionTableModel(getLayer());
    135127        referrerModel = new ReferringRelationsBrowserModel(relation);
    136128
     129        tagEditorPanel = new TagEditorPanel();
    137130        // populate the models
    138131        //
    139132        if (relation != null) {
    140             this.tagEditorModel.initFromPrimitive(relation);
     133            tagEditorPanel.getModel().initFromPrimitive(relation);
     134            //this.tagEditorModel.initFromPrimitive(relation);
    141135            this.memberTableModel.populate(relation);
    142136            if (!getLayer().data.relations.contains(relation)) {
     
    146140            }
    147141        } else {
    148             tagEditorModel.clear();
     142            tagEditorPanel.getModel().clear();
    149143            this.memberTableModel.populate(null);
    150144        }
    151         tagEditorModel.ensureOneTag();
     145        tagEditorPanel.getModel().ensureOneTag();
    152146
    153147        JSplitPane pane = buildSplitPane();
     
    211205
    212206    /**
    213      * build the panel with the buttons on the left
    214      *
    215      * @return
     207     * builds the panel with the tag editor
     208     *
     209     * @return the panel with the tag editor
    216210     */
    217     protected JPanel buildTagEditorControlPanel() {
     211    protected JPanel buildTagEditorPanel() {
    218212        JPanel pnl = new JPanel();
    219213        pnl.setLayout(new GridBagLayout());
     
    224218        gc.gridheight = 1;
    225219        gc.gridwidth = 1;
    226         gc.insets = new Insets(0, 5, 0, 5);
    227         gc.fill = GridBagConstraints.HORIZONTAL;
    228         gc.anchor = GridBagConstraints.CENTER;
    229         gc.weightx = 0.0;
    230         gc.weighty = 0.0;
    231 
    232         // -----
    233         AddTagAction addTagAction = new AddTagAction();
    234         pnl.add(new JButton(addTagAction), gc);
    235 
    236         // -----
    237         gc.gridy = 1;
    238         DeleteTagAction deleteTagAction = new DeleteTagAction();
    239         tagTable.getSelectionModel().addListSelectionListener(deleteTagAction);
    240         pnl.add(new JButton(deleteTagAction), gc);
    241 
    242         // ------
    243         // just grab the remaining space
    244         gc.gridy = 2;
    245         gc.weighty = 1.0;
    246         gc.fill = GridBagConstraints.BOTH;
    247         pnl.add(new JPanel(), gc);
    248         return pnl;
    249     }
    250 
    251     /**
    252      * builds the panel with the tag editor
    253      *
    254      * @return the panel with the tag editor
    255      */
    256     protected JPanel buildTagEditorPanel() {
    257         JPanel pnl = new JPanel();
    258         pnl.setLayout(new GridBagLayout());
    259 
    260         // setting up the tag table
    261         //
    262         tagTable = new TagTable(tagEditorModel);
    263         TagCellEditor editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(0).getCellEditor());
    264         editor.setAutoCompletionCache(acCache);
    265         editor.setAutoCompletionList(acList);
    266         editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(1).getCellEditor());
    267         editor.setAutoCompletionCache(acCache);
    268         editor.setAutoCompletionList(acList);
    269 
    270         final JScrollPane scrollPane = new JScrollPane(tagTable);
    271 
    272         GridBagConstraints gc = new GridBagConstraints();
    273         gc.gridx = 0;
    274         gc.gridy = 0;
    275         gc.gridheight = 1;
    276         gc.gridwidth = 3;
    277220        gc.fill = GridBagConstraints.HORIZONTAL;
    278221        gc.anchor = GridBagConstraints.FIRST_LINE_START;
     
    283226        gc.gridx = 0;
    284227        gc.gridy = 1;
    285         gc.gridheight = 1;
    286         gc.gridwidth = 1;
    287         gc.fill = GridBagConstraints.VERTICAL;
    288         gc.anchor = GridBagConstraints.NORTHWEST;
    289         gc.weightx = 0.0;
    290         gc.weighty = 1.0;
    291         pnl.add(buildTagEditorControlPanel(), gc);
    292 
    293         gc.gridx = 1;
    294         gc.gridy = 1;
    295228        gc.fill = GridBagConstraints.BOTH;
    296229        gc.anchor = GridBagConstraints.CENTER;
    297         gc.weightx = 0.8;
     230        gc.weightx = 1.0;
    298231        gc.weighty = 1.0;
    299         pnl.add(scrollPane, gc);
     232        pnl.add(tagEditorPanel, gc);
    300233        return pnl;
    301234    }
     
    311244        // setting up the member table
    312245        memberTable = new MemberTable(getLayer(),memberTableModel);
    313         MemberRoleCellEditor editor = ((MemberRoleCellEditor) memberTable.getColumnModel().getColumn(0).getCellEditor());
    314         editor.setAutoCompletionCache(acCache);
    315         editor.setAutoCompletionList(acList);
    316 
    317246        memberTable.addMouseListener(new MemberTableDblClickAdapter());
    318247        memberTableModel.addMemberModelListener(memberTable);
     
    587516            }
    588517        });
    589         tfRole.setAutoCompletionList(acList);
     518        tfRole.setAutoCompletionList(new AutoCompletionList());
    590519        tfRole.addFocusListener(
    591520                new FocusAdapter() {
    592521                    @Override
    593522                    public void focusGained(FocusEvent e) {
    594                         acCache.populateWithMemberRoles(acList);
     523                        AutoCompletionList list = tfRole.getAutoCompletionList();
     524                        AutoCompletionCache.getCacheForLayer(Main.main.getEditLayer()).populateWithMemberRoles(list);
    595525                    }
    596526                }
     
    629559
    630560    @Override
    631     public void setVisible(boolean b) {
    632         super.setVisible(b);
    633         if (!b) {
     561    public void setVisible(boolean visible) {
     562        if (visible) {
     563            tagEditorPanel.initAutoCompletion(Main.main.getEditLayer());
     564        }
     565        super.setVisible(visible);
     566        if (!visible) {
    634567            dispose();
    635568        }
     
    1063996            // If the user wanted to create a new relation, but hasn't added any members or
    1064997            // tags, don't add an empty relation
    1065             if (memberTableModel.getRowCount() == 0 && tagEditorModel.getKeys().isEmpty())
     998            if (memberTableModel.getRowCount() == 0 && tagEditorPanel.getModel().getKeys().isEmpty())
    1066999                return;
    10671000            Relation newRelation = new Relation();
    1068             tagEditorModel.applyToPrimitive(newRelation);
     1001            tagEditorPanel.getModel().applyToPrimitive(newRelation);
    10691002            memberTableModel.applyToRelation(newRelation);
    10701003            Main.main.undoRedo.add(new AddCommand(getLayer(),newRelation));
     
    10891022        protected void applyExistingConflictingRelation() {
    10901023            Relation editedRelation = new Relation(getRelation());
    1091             tagEditorModel.applyToPrimitive(editedRelation);
     1024            tagEditorPanel.getModel().applyToPrimitive(editedRelation);
    10921025            memberTableModel.applyToRelation(editedRelation);
    10931026            Conflict<Relation> conflict = new Conflict<Relation>(getRelation(), editedRelation);
     
    11021035        protected void applyExistingNonConflictingRelation() {
    11031036            Relation editedRelation = new Relation(getRelation());
    1104             tagEditorModel.applyToPrimitive(editedRelation);
     1037            tagEditorPanel.getModel().applyToPrimitive(editedRelation);
    11051038            memberTableModel.applyToRelation(editedRelation);
    11061039            Main.main.undoRedo.add(new ChangeCommand(getRelation(), editedRelation));
     
    11651098                applyNewRelation();
    11661099            } else if (!memberTableModel.hasSameMembersAs(getRelationSnapshot())
    1167                     || tagEditorModel.isDirty()) {
     1100                    || tagEditorPanel.getModel().isDirty()) {
    11681101                if (isDirtyRelation()) {
    11691102                    if (confirmClosingBecauseOfDirtyState()) {
     
    11981131                applyNewRelation();
    11991132            } else if (!memberTableModel.hasSameMembersAs(getRelationSnapshot())
    1200                     || tagEditorModel.isDirty()) {
     1133                    || tagEditorPanel.getModel().isDirty()) {
    12011134                if (isDirtyRelation()) {
    12021135                    if (confirmClosingBecauseOfDirtyState()) {
     
    12461179
    12471180        public void actionPerformed(ActionEvent e) {
    1248             tagEditorModel.appendNewTag();
    1249         }
    1250     }
    1251 
    1252     class DeleteTagAction extends AbstractAction implements ListSelectionListener {
    1253         public DeleteTagAction() {
    1254             putValue(SHORT_DESCRIPTION, tr("Delete the currently selected tags"));
    1255             putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
    1256             // putValue(NAME, tr("Cancel"));
    1257             refreshEnabled();
    1258         }
    1259 
    1260         public void actionPerformed(ActionEvent e) {
    1261             run();
    1262         }
    1263 
    1264         /**
    1265          * delete a selection of tag names
    1266          */
    1267         protected void deleteTagNames() {
    1268             int[] rows = tagTable.getSelectedRows();
    1269             tagEditorModel.deleteTagNames(rows);
    1270         }
    1271 
    1272         /**
    1273          * delete a selection of tag values
    1274          */
    1275         protected void deleteTagValues() {
    1276             int[] rows = tagTable.getSelectedRows();
    1277             tagEditorModel.deleteTagValues(rows);
    1278         }
    1279 
    1280         /**
    1281          * delete a selection of tags
    1282          */
    1283         protected void deleteTags() {
    1284             tagEditorModel.deleteTags(tagTable.getSelectedRows());
    1285         }
    1286 
    1287         public void run() {
    1288             if (!isEnabled())
    1289                 return;
    1290             if (tagTable.getSelectedColumnCount() == 1) {
    1291                 if (tagTable.getSelectedColumn() == 0) {
    1292                     deleteTagNames();
    1293                 } else if (tagTable.getSelectedColumn() == 1) {
    1294                     deleteTagValues();
    1295                 } else
    1296                     // should not happen
    1297                     //
    1298                     throw new IllegalStateException("unexpected selected clolumn: getSelectedColumn() is "
    1299                             + tagTable.getSelectedColumn());
    1300             } else if (tagTable.getSelectedColumnCount() == 2) {
    1301                 deleteTags();
    1302             }
    1303             if (tagEditorModel.getRowCount() == 0) {
    1304                 tagEditorModel.ensureOneTag();
    1305             }
    1306         }
    1307 
    1308         protected void refreshEnabled() {
    1309             setEnabled(tagTable.getSelectedRowCount() > 0 || tagTable.getSelectedColumnCount() > 0);
    1310         }
    1311 
    1312         public void valueChanged(ListSelectionEvent e) {
    1313             refreshEnabled();
     1181            tagEditorPanel.getModel().appendNewTag();
    13141182        }
    13151183    }
     
    14191287        public void actionPerformed(ActionEvent e) {
    14201288            Relation copy = new Relation();
    1421             tagEditorModel.applyToPrimitive(copy);
     1289            tagEditorPanel.getModel().applyToPrimitive(copy);
    14221290            memberTableModel.applyToRelation(copy);
    14231291            RelationEditor editor = RelationEditor.getEditor(getLayer(), copy, memberTableModel.getSelectedMembers());
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java

    r2048 r2156  
    99import javax.swing.table.TableCellEditor;
    1010
     11import org.openstreetmap.josm.Main;
    1112import org.openstreetmap.josm.gui.tagging.AutoCompletingTextField;
    1213import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache;
    13 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority;
    1414import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
    15 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
    1615
    1716public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor {
     
    2120
    2221    private AutoCompletingTextField editor = null;
    23 
    24     /** the cache of auto completion items derived from the current JOSM data set */
    25     private AutoCompletionCache acCache = null;
    2622
    2723    /** user input is matched against this list of auto completion items */
     
    3329    public MemberRoleCellEditor() {
    3430        editor = new AutoCompletingTextField();
    35         acCache = new AutoCompletionCache();
    36     }
    37 
    38     /**
    39      * initializes the autocompletion editor with the list of member roles in
    40      * the current dataset
    41      *
    42      */
    43     protected void initAutoCompletionListRoles() {
    44         if (autoCompletionList == null) {
    45             logger.warning("autoCompletionList is null. Make sure an instance of AutoCompletionList is injected into MemberRoleCellEditor.");
    46             return;
    47         }
    48         autoCompletionList.clear();
    49 
    50         // add the list of keys in the current data set
    51         //
    52         for (String key : acCache.getMemberRoles()) {
    53             autoCompletionList.add(
    54                     new AutoCompletionListItem(key, AutoCompletionItemPritority.IS_IN_DATASET)
    55             );
    56         }
    57         autoCompletionList.fireTableDataChanged();
     31        autoCompletionList = new AutoCompletionList();
     32        editor.setAutoCompletionList(autoCompletionList);
    5833    }
    5934
     
    6641        String role = (String)value;
    6742        editor.setText(role);
    68         initAutoCompletionListRoles();
     43        System.out.println(role + " - initializing autocompletion list ...");
     44        AutoCompletionCache.getCacheForLayer(Main.main.getEditLayer()).populateWithMemberRoles(autoCompletionList);
     45        autoCompletionList.dump();
    6946        return editor;
    7047    }
     
    8360        return super.stopCellEditing();
    8461    }
    85 
    86     /**
    87      * replies the {@link AutoCompletionList} this table cell editor synchronizes with
    88      *
    89      * @return the auto completion list
    90      */
    91     public AutoCompletionList getAutoCompletionList() {
    92         return autoCompletionList;
    93     }
    94 
    95     /**
    96      * sets the {@link AutoCompletionList} this table cell editor synchronizes with
    97      * @param autoCompletionList the auto completion list
    98      */
    99     public void setAutoCompletionList(AutoCompletionList autoCompletionList) {
    100         this.autoCompletionList = autoCompletionList;
    101         editor.setAutoCompletionList(autoCompletionList);
    102     }
    103 
    104     public void setAutoCompletionCache(AutoCompletionCache acCache) {
    105         this.acCache = acCache;
    106     }
    107 
    108     public AutoCompletingTextField getEditor() {
    109         return editor;
    110     }
    11162}
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java

    r2048 r2156  
    55
    66import java.awt.BorderLayout;
    7 import java.awt.Component;
    87import java.awt.GridBagConstraints;
    98import java.awt.GridBagLayout;
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java

    r2088 r2156  
    272272     */
    273273    public void clear() {
     274        valutToItemMap.clear();
    274275        list.clear();
    275276        fireTableDataChanged();
     
    290291    }
    291292
     293    public void dump() {
     294        System.out.println("---------------------------------");
     295        for (AutoCompletionListItem item: list) {
     296            System.out.println(item.getValue());
     297        }
     298        System.out.println("---------------------------------");
     299    }
    292300}
Note: See TracChangeset for help on using the changeset viewer.