r3207 - in isis-fish/branches/3.3.1/src: main/java/fr/ifremer/isisfish/ui/input main/java/fr/ifremer/isisfish/ui/sensitivity main/java/fr/ifremer/isisfish/ui/sensitivity/model main/java/fr/ifremer/isisfish/ui/simulator test/java/fr/ifremer/isisfish/ui/sensitivity
Author: chatellier Date: 2011-03-25 17:13:30 +0000 (Fri, 25 Mar 2011) New Revision: 3207 Log: Modification du mecanisme de mise en facteur (bas?\195?\169 sur les path de ce qu'il y a a mettre en facteur eu lieu du composant d'origine) pour pouvoir modifier un facteur apres rechargement sans son composant d'origine. Removed: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelper.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityAction.java isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelperTest.java Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorWizardUI.jaxx isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityUI.jaxx isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/TableBlockingLayerUI.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTreeCellRenderer.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx 2011-03-25 17:07:54 UTC (rev 3206) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx 2011-03-25 17:13:30 UTC (rev 3207) @@ -24,6 +24,8 @@ --> <JPanel layout='{new BorderLayout()}' genericType='B extends TopiaEntityContextable' abstract="true"> + <InputHandler id="handler" /> + <!-- UI state when editing. If no entity selected, active = false --> <Boolean id='active' javaBean='false'/> @@ -48,7 +50,7 @@ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { - accept(e); + getHandler().accept(InputContentUI.this, e); } }}' /> @@ -60,7 +62,6 @@ fr.ifremer.isisfish.entities.FisheryRegion; fr.ifremer.isisfish.ui.sensitivity.SensitivityUtils; fr.ifremer.isisfish.ui.sensitivity.FactorWizardUI; - fr.ifremer.isisfish.ui.sensitivity.EditorHelper; fr.ifremer.isisfish.ui.sensitivity.SensitivityTabbedPaneListener; fr.ifremer.isisfish.ui.WelcomePanelUI; org.nuiton.topia.persistence.TopiaEntityContextable; @@ -152,14 +153,12 @@ * Method appelée par l'arbre de navigation et le gestionnaire * de changement d'onglet pour ajouter les layers sur une interface * 'input' seulement dans le cas de la sensibilité. - * - * @param active if {@code true} set layer, otherwize do nothing */ public void setLayer(boolean active) { - if (this.get$objectMap() != null && active) { + if (get$objectMap() != null) { for (JComponent boxed : SwingUtil.getLayeredComponents(this)) { // Verifie si dans l'entré existe dans le fichier sensitivity.properties - Class sensitivityBeanClass = (Class)boxed.getClientProperty("sensitivityBean"); + Class<?> sensitivityBeanClass = (Class<?>)boxed.getClientProperty("sensitivityBean"); String method = (String)boxed.getClientProperty("sensitivityMethod"); // test if factor is enabled @@ -177,18 +176,14 @@ // install correct layer depending if factor enable if (isSensitivityFactorEnabled) { - jaxx.runtime.swing.BlockingLayerUI2 ui = layerUI2.clone(); + jaxx.runtime.swing.BlockingLayerUI2 ui = getLayerUI2().clone(); SwingUtil.getLayer(boxed).setUI(ui); } else { if (boxed instanceof JTable) { - //fr.ifremer.isisfish.ui.sensitivity.TableBlockingLayerUI layerui = - // new fr.ifremer.isisfish.ui.sensitivity.TableBlockingLayerUI(); - //layerui.parent = this; - //layerui.verifier = getVerifier(); - SwingUtil.getLayer(boxed).setUI(tableLayerUI); + SwingUtil.getLayer(boxed).setUI(getTableLayerUI()); } else { - jaxx.runtime.swing.BlockingLayerUI ui = layerUI.clone(); + jaxx.runtime.swing.BlockingLayerUI ui = getLayerUI().clone(); ui.setBlock(true); ui.setUseIcon(isActive()); SwingUtil.getLayer(boxed).setUI(ui); @@ -199,89 +194,6 @@ } /** - * Action appelée lors du clic sur un layer. - * - * @param e l'event initial intersepté par le layer - */ -protected void accept(ActionEvent e) { - if (log.isDebugEnabled()) { - log.debug("Event intercepted on " + e); - } - - JComponent source = (JComponent) e.getSource(); - Class<? extends TopiaEntityContextable> sensitivityBeanClass = (Class<? extends TopiaEntityContextable>)source.getClientProperty("sensitivityBean"); - String sensitivityBeanID = (String)source.getClientProperty("sensitivityBeanID"); - /*TopiaEntity bean = null; - if (sensitivityBeanID == null) { - bean = getVerifier().getEntity(sensitivityBeanClass); - } - else { - bean = getVerifier().getEntity(sensitivityBeanClass, sensitivityBeanID); - } - if (bean != null) { - FactorWizardUI wizard = new FactorWizardUI(this); - boolean continuePossible = EditorHelper.canBeContinue(source, bean); - wizard.initNew(source, bean, continuePossible); - wizard.pack(); - wizard.setVisible(true); - }*/ - - String sensitivityMethod = (String)source.getClientProperty("sensitivityMethod"); - displayFactorWizard(source, sensitivityBeanClass, sensitivityBeanID, sensitivityMethod); -} - -/** - * Display factor wizard for bean/property in registred in verifier. - */ -public void displayFactorWizard(JComponent source, Class<? extends TopiaEntityContextable> sensitivityBeanClass, String sensitivityBeanID, String sensitivityMethod) { - - if (log.isDebugEnabled()) { - log.debug("Event intercepted " + source); - log.debug(" client property (bean) : " + sensitivityBeanClass); - log.debug(" client property (beanID) : " + sensitivityBeanID); - log.debug(" client property (method) : " + sensitivityMethod); - } - - TopiaEntityContextable bean = null; - if (sensitivityBeanID == null) { - bean = getVerifier().getEntity(sensitivityBeanClass); - } - else { - bean = getVerifier().getEntity(sensitivityBeanClass, sensitivityBeanID); - } - - if (bean != null) { - - JComponent editor = source; - - // This is a special case for table source component - // If current entity is displayed by a JTable component - // we need to find a better component than - // can display 'property' on 'bean' - if (editor instanceof JTable) { - editor = EditorHelper.getEditorForValue(bean, sensitivityMethod); - } - - if (editor != null) { - FactorWizardUI wizard = new FactorWizardUI(this); - boolean continuePossible = EditorHelper.canBeContinue(source, bean); - wizard.initNew(source, bean, continuePossible); - wizard.pack(); - wizard.setLocationRelativeTo(this); - wizard.setVisible(true); - } - else if (log.isWarnEnabled()) { - log.warn("Can't find editor for " + sensitivityBeanClass.getSimpleName() + "#" + sensitivityMethod); - } - } - else { - if (log.isErrorEnabled()) { - log.error("Can't find bean in current verifier (sensitivityBeanClass = " + sensitivityBeanClass + ", sensitivityBeanID = " + sensitivityBeanID + ")"); - } - } -} - -/** * Install tabbed pane change listener depending on sensitivity. * (init at first call) * Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java 2011-03-25 17:07:54 UTC (rev 3206) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java 2011-03-25 17:13:30 UTC (rev 3207) @@ -26,6 +26,7 @@ import static org.nuiton.i18n.I18n._; import java.awt.BorderLayout; +import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.io.File; import java.io.IOException; @@ -34,6 +35,7 @@ import java.util.List; import java.util.Map; +import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTextArea; @@ -44,7 +46,6 @@ import javax.swing.tree.TreePath; import jaxx.runtime.JAXXContext; -import jaxx.runtime.JAXXUtil; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -80,6 +81,8 @@ import fr.ifremer.isisfish.ui.input.tree.FisheryTreeHelper; import fr.ifremer.isisfish.ui.input.tree.FisheryTreeNode; import fr.ifremer.isisfish.ui.input.tree.FisheryTreeRenderer; +import fr.ifremer.isisfish.ui.sensitivity.FactorWizardUI; +import fr.ifremer.isisfish.ui.sensitivity.SensitivityInputHandler; import fr.ifremer.isisfish.ui.simulator.filter.SimulationFilterUtil; import fr.ifremer.isisfish.vcs.VCSException; @@ -138,6 +141,9 @@ throw new IsisFishRuntimeException("Can't load region", ex); } + // TODO echatellier 20110323 voir pour remplacer le binding + inputUI.setRegionLoaded(fisheryRegion != null); + if (fisheryRegion == null) { // show empty region ui inputUI.getCardlayoutPrincipal().show(inputUI.getInputPanePrincipal(),"none"); @@ -642,4 +648,79 @@ FisheryTreeNode newSelectNode = fisheryTreeHelper.findNode((FisheryTreeNode)fisheryTreeModel.getRoot(), topiaId); fisheryTreeHelper.refreshNode(newSelectNode, false); } + + /** + * Action appelée lors du clic sur un layer (sensitivity). + * + * @param inputContentUI inputContentUI + * @param e l'event initial intersepté par le layer + */ + public void accept(InputContentUI<?> inputContentUI, ActionEvent e) { + + // get clicked component info + JComponent source = (JComponent) e.getSource(); + Class<? extends TopiaEntityContextable> sensitivityBeanClass = + (Class<? extends TopiaEntityContextable>)source.getClientProperty("sensitivityBean"); + String sensitivityBeanID = (String)source.getClientProperty("sensitivityBeanID"); + String sensitivityMethod = (String)source.getClientProperty("sensitivityMethod"); + + if (log.isDebugEnabled()) { + log.debug("Event intercepted " + source); + log.debug(" client property (bean) : " + sensitivityBeanClass); + log.debug(" client property (beanID) : " + sensitivityBeanID); + log.debug(" client property (method) : " + sensitivityMethod); + } + + displayFactorWizard(inputContentUI, sensitivityBeanClass, sensitivityBeanID, sensitivityMethod); + } + + public void displayFactorWizard(InputContentUI<?> inputContentUI, Class<? extends TopiaEntityContextable> sensitivityBeanClass, + String sensitivityBeanID, String sensitivityMethod) { + + // get bean for component class info + TopiaEntityContextable bean = null; + if (sensitivityBeanID == null) { + bean = inputContentUI.getVerifier().getEntity(sensitivityBeanClass); + } + else { + bean = inputContentUI.getVerifier().getEntity(sensitivityBeanClass, sensitivityBeanID); + } + + if (bean != null) { + + //JComponent editor = source; + + // This is a special case for table source component + // If current entity is displayed by a JTable component + // we need to find a better component than + // can display 'property' on 'bean' + /*if (editor instanceof JTable) { + editor = EditorHelper.getEditorForValue(bean, sensitivityMethod); + }*/ + + //if (editor != null) { + FactorWizardUI factorWizardUI = new FactorWizardUI(inputContentUI); + SensitivityInputHandler handler = factorWizardUI.getHandler(); + handler.initNewFactor(factorWizardUI, bean, sensitivityMethod); + factorWizardUI.pack(); + factorWizardUI.setLocationRelativeTo(inputContentUI); + factorWizardUI.setVisible(true); + + //Object value = EditorHelper.getMethodValue(bean, fieldName); + //boolean continuePossible = EditorHelper.canBeContinue(/*source, */value); + //wizard.initNew(/*source, */bean, continuePossible); + //wizard.pack(); + //wizard.setLocationRelativeTo(inputContentUI); + //wizard.setVisible(true); + /*} + else if (log.isWarnEnabled()) { + log.warn("Can't find editor for " + sensitivityBeanClass.getSimpleName() + "#" + sensitivityMethod); + }*/ + } + else { + if (log.isErrorEnabled()) { + log.error("Can't find bean in current verifier (sensitivityBeanClass = " + sensitivityBeanClass + ", sensitivityBeanID = " + sensitivityBeanID + ")"); + } + } + } } Deleted: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelper.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelper.java 2011-03-25 17:07:54 UTC (rev 3206) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelper.java 2011-03-25 17:13:30 UTC (rev 3207) @@ -1,913 +0,0 @@ -/* - * #%L - * IsisFish - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2011 Ifremer, CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 2 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 Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-2.0.html>. - * #L% - */ - -package fr.ifremer.isisfish.ui.sensitivity; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JList; -import javax.swing.JRadioButton; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.text.JTextComponent; - -import jaxx.runtime.context.JAXXInitialContext; -import jaxx.runtime.swing.editor.NumberEditor; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.math.matrix.MatrixND; -import org.nuiton.math.matrix.gui.MatrixEditor; -import org.nuiton.math.matrix.gui.MatrixPanelEditor; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaEntityContextable; - -import fr.ifremer.isisfish.entities.Equation; -import fr.ifremer.isisfish.entities.Selectivity; -import fr.ifremer.isisfish.entities.TargetSpecies; -import fr.ifremer.isisfish.rule.Rule; -import fr.ifremer.isisfish.simulator.sensitivity.Factor; -import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; -import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain; -import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain; -import fr.ifremer.isisfish.types.Month; -import fr.ifremer.isisfish.types.RangeOfValues; -import fr.ifremer.isisfish.ui.input.InputAction; -import fr.ifremer.isisfish.ui.input.InputOneEquationUI; -import fr.ifremer.isisfish.ui.input.InputSaveVerifier; -import fr.ifremer.isisfish.ui.input.MetierSeasonInfoSpeciesEditorUI; -import fr.ifremer.isisfish.ui.input.PopulationMigrationEmigrationUI; -import fr.ifremer.isisfish.ui.input.PopulationMigrationImmigrationUI; -import fr.ifremer.isisfish.ui.input.PopulationMigrationMigrationUI; -import fr.ifremer.isisfish.ui.input.PopulationZonesEditorUI; -import fr.ifremer.isisfish.ui.input.RangeOfValuesUI; -import fr.ifremer.isisfish.ui.input.SelectivityEditorUI; -import fr.ifremer.isisfish.ui.input.SpeciesStructuredUI; -import fr.ifremer.isisfish.ui.simulator.RuleChooser; -import fr.ifremer.isisfish.ui.widget.IntervalPanel; - -/** - * Helper for sensitivity Swing component manipulation. - * - * @author letellier - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class EditorHelper { - - /** Class logger. */ - private static Log log = LogFactory.getLog(EditorHelper.class); - - /** - * Get "method" property value for wing component. - * - * @param component component - * @return property value - */ - public static String getMethod(JComponent component) { - String method = (String)component.getClientProperty("sensitivityMethod"); - return method; - } - - /** - * Get copy of component with original entity value as default value. - * - * @param component component - * @param entity entity - * @return component copy - */ - public static JComponent getEditor(JComponent component, TopiaEntityContextable entity) { - JComponent result = null; - try { - String fieldName = getMethod(component); - result = component.getClass().newInstance(); - - if (result instanceof JTextField) { - ((JTextComponent) result).setText(String.valueOf(getMethodValue(entity, fieldName))); - - } else if (result instanceof NumberEditor) { - NumberEditor ui = (NumberEditor) component; - JTextField numEditor = new JTextField(); - numEditor.setText(String.valueOf(ui.getModel())); - result = numEditor; - - } else if (result instanceof MatrixEditor) { - MatrixEditor ui = (MatrixEditor) component; - - MatrixND m = null; - // cas des paramtres de simulation (population de depart) - if (entity == null) { - m = (MatrixND) ui.getMatrix(); - } - // autre cas, attribut d'un bean - else { - m = (MatrixND) getMethodValue(entity, fieldName); - } - MatrixPanelEditor matrix = new MatrixPanelEditor(false); - if (m != null) { - matrix.setMatrix(m.clone()); - } - matrix.setLinearModel(ui.isLinearModel()); - matrix.setLinearModelShowDefault(ui.isLinearModelShowDefault()); - result = matrix; - - } else if (result instanceof JTable) { - ((JTable) result).setModel(((JTable) component).getModel()); - - } else if (result instanceof JComboBox) { - JComboBox combo = (JComboBox) component; - JComboBox comboResult = new JComboBox(); - comboResult.setModel(combo.getModel()); - comboResult.setSelectedIndex(combo.getSelectedIndex()); - result = comboResult; - - } else if (result instanceof JList) { - JList list = (JList) component; - JList listResult = new JList(); - listResult.setModel(list.getModel()); - listResult.setSelectedIndices(list.getSelectedIndices()); - result = listResult; - } else if (result instanceof JCheckBox) { - ((JCheckBox) result).setSelected((Boolean) getMethodValue(entity, - fieldName)); - JCheckBox cOrigin = (JCheckBox) component; - ((JCheckBox) result).setText(cOrigin.getText()); - } else if (result instanceof JRadioButton) { - ((JRadioButton) result).setSelected((Boolean) getMethodValue(entity, - fieldName)); - JRadioButton cOrigin = (JRadioButton) component; - ((JRadioButton) result).setText(cOrigin.getText()); - } else if (result instanceof SpeciesStructuredUI) { - SpeciesStructuredUI ui = new SpeciesStructuredUI(); - ui.setActif(true); - result = ui; - } else if (result instanceof InputOneEquationUI) { - InputOneEquationUI origine = (InputOneEquationUI) component; - InputOneEquationUI ui = new InputOneEquationUI( - new JAXXInitialContext().add(new InputAction())); - ui.setSelectedEquation(origine.getSelectedEquation()); - ui.setText(origine.getText()); - ui.setFormuleCategory(origine.getFormuleCategory()); - ui.setClazz(origine.getClazz()); - //ui.setMethodGet(origine.getMethodGet()); - //ui.setMethodSet(origine.getMethodSet()); - ui.setBeanProperty(origine.getBeanProperty()); - ui.setBean(entity); - ui.setActive(true); - ui.refresh(); - result = ui; - } else if (result instanceof IntervalPanel) { - IntervalPanel ipResult = new IntervalPanel(); - IntervalPanel ip = (IntervalPanel) component; - ipResult.setLabelRenderer(Month.MONTH); - ipResult.setModel(ip.getModel().clone()); - result = ipResult; - } else if (result instanceof RangeOfValuesUI) { - result = new JTextField(""); - } else if (result instanceof SelectivityEditorUI) { - SelectivityEditorUI origine = (SelectivityEditorUI) component; - SelectivityEditorUI ui = new SelectivityEditorUI( - new JAXXInitialContext().add(new InputAction()).add( - origine.getRegion()).add( - new InputSaveVerifier())); - ui.setBean(origine.getBean()); - ui.setActive(true); - ui.refresh(); - ui.setActive(true); - result = ui; - } else if (result instanceof MetierSeasonInfoSpeciesEditorUI) { - MetierSeasonInfoSpeciesEditorUI origine = (MetierSeasonInfoSpeciesEditorUI) component; - MetierSeasonInfoSpeciesEditorUI ui = new MetierSeasonInfoSpeciesEditorUI( - new JAXXInitialContext().add(new InputAction()).add( - origine.getRegion()).add( - new InputSaveVerifier())); - ui.setBean(origine.getBean()); - if (origine.getMetierSeasonInfo() != null) { - ui.setMetierSeasonInfo(origine.getMetierSeasonInfo()); - ui.setMetierSeasonSelected(true); - ui.setActive(true); - } - ui.refresh(); - result = ui; - } else if (result instanceof PopulationZonesEditorUI) { - PopulationZonesEditorUI origine = (PopulationZonesEditorUI) component; - PopulationZonesEditorUI ui = new PopulationZonesEditorUI(new JAXXInitialContext().add(new InputAction()).add(origine.getRegion())); - ui.setBean(origine.getBean()); - ui.setActive(true); - ui.refresh(); - result = ui; - } else if (result instanceof PopulationMigrationMigrationUI) { - PopulationMigrationMigrationUI origine = (PopulationMigrationMigrationUI) component; - PopulationMigrationMigrationUI ui = new PopulationMigrationMigrationUI( - new JAXXInitialContext().add(new InputAction())); - ui.setBean(origine.getBean()); - ui.setPopInfo(origine.getPopInfo()); - ui.setActive(true); - ui.refreshPanel(); - result = ui; - } else if (result instanceof PopulationMigrationEmigrationUI) { - PopulationMigrationEmigrationUI origine = (PopulationMigrationEmigrationUI) component; - PopulationMigrationEmigrationUI ui = new PopulationMigrationEmigrationUI(new JAXXInitialContext().add(new InputAction())); - ui.setBean(origine.getBean()); - ui.setPopInfo(origine.getPopInfo()); - ui.setActive(true); - ui.refreshPanel(); - result = ui; - } else if (result instanceof PopulationMigrationImmigrationUI) { - PopulationMigrationImmigrationUI origine = (PopulationMigrationImmigrationUI) component; - PopulationMigrationImmigrationUI ui = new PopulationMigrationImmigrationUI(new JAXXInitialContext().add(new InputAction())); - ui.setBean(origine.getBean()); - ui.setPopInfo(origine.getPopInfo()); - ui.setActive(true); - ui.refreshPanel(); - result = ui; - } - } catch (IllegalAccessException ex) { - if (log.isErrorEnabled()) { - log.error("Can't make new instance of " + component, ex); - } - } catch (InstantiationException ex) { - if (log.isErrorEnabled()) { - log.error("Can't make new instance of " + component, ex); - } - } - return result; - } - - /** - * Get copy of component with original entity value as default value. - * - * @param component component - * @param entity entity - * @return component copy - */ - public static ContinuousPanelContainerUI getContinuousPanel(JComponent component, TopiaEntityContextable entity) { - ContinuousPanelContainerUI result = null; - String fieldName = getMethod(component); - DefaultContinuousPanelUI continuousPanel = null; - if (component instanceof InputOneEquationUI) { - InputOneEquationUI origine = (InputOneEquationUI) component; - EquationContinuousPanelUI ui = new EquationContinuousPanelUI( - new JAXXInitialContext().add(new InputAction())); - ui.setSelectedEquation(origine.getSelectedEquation()); - ui.setText(origine.getText()); - ui.setFormuleCategory(origine.getFormuleCategory()); - ui.setClazz(origine.getClazz()); - //ui.setMethodGet(origine.getMethodGet()); - //ui.setMethodSet(origine.getMethodSet()); - ui.setBeanProperty(origine.getBeanProperty()); - ui.setBean(entity); - result = ui; - } else if (component instanceof MatrixEditor) { - MatrixContinuousPanelUI matrixPanel = new MatrixContinuousPanelUI(); - MatrixND m = (MatrixND) getMethodValue(entity, fieldName); - if (m != null) { - matrixPanel.setMatrix(m.clone()); - } - result = matrixPanel; - } else { - continuousPanel = new DefaultContinuousPanelUI(); - result = continuousPanel; - } - if (continuousPanel != null) { - continuousPanel.init(getNewBoundEditor(component, entity), getNewBoundEditor(component, entity)); - } - return result; - } - - /** - * Get new text component with current entity default value. - * - * @param component component - * @param entity entity - * @return bound editor - */ - protected static JTextField getNewBoundEditor(JComponent component, TopiaEntity entity) { - String fieldName = getMethod(component); - Object value = getMethodValue(entity, fieldName); - if (component instanceof JTextComponent) { - return new JTextField(String.valueOf(value)); - } - return new JTextField(); - } - - /** - * Get continuous editor for component with given value. - * - * @param component component - * @param domain domain - * @param factor factor - * @return component copy - */ - public static ContinuousPanelContainerUI getContinuousPanelWithValue( - JComponent component, ContinuousDomain domain, Factor factor) { - ContinuousPanelContainerUI result = null; - - DefaultContinuousPanelUI continuousPanel = null; - if (component instanceof InputOneEquationUI) { - InputOneEquationUI origine = (InputOneEquationUI) component; - EquationContinuousPanelUI ui = new EquationContinuousPanelUI( - new JAXXInitialContext().add(new InputAction())); - ui.setText(origine.getText()); - ui.setFormuleCategory(origine.getFormuleCategory()); - ui.getEditor().getEditor().setText((String) factor.getValue()); - ui.setClazz(origine.getClazz()); - //ui.setMethodGet(origine.getMethodGet()); - //ui.setMethodSet(origine.getMethodSet()); - ui.setBeanProperty(origine.getBeanProperty()); - ui.setBean(origine.getBean()); - - EquationContinuousDomain equationDomain = (EquationContinuousDomain) domain; - ui.addDomain(equationDomain); - ui.setTable(); - - result = ui; - } else if (component instanceof MatrixEditor) { - MatrixContinuousPanelUI panel = new MatrixContinuousPanelUI(); - MatrixContinuousDomain matrixDomain = (MatrixContinuousDomain) domain; - MatrixND m = matrixDomain.getMatrix(); - if (m != null) { - panel.setMatrix(m.clone()); - } - panel.getOperator().setSelectedItem(matrixDomain.getOperator()); - panel.getCoef().setText( - String.valueOf(matrixDomain.getCoefficient() * 100)); - result = panel; - } else { - continuousPanel = new DefaultContinuousPanelUI(); - result = continuousPanel; - } - if (continuousPanel != null) { - continuousPanel.init(new JTextField(String.valueOf(domain - .getMinBound())), new JTextField(String.valueOf(domain - .getMaxBound()))); - } - - return result; - } - - /** - * Get new instance of component filled with original swing component value. - * - * @param component component - * @return new component instance - */ - public static JComponent getEditorWithValue(JComponent component) { - Object value = getValue(component); - return getEditorWithValue(component, value); - } - - /** - * Get new instance of component filled with specified value depending - * of component type. - * - * @param component component - * @param value value - * @return new component instance - */ - public static JComponent getEditorWithValue(JComponent component, Object value) { - JComponent result = null; - - if (log.isDebugEnabled()) { - log.debug("Get editor for " + component + " with value = " + value); - } - - try { - result = component.getClass().newInstance(); - - if (result instanceof JTextComponent) { - ((JTextComponent) result).setText(String.valueOf(value)); - } else if (result instanceof NumberEditor) { - JTextField numEditor = new JTextField(); - numEditor.setText(String.valueOf(value)); - result = numEditor; - } else if (result instanceof RangeOfValuesUI) { - result = new JTextField(value.toString()); - } else if (result instanceof MatrixEditor) { - MatrixEditor ui = (MatrixEditor) component; - MatrixND m = (MatrixND) value; - MatrixPanelEditor matrix = new MatrixPanelEditor(false); - if (m != null) { - matrix.setMatrix(m.clone()); - } - matrix.setLinearModel(ui.isLinearModel()); - matrix.setLinearModelShowDefault(ui.isLinearModelShowDefault()); - result = matrix; - } else if (result instanceof JComboBox) { - JComboBox combo = (JComboBox) component; - JComboBox comboResult = new JComboBox(); - comboResult.setModel(combo.getModel()); - comboResult.setSelectedItem(value); - result = comboResult; - } else if (result instanceof JList) { - JList list = (JList) component; - JList listResult = new JList(); - listResult.setModel(list.getModel()); - //listResult.setSelectedValues((Object[]) value); - listResult.setSelectedIndices(list.getSelectedIndices()); - result = listResult; - } else if (result instanceof JCheckBox) { - ((JCheckBox) result).setSelected((Boolean) value); - JCheckBox ch = (JCheckBox) component; - ((JCheckBox) result).setText(ch.getText()); - - } else if (result instanceof JRadioButton) { - ((JRadioButton) result).setSelected((Boolean) value); - JRadioButton cOrigin = (JRadioButton) component; - ((JRadioButton) result).setText(cOrigin.getText()); - } else if (result instanceof SpeciesStructuredUI) { - //SpeciesStructuredUI origine = (SpeciesStructuredUI) component; - SpeciesStructuredUI ui = new SpeciesStructuredUI(); - ui.getFieldSpeciesDynamicAge().setSelected((Boolean) value); - ui.setActif(true); - result = ui; - } else if (result instanceof InputOneEquationUI) { - InputOneEquationUI origine = (InputOneEquationUI) component; - InputOneEquationUI ui = new InputOneEquationUI(new JAXXInitialContext().add(new InputAction())); - ui.getEditor().setText((String) value); - ui.setText(origine.getText()); - ui.setFormuleCategory(origine.getFormuleCategory()); - ui.setClazz(origine.getClazz()); - /// ??? was not set before - ui.setBeanProperty(origine.getBeanProperty()); - ui.setFormule(origine.getFormule()); - ui.setActive(true); - ui.refresh(); - result = ui; - } else if (result instanceof IntervalPanel) { - IntervalPanel ipResult = new IntervalPanel(); - IntervalPanel ip = (IntervalPanel) component; - ipResult.setLabelRenderer(Month.MONTH); - ipResult.setModel(ip.getModel().clone()); - result = ipResult; - } else if (result instanceof SelectivityEditorUI) { - SelectivityEditorUI origine = (SelectivityEditorUI) component; - SelectivityEditorUI ui = new SelectivityEditorUI( - new JAXXInitialContext().add(new InputAction()).add( - origine.getRegion()).add(new InputSaveVerifier())); - ui.setBean(origine.getBean()); - ui.getBean().setPopulationSelectivity((Collection<Selectivity>) value); - ui.setActive(true); - ui.refresh(); - ui.setActive(true); - result = ui; - } else if (result instanceof MetierSeasonInfoSpeciesEditorUI) { - MetierSeasonInfoSpeciesEditorUI origine = (MetierSeasonInfoSpeciesEditorUI) component; - MetierSeasonInfoSpeciesEditorUI ui = new MetierSeasonInfoSpeciesEditorUI( - new JAXXInitialContext().add(new InputAction()).add( - origine.getRegion()).add( - new InputSaveVerifier())); - ui.setBean(origine.getBean()); - if (origine.getMetierSeasonInfo() != null) { - ui.setMetierSeasonInfo(origine.getMetierSeasonInfo()); - ui.getMetierSeasonInfo().setSpeciesTargetSpecies((Collection<TargetSpecies>) value); - ui.setMetierSeasonSelected(true); - ui.setActive(true); - } - ui.refresh(); - result = ui; - } else if (result instanceof PopulationZonesEditorUI) { - PopulationZonesEditorUI origine = (PopulationZonesEditorUI) component; - PopulationZonesEditorUI ui = new PopulationZonesEditorUI( - new JAXXInitialContext().add(new InputAction()).add(origine.getRegion())); - ui.setBean(origine.getBean()); - MatrixND m = (MatrixND) value; - ui.getFieldPopulationMappingZoneReproZoneRecru().setMatrix(m == null ? null : m.clone()); - ui.setActive(true); - ui.refresh(); - result = ui; - } else if (result instanceof PopulationMigrationMigrationUI) { - PopulationMigrationMigrationUI origine = (PopulationMigrationMigrationUI) component; - PopulationMigrationMigrationUI ui = new PopulationMigrationMigrationUI( - new JAXXInitialContext().add(new InputAction())); - ui.setBean(origine.getBean()); - ui.setPopInfo(origine.getPopInfo()); - MatrixND m = (MatrixND) value; - ui.getPopInfo().setMigrationMatrix(m == null ? null : m.clone()); - ui.setActive(true); - ui.refreshPanel(); - result = ui; - } else if (result instanceof PopulationMigrationEmigrationUI) { - PopulationMigrationEmigrationUI origine = (PopulationMigrationEmigrationUI) component; - PopulationMigrationEmigrationUI ui = new PopulationMigrationEmigrationUI( - new JAXXInitialContext().add(new InputAction())); - ui.setBean(origine.getBean()); - ui.setPopInfo(origine.getPopInfo()); - MatrixND m = (MatrixND) value; - ui.getPopInfo().setEmigrationMatrix(m == null ? null : m.clone()); - ui.setActive(true); - ui.refreshPanel(); - result = ui; - } else if (result instanceof PopulationMigrationImmigrationUI) { - PopulationMigrationImmigrationUI origine = (PopulationMigrationImmigrationUI) component; - PopulationMigrationImmigrationUI ui = new PopulationMigrationImmigrationUI( - new JAXXInitialContext().add(new InputAction())); - ui.setBean(origine.getBean()); - ui.setPopInfo(origine.getPopInfo()); - MatrixND m = (MatrixND) value; - ui.getPopInfo().setImmigrationMatrix(m == null ? null : m.clone()); - ui.setActive(true); - ui.refreshPanel(); - result = ui; - } else if (result instanceof RuleChooser) { - RuleChooser ui = new RuleChooser(); - ui.setRulesList((List<Rule>)value); - result = ui; - } - } catch (IllegalAccessException ex) { - if (log.isErrorEnabled()) { - log.error("Can't make new instance of " + component, ex); - } - } catch (InstantiationException ex) { - if (log.isErrorEnabled()) { - log.error("Can't make new instance of " + component, ex); - } - } - return result; - } - - /** - * Return value in swing component that could be next used into factor. - * - * @param component component - * @return factor value - */ - public static Object getValue(JComponent component) { - Object result = null; - if (component instanceof JTextComponent) { - result = ((JTextComponent) component).getText(); - } else if (component instanceof NumberEditor) { - result = ((NumberEditor) component).getModel(); - } else if (component instanceof PopulationZonesEditorUI) { - result = ((PopulationZonesEditorUI) component) - .getFieldPopulationMappingZoneReproZoneRecru().getMatrix(); - } else if (component instanceof MatrixPanelEditor) { - result = ((MatrixPanelEditor) component).getMatrix(); - - } else if (component instanceof JComboBox) { - result = ((JComboBox) component).getSelectedItem(); - - } else if (component instanceof JList) { - result = ((JList) component).getSelectedValues(); - - } else if (component instanceof JCheckBox) { - result = ((JCheckBox) component).isSelected(); - - } else if (component instanceof JRadioButton) { - result = ((JRadioButton) component).isSelected(); - - } else if (component instanceof InputOneEquationUI) { - result = ((InputOneEquationUI) component).getEditor().getText(); - - } else if (component instanceof SpeciesStructuredUI) { - result = ((SpeciesStructuredUI) component) - .getFieldSpeciesDynamicAge().isSelected(); - - } else if (component instanceof SelectivityEditorUI) { - result = ((SelectivityEditorUI) component).getBean() - .getPopulationSelectivity(); - - } else if (component instanceof MetierSeasonInfoSpeciesEditorUI) { - result = ((MetierSeasonInfoSpeciesEditorUI) component) - .getMetierSeasonInfo().getSpeciesTargetSpecies(); - - } else if (component instanceof PopulationZonesEditorUI) { - result = ((PopulationZonesEditorUI) component) - .getFieldPopulationMappingZoneReproZoneRecru().getMatrix(); - - } /*else if (component instanceof RangeOfValuesUI) { - - } */else if (component instanceof PopulationMigrationMigrationUI) { - result = ((PopulationMigrationMigrationUI) component).getPopInfo() - .getMigrationMatrix(); - - } else if (component instanceof PopulationMigrationEmigrationUI) { - result = ((PopulationMigrationEmigrationUI) component).getPopInfo() - .getEmigrationMatrix(); - - } else if (component instanceof PopulationMigrationImmigrationUI) { - result = ((PopulationMigrationImmigrationUI) component) - .getPopInfo().getImmigrationMatrix(); - } - return result; - } - - /** - * Return if component is instanceof {@link RangeOfValuesUI}. - * @param component component - * @return {@code true} if component is intance of {@link RangeOfValuesUI} - */ - public static boolean isRangeOfValue(JComponent component) { - if (component instanceof RangeOfValuesUI) { - return true; - } - return false; - } - - /** - * Return if component is is continue factor enable. - * - * @param component component - * @return {@code true} if component is is continue factor enable - */ - public static boolean isContinue(JComponent component) { - if (component instanceof RangeOfValuesUI) { - RangeOfValuesUI ui = (RangeOfValuesUI) component; - if (ui.getFieldGearParamType().getSelectedItem().equals("Float")) { - String value = ui.getFieldGearParamPossibleValue().getText(); - if (value.matches("^\\ *[0-9]*\\ *\\-\\ *[0-9]*\\ *$")) { - return true; - } - } - } - return false; - } - - /** - * Return true if component or entity can be defined in continuous factor. - * - * @param component component - * @param entity entity - * @return continuous enabled - */ - public static boolean canBeContinue(JComponent component, - TopiaEntity entity) { - String fieldName = (String) component.getClientProperty("sensitivityMethod"); - if (component instanceof JTextComponent) { - Object o = getMethodValue(entity, fieldName); - return canBeContinue(component, o); - } else if (component instanceof NumberEditor) { - return true; - } else if (component instanceof InputOneEquationUI) { - return true; - } else if (component instanceof MatrixEditor) { - return true; - } else if (component instanceof RangeOfValuesUI) { - RangeOfValuesUI ui = (RangeOfValuesUI) component; - if (ui.getFieldGearParamType().getSelectedItem().equals("Float")) { - return true; - } - } - return false; - } - - /** - * Return true if component or value can be defined in continuous factor. - * - * @param component component - * @param value value - * @return continuous enabled - */ - public static boolean canBeContinue(JComponent component, Object value) { - boolean result = false; - - if (component instanceof JTextComponent) { - if (value instanceof Double) { - result = true; - } else if (value instanceof Long) { - result = true; - } - } - else if (component instanceof InputOneEquationUI) { - result = true; - } - else if (component instanceof MatrixPanelEditor) { - result = true; - } - // Metier.gearPossibleValue case - else if (value instanceof RangeOfValues) { - RangeOfValues rangeOfValues = (RangeOfValues)value; - if (rangeOfValues.getType().equals("Float")) { - result = true; - } - } - - if (log.isDebugEnabled()) { - log.debug("Component " + component.getClass().getSimpleName() + - " with value " + value + "(" + value.getClass().getSimpleName() + ") can be continuous : " + result); - } - return result; - } - - /** - * Get value for fieldName in entity. - * - * @param entity - * @param fieldName - * @return method return value - */ - protected static Object getMethodValue(Object entity, String fieldName) { - Object result = null; - try { - // fieldName maybe be sometime lower case - String getMethod = "get" + StringUtils.capitalize(fieldName); - - Method m = entity.getClass().getMethod(getMethod); - result = m.invoke(entity); - } catch (Exception ex) { - if (log.isErrorEnabled()) { - log.error("Can't get entity value", ex); - } - } - return result; - } - - // RangeOfValue - public static ContinuousPanelContainerUI getContinuousRangeOfValuePanel( - JComponent cOrigine, TopiaEntity bean) { - DefaultContinuousPanelUI continuousPanel = new DefaultContinuousPanelUI(); - RangeOfValuesUI ui = (RangeOfValuesUI) cOrigine; - String value = ui.getFieldGearParamPossibleValue().getText(); - String min = "0"; - String max = "0"; - if (value.matches("^\\ *[0-9]*\\ *\\-\\ *[0-9]*\\ *$")) { - int first = 0; - if (value.startsWith("-")) { - first = 1; - } - first = value.indexOf("-"); - if (first != -1) { - min = value.substring(0, first); - max = value.substring(first + 1); - } - } - continuousPanel.init(new JTextField(min), new JTextField(max)); - return continuousPanel; - } - - public static List<String> getDiscretRangeOfValueValues( - JComponent cOrigine, TopiaEntity bean) { - List<String> result = new ArrayList<String>(); - RangeOfValuesUI ui = (RangeOfValuesUI) cOrigine; - String value = ui.getFieldGearParamPossibleValue().getText(); - if (value.matches("^\\ *[0-9]*\\ *\\-\\ *[0-9]*\\ *$")) { - int first = 0; - if (value.startsWith("-")) { - first = 1; - } - first = value.indexOf("-"); - int min = 0; - int max = 0; - if (first != -1) { - min = Integer.valueOf(value.substring(0, first).trim()); - max = Integer.valueOf(value.substring(first + 1).trim()); - } - for (int i = min; i <= max; i++) { - result.add(i + ""); - } - } else { - if (value.indexOf(";") != -1) { - for (String s : value.split("\\;")) { - result.add(s); - } - } else { - result.add(value); - } - } - return result; - } - - /** - * Return the component to edit factor depending on factor path. - * (inspect the return type of entity denoted by path) - * - * Used to edit reloader factor from old simulation. - * - * @param factor factor - * @param context context - * @return component - */ - public static JComponent getEditorForFactor(Factor factor, TopiaContext context) { - JComponent result = null; - - // we can't do it only with path maybe ? - // need to check property type with introspection - String path = factor.getPath(); - - if (log.isDebugEnabled()) { - log.debug("Try to find component for path " + path); - } - - String topiaId = path.substring(0, path.lastIndexOf('#')); - String property = path.substring(path.lastIndexOf('#') + 1); - - Class<?> typeClazz = null; - try { - TopiaEntity entity = context.findByTopiaId(topiaId); - - if (log.isDebugEnabled()) { - log.debug("Factor " + factor.getName() + " denoted entity " + entity); - } - - String getter = "get" + StringUtils.capitalize(property); - Method method = entity.getClass().getMethod(getter); - typeClazz = method.getReturnType(); - - if (log.isDebugEnabled()) { - log.debug("Property " + property + " denoted type " + typeClazz.getSimpleName()); - } - - result = getEditorForType(typeClazz); - - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Can't find entity for " + topiaId, ex); - } - } catch (SecurityException ex) { - if (log.isErrorEnabled()) { - log.error("Can't get type info for " + topiaId, ex); - } - } catch (NoSuchMethodException ex) { - if (log.isErrorEnabled()) { - log.error("Can't get type info for " + topiaId, ex); - } - } - - return result; - } - - /** - * Get editor for type. - * - * @param typeClazz type to get editor - * @return component - */ - public static JComponent getEditorForType(Class<?> typeClazz) { - - JComponent result = null; - - if (Double.class.isAssignableFrom(typeClazz)) { - result = new JTextField(); - } - else if (double.class.isAssignableFrom(typeClazz)) { - result = new JTextField(); - } - else if (MatrixND.class.isAssignableFrom(typeClazz)) { - result = new MatrixPanelEditor(); - } - else if (Equation.class.isAssignableFrom(typeClazz)) { - result = new InputOneEquationUI(); - } - - return result; - } - - /** - * Get editor for editing value. - * - * @param bean bean - * @param beanProperty bean property - * @return component - */ - public static JComponent getEditorForValue(Object bean, String beanProperty) { - Object basicType = getMethodValue(bean, beanProperty); - - JComponent component = null; - - if (basicType instanceof Equation) { - Equation basicEquation = (Equation)basicType; - InputOneEquationUI equationComponent = new InputOneEquationUI( - new JAXXInitialContext().add(new InputAction())); - equationComponent.setFormuleCategory(basicEquation.getCategory()); - equationComponent.setBean((TopiaEntityContextable)bean); - equationComponent.setBeanProperty(beanProperty); - equationComponent.putClientProperty("sensitivityMethod", beanProperty); - component = equationComponent; - } - - return component; - } -} Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorWizardUI.jaxx =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorWizardUI.jaxx 2011-03-25 17:07:54 UTC (rev 3206) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorWizardUI.jaxx 2011-03-25 17:13:30 UTC (rev 3207) @@ -41,23 +41,26 @@ javax.swing.JComponent </import> + <SensitivityInputHandler id="handler" /> + <Boolean id='continuePossible' javaBean='true'/> <Boolean id='continueSelected' javaBean='false'/> - - <Boolean id='discretePossible' javaBean='true'/> <Boolean id='existingValue' javaBean='false'/> + <String id="factorPath" javaBean="null"/> + <script><![CDATA[ -protected JComponent cOrigine = null; -protected TopiaEntityContextable bean = null; protected java.util.List<JComponent> discretComponents = new ArrayList<JComponent>(); -protected String path = null; protected ContinuousPanelContainerUI continuousPanel = null; -protected Factor factor = null; +/*protected JComponent cOrigine = null; +protected TopiaEntityContextable bean = null; +protected String path = null; +protected Factor factor = null;*/ + protected void $afterCompleteSetup() { addPropertyChangeListener(PROPERTY_CONTINUE_POSSIBLE, new PropertyChangeListener() { @Override @@ -77,168 +80,10 @@ } }); } - -public void initNew(JComponent source, TopiaEntityContextable be, boolean continuePossible) { - this.bean = be; - this.cOrigine = source; - - // path is topiaId#property - // ex : fwn#fsd#0.3425345#name - // for JAXX : cOrigine start with upper case - // for commons beanutils : must be lower case - String methodName = StringUtils.uncapitalize(EditorHelper.getMethod(cOrigine)); - this.path = bean.getTopiaId() + "#" + methodName; - - factorNameField.setText(bean.toString() + "." + methodName); - setDiscretePossible(discretePossible); - setContinuePossible(continuePossible); - boolean selected = EditorHelper.isContinue(cOrigine); - - // continue always auto selected ? - // warning equation can be discrete for now (only variable are continuous) - setContinueSelected(selected); - continueRadio.setSelected(selected); - - if (isContinuePossible()){ - if (EditorHelper.isRangeOfValue(cOrigine)) { - continuousPanel = EditorHelper.getContinuousRangeOfValuePanel(cOrigine, bean); - } - else { - continuousPanel = EditorHelper.getContinuousPanel(cOrigine, bean); - } - init(); - } - if (!isContinueSelected() && EditorHelper.isRangeOfValue(cOrigine)) { - int i = 0; - for (String s : EditorHelper.getDiscretRangeOfValueValues(cOrigine, bean)) { - JTextField text = new JTextField(s); - discretComponents.add(text); - tabPane.add(text, "Factor " + (i+1)); - i++; - } - } - if (continuousPanel != null) { - continuousPanel.setContinueSelected(selected); - } - setContinueSelected(EditorHelper.isContinue(cOrigine)); -} - -/** - * Reaffiche un facteur existant. - */ -public void initExisting(JComponent cOrigine, Factor f) { - setExistingValue(true); - this.cOrigine = cOrigine; - this.path = f.getPath(); - comment.setText(f.getComment()); - Domain domain = f.getDomain(); - this.factor = f; - - String factorName = f.getName(); - if (domain instanceof ContinuousDomain) { - if (domain instanceof EquationContinuousDomain) { - EquationContinuousDomain equationDomain = (EquationContinuousDomain)domain; - - // dans le cas d'un facteur equation - // il faut enlever la varible du nom - // sinon, à la sauvegarde elle sera reajoutée - String suffix = "." + equationDomain.getVariableName(); - factorName = StringUtils.removeEnd(factorName, suffix); - } - - ContinuousDomain cDomain = (ContinuousDomain) domain; - - continuousPanel = EditorHelper.getContinuousPanelWithValue(cOrigine, cDomain, f); - init(); - - continueRadio.setSelected(true); - setContinueSelected(true); - setContinuePossible(true); - } else { - - DiscreteDomain dDomain = (DiscreteDomain)domain; - - int nb = dDomain.getValues().size(); - discretNumber.setText(nb + ""); - - discretComponents.clear(); - tabPane.removeAll(); - - SortedMap values = dDomain.getValues(); - int i = 0; - Object cache = null; - for (Object o : values.values()) { - i++; - cache = o; - JComponent c = null; - if (o != null) { - c = EditorHelper.getEditorWithValue(cOrigine, o); - } - else { - c = EditorHelper.getEditorWithValue(cOrigine); - } - discretComponents.add(c); - JScrollPane js = new JScrollPane(c); - tabPane.addTab("Factor " + i, js); - } - setContinuePossible(EditorHelper.canBeContinue(cOrigine, cache)); - } - - factorNameField.setText(factorName); - if (factorName.startsWith("parameters.")) { - // les facteurs de parametres sont speciaux - // et ne doivent pas changer de nom - factorNameField.setEditable(false); - } - - this.pack(); -} -protected void init() { - continuousPanelContainer.add(continuousPanel, BorderLayout.CENTER); - this.pack(); -} -protected JComponent getNewComponent() { - return EditorHelper.getEditor(cOrigine, bean); -} -protected void addTabs(String sNbTab) { - int nbTab = Integer.parseInt(sNbTab); - discretComponents.clear(); - tabPane.removeAll(); - for (int i=0;i<nbTab;i++) { - JComponent c = getNewComponent(); - discretComponents.add(c); - JScrollPane js = new JScrollPane(c); - tabPane.addTab("Factor " + (i+1), js); - } - this.pack(); -} -protected SensitivityAction getSensitivityAction() { - return getContextValue(SensitivityAction.class); -} protected SimulAction getSimulAction() { return getContextValue(SimulAction.class); } -protected void save() { - if (continueRadio.isSelected()) { - getSensitivityAction().saveContinue(cOrigine, factorNameField.getText(), - comment.getText(), path, continuousPanel, getSimulAction(), isExistingValue()); - } else { - getSensitivityAction().saveDiscret(cOrigine, factorNameField.getText(), - comment.getText(), path, discretComponents, getSimulAction(), isExistingValue()); - } - getContextValue(SimulationUI.class, "SimulationUI").refreshFactorTree(); - exit(); -} -protected void remove() { - getSimulAction().removeFactor(factor); - getContextValue(SimulationUI.class, "SimulationUI").refreshFactorTree(); - exit(); -} -protected void exit() { - this.dispose(); -} - ]]> - </script> + ]]></script> <Table constraints='BorderLayout.CENTER'> <row> <cell fill='horizontal'> @@ -276,7 +121,8 @@ <JTextField id='discretNumber' enabled='{!isContinueSelected()}'/> </cell> <cell fill='horizontal'> - <JButton text='isisfish.sensitivity.validDiscretNumber' enabled='{!isContinueSelected()}' onActionPerformed='addTabs(discretNumber.getText())'/> + <JButton text='isisfish.sensitivity.validDiscretNumber' enabled='{!isContinueSelected()}' + onActionPerformed='getHandler().addTabs(this)'/> </cell> </row> <row> @@ -302,13 +148,15 @@ </row> <row> <cell fill='horizontal'> - <JButton id='cancel' text='isisfish.common.cancel' onActionPerformed='exit()'/> + <JButton id='cancel' text='isisfish.common.cancel' onActionPerformed='dispose()'/> </cell> <cell fill='horizontal'> - <JButton id='remove' text='isisfish.common.remove' visible='{isExistingValue()}' onActionPerformed='remove()'/> + <JButton id='remove' text='isisfish.common.remove' visible='{isExistingValue()}' + onActionPerformed='getHandler().remove(this)'/> </cell> <cell fill='horizontal'> - <JButton id='save' text='isisfish.common.save' enabled='{!getFactorNameField().getText().isEmpty()}' onActionPerformed='save()'/> + <JButton id='save' text='isisfish.common.save' enabled='{!getFactorNameField().getText().isEmpty()}' + onActionPerformed='getHandler().save(this)'/> </cell> </row> </Table> Deleted: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityAction.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityAction.java 2011-03-25 17:07:54 UTC (rev 3206) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityAction.java 2011-03-25 17:13:30 UTC (rev 3207) @@ -1,150 +0,0 @@ -/* - * #%L - * IsisFish - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 Ifremer, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 2 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 Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-2.0.html>. - * #L% - */ - -package fr.ifremer.isisfish.ui.sensitivity; - -import static org.nuiton.i18n.I18n._; - -import java.io.Serializable; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JComponent; -import javax.swing.JOptionPane; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.math.matrix.MatrixND; -import org.nuiton.topia.persistence.TopiaEntityContextable; - -import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain; -import fr.ifremer.isisfish.ui.simulator.SimulAction; - -/** - * Action for sensitivity package. - * - * @author letellier - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class SensitivityAction { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - private static Log log = LogFactory.getLog(SensitivityAction.class); - - public void saveContinue(JComponent cOrigine, String name, - String comment, String path, ContinuousPanelContainerUI panel, - SimulAction action, boolean exist) { - DefaultContinuousPanelUI defaultPanel = null; - if (panel instanceof MatrixContinuousPanelUI) { - MatrixContinuousPanelUI matrixPanel = (MatrixContinuousPanelUI) panel; - Double coef = Double.valueOf(matrixPanel.getCoef().getText()) / 100; - MatrixND matrix = matrixPanel.getMatrix(); - String operateur = (String) matrixPanel.getOperator() - .getSelectedItem(); - action.addContinuousMatrixFactor(name, comment, path, coef, matrix, - operateur, cOrigine, exist); - - } else if (panel instanceof EquationContinuousPanelUI) { - try { - EquationContinuousPanelUI equationPanel = (EquationContinuousPanelUI) panel; - - TopiaEntityContextable bean = (TopiaEntityContextable)equationPanel.getBean(); - //String methodSet = equationPanel.getMethodSet(); - String property = equationPanel.getBeanProperty(); - property = StringUtils.capitalize(property) + "Content"; - Method m = bean.getClass().getMethod("set" + property, String.class); - m.invoke(bean, equationPanel.getEditor().getEditor().getText()); - - // Save equation - bean.update(); - bean.getTopiaContext().commitTransaction(); - - List<EquationContinuousDomain> domains = equationPanel - .getDomains(); - for (EquationContinuousDomain domain : domains) { - if (domain.getReferenceValue() != null - && domain.getCoefficient() != null - && domain.getCoefficient() <= 100 - && domain.getCoefficient() > 0 - && domain.getOperator() != null - && domain.getVariableName() != null) { - action.addContinuousEquationFactor(name, comment, path, - domain, cOrigine, exist); - } else { - log.warn("domain: " + domain); - log.warn("domain invalid: " - + "domain.getReferenceValue() != null(" - + (domain.getReferenceValue()) - + ") domain.getCoefficient() != null(" - + (domain.getCoefficient()) - + ") domain.getCoefficient() <= 100 (" - + (domain.getCoefficient()) - + ") domain.getCoefficient() > 0 (" - + (domain.getCoefficient()) - + ") domain.getOperator() != null (" - + (domain.getOperator()) - + ") domain.getVariableName() != null(" - + (domain.getVariableName()) + ")"); - JOptionPane.showMessageDialog(equationPanel, - _("isisfish.error.factor.invalid") - + domain.getVariableName()); - } - } - } catch (Exception ex) { - if (log.isErrorEnabled()) { - log.error("Can't call method : ", ex); - } - } - } else if (panel instanceof DefaultContinuousPanelUI) { - defaultPanel = (DefaultContinuousPanelUI) panel; - action.addContinuousFactor(name, comment, path, - getMin(defaultPanel), getMax(defaultPanel), - cOrigine, exist); - } - } - - protected Double getMin(DefaultContinuousPanelUI defaultPanel) { - return Double.parseDouble(defaultPanel.getMin()); - } - - protected Double getMax(DefaultContinuousPanelUI defaultPanel) { - return Double.parseDouble(defaultPanel.getMax()); - } - - public void saveDiscret(JComponent cOrigine, String name, - String comment, String path, List<JComponent> components, - SimulAction action, boolean exist) { - List<Serializable> values = new ArrayList<Serializable>(); - for (JComponent c : components) { - values.add((Serializable) EditorHelper.getValue(c)); - } - action.addDiscreteFactor(name, comment, path, values, cOrigine, exist); - } -} \ No newline at end of file Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java 2011-03-25 17:07:54 UTC (rev 3206) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java 2011-03-25 17:13:30 UTC (rev 3207) @@ -29,33 +29,72 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; +import java.io.Serializable; +import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.List; +import java.util.SortedMap; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; import javax.swing.JComponent; +import javax.swing.JList; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPopupMenu; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTextField; import javax.swing.event.TreeSelectionEvent; +import javax.swing.text.JTextComponent; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; +import jaxx.runtime.context.JAXXInitialContext; +import jaxx.runtime.swing.editor.NumberEditor; + import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixND; +import org.nuiton.math.matrix.gui.MatrixPanelEditor; import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityContextable; import fr.ifremer.isisfish.IsisFishRuntimeException; +import fr.ifremer.isisfish.entities.Equation; import fr.ifremer.isisfish.entities.FisheryRegion; +import fr.ifremer.isisfish.rule.Rule; +import fr.ifremer.isisfish.simulator.sensitivity.Domain; import fr.ifremer.isisfish.simulator.sensitivity.Factor; import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; +import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; +import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain; +import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain; +import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain; +import fr.ifremer.isisfish.simulator.sensitivity.domain.RuleDomain; +import fr.ifremer.isisfish.types.RangeOfValues; +import fr.ifremer.isisfish.ui.SimulationUI; +import fr.ifremer.isisfish.ui.input.InputAction; import fr.ifremer.isisfish.ui.input.InputContentUI; import fr.ifremer.isisfish.ui.input.InputHandler; +import fr.ifremer.isisfish.ui.input.InputOneEquationUI; +import fr.ifremer.isisfish.ui.input.MetierSeasonInfoSpeciesEditorUI; +import fr.ifremer.isisfish.ui.input.PopulationMigrationEmigrationUI; +import fr.ifremer.isisfish.ui.input.PopulationMigrationImmigrationUI; +import fr.ifremer.isisfish.ui.input.PopulationMigrationMigrationUI; +import fr.ifremer.isisfish.ui.input.PopulationZonesEditorUI; +import fr.ifremer.isisfish.ui.input.SelectivityEditorUI; +import fr.ifremer.isisfish.ui.input.SpeciesStructuredUI; import fr.ifremer.isisfish.ui.input.tree.FisheryDataProvider; import fr.ifremer.isisfish.ui.input.tree.FisheryTreeHelper; import fr.ifremer.isisfish.ui.input.tree.FisheryTreeNode; import fr.ifremer.isisfish.ui.input.tree.FisheryTreeRenderer; +import fr.ifremer.isisfish.ui.simulator.RuleChooser; +import fr.ifremer.isisfish.ui.simulator.SimulAction; /** * Handler for sensitivity tab ui (fishery region factors). @@ -95,8 +134,11 @@ treeHelper.setUI(sensitivityTabUI.getFisheryRegionTree(), true, false, null); // global context value : fisheryRegion, regionStorage, treeHelper + sensitivityTabUI.setContextValue(fisheryRegion); + //sensitivityTabUI.setContextValue(regionStorage); sensitivityTabUI.setContextValue(treeHelper); sensitivityTabUI.setContextValue(model); + sensitivityTabUI.setContextValue(fisheryRegion.getTopiaContext()); sensitivityTabUI.getCardlayoutPrincipal().show(sensitivityTabUI.getInputPanePrincipal(),"normale"); } @@ -253,36 +295,36 @@ if (selectedObject != null) { if (!(selectedObject instanceof FactorGroup)) { Factor selectedFactor = (Factor)selectedObject; - FactorWizardUI wizard = new FactorWizardUI(sensitivityTabUI); - - JComponent component = sensitivityTabUI.getSimulAction().getFactorComponent(selectedFactor); + FactorWizardUI factorWizardUI = new FactorWizardUI(sensitivityTabUI); + SensitivityInputHandler handler = factorWizardUI.getHandler(); + /*JComponent component = sensitivityTabUI.getSimulAction().getFactorComponent(selectedFactor); if (component != null) { wizard.initExisting(component, selectedFactor); wizard.pack(); wizard.setLocationRelativeTo(sensitivityTabUI); wizard.setVisible(true); } - else { + else {*/ // cas d'un rechargement de simulation // le facteur n'a pas d'instance de composant associé // method 2 - JComponent component2 = EditorHelper.getEditorForFactor(selectedFactor, sensitivityTabUI.getFisheryRegion().getTopiaContext()); - if (component2 != null) { + //JComponent component2 = EditorHelper.getEditorForFactor(selectedFactor, sensitivityTabUI.getFisheryRegion().getTopiaContext()); + //if (component2 != null) { + //if (log.isDebugEnabled()) { + // log.debug("Component found is " + component2); + //} + handler.initExistingFactor(factorWizardUI, selectedFactor); + factorWizardUI.pack(); + factorWizardUI.setLocationRelativeTo(sensitivityTabUI.getFactorsTree()); + factorWizardUI.setVisible(true); + //} + /*else { if (log.isDebugEnabled()) { - log.debug("Component found is " + component2); - } - wizard.initExisting(component2, selectedFactor); - wizard.pack(); - wizard.setLocationRelativeTo(sensitivityTabUI); - wizard.setVisible(true); - } - else { - if (log.isDebugEnabled()) { log.debug("No component found, skip edition of factor " + selectedFactor.getName()); } - } - } + }*/ + //} } } } @@ -299,12 +341,661 @@ if (selectedObject != null) { if (selectedObject instanceof Factor) { Factor selectedFactor = (Factor)selectedObject; + FactorGroup selectedFactorGroup = (FactorGroup)pathWay[pathWay.length - 2]; if (log.isDebugEnabled()) { log.debug("Deleting factor " + selectedFactor.getName()); } - sensitivityTabUI.getSimulAction().removeFactor(selectedFactor); + selectedFactorGroup.remove(selectedFactor); sensitivityTabUI.setFactorModel(); } } } + + /** + * Un init new se fait toujours sur une entité. + * + * On recupere des info sur le type correspondant à la proprieté a mettre + * en facteur pour savoir le composant d'edition et s'il peut etre continue + * ou pas. + * + * @param factorWizardUI factorWizardUI + * @param bean bean in current ui + * @param property bean property to edit + */ + public void initNewFactor(FactorWizardUI factorWizardUI, TopiaEntityContextable bean, String property) { + //factorWizardUI.setBean(bean); + //this.cOrigine = source; + + // path is topiaId#property + // ex : fwn#fsd#0.3425345#name + // for JAXX : cOrigine start with upper case + // for commons beanutils : must be lower case + String beanProperty = StringUtils.uncapitalize(property); + String path = bean.getTopiaId() + "#" + beanProperty; + factorWizardUI.setFactorPath(path); + factorWizardUI.getFactorNameField().setText(bean.toString() + "." + beanProperty); + + // get value for pointed path + //TopiaContext topiaContext = factorWizardUI.getContextValue(TopiaContext.class); + //Class<?> classForPath = getPropertyClass(path, topiaContext); + Object valueForPath = getPropertyValue(bean, beanProperty); + boolean continuePossible = canBeContinue(valueForPath); + boolean continueSelected = isContinue(valueForPath); + factorWizardUI.setContinuePossible(continuePossible); + factorWizardUI.setContinueSelected(continueSelected); + factorWizardUI.getContinueRadio().setSelected(continueSelected); + + // init panel + if (continuePossible) { + factorWizardUI.continuousPanel = getContinuousPanel(valueForPath, bean, property); + factorWizardUI.getContinuousPanelContainer().add(factorWizardUI.continuousPanel, BorderLayout.CENTER); + } + /*if (!continueSelected && valueForPath instanceof RangeOfValues) { + int i = 0; + for (String s : EditorHelper.getDiscretRangeOfValueValues(cOrigine, bean)) { + JTextField text = new JTextField(s); + discretComponents.add(text); + tabPane.add(text, "Factor " + (i+1)); + i++; + } + }*/ + /*if (continuousPanel != null) { + continuousPanel.setContinueSelected(selected); + }*/ + //setContinueSelected(EditorHelper.isContinue(cOrigine)); + } + + /** + * Reaffiche un facteur existant. + * + * @param factorWizardUI + * @param factor factor + */ + public void initExistingFactor(FactorWizardUI factorWizardUI, Factor factor) { + + factorWizardUI.setExistingValue(true); + String factorPath = factor.getPath(); + Domain domain = factor.getDomain(); + String factorName = factor.getName(); + factorWizardUI.setFactorPath(factorPath); + factorWizardUI.getComment().setText(factor.getComment()); + + // dans le cas d'un facteur equation + // il faut enlever la varible du nom + // sinon, à la sauvegarde elle sera reajoutée + if (domain instanceof EquationContinuousDomain) { + EquationContinuousDomain equationDomain = (EquationContinuousDomain)domain; + String suffix = "." + equationDomain.getVariableName(); + factorName = StringUtils.removeEnd(factorName, suffix); + } + + if (domain instanceof ContinuousDomain) { + + ContinuousDomain cDomain = (ContinuousDomain) domain; + + TopiaContext topiaContext = factorWizardUI.getContextValue(TopiaContext.class); + factorWizardUI.continuousPanel = getContinuousPanelWithValue(factor, cDomain, topiaContext); + factorWizardUI.getContinuousPanelContainer().add(factorWizardUI.continuousPanel, BorderLayout.CENTER); + + factorWizardUI.getContinueRadio().setSelected(true); + factorWizardUI.setContinueSelected(true); + factorWizardUI.setContinuePossible(true); + } else { + + // restaure discrete domain + DiscreteDomain dDomain = (DiscreteDomain)domain; + + int nb = dDomain.getValues().size(); + factorWizardUI.getDiscretNumber().setText(String.valueOf(nb)); + factorWizardUI.discretComponents.clear(); + factorWizardUI.getTabPane().removeAll(); + + SortedMap<Object, Object> values = dDomain.getValues(); + int i = 0; + Object cache = null; + for (Object o : values.values()) { + i++; + cache = o; + JComponent c = null; + if (o != null) { + c = getEditorWithValue(dDomain, o); + } + else { + if (log.isWarnEnabled()) { + log.warn("Null value in factor"); + } + } + factorWizardUI.discretComponents.add(c); + JScrollPane js = new JScrollPane(c); + factorWizardUI.getTabPane().addTab("Factor " + i, js); + } + + // init non selected continous panel + if (factorPath.indexOf('#') != -1) { + try { + // get initial value in database + String topiaId = factorPath.substring(0, factorPath.lastIndexOf('#')); + String property = factorPath.substring(factorPath.lastIndexOf('#') + 1); + TopiaContext topiaContext = factorWizardUI.getContextValue(TopiaContext.class); + TopiaEntityContextable entity = (TopiaEntityContextable)topiaContext.findByTopiaId(topiaId); + String getter = "get" + StringUtils.capitalize(property); + Method m = entity.getClass().getMethod(getter); + Object valueForPath = m.invoke(entity); + + boolean continuePossible = canBeContinue(valueForPath); + factorWizardUI.setContinuePossible(continuePossible); + if (continuePossible) { + factorWizardUI.continuousPanel = getContinuousPanel(valueForPath, entity, property); + factorWizardUI.getContinuousPanelContainer().add(factorWizardUI.continuousPanel, BorderLayout.CENTER); + } + } catch (Exception ex) { + throw new IsisFishRuntimeException("", ex); + } + } + + } + + factorWizardUI.getFactorNameField().setText(factorName); + } + + /** + * Refresh tab for discrete factor numbers. + * + * @param factorWizardUI factorWizardUI + */ + public void addTabs(FactorWizardUI factorWizardUI) { + String discreteNumber = factorWizardUI.getDiscretNumber().getText(); + int nbTab = Integer.parseInt(discreteNumber); + factorWizardUI.discretComponents.clear(); + factorWizardUI.getTabPane().removeAll(); + for (int i = 0; i < nbTab ; i++) { + JComponent c = getNewDiscreteComponent(factorWizardUI); + factorWizardUI.discretComponents.add(c); + JScrollPane js = new JScrollPane(c); + factorWizardUI.getTabPane().addTab("Factor " + (i+1), js); + } + factorWizardUI.pack(); + } + + /*protected JComponent getNewComponent() { + return EditorHelper.getEditor(cOrigine, bean); + }*/ + + /** + * Retourne le type de valeur pointé par le path du facteur. + * + * @param factorPath factor path + * @param context context + * @return class + */ + protected Class<?> getPropertyClass(String factorPath, TopiaContext context) { + Class<?> result = null; + if (factorPath.indexOf('#') != -1) { + String topiaId = factorPath.substring(0, factorPath.lastIndexOf('#')); + String property = factorPath.substring(factorPath.lastIndexOf('#') + 1); + + try { + TopiaEntity entity = context.findByTopiaId(topiaId); + + if (log.isDebugEnabled()) { + log.debug("Factor path " + factorPath + " denoted entity " + entity); + } + + String getter = "get" + StringUtils.capitalize(property); + Method method = entity.getClass().getMethod(getter); + result = method.getReturnType(); + + } catch (Exception ex) { + if (log.isErrorEnabled()) { + log.error("Can't find entity for " + topiaId, ex); + } + } + } + return result; + } + + /** + * Get value for fieldName in entity. + * + * @param entity + * @param fieldName + * @return method return value + */ + protected Object getPropertyValue(Object entity, String fieldName) { + Object result = null; + try { + // fieldName maybe be sometime lower case + String getMethod = "get" + StringUtils.capitalize(fieldName); + + Method m = entity.getClass().getMethod(getMethod); + result = m.invoke(entity); + } catch (Exception ex) { + if (log.isErrorEnabled()) { + log.error("Can't get entity value", ex); + } + } + return result; + } + + /** + * Return true if value can be defined in continuous factor. + * + * @param value value + * @return continuous enabled + */ + public boolean canBeContinue(Object value) { + boolean result = false; + + if (value instanceof Double) { + result = true; + } else if (value instanceof Long) { + result = true; + } else if (value instanceof Equation) { + result = true; + } else if (value instanceof MatrixND) { + result = true; + } else if (value instanceof RangeOfValues) { + RangeOfValues rangeOfValues = (RangeOfValues)value; + if (rangeOfValues.getType().equals("Float")) { + result = true; + } + } else if (value instanceof String) { + // todo fix string value :( + result = true; + } + + /*if (log.isDebugEnabled()) { + log.debug("Component " + component.getClass().getSimpleName() + + " with value " + value + "(" + value.getClass().getSimpleName() + ") can be continuous : " + result); + }*/ + return result; + } + + /** + * Return if value is is continue factor enable. + * + * @param value value to test + * @return {@code true} if value is is continue factor enable + */ + public boolean isContinue(Object value) { + boolean result = false; + if (value instanceof RangeOfValues) { + RangeOfValues range = (RangeOfValues)value; + if (range.getType().equals(RangeOfValues.TYPE_FLOAT)) { + String textValue = range.getValues(); + // TODO need comment !!! + if (textValue.matches("^\\ *[0-9]*\\ *\\-\\ *[0-9]*\\ *$")) { + result = true; + } + } + } + return result; + } + + /** + * Get copy of component with original entity value as default value. + * + * @param value value + * @return component copy + */ + public ContinuousPanelContainerUI getContinuousPanel(Object value, TopiaEntityContextable bean, String property) { + ContinuousPanelContainerUI result = null; + + if (value instanceof RangeOfValues) { + RangeOfValues rangeOfValues = (RangeOfValues)value; + DefaultContinuousPanelUI ui = new DefaultContinuousPanelUI(); + String values = rangeOfValues.getValues(); + String min = "0"; + String max = "0"; + if (values.matches("^\\ *[0-9]*\\ *\\-\\ *[0-9]*\\ *$")) { + int first = 0; + if (values.startsWith("-")) { + first = 1; + } + first = values.indexOf("-"); + if (first != -1) { + min = values.substring(0, first); + max = values.substring(first + 1); + } + } + ui.init(new JTextField(min), new JTextField(max)); + result = ui; + } + else if (value instanceof Equation) { + Equation equation = (Equation)value; + EquationContinuousPanelUI ui = new EquationContinuousPanelUI(new JAXXInitialContext().add(new InputAction())); + ui.setSelectedEquation(equation); + ui.setText(_("isisfish.common.equation")); // can't get real name + ui.setFormuleCategory(equation.getCategory()); + ui.setClazz(equation.getClass()); + ui.setBeanProperty(property); + ui.setBean(bean); + result = ui; + } else if (value instanceof MatrixND) { + MatrixND matrix = (MatrixND)value; + MatrixContinuousPanelUI matrixPanel = new MatrixContinuousPanelUI(); + if (matrix != null) { + matrixPanel.setMatrix(matrix.clone()); + } + result = matrixPanel; + } else { + DefaultContinuousPanelUI ui = new DefaultContinuousPanelUI(); + ui.init(new JTextField(String.valueOf(value)), new JTextField(String.valueOf(value))); + result = ui; + } + + if (log.isDebugEnabled()) { + log.debug("Component for " + value + " (" + bean + ", " + property + ")"); + log.debug(" > " + result); + } + + return result; + } + + /** + * Get continuous editor for component with given value. + * + * @param domain domain + * @param factor factor + * @return component copy + */ + public ContinuousPanelContainerUI getContinuousPanelWithValue(Factor factor, ContinuousDomain domain, TopiaContext topiaContext) { + ContinuousPanelContainerUI result = null; + + DefaultContinuousPanelUI continuousPanel = null; + if (domain instanceof EquationContinuousDomain) { + String factorPath = factor.getPath(); + if (factor.getPath().indexOf('#') != -1) { + String topiaId = factorPath.substring(0, factorPath.lastIndexOf('#')); + String property = factorPath.substring(factorPath.lastIndexOf('#') + 1); + + // get bean in database + try { + TopiaEntityContextable entity = (TopiaEntityContextable)topiaContext.findByTopiaId(topiaId); + + String getter = "get" + StringUtils.capitalize(property); + Method m = entity.getClass().getMethod(getter); + Equation value = (Equation)m.invoke(entity); + + // fill component + EquationContinuousPanelUI ui = new EquationContinuousPanelUI( + new JAXXInitialContext().add(new InputAction())); + ui.setText(value.getContent()); + ui.setFormuleCategory(value.getCategory()); + ui.setText(_("isisfish.common.equation")); // can't get real name + ui.setClazz(value.getClass()); + ui.setBeanProperty(property); + ui.setBean(entity); + + EquationContinuousDomain equationDomain = (EquationContinuousDomain) domain; + ui.addDomain(equationDomain); + ui.setTable(); + + result = ui; + } catch (Exception ex) { + throw new IsisFishRuntimeException("Can't restore intial factor database property", ex); + } + } + // TODO path with no # (normalement pas possible pour les equations) + } else if (domain instanceof MatrixContinuousDomain) { + MatrixContinuousDomain matrixDomain = (MatrixContinuousDomain)domain; + MatrixND matrix = matrixDomain.getMatrix(); + MatrixContinuousPanelUI panel = new MatrixContinuousPanelUI(); + if (matrix != null) { + panel.setMatrix(matrix.clone()); + } + panel.getOperator().setSelectedItem(matrixDomain.getOperator()); + panel.getCoef().setText(String.valueOf(matrixDomain.getCoefficient() * 100)); + result = panel; + } else { + continuousPanel = new DefaultContinuousPanelUI(); + continuousPanel.init(new JTextField(String.valueOf(domain.getMinBound())), + new JTextField(String.valueOf(domain.getMaxBound()))); + result = continuousPanel; + } + + return result; + } + + /** + * Get editor for value (discrete). + * + * @param value type to get editor + * @param factorPath for equation + * @param context for equation + * @return component + */ + protected JComponent getEditorWithValue(Domain domain, Object value) { + + JComponent result = null; + + if (Double.class.isAssignableFrom(value.getClass())) { + result = new JTextField(); + ((JTextField)result).setText(String.valueOf(value)); + } + else if (double.class.isAssignableFrom(value.getClass())) { + result = new JTextField(); + ((JTextField)result).setText(String.valueOf(value)); + } + else if (MatrixND.class.isAssignableFrom(value.getClass())) { + result = new MatrixPanelEditor(); + ((MatrixPanelEditor)result).setMatrix((MatrixND)value); + } + else if (domain instanceof RuleDomain) { + result = new RuleChooser(); + ((RuleChooser)result).setRulesList((List<Rule>)value); + } + else if (value instanceof String) { + // valeur nom typées ??? + result = new JTextField(); + ((JTextField)result).setText(String.valueOf(value)); + } + + if (log.isDebugEnabled()) { + log.debug("Editor for value " + value + " is " + result); + } + + return result; + } + + /** + * Get copy of component with original entity value as default value. + * Used to add new tab to a new or existing factor. + * + * @param factorWizardUI factorWizardUI + * @return component copy + */ + public JComponent getNewDiscreteComponent(FactorWizardUI factorWizardUI) { + + JComponent result = null; + String factorPath = factorWizardUI.getFactorPath(); + + if (factorPath.indexOf('#') != -1) { + String topiaId = factorPath.substring(0, factorPath.lastIndexOf('#')); + String property = factorPath.substring(factorPath.lastIndexOf('#') + 1); + TopiaContext topiaContext = factorWizardUI.getContextValue(TopiaContext.class); + + + try { + // get bean in database + TopiaEntityContextable entity = (TopiaEntityContextable)topiaContext.findByTopiaId(topiaId); + String getter = "get" + StringUtils.capitalize(property); + Method m = entity.getClass().getMethod(getter); + Object value = m.invoke(entity); + + // init new jcomponent for value + if (value instanceof Number) { + result = new JTextField(String.valueOf(value)); + } else if (value instanceof MatrixND) { + result = new MatrixPanelEditor(); + MatrixND matrix = ((MatrixND)value).copy(); + ((MatrixPanelEditor)result).setMatrix(matrix); + } else if (value instanceof RangeOfValues) { + RangeOfValues rangeOfValues = (RangeOfValues)value; + result = new JTextField(rangeOfValues.getValues()); + } + } catch (Exception ex) { + throw new IsisFishRuntimeException("Can't restore intial factor database property", ex); + } + } + else { + + // dans ce cas c'est des regles ou pop de départ + if (factorPath.equals("parameters.rules")) { + result = new RuleChooser(); + } + else if (factorPath.startsWith("parameters.population.")) { + // todo + } + else { + if (log.isWarnEnabled()) { + log.warn("Can't find component for path " + factorPath); + } + } + } + + return result; + } + + /** + * Save current factor. + * + * @param factorWizardUI factorWizardUI + */ + public void save(FactorWizardUI factorWizardUI) { + if (factorWizardUI.getContinueRadio().isSelected()) { + saveContinue(factorWizardUI.getFactorNameField().getText(), + factorWizardUI.getComment().getText(), factorWizardUI.getFactorPath(), factorWizardUI.continuousPanel, + factorWizardUI.getSimulAction(), factorWizardUI.isExistingValue()); + } else { + saveDiscret(factorWizardUI.getFactorNameField().getText(), + factorWizardUI.getComment().getText(), factorWizardUI.getFactorPath(), factorWizardUI.discretComponents, + factorWizardUI.getSimulAction(), factorWizardUI.isExistingValue()); + } + factorWizardUI.getContextValue(SimulationUI.class, "SimulationUI").refreshFactorTree(); + factorWizardUI.dispose(); + } + + /** + * Remove current factor. + * + * @param factorWizardUI factorWizardUI + */ + public void remove(FactorWizardUI factorWizardUI) { + factorWizardUI.getSimulAction().removeFactor(factorWizardUI.getFactorPath()); + factorWizardUI.getContextValue(SimulationUI.class, "SimulationUI").refreshFactorTree(); + factorWizardUI.dispose(); + } + + protected void saveContinue(String name, + String comment, String path, ContinuousPanelContainerUI panel, + SimulAction action, boolean exist) { + System.out.println(" panel = " + panel); + DefaultContinuousPanelUI defaultPanel = null; + if (panel instanceof MatrixContinuousPanelUI) { + MatrixContinuousPanelUI matrixPanel = (MatrixContinuousPanelUI) panel; + Double coef = Double.valueOf(matrixPanel.getCoef().getText()) / 100; + MatrixND matrix = matrixPanel.getMatrix(); + String operateur = (String) matrixPanel.getOperator() + .getSelectedItem(); + action.addContinuousMatrixFactor(name, comment, path, coef, matrix, + operateur, exist); + + } else if (panel instanceof EquationContinuousPanelUI) { + try { + EquationContinuousPanelUI equationPanel = (EquationContinuousPanelUI) panel; + + TopiaEntityContextable bean = (TopiaEntityContextable)equationPanel.getBean(); + String property = equationPanel.getBeanProperty(); + property = StringUtils.capitalize(property) + "Content"; + Method m = bean.getClass().getMethod("set" + property, String.class); + m.invoke(bean, equationPanel.getEditor().getEditor().getText()); + + // Save equation + bean.update(); + bean.getTopiaContext().commitTransaction(); + + List<EquationContinuousDomain> domains = equationPanel + .getDomains(); + for (EquationContinuousDomain domain : domains) { + if (domain.getReferenceValue() != null + && domain.getCoefficient() != null + && domain.getCoefficient() <= 100 + && domain.getCoefficient() > 0 + && domain.getOperator() != null + && domain.getVariableName() != null) { + action.addContinuousEquationFactor(name, comment, path, + domain, exist); + } else { + log.warn("domain: " + domain); + log.warn("domain invalid: " + + "domain.getReferenceValue() != null(" + + (domain.getReferenceValue()) + + ") domain.getCoefficient() != null(" + + (domain.getCoefficient()) + + ") domain.getCoefficient() <= 100 (" + + (domain.getCoefficient()) + + ") domain.getCoefficient() > 0 (" + + (domain.getCoefficient()) + + ") domain.getOperator() != null (" + + (domain.getOperator()) + + ") domain.getVariableName() != null(" + + (domain.getVariableName()) + ")"); + JOptionPane.showMessageDialog(equationPanel, + _("isisfish.error.factor.invalid") + + domain.getVariableName()); + } + } + } catch (Exception ex) { + if (log.isErrorEnabled()) { + log.error("Can't call method : ", ex); + } + } + } else if (panel instanceof DefaultContinuousPanelUI) { + defaultPanel = (DefaultContinuousPanelUI) panel; + action.addContinuousFactor(name, comment, path, + getMin(defaultPanel), getMax(defaultPanel), + exist); + } + } + + protected Double getMin(DefaultContinuousPanelUI defaultPanel) { + return Double.parseDouble(defaultPanel.getMin()); + } + + protected Double getMax(DefaultContinuousPanelUI defaultPanel) { + return Double.parseDouble(defaultPanel.getMax()); + } + + protected void saveDiscret(String name, + String comment, String path, List<JComponent> components, + SimulAction action, boolean exist) { + List<Serializable> values = new ArrayList<Serializable>(); + for (JComponent c : components) { + values.add((Serializable) getComponentValue(c)); + } + action.addDiscreteFactor(name, comment, path, values, exist); + } + + /** + * Return value in swing component that could be next used into factor. + * + * @param component component + * @return factor value + */ + protected Object getComponentValue(JComponent component) { + Object result = null; + if (component instanceof JTextComponent) { + result = ((JTextComponent) component).getText(); + } else if (component instanceof MatrixPanelEditor) { + result = ((MatrixPanelEditor) component).getMatrix(); + } /*else if (component instanceof InputOneEquationUI) { + result = ((InputOneEquationUI) component).getEditor().getText();*/ + + if (log.isDebugEnabled()) { + log.debug("Value for component : " + component.getClass().getSimpleName() + " is " + result); + } + + return result; + } } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityUI.jaxx =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityUI.jaxx 2011-03-25 17:07:54 UTC (rev 3206) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityUI.jaxx 2011-03-25 17:13:30 UTC (rev 3207) @@ -31,11 +31,11 @@ </import> <script><![CDATA[ - protected void $afterCompleteSetup() { + /*protected void $afterCompleteSetup() { super.$afterCompleteSetup(); // both ParamsUI and SensitivityTabUI setContextValue(new SensitivityAction()); - } + }*/ /** * Refresh all simulation launch UI. Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/TableBlockingLayerUI.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/TableBlockingLayerUI.java 2011-03-25 17:07:54 UTC (rev 3206) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/TableBlockingLayerUI.java 2011-03-25 17:13:30 UTC (rev 3207) @@ -39,6 +39,7 @@ import org.jdesktop.jxlayer.plaf.AbstractLayerUI; import org.jdesktop.jxlayer.plaf.LayerUI; import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaEntityContextable; import fr.ifremer.isisfish.ui.input.InputContentUI; @@ -115,8 +116,8 @@ // test if sensitivity property is enabled SensitivityTableModel sensitivityModel = (SensitivityTableModel) model; - TopiaEntity value = (TopiaEntity) sensitivityTableModel.getBeanAtRow(rowIndex); - Class<? extends TopiaEntity> beanClass = value.getClass(); + TopiaEntityContextable value = (TopiaEntityContextable) sensitivityTableModel.getBeanAtRow(rowIndex); + Class<? extends TopiaEntityContextable> beanClass = value.getClass(); String property = sensitivityModel.getPropertyAtColumn(columnIndex); String sensitivityName = beanClass.getSimpleName().replaceFirst("Impl", "") + "." + property; @@ -128,7 +129,7 @@ log.debug("Clic done on an enabled factor : " + sensitivityName); } - parent.displayFactorWizard(tableSource, beanClass, value.getTopiaId(), property); + parent.getHandler().displayFactorWizard(parent, beanClass, value.getTopiaId(), property); } // mouse moved over table Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTreeCellRenderer.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTreeCellRenderer.java 2011-03-25 17:07:54 UTC (rev 3206) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTreeCellRenderer.java 2011-03-25 17:13:30 UTC (rev 3207) @@ -25,6 +25,8 @@ package fr.ifremer.isisfish.ui.sensitivity.model; +import static org.nuiton.i18n.I18n._; + import java.awt.Component; import java.util.HashMap; import java.util.Map; @@ -87,7 +89,10 @@ Factor factor = (Factor)value; if (value instanceof FactorGroup) { FactorGroup factorGroup = (FactorGroup)value; - if (!factorGroup.isMixed()) { // root + if (factorGroup.isMixed()) { // root + // non du facteur group principal (mixed) + text = _("isisfish.sensitivity.factors"); + } else { if (factorGroup.isDiscrete()) { icon = "d"; } @@ -98,6 +103,7 @@ icon = "x"; } icon +="g"; // group + text = factor.getName(); } } else { @@ -118,8 +124,8 @@ else if (domain instanceof MatrixContinuousDomain) { icon += "m"; } + text = factor.getName(); } - text = factor.getName(); } c.setIcon(iconCache.get(icon)); c.setText(text); Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java 2011-03-25 17:07:54 UTC (rev 3206) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java 2011-03-25 17:13:30 UTC (rev 3207) @@ -39,7 +39,6 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; @@ -96,6 +95,7 @@ import fr.ifremer.isisfish.simulator.sensitivity.domain.RuleDomain; import fr.ifremer.isisfish.ui.SimulationUI; import fr.ifremer.isisfish.ui.sensitivity.FactorWizardUI; +import fr.ifremer.isisfish.ui.sensitivity.SensitivityInputHandler; import fr.ifremer.isisfish.ui.util.ErrorHelper; /** @@ -116,23 +116,26 @@ private static final SimpleDateFormat DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd-HH-mm"); + /** Les parametres de simulation (commun a tous les onglet de l'interface de simulation). */ protected SimulationParameter param = null; + protected RegionStorage regionStorage = null; protected SimulationStorage simulStorage = null; protected List<String> oldSimulNames = null; protected String simulName = null; protected SensitivityStorage sensitivityStorage = null; - protected FactorGroup factorGroup = new FactorGroup(_("isisfish.sensitivity.factors"), true); - protected SortedMap<String, Factor> factors = new TreeMap<String, Factor>(); + /** List de facteur sous forme d'arbre (factor group). {@code null} name for compatibility with 3.3.0.0 */ + protected FactorGroup factorGroup = new FactorGroup(null, true); + //protected SortedMap<String, Factor> factors = new TreeMap<String, Factor>(); - /** + /* * @deprecated this is not a good idea to store factor source component in * case, and found a new component instance that can edit a factor (simulation reloading) - */ - protected Map<String, JComponent> factorComponent = new HashMap<String, JComponent>(); + * + protected Map<String, JComponent> factorComponent = new HashMap<String, JComponent>();*/ - protected DesignPlan designPlan = new DesignPlan(); + //protected DesignPlan designPlan = new DesignPlan(); /* ************ @@ -309,19 +312,19 @@ // Chargement des facteurs // clear list even if mexico file doesn't exists - factors.clear(); + //factors.clear(); File f = SimulationStorage.getMexicoDesignPlan(SimulationStorage.getSimulationDirectory(simulName)); if (f != null && f.canRead()) { if (log.isInfoEnabled()) { log.info("Import design plan from : " + f.getAbsolutePath()); } TopiaContext topiaContext = regionStorage.getStorage(); - designPlan = MexicoHelper.getDesignPlanFromXML(f, topiaContext); + DesignPlan designPlan = MexicoHelper.getDesignPlanFromXML(f, topiaContext); for (Factor factor : designPlan.getFactors()) { if (log.isDebugEnabled()) { log.debug("Find factor : " + factor.getName()); } - factors.put(factor.getPath() + factor.getName(), factor); + //factors.put(factor.getPath() + factor.getName(), factor); } } else { @@ -835,22 +838,79 @@ return factorGroup; } - public SortedMap<String, Factor> getFactors() { + /*public SortedMap<String, Factor> getFactors() { return factors; + }*/ + + /** + * Search factor in factor group tree by path. + * + * @param factorPath factor path to search + * @return found factor + */ + public Factor getFactor(String factorPath) { + return getFactor(factorGroup, factorPath); } - public void addFactor(Factor f, JComponent c) { + /** + * Recursive search for factor in factor group by path. + * + * @param factorGroup factor group to search to + * @param factorPath factor path to search + * @return found factor + */ + protected Factor getFactor(FactorGroup factorGroup, String factorPath) { + Factor result = null; + for (Factor factor : factorGroup.getFactors()) { + if (factor instanceof FactorGroup) { + result = getFactor((FactorGroup)factor, factorPath); + } + if (factorPath.equals(factor.getPath())) { + result = factor; + } + } + return result; + } + + /** + * Remove factor in factor group tree by path. + * + * @param factorPath factor path to remove + */ + public void removeFactor(String factorPath) { + removeFactor(factorGroup, factorPath); + } + + /** + * Recursive remove for factor in factor group by path. + * + * @param factorGroup factor group to search to + * @param factorPath factor path to remove + */ + protected void removeFactor(FactorGroup factorGroup, String factorPath) { + Collection<Factor> factorCopy = new ArrayList<Factor>(factorGroup.getFactors()); + for (Factor factor : factorCopy) { + if (factor instanceof FactorGroup) { + removeFactor((FactorGroup)factor, factorPath); + } + if (factorPath.equals(factor.getPath())) { + factorGroup.remove(factor); + } + } + } + + public void addFactor(Factor f) { if (log.isDebugEnabled()) { log.debug("Add factor (" + f.getName() + ") : " +f.getPath()); } factorGroup.addFactor(f); - factors.put(f.getPath() + f.getName(), f); - factorComponent.put(f.getPath() + f.getName(), c); - designPlan.setFactors(getFactorGroup().getFactors()); + //factors.put(f.getPath() + f.getName(), f); + //factorComponent.put(f.getPath() + f.getName(), c); + //designPlan.setFactors(getFactorGroup().getFactors()); } public void addContinuousFactor(String name, String comment, String path, Double min, - Double max, JComponent c, boolean exist) { + Double max, boolean exist) { Factor f = new Factor(name); ContinuousDomain domain = new ContinuousDomain(); domain.setMinBound(min); @@ -859,13 +919,13 @@ f.setComment(comment); f.setPath(path); if (exist) { - removeFactor(f); + removeFactor(path); } - addFactor(f, c); + addFactor(f); } public void addDiscreteFactor(String name, String comment, String path, - List<Serializable> values, JComponent c, boolean exist) { + List<Serializable> values, boolean exist) { Factor f = new Factor(name); DiscreteDomain domain = new DiscreteDomain(); int i = 0; @@ -880,14 +940,13 @@ f.setComment(comment); f.setPath(path); if (exist) { - removeFactor(f); + removeFactor(path); } - addFactor(f, c); + addFactor(f); } public void addContinuousEquationFactor(String name, String comment, String path, - EquationContinuousDomain domain, JComponent c, - boolean exist) { + EquationContinuousDomain domain, boolean exist) { // factor name need to be composed Factor f = new Factor(name + "." + domain.getVariableName()); f.setDomain(domain); @@ -896,14 +955,14 @@ //f.setPath(path + domain.getVariableName()); f.setPath(path); if (exist) { - removeFactor(f); + removeFactor(path); } - addFactor(f, c); + addFactor(f); } public void addContinuousMatrixFactor(String name, String comment, String path, Double coef, MatrixND matrix, - String operateur, JComponent c, boolean exist) { + String operateur, boolean exist) { Factor f = new Factor(name); MatrixContinuousDomain domain = new MatrixContinuousDomain(); domain.setMatrix(matrix); @@ -913,20 +972,20 @@ f.setDomain(domain); f.setPath(path); if (exist) { - removeFactor(f); + removeFactor(path); } - addFactor(f, c); + addFactor(f); } - public JComponent getFactorComponent(Factor f) { + /*public JComponent getFactorComponent(Factor f) { return factorComponent.get(f.getPath() + f.getName()); - } + }*/ - public void removeFactor(Factor f) { + /*public void removeFactor(Factor f) { factors.remove(f.getPath() + f.getName()); factorComponent.remove(f.getPath() + f.getName()); - designPlan.setFactors(getFactorGroup().getFactors()); - } + //designPlan.setFactors(getFactorGroup().getFactors()); + }*/ /* ************ @@ -998,15 +1057,13 @@ * @param simulationId id of the simulation to simulate * @param launcher launcher to use * @param sensitivityCalculator sensitivity calculator to use - * @param designPlan design plan for this simulation * * @see SimulatorLauncher * @see SensitivityCalculator * @see DesignPlan */ public void launchSimulation(String simulationId, - SimulatorLauncher launcher, - SensitivityCalculator sensitivityCalculator, DesignPlan designPlan) { + SimulatorLauncher launcher, SensitivityCalculator sensitivityCalculator) { String fullSimulationId = "as_" + simulationId + "_" + DATEFORMAT.format(new java.util.Date()); @@ -1026,6 +1083,8 @@ ErrorHelper.showErrorDialog(_("isisfish.simulator.simulaction.badid", fullSimulationId), null); } else { + DesignPlan designPlan = new DesignPlan(); + designPlan.setFactorGroup(factorGroup); SimulationService.getService().submit(fullSimulationId, param, launcher, 0, sensitivityCalculator, designPlan); } @@ -1039,8 +1098,7 @@ public void launchSimulationWithSensibility(String simulationId, SimulatorLauncher launcher) { - launchSimulation(simulationId, launcher, getSensitivityCalculator(), - designPlan); + launchSimulation(simulationId, launcher, getSensitivityCalculator()); } /** @@ -1192,10 +1250,11 @@ // new factor with rule domain if (source instanceof RuleChooser) { - selectedFactor = getFactors().get("parameters.rules"); + String factorName = "parameters.rules"; + selectedFactor = getFactor(factorName); if (selectedFactor == null) { - selectedFactor = new Factor("parameters.rules"); - selectedFactor.setPath("parameters.rules"); + selectedFactor = new Factor(factorName); + selectedFactor.setPath(factorName); selectedFactor.setDomain(new RuleDomain()); } } @@ -1204,7 +1263,7 @@ else if (source instanceof MatrixPanelEditor) { Population population = (Population)source.getClientProperty("sensitivityPopulation"); String factorName = "parameters.population." + population.getName(); - selectedFactor = getFactors().get(factorName); + selectedFactor = getFactor(factorName); if (selectedFactor == null) { selectedFactor = new Factor(factorName); selectedFactor.setPath(factorName); @@ -1217,9 +1276,10 @@ if (selectedFactor != null) { FactorWizardUI wizard = new FactorWizardUI(paramsUI); - wizard.initExisting(source, selectedFactor); + SensitivityInputHandler handler = wizard.getHandler(); + handler.initExistingFactor(wizard, selectedFactor); wizard.pack(); - wizard.setLocationRelativeTo(paramsUI); + wizard.setLocationRelativeTo(source); wizard.setVisible(true); } } Deleted: isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelperTest.java =================================================================== --- isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelperTest.java 2011-03-25 17:07:54 UTC (rev 3206) +++ isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelperTest.java 2011-03-25 17:13:30 UTC (rev 3207) @@ -1,76 +0,0 @@ -/* - * #%L - * IsisFish - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 Ifremer, Code Lutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 2 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 Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-2.0.html>. - * #L% - */ - -package fr.ifremer.isisfish.ui.sensitivity; - -import javax.swing.JComponent; -import javax.swing.JTextField; - -import org.junit.Assert; -import org.junit.Test; -import org.nuiton.math.matrix.MatrixND; -import org.nuiton.math.matrix.MatrixNDImpl; -import org.nuiton.math.matrix.gui.MatrixPanelEditor; - -import fr.ifremer.isisfish.AbstractIsisFishTest; -import fr.ifremer.isisfish.entities.Equation; -import fr.ifremer.isisfish.ui.input.InputOneEquationUI; - -/** - * Test for {@link EditorHelper} class. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class EditorHelperTest extends AbstractIsisFishTest { - - /** - * Test that editor for given type are those excepted. - */ - @Test - public void testGetEditorForType() { - - JComponent result = EditorHelper.getEditorForType(double.class); - Assert.assertTrue(result instanceof JTextField); - - result = EditorHelper.getEditorForType(Double.class); - Assert.assertTrue(result instanceof JTextField); - - result = EditorHelper.getEditorForType(MatrixND.class); - Assert.assertTrue(result instanceof MatrixPanelEditor); - - result = EditorHelper.getEditorForType(MatrixNDImpl.class); - Assert.assertTrue(result instanceof MatrixPanelEditor); - - result = EditorHelper.getEditorForType(Equation.class); - Assert.assertTrue(result instanceof InputOneEquationUI); - - //result = EditorHelper.getEditorForType(PopulationReproductionEquation.class); - //Assert.assertTrue(result instanceof InputOneEquationUI); - } -}
participants (1)
-
chatellier@users.labs.libre-entreprise.org