Author: tchemit Date: 2012-01-18 17:16:00 +0100 (Wed, 18 Jan 2012) New Revision: 31 Url: http://forge.codelutin.com/repositories/revision/jmexico/31 Log: change packages Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignTableModel.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/MexicoDecoratorProvider.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueCellEditor.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueCellRenderer.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueEditor.jaxx trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueEditorFactory.java Removed: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/decorator/MexicoDecoratorProvider.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditor.jaxx trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditorHandler.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignTableModel.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/factorValue/ Modified: trunk/jmexico-editor-demo/pom.xml trunk/jmexico-editor-demo/src/main/java/fr/reseaumexico/editor/demo/MexicoEditorDemoUI.jaxx Copied: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx (from rev 30, trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditor.jaxx) =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx 2012-01-18 16:16:00 UTC (rev 31) @@ -0,0 +1,85 @@ +<!-- + #%L + JMexico :: Swing Editor + + $Id$ + $HeadURL$ + %% + Copyright (C) 2011 Réseau Mexico, Codelutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<JPanel id='inputDesignEditor' layout='{new BorderLayout()}'> + + <import> + fr.reseaumexico.model.InputDesign + fr.reseaumexico.model.Factor + fr.reseaumexico.editor.InputDesignTableModel + fr.reseaumexico.editor.factorValue.FactorValueCellEditor + fr.reseaumexico.editor.factorValue.FactorValueCellRenderer + fr.reseaumexico.editor.MexicoDecoratorProvider + jaxx.runtime.swing.renderer.DecoratorProviderTableCellRenderer + </import> + + <InputDesignEditorHandler id='handler'/> + + <InputDesignTableModel id='model' javaBean="new InputDesignTableModel()"/> + + <FactorValueCellEditor id='cellEditor' constructorParams='this'/> + + <FactorValueCellRenderer id='cellRenderer' constructorParams='this'/> + + <script> + <![CDATA[ + +private void $afterCompleteSetup() { + + // table renderer + // TODO sletellier 20111221 : do on time for all, put in context ? + MexicoDecoratorProvider mexicoDecoratorProvider = new MexicoDecoratorProvider(); + inputDesignTable.setDefaultRenderer(Factor.class, new DecoratorProviderTableCellRenderer(mexicoDecoratorProvider)); + inputDesignTable.setDefaultRenderer(Object.class, getCellRenderer()); + + // cell editor + inputDesignTable.setDefaultEditor(Object.class, getCellEditor()); +} + +public void setInputDesign(InputDesign inputDesign) { + getModel().setInputDesign(inputDesign); +} + +public InputDesign getInputDesign() { + return getModel().getInputDesign(); +} + ]]> + </script> + + <JScrollPane constraints='BorderLayout.CENTER'> + <JTable id='inputDesignTable' model='{getModel()}'/> + </JScrollPane> + + <JPanel id='factorActionPanel' constraints='BorderLayout.SOUTH'> + <JButton id='addScenarioButton' + text='jmexico.add.scenario' + constraints='BorderLayout.WEST' + onActionPerformed='getHandler().addScenario(this)'/> + <JButton id='removeScenarioButton' + text='jmexico.remove.scenario' + constraints='BorderLayout.EAST' + onActionPerformed='getHandler().removeScenario(this)'/> + </JPanel> + +</JPanel> Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java (from rev 30, trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditorHandler.java) =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java 2012-01-18 16:16:00 UTC (rev 31) @@ -0,0 +1,117 @@ +/* + * #%L + * JMexico :: Swing Editor + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Réseau Mexico, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package fr.reseaumexico.editor; + +import com.google.common.collect.Maps; +import fr.reseaumexico.model.Factor; +import fr.reseaumexico.model.InputDesign; +import fr.reseaumexico.model.Scenario; +import fr.reseaumexico.model.ScenarioImpl; +import java.util.Collection; +import java.util.Map; +import javax.swing.JOptionPane; +import org.apache.commons.lang3.StringUtils; + +import static org.nuiton.i18n.I18n._; + +/** + * @author sletellier <letellier@codelutin.com> + * @since 0.1 + */ +public class InputDesignEditorHandler { + + public void addScenario(InputDesignEditor editor) { + InputDesign inputDesign = editor.getInputDesign(); + + String selectedName = JOptionPane.showInputDialog(editor, + _("jmexico.scenario.inputName"), + _("jmexico.scenario.inputName.title"), + JOptionPane.QUESTION_MESSAGE); + + // if user enter name + if (StringUtils.isNotBlank(selectedName)) { + + // check that name is never used + Collection<Scenario> scenarios = inputDesign.getScenario(); + + int maxOrder = 0; + for (Scenario scenario : scenarios) { + if (selectedName.equalsIgnoreCase(scenario.getName())) { + + JOptionPane.showMessageDialog(editor, + _("jmexico.error.title"), + _("jmexico.error.scenario.name.used"), + JOptionPane.ERROR_MESSAGE); + + return; + } + int orderNumber = scenario.getOrderNumber(); + if (maxOrder < orderNumber) { + maxOrder = orderNumber; + } + } + + // create new scenario + Scenario scenarioToAdd = new ScenarioImpl(); + + // set last order + // TODO sletellier 20111219 : ask user order number + scenarioToAdd.setOrderNumber(maxOrder + 1); + + // set name + scenarioToAdd.setName(selectedName); + + // create all empty factor values + Collection<Factor> factors = inputDesign.getExperimentDesign().getFactor(); + Map<Factor, Object> factorValues = Maps.newHashMap(); + for (Factor factor : factors) { + factorValues.put(factor, null); + } + scenarioToAdd.setFactorValues(factorValues); + + inputDesign.addScenario(scenarioToAdd); + } + } + + 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); + } + } +} Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignTableModel.java (from rev 30, trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignTableModel.java) =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignTableModel.java (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignTableModel.java 2012-01-18 16:16:00 UTC (rev 31) @@ -0,0 +1,212 @@ +/* + * #%L + * JMexico :: Swing Editor + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Réseau Mexico, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package fr.reseaumexico.editor; + +import fr.reseaumexico.model.Factor; +import fr.reseaumexico.model.InputDesign; +import fr.reseaumexico.model.MexicoUtil; +import fr.reseaumexico.model.Scenario; +import fr.reseaumexico.model.ValueType; +import fr.reseaumexico.model.event.InputDesignScenarioEvent; +import fr.reseaumexico.model.event.InputDesignScenarioListener; +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 javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; +import org.apache.commons.lang3.ObjectUtils; + +import static org.nuiton.i18n.I18n._; + +/** + * @author sletellier <letellier@codelutin.com> + * @since 0.1 + */ +public class InputDesignTableModel extends AbstractTableModel implements InputDesignScenarioListener { + + private static final long serialVersionUID = 1L; + + protected TableModel delegate; + + protected InputDesign inputDesign; + + protected List<Factor> factors; + + public InputDesignTableModel() { + delegate = new DefaultTableModel(); + } + + public void setInputDesign(InputDesign inputDesign) { + 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(); + } + + @Override + public void onScenarioAdded(InputDesignScenarioEvent event) { + fireTableStructureChanged(); + } + + @Override + public void onScenarioRemoved(InputDesignScenarioEvent event) { + fireTableStructureChanged(); + } + + public InputDesign getInputDesign() { + return inputDesign; + } + + public Collection<Scenario> getScenarios() { + return inputDesign.getScenario(); + } + + public Scenario getScenario(int i) { + return inputDesign.getScenario(i); + } + + public Factor getFactor(int i) { + return factors.get(i); + } + + @Override + public int getRowCount() { + if (inputDesign == null) { + return delegate.getRowCount(); + } + return factors == null ? 0 : factors.size(); + } + + @Override + public int getColumnCount() { + if (inputDesign == null) { + return delegate.getColumnCount(); + } + Collection<Scenario> scenarios = getScenarios(); + if (scenarios == null) { + return 1; + } + return scenarios.size() + 1; + } + + @Override + public String getColumnName(int rowIndex) { + if (inputDesign == null) { + return delegate.getColumnName(rowIndex); + } + if (rowIndex == 0) { + return _("jmexico.factor.name"); + } + Scenario scenario = getScenario(rowIndex - 1); + return scenario == null ? "" : scenario.getName(); + } + + @Override + public Class<?> getColumnClass(int rowIndex) { + if (inputDesign == null) { + return delegate.getColumnClass(rowIndex); + } + if (rowIndex == 0) { + return Factor.class; + } + return Object.class; + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + if (inputDesign == null) { + return delegate.isCellEditable(rowIndex, columnIndex); + } + return columnIndex > 0; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + if (inputDesign == null) { + return delegate.getValueAt(rowIndex, columnIndex); + } + + // get key on rowIndex + Factor factor = getFactor(rowIndex); + + // first column is factors + if (columnIndex == 0) { + return factor; + } + + // others are scenarios + columnIndex = columnIndex - 1; + Scenario scenario = getScenario(columnIndex); + if (scenario == null) { + return null; + } + Map<Factor,Object> factorValues = scenario.getFactorValues(); + + Object result = factorValues.get(factor); + return result; + } + + @Override + public void setValueAt(Object o, int rowIndex, int columnIndex) { + if (inputDesign == null) { + delegate.setValueAt(o, rowIndex, columnIndex); + return; + } + if (columnIndex == 0) { + + // must never append + return; + } + int scenarioIndex = columnIndex - 1; + Scenario scenario = getScenario(scenarioIndex); + + // get key if rowIndex + Factor factor = getFactor(rowIndex); + + // take care of type + ValueType valueType = factor.getDomain().getValueType(); + + String value = ObjectUtils.toString(o); + scenario.setFactorValue(factor, MexicoUtil.getTypedValue(valueType, value)); + + fireTableCellUpdated(rowIndex, columnIndex); + } +} Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/MexicoDecoratorProvider.java (from rev 30, trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/decorator/MexicoDecoratorProvider.java) =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/MexicoDecoratorProvider.java (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/MexicoDecoratorProvider.java 2012-01-18 16:16:00 UTC (rev 31) @@ -0,0 +1,39 @@ +/* + * #%L + * JMexico :: Swing Editor + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Réseau Mexico, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package fr.reseaumexico.editor; + +import fr.reseaumexico.model.Factor; +import jaxx.runtime.decorator.DecoratorProvider; + +/** + * @author sletellier <letellier@codelutin.com> + */ +public class MexicoDecoratorProvider extends DecoratorProvider { + + @Override + protected void loadDecorators() { + registerJXPathDecorator(Factor.class, "${" + Factor.PROPERTY_ID + "}$s"); + } +} Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/MexicoDecoratorProvider.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueCellEditor.java (from rev 30, trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/factorValue/FactorValueCellEditor.java) =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueCellEditor.java (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueCellEditor.java 2012-01-18 16:16:00 UTC (rev 31) @@ -0,0 +1,147 @@ +/* + * #%L + * JMexico :: Swing Editor + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Réseau Mexico, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package fr.reseaumexico.editor.factorValue; + +import fr.reseaumexico.model.Factor; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import javax.swing.AbstractCellEditor; +import javax.swing.JComboBox; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.table.TableCellEditor; +import jaxx.runtime.JAXXContext; + +/** + * Cell editor for factor values + * + * @author sletellier <letellier@codelutin.com> + * @since 0.1 + * @see TableCellEditor + */ +public class FactorValueCellEditor extends AbstractCellEditor + implements TableCellEditor, FocusListener { + + private static final long serialVersionUID = 1L; + + protected JTable table; + protected Factor factor; + protected Object currentValue; + protected JTextField defaultInlineEditor; + protected FactorValueEditorFactory.FactorValueCellEditor specificEditor; + protected boolean isEditing; + protected FactorValueEditorFactory factory; + + public FactorValueCellEditor(JAXXContext context) { + defaultInlineEditor = new JTextField(); + defaultInlineEditor.addFocusListener(this); + + // search specific factory in context + factory = context.getContextValue(FactorValueEditorFactory.class); + + // if not found, use mexico one + if (factory == null) { + factory = new FactorValueEditorFactory(); + } + } + + @Override + public Object getCellEditorValue() { + if (isEditing) { + currentValue = defaultInlineEditor.getText(); + isEditing = false; + } + if (specificEditor != null) { + currentValue = specificEditor.getValue(); + } + return currentValue; + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + // get factor + factor = (Factor) table.getValueAt(row, 0); + + currentValue = value; + + specificEditor = factory.getCellEditor(factor, currentValue); + + if (specificEditor != null) { + Component component = specificEditor.getComponent(); + + // stop editing on select for combos + if (component instanceof JComboBox) { + ((JComboBox)component).addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + fireEditingStopped(); + } + }); + } + + component.addFocusListener(new FocusListener() { + + @Override + public void focusGained(FocusEvent e) { + // do nothing + } + + @Override + public void focusLost(FocusEvent e) { + fireEditingStopped(); + } + }); + + return component; + } + defaultInlineEditor.setText(currentValue == null ? "" : String.valueOf(currentValue)); + return defaultInlineEditor; + } + + @Override + public void focusGained(FocusEvent e) { + + // get factor + FactorValueEditor editor = factory.getDialogEditor(factor, currentValue); + if (editor == null) { + isEditing = true; + } else { + // display ui + editor.setVisible(true); + currentValue = editor.getValue(); + defaultInlineEditor.setText(currentValue == null ? "" : String.valueOf(currentValue)); + fireEditingStopped(); + } + } + + @Override + public void focusLost(FocusEvent e) { + fireEditingStopped(); + } +} Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueCellEditor.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueCellRenderer.java (from rev 30, trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/factorValue/FactorValueCellRenderer.java) =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueCellRenderer.java (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueCellRenderer.java 2012-01-18 16:16:00 UTC (rev 31) @@ -0,0 +1,71 @@ +/* + * #%L + * JMexico :: Swing Editor + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Réseau Mexico, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package fr.reseaumexico.editor.factorValue; + +import fr.reseaumexico.model.Factor; +import java.awt.Component; +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellRenderer; +import jaxx.runtime.JAXXContext; + +/** + * @author sletellier <letellier@codelutin.com> + */ +public class FactorValueCellRenderer implements TableCellRenderer { + + protected FactorValueEditorFactory factory; + protected TableCellRenderer delegate; + + public FactorValueCellRenderer(JAXXContext context) { + + // search specific factory in context + factory = context.getContextValue(FactorValueEditorFactory.class); + + // if not found, use mexico one + if (factory == null) { + factory = new FactorValueEditorFactory(); + } + + delegate = new DefaultTableCellRenderer(); + + } + + @Override + public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { + Factor factor = (Factor) table.getValueAt(row, 0); + + FactorValueEditorFactory.FactorValueCellRenderer specificRenderer = factory.getRenderedComponent(factor, value); + + Component result; + if (specificRenderer == null) { + result = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + } else { + result = specificRenderer.getComponent(); + } + + return result; + } +} Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueCellRenderer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueEditor.jaxx (from rev 30, trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/factorValue/FactorValueEditor.jaxx) =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueEditor.jaxx (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueEditor.jaxx 2012-01-18 16:16:00 UTC (rev 31) @@ -0,0 +1,45 @@ +<!-- + #%L + JMexico :: Swing Editor + + $Id$ + $HeadURL$ + %% + Copyright (C) 2011 - 2012 Réseau Mexico, Codelutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<JDialog abstract='true' + genericType='B' + modal='true' + layout='{new BorderLayout()}'> + + <import> +java.awt.BorderLayout +fr.reseaumexico.model.Factor + </import> + + <Factor id='factor' initializer='getContextValue(Factor.class)'/> + + <script><![CDATA[ + +public abstract B getValue(); + +public abstract void setValue(B data); + ]]> + </script> + +</JDialog> \ No newline at end of file Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueEditor.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueEditorFactory.java (from rev 30, trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/factorValue/FactorValueEditorFactory.java) =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueEditorFactory.java (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueEditorFactory.java 2012-01-18 16:16:00 UTC (rev 31) @@ -0,0 +1,266 @@ +/* + * #%L + * JMexico :: Swing Editor + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Réseau Mexico, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package fr.reseaumexico.editor.factorValue; + +import com.google.common.collect.Maps; +import fr.reseaumexico.model.Domain; +import fr.reseaumexico.model.Factor; +import fr.reseaumexico.model.ValueType; +import jaxx.runtime.swing.editor.NumberEditor; +import org.apache.commons.lang3.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.util.Map; + +/** + * Factory used to open specific editor to input factor value + * + * @author sletellier <letellier@codelutin.com> + * @since 0.1 + */ +public class FactorValueEditorFactory { + + protected Map<Factor, FactorValueCellEditor<?>> factorValueEditorCache = Maps.newHashMap(); + + /** + * Provide specific {@link JDialog} editor for factor value + * + * @param factor concerned + * @param value value to edit + * @return {@link FactorValueEditor} contain editor to open as {@link JDialog}, + * null if cell editor must be used + */ + public FactorValueEditor getDialogEditor(Factor factor, Object value) { + + // TODO sletellier 20121221 : open specific editor + +// if (oldValue == null) { +// +// JAXXInitialContext context = new JAXXInitialContext(); +// context.add(factor); +// FactorValueEditor<B> editor = (FactorValueEditor<B>) new FactorValueEditorImpl(context); +// editor.setValue(oldValue); +// return editor; +// } + + return null; + } + + protected FactorValueCellEditor<?> getFactorValueCellEditor(Factor factor) { + return factorValueEditorCache.get(factor); + } + + protected void setFactorValueCellEditor(Factor factor, FactorValueCellEditor<?> editor) { + factorValueEditorCache.put(factor, editor); + } + + /** + * Provide specific cell editor for factor value + * + * @param factor concerned + * @param value value to edit + * @return {@link FactorValueCellEditor} contain editor to display + */ + public FactorValueCellEditor getCellEditor(Factor factor, Object value) { + + FactorValueCellEditor<?> factorValueCellEditor = getFactorValueCellEditor(factor); + + // get type + Domain domain = factor.getDomain(); + ValueType valueType = ValueType.STRING; + if (domain != null) { + valueType = domain.getValueType(); + } + + if (factorValueCellEditor == null) { + switch (valueType) { + case INTEGER: + factorValueCellEditor = new IntegerFactorValueInlineEditor(); + break; + case DECIMAL: + factorValueCellEditor = new DecimalFactorValueInlineEditor(); + break; + case BOOLEAN: + factorValueCellEditor = new BooleanFactorValueInlineEditor(); + break; + default: + factorValueCellEditor = new DefaultFactorValueInlineEditor(); + } + } + + setFactorValueCellEditor(factor, factorValueCellEditor); + + factorValueCellEditor.setValue(value); + return factorValueCellEditor; + } + + /** + * Provide a specific cell renderer for factor value + * + * @param factor concerned + * @param value value to edit + * @return {@link FactorValueCellRenderer} contain renderer to display + */ + public FactorValueCellRenderer getRenderedComponent(Factor factor, Object value) { + return getCellEditor(factor, value); + } + + protected interface FactorValueCellRenderer { + + Component getComponent(); + + void setValue(Object value); + } + + protected interface FactorValueCellEditor<B> extends FactorValueCellRenderer { + + B getValue(); + + void setValue(Object value); + + Component getComponent(); + } + + protected static class DefaultFactorValueInlineEditor implements FactorValueCellEditor<String> { + + protected JTextField component; + + public DefaultFactorValueInlineEditor() { + component = new JTextField(); + component.setBorder(null); + } + + @Override + public void setValue(Object value) { + component.setText(getStringValue(value)); + } + + @Override + public String getValue() { + return component.getText(); + } + + @Override + public Component getComponent() { + return component; + } + } + + protected static class BooleanFactorValueInlineEditor implements FactorValueCellEditor<Boolean> { + + protected JCheckBox checkBox; + + public BooleanFactorValueInlineEditor() { + checkBox = new JCheckBox(); + } + + @Override + public Boolean getValue() { + return checkBox.isSelected(); + } + + @Override + public void setValue(Object value) { + if (value != null) { + checkBox.setSelected((Boolean) value); + } + } + + @Override + public Component getComponent() { + return checkBox; + } + } + + protected static class IntegerFactorValueInlineEditor implements FactorValueCellEditor<Integer> { + + protected NumberEditor numberEditor; + + public IntegerFactorValueInlineEditor() { + numberEditor = new NumberEditor(); + numberEditor.getTextField().setBorder(null); + + numberEditor.setUseFloat(false); + numberEditor.setUseSign(true); + } + + @Override + public Integer getValue() { + return (Integer) numberEditor.getModel(); + } + + @Override + public void setValue(Object value) { + // FIXME sletellier 20120105 : we dont need to set modelText + numberEditor.setModel((Integer) value); + numberEditor.setModelText(getStringValue(value)); + } + + @Override + public Component getComponent() { + return numberEditor; + } + } + + protected static class DecimalFactorValueInlineEditor implements FactorValueCellEditor<Double> { + + protected NumberEditor numberEditor; + + public DecimalFactorValueInlineEditor() { + numberEditor = new NumberEditor(); + numberEditor.getTextField().setBorder(null); + + numberEditor.setModelType(Double.class); + numberEditor.setUseFloat(true); + numberEditor.setUseSign(true); + } + + @Override + public Double getValue() { + return (Double) numberEditor.getModel(); + } + + @Override + public void setValue(Object value) { + numberEditor.setModel((Double) value); + // FIXME sletellier 20120105 : we dont need to set modelText + numberEditor.setModelText(getStringValue(value)); + } + + @Override + public Component getComponent() { + return numberEditor; + } + } + + protected static String getStringValue(Object value) { + String text = String.valueOf(value); + if (value == null) { + text = StringUtils.EMPTY; + } + return text; + } +} Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/factorValue/FactorValueEditorFactory.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/decorator/MexicoDecoratorProvider.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/decorator/MexicoDecoratorProvider.java 2012-01-18 16:06:23 UTC (rev 30) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/decorator/MexicoDecoratorProvider.java 2012-01-18 16:16:00 UTC (rev 31) @@ -1,39 +0,0 @@ -/* - * #%L - * JMexico :: Swing Editor - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 - 2012 Réseau Mexico, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package fr.reseaumexico.editor.ui.decorator; - -import fr.reseaumexico.model.Factor; -import jaxx.runtime.decorator.DecoratorProvider; - -/** - * @author sletellier <letellier@codelutin.com> - */ -public class MexicoDecoratorProvider extends DecoratorProvider { - - @Override - protected void loadDecorators() { - registerJXPathDecorator(Factor.class, "${" + Factor.PROPERTY_ID + "}$s"); - } -} Deleted: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditor.jaxx =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditor.jaxx 2012-01-18 16:06:23 UTC (rev 30) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditor.jaxx 2012-01-18 16:16:00 UTC (rev 31) @@ -1,85 +0,0 @@ -<!-- - #%L - JMexico :: Swing Editor - - $Id$ - $HeadURL$ - %% - Copyright (C) 2011 Réseau Mexico, Codelutin - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Lesser Public License for more details. - - You should have received a copy of the GNU General Lesser Public - License along with this program. If not, see - <http://www.gnu.org/licenses/lgpl-3.0.html>. - #L% - --> -<JPanel id='inputDesignEditor' layout='{new BorderLayout()}'> - - <import> - fr.reseaumexico.model.InputDesign - fr.reseaumexico.model.Factor - fr.reseaumexico.editor.ui.editor.InputDesignTableModel - fr.reseaumexico.editor.ui.editor.factorValue.FactorValueCellEditor - fr.reseaumexico.editor.ui.editor.factorValue.FactorValueCellRenderer - fr.reseaumexico.editor.ui.decorator.MexicoDecoratorProvider - jaxx.runtime.swing.renderer.DecoratorProviderTableCellRenderer - </import> - - <InputDesignEditorHandler id='handler'/> - - <InputDesignTableModel id='model' javaBean="new InputDesignTableModel()"/> - - <FactorValueCellEditor id='cellEditor' constructorParams='this'/> - - <FactorValueCellRenderer id='cellRenderer' constructorParams='this'/> - - <script> - <![CDATA[ - -private void $afterCompleteSetup() { - - // table renderer - // TODO sletellier 20111221 : do on time for all, put in context ? - MexicoDecoratorProvider mexicoDecoratorProvider = new MexicoDecoratorProvider(); - inputDesignTable.setDefaultRenderer(Factor.class, new DecoratorProviderTableCellRenderer(mexicoDecoratorProvider)); - inputDesignTable.setDefaultRenderer(Object.class, getCellRenderer()); - - // cell editor - inputDesignTable.setDefaultEditor(Object.class, getCellEditor()); -} - -public void setInputDesign(InputDesign inputDesign) { - getModel().setInputDesign(inputDesign); -} - -public InputDesign getInputDesign() { - return getModel().getInputDesign(); -} - ]]> - </script> - - <JScrollPane constraints='BorderLayout.CENTER'> - <JTable id='inputDesignTable' model='{getModel()}'/> - </JScrollPane> - - <JPanel id='factorActionPanel' constraints='BorderLayout.SOUTH'> - <JButton id='addScenarioButton' - text='jmexico.add.scenario' - constraints='BorderLayout.WEST' - onActionPerformed='getHandler().addScenario(this)'/> - <JButton id='removeScenarioButton' - text='jmexico.remove.scenario' - constraints='BorderLayout.EAST' - onActionPerformed='getHandler().removeScenario(this)'/> - </JPanel> - -</JPanel> Deleted: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditorHandler.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditorHandler.java 2012-01-18 16:06:23 UTC (rev 30) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditorHandler.java 2012-01-18 16:16:00 UTC (rev 31) @@ -1,117 +0,0 @@ -/* - * #%L - * JMexico :: Swing Editor - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Réseau Mexico, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package fr.reseaumexico.editor.ui.editor; - -import com.google.common.collect.Maps; -import fr.reseaumexico.model.Factor; -import fr.reseaumexico.model.InputDesign; -import fr.reseaumexico.model.Scenario; -import fr.reseaumexico.model.ScenarioImpl; -import java.util.Collection; -import java.util.Map; -import javax.swing.JOptionPane; -import org.apache.commons.lang3.StringUtils; - -import static org.nuiton.i18n.I18n._; - -/** - * @author sletellier <letellier@codelutin.com> - * @since 0.1 - */ -public class InputDesignEditorHandler { - - public void addScenario(InputDesignEditor editor) { - InputDesign inputDesign = editor.getInputDesign(); - - String selectedName = JOptionPane.showInputDialog(editor, - _("jmexico.scenario.inputName"), - _("jmexico.scenario.inputName.title"), - JOptionPane.QUESTION_MESSAGE); - - // if user enter name - if (StringUtils.isNotBlank(selectedName)) { - - // check that name is never used - Collection<Scenario> scenarios = inputDesign.getScenario(); - - int maxOrder = 0; - for (Scenario scenario : scenarios) { - if (selectedName.equalsIgnoreCase(scenario.getName())) { - - JOptionPane.showMessageDialog(editor, - _("jmexico.error.title"), - _("jmexico.error.scenario.name.used"), - JOptionPane.ERROR_MESSAGE); - - return; - } - int orderNumber = scenario.getOrderNumber(); - if (maxOrder < orderNumber) { - maxOrder = orderNumber; - } - } - - // create new scenario - Scenario scenarioToAdd = new ScenarioImpl(); - - // set last order - // TODO sletellier 20111219 : ask user order number - scenarioToAdd.setOrderNumber(maxOrder + 1); - - // set name - scenarioToAdd.setName(selectedName); - - // create all empty factor values - Collection<Factor> factors = inputDesign.getExperimentDesign().getFactor(); - Map<Factor, Object> factorValues = Maps.newHashMap(); - for (Factor factor : factors) { - factorValues.put(factor, null); - } - scenarioToAdd.setFactorValues(factorValues); - - inputDesign.addScenario(scenarioToAdd); - } - } - - 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); - } - } -} Deleted: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignTableModel.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignTableModel.java 2012-01-18 16:06:23 UTC (rev 30) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignTableModel.java 2012-01-18 16:16:00 UTC (rev 31) @@ -1,210 +0,0 @@ -/* - * #%L - * JMexico :: Swing Editor - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Réseau Mexico, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package fr.reseaumexico.editor.ui.editor; - -import fr.reseaumexico.model.Factor; -import fr.reseaumexico.model.InputDesign; -import fr.reseaumexico.model.MexicoUtil; -import fr.reseaumexico.model.Scenario; -import fr.reseaumexico.model.ValueType; -import fr.reseaumexico.model.event.InputDesignScenarioEvent; -import fr.reseaumexico.model.event.InputDesignScenarioListener; -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 javax.swing.table.AbstractTableModel; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableModel; -import org.apache.commons.lang3.ObjectUtils; - -import static org.nuiton.i18n.I18n._; - -/** - * @author sletellier <letellier@codelutin.com> - * @since 0.1 - */ -public class InputDesignTableModel extends AbstractTableModel implements InputDesignScenarioListener { - - private static final long serialVersionUID = 1L; - - protected TableModel delegate; - protected InputDesign inputDesign; - protected List<Factor> factors; - - public InputDesignTableModel() { - delegate = new DefaultTableModel(); - } - - public void setInputDesign(InputDesign inputDesign) { - 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(); - } - - @Override - public void onScenarioAdded(InputDesignScenarioEvent event) { - fireTableStructureChanged(); - } - - @Override - public void onScenarioRemoved(InputDesignScenarioEvent event) { - fireTableStructureChanged(); - } - - public InputDesign getInputDesign() { - return inputDesign; - } - - public Collection<Scenario> getScenarios() { - return inputDesign.getScenario(); - } - - public Scenario getScenario(int i) { - return inputDesign.getScenario(i); - } - - public Factor getFactor(int i) { - return factors.get(i); - } - - @Override - public int getRowCount() { - if (inputDesign == null) { - return delegate.getRowCount(); - } - return factors == null ? 0 : factors.size(); - } - - @Override - public int getColumnCount() { - if (inputDesign == null) { - return delegate.getColumnCount(); - } - Collection<Scenario> scenarios = getScenarios(); - if (scenarios == null) { - return 1; - } - return scenarios.size() + 1; - } - - @Override - public String getColumnName(int rowIndex) { - if (inputDesign == null) { - return delegate.getColumnName(rowIndex); - } - if (rowIndex == 0) { - return _("jmexico.factor.name"); - } - Scenario scenario = getScenario(rowIndex - 1); - return scenario == null ? "" : scenario.getName(); - } - - @Override - public Class<?> getColumnClass(int rowIndex) { - if (inputDesign == null) { - return delegate.getColumnClass(rowIndex); - } - if (rowIndex == 0) { - return Factor.class; - } - return Object.class; - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - if (inputDesign == null) { - return delegate.isCellEditable(rowIndex, columnIndex); - } - return columnIndex > 0; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - if (inputDesign == null) { - return delegate.getValueAt(rowIndex, columnIndex); - } - - // get key on rowIndex - Factor factor = getFactor(rowIndex); - - // first column is factors - if (columnIndex == 0) { - return factor; - } - - // others are scenarios - columnIndex = columnIndex - 1; - Scenario scenario = getScenario(columnIndex); - if (scenario == null) { - return null; - } - Map<Factor,Object> factorValues = scenario.getFactorValues(); - - Object result = factorValues.get(factor); - return result; - } - - @Override - public void setValueAt(Object o, int rowIndex, int columnIndex) { - if (inputDesign == null) { - delegate.setValueAt(o, rowIndex, columnIndex); - return; - } - if (columnIndex == 0) { - - // must never append - return; - } - int scenarioIndex = columnIndex - 1; - Scenario scenario = getScenario(scenarioIndex); - - // get key if rowIndex - Factor factor = getFactor(rowIndex); - - // take care of type - ValueType valueType = factor.getDomain().getValueType(); - - String value = ObjectUtils.toString(o); - scenario.setFactorValue(factor, MexicoUtil.getTypedValue(valueType, value)); - - fireTableCellUpdated(rowIndex, columnIndex); - } -} Modified: trunk/jmexico-editor-demo/pom.xml =================================================================== --- trunk/jmexico-editor-demo/pom.xml 2012-01-18 16:06:23 UTC (rev 30) +++ trunk/jmexico-editor-demo/pom.xml 2012-01-18 16:16:00 UTC (rev 31) @@ -64,8 +64,8 @@ <!-- *** Project Information ************************************* --> <!-- ************************************************************* --> - <name>JMexico :: Swing Editor</name> - <description>JMexico - Swing Editor module</description> + <name>JMexico :: Swing Editor Demo</name> + <description>JMexico - Swing Editor Demo module</description> <properties> Modified: trunk/jmexico-editor-demo/src/main/java/fr/reseaumexico/editor/demo/MexicoEditorDemoUI.jaxx =================================================================== --- trunk/jmexico-editor-demo/src/main/java/fr/reseaumexico/editor/demo/MexicoEditorDemoUI.jaxx 2012-01-18 16:06:23 UTC (rev 30) +++ trunk/jmexico-editor-demo/src/main/java/fr/reseaumexico/editor/demo/MexicoEditorDemoUI.jaxx 2012-01-18 16:16:00 UTC (rev 31) @@ -28,7 +28,7 @@ onWindowClosing='getHandler().closeApplication(this)'> <import> - fr.reseaumexico.editor.ui.editor.InputDesignEditor + fr.reseaumexico.editor.InputDesignEditor fr.reseaumexico.model.InputDesign </import>