# HG changeset patch # User dirk # Date 1317952721 -7200 # Node ID 4ccf7e7f03b0658b7bfe689649639f237959c6ff # Parent cc648f83cdbcb6ac19e433f6293416c693b36e54 replace the text field for the db url with a combo box that is populated from the preferences. diff -r cc648f83cdbc -r 4ccf7e7f03b0 conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java --- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java Tue Sep 20 17:47:59 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java Fri Oct 07 03:58:41 2011 +0200 @@ -158,7 +158,7 @@ protected void findConflicts() throws IOException { - String dbUrl = _frame.getDatabaseUrlTextField().getText(); + String dbUrl = (String)_frame.getDatabaseUrlCombo().getSelectedItem(); JsonNode conflicts = _controller.findConflicts(dbUrl); ListModel model = new ConflictsListModel(conflicts); _frame.getConflictsList().setModel(model); diff -r cc648f83cdbc -r 4ccf7e7f03b0 conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java --- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java Tue Sep 20 17:47:59 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java Fri Oct 07 03:58:41 2011 +0200 @@ -7,6 +7,7 @@ import java.awt.HeadlessException; import javax.swing.JButton; +import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; @@ -14,13 +15,12 @@ import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTable; -import javax.swing.JTextField; import javax.swing.ListSelectionModel; import javax.swing.table.TableModel; public class ConflictEditorFrame extends JFrame { - private JTextField _databaseUrlTextField; + private JComboBox _databaseUrlCombo; private JButton _findConflictsButton; private JList _conflictsList; private JTable _differencesTable; @@ -57,8 +57,11 @@ JLabel label = new JLabel("Database URL:"); databasePanel.add(label); - _databaseUrlTextField = new JTextField(40); - databasePanel.add(_databaseUrlTextField); + _databaseUrlCombo = new JComboBox(); + _databaseUrlCombo.setEditable(true); + _databaseUrlCombo.setEditor(new TextFieldComboBoxEditor()); + _databaseUrlCombo.setModel(new DatabaseUrlComboBoxModel()); + databasePanel.add(_databaseUrlCombo); _findConflictsButton = new JButton("Find Conflicts"); databasePanel.add(_findConflictsButton); @@ -157,9 +160,9 @@ _buttonPanel.enableButtons(); } - public JTextField getDatabaseUrlTextField() + public JComboBox getDatabaseUrlCombo() { - return _databaseUrlTextField; + return _databaseUrlCombo; } public JButton getFindConflictsButton() diff -r cc648f83cdbc -r 4ccf7e7f03b0 conflict-editor/src/main/java/de/codedo/conflicteditor/gui/DatabaseUrlComboBoxModel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/DatabaseUrlComboBoxModel.java Fri Oct 07 03:58:41 2011 +0200 @@ -0,0 +1,73 @@ + +package de.codedo.conflicteditor.gui; + +import de.codedo.conflicteditor.gui.util.PreferencesAccess; + +import java.util.List; + +import javax.swing.AbstractListModel; +import javax.swing.MutableComboBoxModel; + +public class DatabaseUrlComboBoxModel extends AbstractListModel implements MutableComboBoxModel +{ + private List _urls; + private Object _selected; + + public DatabaseUrlComboBoxModel() + { + super(); + _urls = new PreferencesAccess().getDatabaseUrls(); + if (_urls.size() > 0) + { + _selected = _urls.get(0); + } + } + + @Override + public int getSize() + { + return _urls.size(); + } + + @Override + public Object getElementAt(int index) + { + return _urls.get(index); + } + + @Override + public Object getSelectedItem() + { + return _selected; + } + + @Override + public void setSelectedItem(Object anItem) + { + _selected = anItem; + } + + @Override + public void addElement(Object obj) + { + _urls.add(obj.toString()); + } + + @Override + public void removeElement(Object obj) + { + _urls.remove(obj); + } + + @Override + public void insertElementAt(Object obj, int index) + { + _urls.add(index, obj.toString()); + } + + @Override + public void removeElementAt(int index) + { + _urls.remove(index); + } +} diff -r cc648f83cdbc -r 4ccf7e7f03b0 conflict-editor/src/main/java/de/codedo/conflicteditor/gui/TextFieldComboBoxEditor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/TextFieldComboBoxEditor.java Fri Oct 07 03:58:41 2011 +0200 @@ -0,0 +1,25 @@ + +package de.codedo.conflicteditor.gui; + +import javax.swing.JTextField; +import javax.swing.border.Border; +import javax.swing.plaf.metal.MetalComboBoxEditor; + +public class TextFieldComboBoxEditor extends MetalComboBoxEditor +{ + public TextFieldComboBoxEditor() + { + super(); + initEditorComponent(); + } + + private void initEditorComponent() + { + // save the border of the original editor component. Since it's a protected inner instance + // class we cannot create a new one here :-( + Border border = editor.getBorder(); + + editor = new JTextField(40); + editor.setBorder(border); + } +} diff -r cc648f83cdbc -r 4ccf7e7f03b0 conflict-editor/src/main/java/de/codedo/conflicteditor/gui/util/PreferencesAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/util/PreferencesAccess.java Fri Oct 07 03:58:41 2011 +0200 @@ -0,0 +1,44 @@ + +package de.codedo.conflicteditor.gui.util; + +import de.codedo.conflicteditor.gui.ConflictEditor; + +import java.util.ArrayList; +import java.util.List; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; + +public class PreferencesAccess extends Object +{ + private Preferences _rootNode; + + public PreferencesAccess() + { + super(); + _rootNode = Preferences.userNodeForPackage(ConflictEditor.class); + } + + public List getDatabaseUrls() + { + try + { + return collectDatabaseUrls(); + } + catch (BackingStoreException bse) + { + throw new IllegalStateException(bse); + } + } + + private List collectDatabaseUrls() throws BackingStoreException + { + List urls = new ArrayList(); + Preferences databaseUrls = _rootNode.node("databaseUrls"); + for (String key : databaseUrls.keys()) + { + String url = databaseUrls.get(key, null); + urls.add(url); + } + return urls; + } +}