# HG changeset patch # User dirk # Date 1316336416 -7200 # Node ID ca9c62a68e878ac2b5f5e6aab8ff0d3cbb8dfb1a # Parent 7593675c1eff1ddf04882b7640e3a6c514daddf5 wire up the current value, conflict value and preview buttons diff -r 7593675c1eff -r ca9c62a68e87 conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java --- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java Sun Sep 18 10:13:48 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java Sun Sep 18 11:00:16 2011 +0200 @@ -3,14 +3,20 @@ import de.codedo.conflicteditor.Difference; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.io.IOException; +import java.io.StringWriter; import java.util.List; +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.ListModel; import javax.swing.table.TableModel; import org.codehaus.jackson.JsonNode; +import org.codehaus.jackson.map.ObjectMapper; public class ConflictEditor { @@ -44,6 +50,9 @@ connectFindConflictsButton(); connectConflictsList(); connectDifferencesTable(); + connectCurrentValueButton(); + connectConflictValueButton(); + connectPreviewButton(); } private void connectFindConflictsButton() @@ -90,6 +99,48 @@ _frame.getDifferencesTable().getSelectionModel().addListSelectionListener(listener); } + private void connectCurrentValueButton() + { + Executable executable = new Executable() + { + @Override + public void execute(ActionEvent event) throws Exception + { + useCurrentValue(); + } + }; + ExceptionHandlingActionListener listener = new ExceptionHandlingActionListener(executable); + _frame.getCurrentValueButton().addActionListener(listener); + } + + private void connectConflictValueButton() + { + Executable executable = new Executable() + { + @Override + public void execute(ActionEvent event) throws Exception + { + useConflictValue(); + } + }; + ExceptionHandlingActionListener listener = new ExceptionHandlingActionListener(executable); + _frame.getConflictValueButton().addActionListener(listener); + } + + private void connectPreviewButton() + { + Executable executable = new Executable() + { + @Override + public void execute(ActionEvent event) throws Exception + { + preview(); + } + }; + ExceptionHandlingActionListener listener = new ExceptionHandlingActionListener(executable); + _frame.getPreviewButton().addActionListener(listener); + } + protected void findConflicts() throws IOException { String dbUrl = _frame.getDatabaseUrlTextField().getText(); @@ -118,4 +169,34 @@ _frame.enableButtons(); } + + protected void useCurrentValue() + { + _controller.useCurrentValue(); + } + + protected void useConflictValue() + { + _controller.useConflictValue(); + } + + protected void preview() throws Exception + { + JsonNode currentConflict = _controller.getCurrentConflict(); + StringWriter writer = new StringWriter(); + new ObjectMapper().defaultPrettyPrintingWriter().writeValue(writer, currentConflict); + + JTextArea text = new JTextArea(); + text.setText(writer.toString()); + + JScrollPane scrollPane = new JScrollPane(text); + + // TODO modal + JFrame preview = new JFrame(); + preview.setPreferredSize(new Dimension(800, 600)); + preview.add(scrollPane); + + preview.pack(); + preview.setVisible(true); + } } diff -r 7593675c1eff -r ca9c62a68e87 conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java --- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java Sun Sep 18 10:13:48 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java Sun Sep 18 11:00:16 2011 +0200 @@ -15,6 +15,7 @@ import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.node.ObjectNode; public class ConflictEditorController extends Object { @@ -57,9 +58,36 @@ } } - public void setCurrentConflict(JsonNode conflictNode) + public void useCurrentValue() + { + JsonNode currentValue = (JsonNode)_currentDifference.currentValue; + ((ObjectNode)_currentConflict).put(_currentDifference.key, currentValue); + } + + public void useConflictValue() + { + JsonNode value = (JsonNode)_currentDifference.otherValue; + ((ObjectNode)_currentConflict).put(_currentDifference.key, value); + } + + public JsonNode getCurrentConflict() { - _currentConflict = conflictNode; + return _currentConflict; + } + + public void setCurrentConflict(JsonNode conflictNode) throws Exception + { + JsonNode node = conflictNode.get("key"); + _currentConflict = deepCopyWithoutConflict(node); + } + + private ObjectNode deepCopyWithoutConflict(JsonNode node) throws Exception + { + // take a deep copy of the conflict node, we will be editing it here. + String docString = node.toString(); + ObjectNode clonedNode = (ObjectNode)new ObjectMapper().readTree(docString); + clonedNode.remove("_conflicts"); + return clonedNode; } public void setCurrentDifference(Difference difference)