Author: sletellier Date: 2012-01-03 18:28:12 +0100 (Tue, 03 Jan 2012) New Revision: 16 Url: http://forge.codelutin.com/repositories/revision/jmexico/16 Log: - Debug table model - Debug specific editor - Add missing traductions Modified: trunk/jmexico-model/src/main/java/fr/reseaumexico/model/ScenarioImpl.java trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/FactorValueCellEditor.java trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditorHandler.java trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/model/InputDesignTableModel.java trunk/jmexico-swing-editor/src/main/resources/i18n/jmexico-swing-editor_en_GB.properties trunk/jmexico-swing-editor/src/main/resources/i18n/jmexico-swing-editor_fr_FR.properties Modified: trunk/jmexico-model/src/main/java/fr/reseaumexico/model/ScenarioImpl.java =================================================================== --- trunk/jmexico-model/src/main/java/fr/reseaumexico/model/ScenarioImpl.java 2011-12-29 14:16:05 UTC (rev 15) +++ trunk/jmexico-model/src/main/java/fr/reseaumexico/model/ScenarioImpl.java 2012-01-03 17:28:12 UTC (rev 16) @@ -83,4 +83,9 @@ listener.onFactorValueChange(event); } } + + @Override + public String toString() { + return getName(); + } } Modified: trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/FactorValueCellEditor.java =================================================================== --- trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/FactorValueCellEditor.java 2011-12-29 14:16:05 UTC (rev 15) +++ trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/FactorValueCellEditor.java 2012-01-03 17:28:12 UTC (rev 16) @@ -26,9 +26,14 @@ import fr.reseaumexico.model.Factor; import java.awt.Component; +import java.awt.Insets; import java.awt.TextField; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import javax.swing.AbstractCellEditor; +import javax.swing.JButton; import javax.swing.JTable; +import javax.swing.SwingConstants; import javax.swing.table.TableCellEditor; /** @@ -36,13 +41,25 @@ * @since 0.1 */ public class FactorValueCellEditor extends AbstractCellEditor - implements TableCellEditor { + implements TableCellEditor, ActionListener { private static final long serialVersionUID = 1L; - protected String currentValue; + protected JTable table; + protected Factor factor; + protected Object currentValue; + protected JButton button; public FactorValueCellEditor() { + //Set up the editor (from the table's point of view), + //which is a button. + //This button brings up the color chooser dialog, + //which is the editor from the user's point of view. + button = new JButton(); + button.addActionListener(this); + button.setBorderPainted(false); + button.setHorizontalAlignment(SwingConstants.LEFT); + button.setMargin(new Insets(0,0,0,0)); } @Override @@ -51,13 +68,25 @@ } @Override - public Component getTableCellEditorComponent(JTable table, Object oldValue, boolean isSelected, int row, int column) { - + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { // get factor // TODO sletellier 20111221 : Take care of type - Factor factor = (Factor) table.getValueAt(row, 0); - currentValue = (String)FactorValueEditorFactory.getInstance().edit(table, factor, oldValue); + factor = (Factor) table.getValueAt(row, 0); - return new TextField(currentValue); + currentValue = value; + button.setText(String.valueOf(currentValue)); + return button; } + + @Override + public void actionPerformed(ActionEvent e) { + // get factor + // TODO sletellier 20111221 : Take care of type + Object editedValue = FactorValueEditorFactory.getInstance().edit(table, factor, currentValue); + if (editedValue != null) { + currentValue = editedValue; + button.setText(String.valueOf(currentValue)); + } + fireEditingStopped(); + } } Modified: trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditorHandler.java =================================================================== --- trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditorHandler.java 2011-12-29 14:16:05 UTC (rev 15) +++ trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditorHandler.java 2012-01-03 17:28:12 UTC (rev 16) @@ -44,7 +44,10 @@ public void addScenario(InputDesignEditor editor) { InputDesign inputDesign = editor.getInputDesign(); - String selectedName = JOptionPane.showInputDialog(editor, _("jmexico.scenario.inputName")); + String selectedName = JOptionPane.showInputDialog(editor, + _("jmexico.scenario.inputName"), + _("jmexico.scenario.inputName.title"), + JOptionPane.QUESTION_MESSAGE); // check that name is never used Collection<Scenario> scenarios = inputDesign.getScenario(); @@ -88,6 +91,22 @@ } public void removeScenario(InputDesignEditor editor) { + InputDesign inputDesign = editor.getInputDesign(); + // show scenario select dialog + Collection<Scenario> scenarios = inputDesign.getScenario(); + Scenario scenario = (Scenario)JOptionPane.showInputDialog( + editor, + _("jmexico.scenario.selectRemove"), + _("jmexico.scenario.selectRemove.title"), + JOptionPane.PLAIN_MESSAGE, + null, + scenarios.toArray(), + null); + + // if scenario is selected + if (scenario != null) { + inputDesign.removeScenario(scenario); + } } } Modified: trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/model/InputDesignTableModel.java =================================================================== --- trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/model/InputDesignTableModel.java 2011-12-29 14:16:05 UTC (rev 15) +++ trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/model/InputDesignTableModel.java 2012-01-03 17:28:12 UTC (rev 16) @@ -29,11 +29,12 @@ import fr.reseaumexico.model.Scenario; import fr.reseaumexico.model.event.InputDesignScenarioEvent; import fr.reseaumexico.model.event.InputDesignScenarioListener; -import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; @@ -50,6 +51,7 @@ protected TableModel delegate; protected InputDesign inputDesign; + protected List<Factor> factors; public InputDesignTableModel() { delegate = new DefaultTableModel(); @@ -59,6 +61,18 @@ this.inputDesign = inputDesign; inputDesign.addInputDesignScenarioListener(this); + // extract factors + factors = new LinkedList<Factor>(inputDesign.getExperimentDesign().getFactor()); + + // sort on id + Collections.sort(factors, new Comparator<Factor>() { + + @Override + public int compare(Factor o1, Factor o2) { + return o1.getId().compareTo(o2.getId()); + } + }); + fireTableStructureChanged(); } @@ -85,7 +99,7 @@ } public Factor getFactor(int i) { - return inputDesign.getExperimentDesign().getFactor(i); + return factors.get(i); } @Override @@ -93,7 +107,6 @@ if (inputDesign == null) { return delegate.getRowCount(); } - Collection<Factor> factors = inputDesign.getExperimentDesign().getFactor(); return factors == null ? 0 : factors.size(); } @@ -162,7 +175,8 @@ } Map<Factor,Object> factorValues = scenario.getFactorValues(); - return factorValues.get(factor); + Object result = factorValues.get(factor); + return result; } @Override @@ -181,9 +195,7 @@ Map<Factor,Object> factorValues = scenario.getFactorValues(); // get key if rowIndex - Set<Factor> factors = factorValues.keySet(); - List<Factor> factorsList = new ArrayList<Factor>(factors); - Factor factor = factorsList.get(rowIndex); + Factor factor = getFactor(rowIndex); factorValues.put(factor, o); scenario.setFactorValues(factorValues); Modified: trunk/jmexico-swing-editor/src/main/resources/i18n/jmexico-swing-editor_en_GB.properties =================================================================== --- trunk/jmexico-swing-editor/src/main/resources/i18n/jmexico-swing-editor_en_GB.properties 2011-12-29 14:16:05 UTC (rev 15) +++ trunk/jmexico-swing-editor/src/main/resources/i18n/jmexico-swing-editor_en_GB.properties 2012-01-03 17:28:12 UTC (rev 16) @@ -9,3 +9,6 @@ jmexico.menu.file.save=Save jmexico.remove.scenario=Suppression d'un scenario jmexico.scenario.inputName=Name of scenario to add \: +jmexico.scenario.inputName.title= +jmexico.scenario.selectRemove= +jmexico.scenario.selectRemove.title= Modified: trunk/jmexico-swing-editor/src/main/resources/i18n/jmexico-swing-editor_fr_FR.properties =================================================================== --- trunk/jmexico-swing-editor/src/main/resources/i18n/jmexico-swing-editor_fr_FR.properties 2011-12-29 14:16:05 UTC (rev 15) +++ trunk/jmexico-swing-editor/src/main/resources/i18n/jmexico-swing-editor_fr_FR.properties 2012-01-03 17:28:12 UTC (rev 16) @@ -9,3 +9,6 @@ jmexico.menu.file.save=Sauvegarder jmexico.remove.scenario=Suppression d'un scenario jmexico.scenario.inputName=Nom du scénario à ajouter \: +jmexico.scenario.inputName.title= +jmexico.scenario.selectRemove= +jmexico.scenario.selectRemove.title=