r8 - in trunk: jmexico-model/src/main/java/fr/reseaumexico/model/parser jmexico-model/src/main/java/fr/reseaumexico/model/writer jmexico-swing-editor jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/model jmexico-swing-editor/src/main/resources/i18n
Author: sletellier Date: 2011-12-19 18:40:54 +0100 (Mon, 19 Dec 2011) New Revision: 8 Url: http://forge.codelutin.com/repositories/revision/jmexico/8 Log: - Write jmexicoTableModel - Creating InputDesignEditor - Debug ExperimentDesign parser Added: trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUI.css trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/ trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditor.jaxx 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/ 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 Modified: trunk/jmexico-model/src/main/java/fr/reseaumexico/model/parser/ExperimentDesignParser.java trunk/jmexico-model/src/main/java/fr/reseaumexico/model/writer/XmlNode.java trunk/jmexico-swing-editor/pom.xml trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUI.jaxx trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUIHandler.java trunk/jmexico-swing-editor/src/main/resources/i18n/jmexico-swing-editor_fr_FR.properties Modified: trunk/jmexico-model/src/main/java/fr/reseaumexico/model/parser/ExperimentDesignParser.java =================================================================== --- trunk/jmexico-model/src/main/java/fr/reseaumexico/model/parser/ExperimentDesignParser.java 2011-12-16 15:54:27 UTC (rev 7) +++ trunk/jmexico-model/src/main/java/fr/reseaumexico/model/parser/ExperimentDesignParser.java 2011-12-19 17:40:54 UTC (rev 8) @@ -68,6 +68,7 @@ import static fr.reseaumexico.model.MexicoXmlConstant.EXPERIMENT_DESIGN_LICENCE; import static fr.reseaumexico.model.MexicoXmlConstant.FACTORS; import static fr.reseaumexico.model.MexicoXmlConstant.FACTOR_DESCRIPTION; +import static fr.reseaumexico.model.MexicoXmlConstant.FACTOR_ID; import static fr.reseaumexico.model.MexicoXmlConstant.FEATURE; import static fr.reseaumexico.model.MexicoXmlConstant.FEATURE_NAME; import static fr.reseaumexico.model.MexicoXmlConstant.FEATURE_VALUE; @@ -156,6 +157,10 @@ Factor factor = new FactorImpl(); + // parse id + String id = parser.getAttributeValue(null, FACTOR_ID); + factor.setId(id); + // parse description int eventType = parser.nextTag(); if (eventType == XmlPullParser.START_TAG && Modified: trunk/jmexico-model/src/main/java/fr/reseaumexico/model/writer/XmlNode.java =================================================================== --- trunk/jmexico-model/src/main/java/fr/reseaumexico/model/writer/XmlNode.java 2011-12-16 15:54:27 UTC (rev 7) +++ trunk/jmexico-model/src/main/java/fr/reseaumexico/model/writer/XmlNode.java 2011-12-19 17:40:54 UTC (rev 8) @@ -118,7 +118,11 @@ for (Map.Entry<String,String> entry : entries) { // add to builder param like : name="value" - builder.append(" ").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\""); + builder.append(" ") + .append(entry.getKey()) + .append("=\"") + .append(StringEscapeUtils.escapeXml(entry.getValue())) + .append("\""); } return builder.toString(); } Modified: trunk/jmexico-swing-editor/pom.xml =================================================================== --- trunk/jmexico-swing-editor/pom.xml 2011-12-16 15:54:27 UTC (rev 7) +++ trunk/jmexico-swing-editor/pom.xml 2011-12-19 17:40:54 UTC (rev 8) @@ -61,6 +61,14 @@ <name>JMexico :: Swing Editor</name> <description>JMexico - Swing Editor module</description> + <properties> + <!-- jaxx configuration --> + <jaxx.addProjectClassPath>true</jaxx.addProjectClassPath> + <jaxx.addSourcesToClassPath>true</jaxx.addSourcesToClassPath> + <jaxx.autoImportCss>true</jaxx.autoImportCss> + <jaxx.autoRecurseInCss>false</jaxx.autoRecurseInCss> + </properties> + <!-- ************************************************************* --> <!-- *** Build Settings ****************************************** --> <!-- ************************************************************* --> Added: trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUI.css =================================================================== --- trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUI.css (rev 0) +++ trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUI.css 2011-12-19 17:40:54 UTC (rev 8) @@ -0,0 +1,36 @@ +/* + * #%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% + */ +#menuFile { + text:"jmexico.menu.file"; + mnemonic:F; +} +#menuFileOpen { + text:"jmexico.menu.file.open"; + mnemonic:O; +} +#menuFileSave { + text:"jmexico.menu.file.save"; + mnemonic:S; +} \ No newline at end of file Modified: trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUI.jaxx =================================================================== --- trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUI.jaxx 2011-12-16 15:54:27 UTC (rev 7) +++ trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUI.jaxx 2011-12-19 17:40:54 UTC (rev 8) @@ -24,8 +24,30 @@ --> <JFrame id='mainFrame' decorator='help' width='800' height='800' + layout='{new BorderLayout()}' onWindowClosing='getHandler().closeApplication(this)'> + <import> + java.io.File + fr.reseaumexico.editor.ui.editor.InputDesignEditor + </import> + <MexicoMainUIHandler id="handler" initializer='getContextValue(MexicoMainUIHandler.class)'/> + + <File id="selectedFile" javaBean='null'/> + + <!-- menu --> + <JMenuBar id='menu'> + <JMenu id='menuFile'> + <JMenuItem id='menuFileOpen' + onActionPerformed="getHandler().openFile(this)"/> + + <JMenuItem id='menuFileSave' + enabled='{selectedFile != null}' + onActionPerformed="getHandler().saveFile(this)"/> + + </JMenu> + </JMenuBar> + <InputDesignEditor id='inputDesignEditor' constraints='BorderLayout.CENTER'/> </JFrame> Modified: trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUIHandler.java =================================================================== --- trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUIHandler.java 2011-12-16 15:54:27 UTC (rev 7) +++ trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/MexicoMainUIHandler.java 2011-12-19 17:40:54 UTC (rev 8) @@ -24,9 +24,18 @@ */ package fr.reseaumexico.editor.ui; +import fr.reseaumexico.model.InputDesign; +import fr.reseaumexico.model.parser.InputDesignParser; import jaxx.runtime.context.JAXXInitialContext; import jaxx.runtime.swing.ErrorDialogUI; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import java.io.File; + +import static org.nuiton.i18n.I18n._; + /** * Handler of main UI * @@ -35,6 +44,9 @@ */ public class MexicoMainUIHandler { + /** Logger */ + private static Log log = LogFactory.getLog(MexicoMainUIHandler.class); + public void closeApplication(MexicoMainUI ui) { ui.dispose(); } @@ -55,4 +67,47 @@ return ui; } + + public void openFile(MexicoMainUI ui) { + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle(_("jmexico.file.open.dialog")); + int returnVal = fileChooser.showOpenDialog(ui); + if(returnVal == JFileChooser.APPROVE_OPTION) { + File selectedFile = fileChooser.getSelectedFile(); + InputDesign inputDesign = readInputDesignFile(selectedFile); + + // keep selected file + ui.setSelectedFile(selectedFile); + + // set input design + ui.getInputDesignEditor().setInputDesign(inputDesign); + } + } + + public void saveFile(MexicoMainUI ui) { + // get selected file + File selectedFile = ui.getSelectedFile(); + + // get modified model + + // TODO save it + } + + protected InputDesign readInputDesignFile(File selectedFile) { + InputDesign inputDesignModel = null; + try { + // parse inputDesign + InputDesignParser inputDesignParser = new InputDesignParser(selectedFile); + try { + inputDesignModel = inputDesignParser.getModel(); + } finally { + inputDesignParser.close(); + } + + } catch (Exception eee) { + log.error("Failed to read inputDesign file '" + selectedFile.getName() + "'", eee); + } + + return inputDesignModel; + } } Added: trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditor.jaxx =================================================================== --- trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditor.jaxx (rev 0) +++ trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditor.jaxx 2011-12-19 17:40:54 UTC (rev 8) @@ -0,0 +1,65 @@ +<!-- + #%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> +javax.swing.table.TableModel +javax.swing.table.DefaultTableModel +fr.reseaumexico.model.InputDesign +fr.reseaumexico.editor.ui.model.InputDesignTableModel + </import> + + <InputDesignEditorHandler id='handler'/> + + <InputDesignTableModel id='model' javaBean="new InputDesignTableModel()"/> + + <script> + <![CDATA[ +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> Added: 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 (rev 0) +++ trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/editor/InputDesignEditorHandler.java 2011-12-19 17:40:54 UTC (rev 8) @@ -0,0 +1,95 @@ +/* + * #%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 javax.swing.*; + +import java.util.Collection; +import java.util.Map; + +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")); + + // check that name is never used + Collection<Scenario> scenarios = inputDesign.getScenarios(); + + 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().getFactors(); + Map<Factor, Object> factorValues = Maps.newHashMap(); + for (Factor factor : factors) { + factorValues.put(factor, null); + } + scenarioToAdd.setFactorValues(factorValues); + + inputDesign.addScenarios(scenarioToAdd); + } + + public void removeScenario(InputDesignEditor editor) { + + } +} Added: 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 (rev 0) +++ trunk/jmexico-swing-editor/src/main/java/fr/reseaumexico/editor/ui/model/InputDesignTableModel.java 2011-12-19 17:40:54 UTC (rev 8) @@ -0,0 +1,204 @@ +/* + * #%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.model; + +import fr.reseaumexico.model.Factor; +import fr.reseaumexico.model.InputDesign; +import fr.reseaumexico.model.Scenario; + +import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.nuiton.i18n.I18n._; + +/** + * @author sletellier <letellier@codelutin.com> + */ +public class InputDesignTableModel extends AbstractTableModel { + + protected TableModel delegate; + protected InputDesign inputDesign; + + public InputDesignTableModel() { + delegate = new DefaultTableModel(); + } + + public void setInputDesign(InputDesign inputDesign) { + this.inputDesign = inputDesign; + inputDesign.addPropertyChangeListener(InputDesign.PROPERTY_SCENARIOS, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent propertyChangeEvent) { + Object newValue = propertyChangeEvent.getNewValue(); + if (newValue == null) { + // was removed + scenarioRemoved(); + } + + Object oldValue = propertyChangeEvent.getOldValue(); + if (oldValue == null) { + // was added + scenarioAdded(); + } + } + }); + + fireTableStructureChanged(); + } + + protected void scenarioAdded() { + fireTableStructureChanged(); + } + + protected void scenarioRemoved() { + fireTableStructureChanged(); + } + + public InputDesign getInputDesign() { + return inputDesign; + } + + public Collection<Scenario> getScenarios() { + return inputDesign.getScenarios(); + } + + public Scenario getScenario(int i) { + return inputDesign.getScenarios(i); + } + + @Override + public int getRowCount() { + if (inputDesign == null) { + return delegate.getRowCount(); + } + Map<Factor, Object> factorValues = getScenario(0).getFactorValues(); + return factorValues == null ? 0 : factorValues.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 String.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); + } + + boolean isFirstColumn = columnIndex == 0; + if (!isFirstColumn) { + columnIndex = columnIndex - 1; + } + Scenario scenario = getScenario(columnIndex); + if (scenario == null) { + return null; + } + 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); + if (isFirstColumn) { + return factor.getId(); + } + return factorValues.get(factor); + } + + @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); + 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); + + // TODO sletellier 20111219 : open specific editor + + factorValues.put(factor, o); + scenario.setFactorValues(factorValues); + + fireTableCellUpdated(rowIndex, columnIndex); + } +} Added: 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 (rev 0) +++ trunk/jmexico-swing-editor/src/main/resources/i18n/jmexico-swing-editor_en_GB.properties 2011-12-19 17:40:54 UTC (rev 8) @@ -0,0 +1,10 @@ +jmexico.add.scenario=Ajout d'un scenario +jmexico.error.scenario.name.used=Error \: scenario name '%1$s' is already used. +jmexico.error.title=Error +jmexico.factor.name=Factor +jmexico.file.open.dialog=Open an InputDesign file. +jmexico.menu.file=File +jmexico.menu.file.open=Open +jmexico.menu.file.save=Save +jmexico.remove.scenario=Suppression d'un scenario +jmexico.scenario.inputName=Name of scenario to add \: 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-16 15:54:27 UTC (rev 7) +++ trunk/jmexico-swing-editor/src/main/resources/i18n/jmexico-swing-editor_fr_FR.properties 2011-12-19 17:40:54 UTC (rev 8) @@ -0,0 +1,10 @@ +jmexico.add.scenario=Ajout d'un scenario +jmexico.error.scenario.name.used=Erreur \: le scenario '%1$s' est déjà utilisé. +jmexico.error.title=Erreur +jmexico.factor.name=Facteur +jmexico.file.open.dialog=Ouvrir un fichier InputDesign +jmexico.menu.file=Fichier +jmexico.menu.file.open=Ouvrir +jmexico.menu.file.save=Sauvegarder +jmexico.remove.scenario=Suppression d'un scenario +jmexico.scenario.inputName=Nom du scénario à ajouter \: \ No newline at end of file
participants (1)
-
sletellier@users.forge.codelutin.com