# HG changeset patch # User Dirk Olmes # Date 1315827119 -7200 # Node ID ebff95a55276cd805dfb6b669b899d7fe190e0b3 # Parent 9c42f25cd944487b7dba330febcd21e2a8d9c020 basic GUI (not yet connected) for connecting to a DB and showing conflicts diff -r 9c42f25cd944 -r ebff95a55276 conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java --- /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 diffs = new ArrayList(); + 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"); + } +} diff -r 9c42f25cd944 -r ebff95a55276 conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java --- /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; + } +} diff -r 9c42f25cd944 -r ebff95a55276 conflict-editor/src/main/java/de/codedo/conflicteditor/gui/DifferenceTableModel.java --- /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 _differences; + + public DifferenceTableModel(List differences) + { + super(); + _differences = differences; + } + + public DifferenceTableModel() + { + this(new ArrayList()); + } + + @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]; + } +}