# HG changeset patch # User Dirk Olmes # Date 1315873211 -7200 # Node ID e7d9a9176e08ff60dd4d403500ee3013d7139c06 # Parent fca19925366c10189f200220a85e816aca57e68b Clean up connecting the widgets diff -r fca19925366c -r e7d9a9176e08 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 13 02:07:14 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java Tue Sep 13 02:20:11 2011 +0200 @@ -15,7 +15,6 @@ import javax.swing.ListModel; import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import javax.swing.table.TableModel; import org.codehaus.jackson.JsonNode; @@ -42,47 +41,66 @@ private void run() { _frame = new ConflictEditorFrame(); - connectListeners(_frame); + connectListeners(); _frame.pack(); _frame.setVisible(true); } - private void connectListeners(ConflictEditorFrame frame) + private void connectListeners() { - frame.getConnectButton().addActionListener( - new ExceptionHandlingActionListener(new Executable() - { - @Override - public void execute(ActionEvent event) throws Exception - { - connectAndFindConflicts(); - } - })); + connectFindConflictsButton(); + connectConflictsList(); + connectDifferencesTable(); + } - frame.getConflictsList().addListSelectionListener( - new ExceptionHandlingListSelectionListener(new Executable() - { - @Override - public void execute(ListSelectionEvent event) throws Exception - { - if (event.getValueIsAdjusting() == false) - { - selectConflictDocument(event.getFirstIndex()); - } - } - })); - - frame.getDifferencesTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() + private void connectFindConflictsButton() + { + Executable executable = new Executable() { @Override - public void valueChanged(ListSelectionEvent e) + public void execute(ActionEvent event) throws Exception + { + findConflicts(); + } + }; + ExceptionHandlingActionListener listener = new ExceptionHandlingActionListener(executable); + _frame.getFindConflictsButton().addActionListener(listener); + } + + private void connectConflictsList() + { + Executable executable = new Executable() + { + @Override + public void execute(ListSelectionEvent event) throws Exception + { + if (event.getValueIsAdjusting() == false) + { + selectConflictDocument(event.getFirstIndex()); + } + } + }; + ExceptionHandlingListSelectionListener listener = new ExceptionHandlingListSelectionListener( + executable); + _frame.getConflictsList().addListSelectionListener(listener); + } + + private void connectDifferencesTable() + { + Executable executable = new Executable() + { + @Override + public void execute(ListSelectionEvent event) throws Exception { selectDifference(); } - }); + }; + ExceptionHandlingListSelectionListener listener = new ExceptionHandlingListSelectionListener( + executable); + _frame.getDifferencesTable().getSelectionModel().addListSelectionListener(listener); } - protected void connectAndFindConflicts() throws Exception + protected void findConflicts() throws Exception { String dbUrl = _frame.getDatabaseUrl(); _database = new CouchDb(dbUrl); diff -r fca19925366c -r e7d9a9176e08 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 13 02:07:14 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java Tue Sep 13 02:20:11 2011 +0200 @@ -19,7 +19,7 @@ public class ConflictEditorFrame extends JFrame { private JTextField _databaseUrlTextField; - private JButton _connectButton; + private JButton _findConflictsButton; private JList _conflictsList; private JTable _differencesTable; @@ -41,13 +41,13 @@ { JLabel label = new JLabel("Database URL:"); _databaseUrlTextField = new JTextField(40); - _connectButton = new JButton("Find Conflicts"); + _findConflictsButton = new JButton("Find Conflicts"); JPanel databaseUrlPanel = new JPanel(); databaseUrlPanel.setLayout(new FlowLayout()); databaseUrlPanel.add(label); databaseUrlPanel.add(_databaseUrlTextField); - databaseUrlPanel.add(_connectButton); + databaseUrlPanel.add(_findConflictsButton); getContentPane().add(databaseUrlPanel, BorderLayout.NORTH); } @@ -85,9 +85,9 @@ return _databaseUrlTextField.getText(); } - public JButton getConnectButton() + public JButton getFindConflictsButton() { - return _connectButton; + return _findConflictsButton; } public JList getConflictsList()