changeset 2:ebff95a55276

basic GUI (not yet connected) for connecting to a DB and showing conflicts
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 12 Sep 2011 13:31:59 +0200
parents 9c42f25cd944
children 84b19f2b1dbb
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/DifferenceTableModel.java
diffstat 3 files changed, 209 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java	Mon Sep 12 13:31:59 2011 +0200
@@ -0,0 +1,74 @@
+
+package de.codedo.conflicteditor.gui;
+
+import de.codedo.conflicteditor.Difference;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.table.TableModel;
+
+public class ConflictEditor
+{
+    private ConflictEditorFrame _frame;
+
+    public static void main(String[] args)
+    {
+        try
+        {
+            new ConflictEditor().run();
+        }
+        catch (Exception ex)
+        {
+            System.out.println("Uncaught toplevel Exception");
+            ex.printStackTrace(System.out);
+        }
+    }
+
+    private void run()
+    {
+        _frame = new ConflictEditorFrame();
+        connectListeners(_frame);
+        _frame.pack();
+        _frame.setVisible(true);
+    }
+
+    private void connectListeners(ConflictEditorFrame frame)
+    {
+        frame.getConnectButton().addActionListener(new ActionListener()
+        {
+            @Override
+            public void actionPerformed(ActionEvent e)
+            {
+                connectAndFindConflicts();
+            }
+        });
+
+        frame.getConflictsTable().getSelectionModel().addListSelectionListener(new ListSelectionListener()
+        {
+            @Override
+            public void valueChanged(ListSelectionEvent e)
+            {
+                selectConflict();
+            }
+        });
+    }
+
+    protected void connectAndFindConflicts()
+    {
+        List<Difference> diffs = new ArrayList<Difference>();
+        diffs.add(new Difference("key", "current", "other"));
+
+        TableModel model = new DifferenceTableModel(diffs);
+        _frame.getConflictsTable().setModel(model);
+    }
+
+    protected void selectConflict()
+    {
+        System.out.println("select a conflict");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java	Mon Sep 12 13:31:59 2011 +0200
@@ -0,0 +1,71 @@
+
+package de.codedo.conflicteditor.gui;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.HeadlessException;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.table.TableModel;
+
+public class ConflictEditorFrame extends JFrame
+{
+    private JTextField _databaseUrlTextField;
+    private JButton _connectButton;
+    private JTable _conflictsTable;
+
+    public ConflictEditorFrame() throws HeadlessException
+    {
+        super();
+        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        setLayout(new BorderLayout());
+        buildGui();
+    }
+
+    private void buildGui()
+    {
+        buildDatabaseUrlPanel();
+        buildConflictsTable();
+    }
+
+    private void buildDatabaseUrlPanel()
+    {
+        JLabel label = new JLabel("Database URL:");
+        _databaseUrlTextField = new JTextField(40);
+        _connectButton = new JButton("Connect");
+
+        JPanel databaseUrlPanel = new JPanel();
+        databaseUrlPanel.setLayout(new FlowLayout());
+        databaseUrlPanel.add(label);
+        databaseUrlPanel.add(_databaseUrlTextField);
+        databaseUrlPanel.add(_connectButton);
+
+        getContentPane().add(databaseUrlPanel);
+    }
+
+    private void buildConflictsTable()
+    {
+        _conflictsTable = new JTable();
+        TableModel model = new DifferenceTableModel();
+        _conflictsTable.setModel(model);
+
+        JScrollPane scrollPane = new JScrollPane(_conflictsTable);
+        getContentPane().add(scrollPane, BorderLayout.SOUTH);
+    }
+
+    public JButton getConnectButton()
+    {
+        return _connectButton;
+    }
+
+    public JTable getConflictsTable()
+    {
+        return _conflictsTable;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/DifferenceTableModel.java	Mon Sep 12 13:31:59 2011 +0200
@@ -0,0 +1,64 @@
+
+package de.codedo.conflicteditor.gui;
+
+import de.codedo.conflicteditor.Difference;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.table.AbstractTableModel;
+
+public class DifferenceTableModel extends AbstractTableModel
+{
+    public static final String[] COLUMN_NAMES = { "Key", "Current value", "Old value" };
+
+    private List<Difference> _differences;
+
+    public DifferenceTableModel(List<Difference> differences)
+    {
+        super();
+        _differences = differences;
+    }
+
+    public DifferenceTableModel()
+    {
+        this(new ArrayList<Difference>());
+    }
+
+    @Override
+    public int getColumnCount()
+    {
+        return 3;
+    }
+
+    @Override
+    public int getRowCount()
+    {
+        return _differences.size();
+    }
+
+    @Override
+    public Object getValueAt(int rowIndex, int columnIndex)
+    {
+        Difference diff = _differences.get(rowIndex);
+        switch (columnIndex)
+        {
+            case 0 :
+                return diff.key;
+
+            case 1 :
+                return diff.currentValue;
+
+            case 2 :
+                return diff.otherValue;
+        }
+
+        throw new IllegalStateException("invalid column index: " + columnIndex);
+    }
+
+    @Override
+    public String getColumnName(int column)
+    {
+        return COLUMN_NAMES[column];
+    }
+}