Mercurial > hg > ConflictEditor
changeset 34:4ccf7e7f03b0
replace the text field for the db url with a combo box that is populated from the preferences.
author | dirk |
---|---|
date | Fri, 07 Oct 2011 03:58:41 +0200 |
parents | cc648f83cdbc |
children | a3f88353554a |
files | conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java conflict-editor/src/main/java/de/codedo/conflicteditor/gui/DatabaseUrlComboBoxModel.java conflict-editor/src/main/java/de/codedo/conflicteditor/gui/TextFieldComboBoxEditor.java conflict-editor/src/main/java/de/codedo/conflicteditor/gui/util/PreferencesAccess.java |
diffstat | 5 files changed, 152 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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()
--- /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<String> _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); + } +}
--- /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); + } +}
--- /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<String> getDatabaseUrls() + { + try + { + return collectDatabaseUrls(); + } + catch (BackingStoreException bse) + { + throw new IllegalStateException(bse); + } + } + + private List<String> collectDatabaseUrls() throws BackingStoreException + { + List<String> urls = new ArrayList<String>(); + Preferences databaseUrls = _rootNode.node("databaseUrls"); + for (String key : databaseUrls.keys()) + { + String url = databaseUrls.get(key, null); + urls.add(url); + } + return urls; + } +}