Mercurial > hg > ConflictEditor
changeset 25:7593675c1eff
pull the buttons into their own panel so they can be activated/deactivated in a single operation
author | dirk |
---|---|
date | Sun, 18 Sep 2011 10:13:48 +0200 |
parents | aa933f4d48e7 |
children | ca9c62a68e87 |
files | conflict-editor/src/main/java/de/codedo/conflicteditor/gui/AdjustingSelectionExecutable.java conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ButtonPanel.java conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java conflict-editor/src/main/java/de/codedo/conflicteditor/gui/DifferenceTableModel.java |
diffstat | 6 files changed, 180 insertions(+), 42 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/AdjustingSelectionExecutable.java Sun Sep 18 10:13:48 2011 +0200 @@ -0,0 +1,18 @@ + +package de.codedo.conflicteditor.gui; + +import javax.swing.event.ListSelectionEvent; + +public abstract class AdjustingSelectionExecutable extends Object implements Executable<ListSelectionEvent> +{ + @Override + public void execute(ListSelectionEvent event) throws Exception + { + if (event.getValueIsAdjusting() == false) + { + execute(event.getFirstIndex()); + } + } + + protected abstract void execute(int index) throws Exception; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ButtonPanel.java Sun Sep 18 10:13:48 2011 +0200 @@ -0,0 +1,96 @@ + +package de.codedo.conflicteditor.gui; + +import java.awt.FlowLayout; + +import javax.swing.JButton; +import javax.swing.JPanel; + +public class ButtonPanel extends JPanel +{ + private JButton _currentValueButton; + private JButton _conflictValueButton; + private JButton _previewButton; + private JButton _saveButton; + + public ButtonPanel() + { + super(); + setLayout(new FlowLayout()); + createButtons(); + } + + private void createButtons() + { + createCurrentValueButton(); + createConflictValueButton(); + createPreviewButton(); + createSaveButton(); + } + + private void createCurrentValueButton() + { + _currentValueButton = new JButton("use current value"); + _currentValueButton.setEnabled(false); + add(_currentValueButton); + } + + private void createConflictValueButton() + { + _conflictValueButton = new JButton("use conflict value"); + _conflictValueButton.setEnabled(false); + add(_conflictValueButton); + } + + private void createPreviewButton() + { + _previewButton = new JButton("preview"); + _previewButton.setEnabled(false); + add(_previewButton); + } + + private void createSaveButton() + { + _saveButton = new JButton("save"); + _saveButton.setEnabled(false); + add(_saveButton); + } + + public void enableButtons() + { + setButtonsEnabled(true); + } + + public void disableButtons() + { + setButtonsEnabled(false); + } + + private void setButtonsEnabled(boolean flag) + { + _currentValueButton.setEnabled(flag); + _conflictValueButton.setEnabled(flag); + _previewButton.setEnabled(flag); + _saveButton.setEnabled(flag); + } + + public JButton getCurrentValueButton() + { + return _currentValueButton; + } + + public JButton getConflictValueButton() + { + return _conflictValueButton; + } + + public JButton getPreviewButton() + { + return _previewButton; + } + + public JButton getSaveButton() + { + return _saveButton; + } +}
--- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java Sun Sep 18 09:40:58 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditor.java Sun Sep 18 10:13:48 2011 +0200 @@ -8,7 +8,6 @@ import java.util.List; import javax.swing.ListModel; -import javax.swing.event.ListSelectionEvent; import javax.swing.table.TableModel; import org.codehaus.jackson.JsonNode; @@ -63,15 +62,12 @@ private void connectConflictsList() { - Executable<ListSelectionEvent> executable = new Executable<ListSelectionEvent>() + AdjustingSelectionExecutable executable = new AdjustingSelectionExecutable() { @Override - public void execute(ListSelectionEvent event) throws Exception + protected void execute(int index) throws Exception { - if (event.getValueIsAdjusting() == false) - { - selectConflictDocument(event.getFirstIndex()); - } + selectConflictDocument(index); } }; ExceptionHandlingListSelectionListener listener = new ExceptionHandlingListSelectionListener( @@ -81,12 +77,12 @@ private void connectDifferencesTable() { - Executable<ListSelectionEvent> executable = new Executable<ListSelectionEvent>() + AdjustingSelectionExecutable executable = new AdjustingSelectionExecutable() { @Override - public void execute(ListSelectionEvent event) throws Exception + protected void execute(int index) throws Exception { - selectDifference(); + selectDifference(index); } }; ExceptionHandlingListSelectionListener listener = new ExceptionHandlingListSelectionListener( @@ -105,13 +101,21 @@ protected void selectConflictDocument(int index) throws Exception { JsonNode conflictNode = (JsonNode)_frame.getConflictsList().getModel().getElementAt(index); + _controller.setCurrentConflict(conflictNode); + List<Difference> differences = _controller.differencesForConflict(conflictNode); TableModel model = new DifferenceTableModel(differences); _frame.getDifferencesTable().setModel(model); + + _frame.disableButtons(); } - protected void selectDifference() + protected void selectDifference(int index) { - System.out.println("select a difference"); + DifferenceTableModel model = (DifferenceTableModel)_frame.getDifferencesTable().getModel(); + Difference difference = model.differenceAtIndex(index); + _controller.setCurrentDifference(difference); + + _frame.enableButtons(); } }
--- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java Sun Sep 18 09:40:58 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorController.java Sun Sep 18 10:13:48 2011 +0200 @@ -19,6 +19,8 @@ public class ConflictEditorController extends Object { private CouchDb _database; + private JsonNode _currentConflict; + private Difference _currentDifference; public JsonNode findConflicts(String dbUrl) throws IOException { @@ -54,4 +56,14 @@ reader.close(); } } + + public void setCurrentConflict(JsonNode conflictNode) + { + _currentConflict = conflictNode; + } + + public void setCurrentDifference(Difference difference) + { + _currentDifference = difference; + } }
--- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java Sun Sep 18 09:40:58 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/ConflictEditorFrame.java Sun Sep 18 10:13:48 2011 +0200 @@ -23,10 +23,7 @@ private JButton _findConflictsButton; private JList _conflictsList; private JTable _differencesTable; - private JButton _originalValueButton; - private JButton _conflictValueButton; - private JButton _previewButton; - private JButton _saveButton; + private ButtonPanel _buttonPanel; public ConflictEditorFrame() throws HeadlessException { @@ -136,32 +133,8 @@ private void createButtonPanel() { - JPanel buttonPanel = buildButtonPanel(); - addButtonPanel(buttonPanel); - } - - private JPanel buildButtonPanel() - { - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new FlowLayout()); - - _originalValueButton = new JButton("original"); - _originalValueButton.setEnabled(false); - buttonPanel.add(_originalValueButton); - - _conflictValueButton = new JButton("conflict"); - _conflictValueButton.setEnabled(false); - buttonPanel.add(_conflictValueButton); - - _previewButton = new JButton("preview"); - _previewButton.setEnabled(false); - buttonPanel.add(_previewButton); - - _saveButton = new JButton("save"); - _saveButton.setEnabled(false); - buttonPanel.add(_saveButton); - - return buttonPanel; + _buttonPanel = new ButtonPanel(); + addButtonPanel(_buttonPanel); } private void addButtonPanel(JPanel buttonPanel) @@ -172,6 +145,16 @@ getContentPane().add(buttonPanel, constraints); } + public void disableButtons() + { + _buttonPanel.disableButtons(); + } + + public void enableButtons() + { + _buttonPanel.enableButtons(); + } + public JTextField getDatabaseUrlTextField() { return _databaseUrlTextField; @@ -191,4 +174,24 @@ { return _differencesTable; } + + public JButton getCurrentValueButton() + { + return _buttonPanel.getCurrentValueButton(); + } + + public JButton getConflictValueButton() + { + return _buttonPanel.getConflictValueButton(); + } + + public JButton getPreviewButton() + { + return _buttonPanel.getPreviewButton(); + } + + public JButton getSaveButton() + { + return _buttonPanel.getSaveButton(); + } }
--- a/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/DifferenceTableModel.java Sun Sep 18 09:40:58 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/gui/DifferenceTableModel.java Sun Sep 18 10:13:48 2011 +0200 @@ -61,4 +61,9 @@ { return COLUMN_NAMES[column]; } + + public Difference differenceAtIndex(int index) + { + return _differences.get(index); + } }