Mercurial > hg > ConflictEditor
changeset 3:84b19f2b1dbb
retrieve conflicts and show them in a very simple form in a JList
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Mon, 12 Sep 2011 13:49:42 +0200 |
parents | ebff95a55276 |
children | c396004a4e55 |
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/ConflictsListModel.java |
diffstat | 3 files changed, 101 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java Mon Sep 12 13:31:59 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java Mon Sep 12 13:49:42 2011 +0200 @@ -1,13 +1,20 @@ package de.codedo.conflicteditor.gui; +import de.codedo.conflicteditor.ConflictsView; +import de.codedo.conflicteditor.CouchDb; import de.codedo.conflicteditor.Difference; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; import java.util.ArrayList; import java.util.List; +import javax.swing.JOptionPane; +import javax.swing.ListModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.table.TableModel; @@ -48,27 +55,57 @@ } }); - frame.getConflictsTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() + frame.getConflictsList().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { - selectConflict(); + selectConflictDocument(); + } + }); + + frame.getDifferencesTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() + { + @Override + public void valueChanged(ListSelectionEvent e) + { + selectDifference(); } }); } protected void connectAndFindConflicts() { + try + { + String dbUrl = _frame.getDatabaseUrl(); + CouchDb database = new CouchDb(dbUrl); + ConflictsView conflictsView = new ConflictsView(database); + + ListModel model = new ConflictsListModel(conflictsView.getConflicts()); + _frame.getConflictsList().setModel(model); + } + catch (IOException iox) + { + PrintStream out = new PrintStream(new ByteArrayOutputStream()); + iox.printStackTrace(out); + out.close(); + + JOptionPane.showMessageDialog(_frame, out.toString()); + } + } + + protected void selectConflictDocument() + { List<Difference> diffs = new ArrayList<Difference>(); diffs.add(new Difference("key", "current", "other")); TableModel model = new DifferenceTableModel(diffs); - _frame.getConflictsTable().setModel(model); + _frame.getDifferencesTable().setModel(model); } - protected void selectConflict() + protected void selectDifference() { - System.out.println("select a conflict"); + System.out.println("select a difference"); } }
--- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java Mon Sep 12 13:31:59 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java Mon Sep 12 13:49:42 2011 +0200 @@ -8,6 +8,7 @@ import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; +import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; @@ -18,7 +19,8 @@ { private JTextField _databaseUrlTextField; private JButton _connectButton; - private JTable _conflictsTable; + private JList _conflictsList; + private JTable _differencesTable; public ConflictEditorFrame() throws HeadlessException { @@ -31,7 +33,8 @@ private void buildGui() { buildDatabaseUrlPanel(); - buildConflictsTable(); + buildConflictsList(); + buildDifferencesTable(); } private void buildDatabaseUrlPanel() @@ -46,26 +49,44 @@ databaseUrlPanel.add(_databaseUrlTextField); databaseUrlPanel.add(_connectButton); - getContentPane().add(databaseUrlPanel); + getContentPane().add(databaseUrlPanel, BorderLayout.NORTH); + } + + private void buildConflictsList() + { + _conflictsList = new JList(); + + JScrollPane scrollPane = new JScrollPane(_conflictsList); + getContentPane().add(scrollPane, BorderLayout.CENTER); } - private void buildConflictsTable() + private void buildDifferencesTable() { - _conflictsTable = new JTable(); + _differencesTable = new JTable(); TableModel model = new DifferenceTableModel(); - _conflictsTable.setModel(model); + _differencesTable.setModel(model); - JScrollPane scrollPane = new JScrollPane(_conflictsTable); + JScrollPane scrollPane = new JScrollPane(_differencesTable); getContentPane().add(scrollPane, BorderLayout.SOUTH); } + public String getDatabaseUrl() + { + return _databaseUrlTextField.getText(); + } + public JButton getConnectButton() { return _connectButton; } - public JTable getConflictsTable() + public JList getConflictsList() { - return _conflictsTable; + return _conflictsList; + } + + public JTable getDifferencesTable() + { + return _differencesTable; } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictsListModel.java Mon Sep 12 13:49:42 2011 +0200 @@ -0,0 +1,29 @@ + +package de.codedo.conflicteditor.gui; + +import javax.swing.AbstractListModel; + +import org.codehaus.jackson.JsonNode; + +public class ConflictsListModel extends AbstractListModel +{ + private JsonNode _conflictsNode; + + public ConflictsListModel(JsonNode conflictsNode) + { + super(); + _conflictsNode = conflictsNode; + } + + @Override + public int getSize() + { + return _conflictsNode.size(); + } + + @Override + public Object getElementAt(int index) + { + return _conflictsNode.get(index); + } +}