Author: chatellier Date: 2011-03-22 14:57:49 +0000 (Tue, 22 Mar 2011) New Revision: 3194 Log: Implementation des groupes de facteurs (drag'n'drop) Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTranferable.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTransferHandler.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTree.java Modified: 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/FactorWizardUI.jaxx 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/SensitivityInputHandler.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabUI.jaxx 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/model/FactorCardinalityTableModel.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/sensitivity/model/FactorTreeModel.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/package-info.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooser.jaxx 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/sensitivity/EditorHelper.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelper.java 2011-03-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/EditorHelper.java 2011-03-22 14:57:49 UTC (rev 3194) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2009 - 2010 Ifremer, CodeLutin + * 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 @@ -39,7 +39,6 @@ import javax.swing.JTextField; import javax.swing.text.JTextComponent; -import jaxx.runtime.JAXXContext; import jaxx.runtime.context.JAXXInitialContext; import jaxx.runtime.swing.editor.NumberEditor; @@ -55,9 +54,9 @@ import org.nuiton.topia.persistence.TopiaEntityContextable; import fr.ifremer.isisfish.entities.Equation; -import fr.ifremer.isisfish.entities.Formule; 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; @@ -75,6 +74,7 @@ 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; /** @@ -126,7 +126,16 @@ } else if (result instanceof MatrixEditor) { MatrixEditor ui = (MatrixEditor) component; - MatrixND m = (MatrixND) getMethodValue(entity, fieldName); + + 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()); @@ -454,7 +463,7 @@ ui.setClazz(origine.getClazz()); /// ??? was not set before ui.setBeanProperty(origine.getBeanProperty()); - ui.setFormule((Formule) value); + ui.setFormule(origine.getFormule()); ui.setActive(true); ui.refresh(); result = ui; @@ -533,6 +542,10 @@ 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()) { 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-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/FactorWizardUI.jaxx 2011-03-22 14:57:49 UTC (rev 3194) @@ -27,6 +27,7 @@ <import> org.apache.commons.lang.StringUtils; org.nuiton.topia.persistence.TopiaEntityContextable; + fr.ifremer.isisfish.ui.SimulationUI; fr.ifremer.isisfish.ui.simulator.SimulAction; fr.ifremer.isisfish.ui.input.InputSaveVerifier; fr.ifremer.isisfish.simulator.sensitivity.Factor; @@ -34,21 +35,22 @@ fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain; fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain; - jaxx.runtime.JAXXUtil; java.beans.PropertyChangeEvent; java.beans.PropertyChangeListener; java.util.SortedMap javax.swing.JComponent </import> + <Boolean id='continuePossible' javaBean='true'/> <Boolean id='continueSelected' javaBean='false'/> + + <Boolean id='discretePossible' javaBean='true'/> <Boolean id='existingValue' javaBean='false'/> <script><![CDATA[ - protected JComponent cOrigine = null; protected TopiaEntityContextable bean = null; protected java.util.List<JComponent> discretComponents = new ArrayList<JComponent>(); @@ -76,9 +78,9 @@ }); } -public void initNew(JComponent c, TopiaEntityContextable be, Boolean b) { +public void initNew(JComponent source, TopiaEntityContextable be, boolean continuePossible) { this.bean = be; - this.cOrigine = c; + this.cOrigine = source; // path is topiaId#property // ex : fwn#fsd#0.3425345#name @@ -87,11 +89,16 @@ String methodName = StringUtils.uncapitalize(EditorHelper.getMethod(cOrigine)); this.path = bean.getTopiaId() + "#" + methodName; - factorName.setText(bean.toString() + "." + methodName); - setContinuePossible(b); + 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); @@ -116,6 +123,9 @@ setContinueSelected(EditorHelper.isContinue(cOrigine)); } +/** + * Reaffiche un facteur existant. + */ public void initExisting(JComponent cOrigine, Factor f) { setExistingValue(true); this.cOrigine = cOrigine; @@ -124,20 +134,18 @@ Domain domain = f.getDomain(); this.factor = f; + String factorName = f.getName(); if (domain instanceof ContinuousDomain) { if (domain instanceof EquationContinuousDomain) { EquationContinuousDomain equationDomain = (EquationContinuousDomain)domain; - String factorName2 = f.getName(); + + // 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(); - if (factorName2.endsWith(suffix)) { - factorName2 = factorName2.substring(0, factorName2.length()-suffix.length()); - } - factorName.setText(factorName2); + factorName = StringUtils.removeEnd(factorName, suffix); } - else { - // for other ContinuousDomain name is the same - factorName.setText(f.getName()); - } + ContinuousDomain cDomain = (ContinuousDomain) domain; continuousPanel = EditorHelper.getContinuousPanelWithValue(cOrigine, cDomain, f); @@ -148,9 +156,6 @@ setContinuePossible(true); } else { - // discret fator, name is the same - factorName.setText(f.getName()); - DiscreteDomain dDomain = (DiscreteDomain)domain; int nb = dDomain.getValues().size(); @@ -177,9 +182,16 @@ tabPane.addTab("Factor " + i, js); } setContinuePossible(EditorHelper.canBeContinue(cOrigine, cache)); - - this.pack(); } + + 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); @@ -208,16 +220,18 @@ } protected void save() { if (continueRadio.isSelected()) { - getSensitivityAction().saveContinue(cOrigine, factorName.getText(), comment.getText(), path, continuousPanel, getSimulAction(), isExistingValue()); + getSensitivityAction().saveContinue(cOrigine, factorNameField.getText(), + comment.getText(), path, continuousPanel, getSimulAction(), isExistingValue()); } else { - getSensitivityAction().saveDiscret(cOrigine, factorName.getText(), comment.getText(), path, discretComponents, getSimulAction(), isExistingValue()); + getSensitivityAction().saveDiscret(cOrigine, factorNameField.getText(), + comment.getText(), path, discretComponents, getSimulAction(), isExistingValue()); } - getContextValue(SensitivityTabUI.class, JAXXUtil.PARENT).setFactorModel(); + getContextValue(SimulationUI.class, "SimulationUI").refreshFactorTree(); exit(); } protected void remove() { getSimulAction().removeFactor(factor); - getContextValue(SensitivityTabUI.class, JAXXUtil.PARENT).setFactorModel(); + getContextValue(SimulationUI.class, "SimulationUI").refreshFactorTree(); exit(); } protected void exit() { @@ -227,54 +241,60 @@ </script> <Table constraints='BorderLayout.CENTER'> <row> - <cell columns='1' fill='horizontal'> + <cell fill='horizontal'> <JLabel text='isisfish.sensitivity.name'/> </cell> - <cell columns='3' fill='horizontal'> - <JTextField id='factorName'/> + <cell columns='2' fill='horizontal'> + <JTextField id='factorNameField'/> </cell> </row> <row> - <cell columns='4' fill='horizontal'> - <JRadioButton id='continueRadio' text='isisfish.sensitivity.continue' - buttonGroup='factorType' visible='{isContinuePossible()}' selected='{false}' onActionPerformed='setContinueSelected(continueRadio.isSelected())'/> + <cell columns='3' fill='both' weightx='1' weighty='3'> + <JPanel layout="{new BorderLayout()}" visible='{isContinuePossible()}'> + <JRadioButton id='continueRadio' text='isisfish.sensitivity.continue' + buttonGroup='factorType' selected='{false}' + onActionPerformed='setContinueSelected(continueRadio.isSelected())' + constraints="BorderLayout.NORTH"/> + <JPanel id='continuousPanelContainer' layout='{new BorderLayout()}' + constraints="BorderLayout.CENTER"/> + </JPanel> </cell> </row> <row> - <cell columns='4' fill='both' weightx='1' weighty='2'> - <JPanel id='continuousPanelContainer' layout='{new BorderLayout()}'/> + <cell columns='3' fill='both' weightx='1' weighty='3'> + <JPanel layout="{new BorderLayout()}"> + <JRadioButton id='discret' text='isisfish.sensitivity.discret' + selected='{true}' buttonGroup='factorType' + onActionPerformed='setContinueSelected(continueRadio.isSelected())' + constraints="BorderLayout.NORTH"/> + <Table id='discretePanelContainer' constraints="BorderLayout.CENTER"> + <row> + <cell fill='horizontal'> + <JLabel text='isisfish.sensitivity.selectDiscretNumber' enabled='{!isContinueSelected()}'/> + </cell> + <cell fill='horizontal' weightx='1'> + <JTextField id='discretNumber' enabled='{!isContinueSelected()}'/> + </cell> + <cell fill='horizontal'> + <JButton text='isisfish.sensitivity.validDiscretNumber' enabled='{!isContinueSelected()}' onActionPerformed='addTabs(discretNumber.getText())'/> + </cell> + </row> + <row> + <cell columns='3' fill='both' weightx='1' weighty='2'> + <JTabbedPane id='tabPane' visible='{!isContinueSelected()}' enabled='{!isContinueSelected()}'/> + </cell> + </row> + </Table> + </JPanel> </cell> </row> <row> - <cell columns='4' fill='horizontal'> - <JRadioButton id='discret' text='isisfish.sensitivity.discret' - selected='{true}' buttonGroup='factorType' - onActionPerformed='setContinueSelected(continueRadio.isSelected())'/> - </cell> - </row> - <row> - <cell fill='horizontal'> - <JLabel text='isisfish.sensitivity.selectDiscretNumber' enabled='{!isContinueSelected()}'/> - </cell> - <cell fill='horizontal'> - <JTextField id='discretNumber' enabled='{!isContinueSelected()}'/> - </cell> - <cell columns='2' fill='horizontal'> - <JButton text='isisfish.sensitivity.validDiscretNumber' enabled='{!isContinueSelected()}' onActionPerformed='addTabs(discretNumber.getText())'/> - </cell> - </row> - <row> - <cell columns='4' fill='both' weightx='1' weighty='2'> - <JTabbedPane id='tabPane' visible='{!isContinueSelected()}' enabled='{!isContinueSelected()}'/> - </cell> - </row> - <row> - <cell columns='4' fill='horizontal'> + <cell columns='3' fill='horizontal'> <JLabel text='isisfish.sensitivity.comment'/> </cell> </row> <row> - <cell columns='4' fill='both' weighty='1'> + <cell columns='3' fill='both' weighty='1'> <JScrollPane> <JTextArea id='comment'/> </JScrollPane> @@ -287,8 +307,8 @@ <cell fill='horizontal'> <JButton id='remove' text='isisfish.common.remove' visible='{isExistingValue()}' onActionPerformed='remove()'/> </cell> - <cell columns='2' fill='horizontal'> - <JButton id='save' text='isisfish.common.save' enabled='{!getFactorName().getText().isEmpty()}' onActionPerformed='save()'/> + <cell fill='horizontal'> + <JButton id='save' text='isisfish.common.save' enabled='{!getFactorNameField().getText().isEmpty()}' onActionPerformed='save()'/> </cell> </row> </Table> Modified: 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-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityAction.java 2011-03-22 14:57:49 UTC (rev 3194) @@ -39,14 +39,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.math.matrix.MatrixND; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaEntityAbstract; import org.nuiton.topia.persistence.TopiaEntityContextable; -import fr.ifremer.isisfish.IsisFishDAOHelper; -import fr.ifremer.isisfish.entities.Equation; -import fr.ifremer.isisfish.entities.EquationDAO; import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain; import fr.ifremer.isisfish.ui.simulator.SimulAction; 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-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java 2011-03-22 14:57:49 UTC (rev 3194) @@ -1,37 +1,46 @@ /* * #%L - * - * * $Id$ * $HeadURL$ * %% * Copyright (C) 2011 Codelutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the + * 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 Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public + * You should have received a copy of the GNU General Public * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * <http://www.gnu.org/licenses/gpl-2.0.html>. * #L% */ package fr.ifremer.isisfish.ui.sensitivity; +import static org.nuiton.i18n.I18n._; + import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.util.List; +import javax.swing.JComponent; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPopupMenu; import javax.swing.event.TreeSelectionEvent; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; @@ -39,9 +48,10 @@ import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.entities.FisheryRegion; +import fr.ifremer.isisfish.simulator.sensitivity.Factor; +import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; import fr.ifremer.isisfish.ui.input.InputContentUI; import fr.ifremer.isisfish.ui.input.InputHandler; -import fr.ifremer.isisfish.ui.input.InputUI; import fr.ifremer.isisfish.ui.input.tree.FisheryDataProvider; import fr.ifremer.isisfish.ui.input.tree.FisheryTreeHelper; import fr.ifremer.isisfish.ui.input.tree.FisheryTreeNode; @@ -146,4 +156,155 @@ } } } + + /** + * Add new factor group in factor tree. + * + * @param sensitivityTabUI + */ + public void addNewFactorGroup(SensitivityTabUI sensitivityTabUI) { + String factorName = JOptionPane.showInputDialog(sensitivityTabUI, _("isisfish.sensitivity.newfactorname"), + _("isisfish.sensitivity.title"), JOptionPane.QUESTION_MESSAGE); + + if (StringUtils.isNotBlank(factorName)) { + FactorGroup rootFactorGroup = sensitivityTabUI.getSimulAction().getFactorGroup(); + FactorGroup factorGroup = new FactorGroup(factorName); + rootFactorGroup.addFactor(factorGroup); + sensitivityTabUI.setFactorModel(); + } + } + + /** + * Move factors to another factorgroup. + * + * @param sensitivityTabUI + * @param selectedFactorGroup + * @param movedFactors + */ + public void moveFactor(SensitivityTabUI sensitivityTabUI, FactorGroup selectedFactorGroup, List<Factor> movedFactors) { + try { + // add all factors, to do first, throw + // exception if can't be done + selectedFactorGroup.addAllFactors(movedFactors); + + // remove duplicated from factor group + FactorGroup rootFactorGroup = sensitivityTabUI.getSimulAction().getFactorGroup(); + if (!rootFactorGroup.equals(selectedFactorGroup)) { + rootFactorGroup.removeAll(movedFactors); + } + for (int index = 0 ; index < rootFactorGroup.size(); ++index) { + Factor factor = rootFactorGroup.get(index); + if (factor instanceof FactorGroup) { + FactorGroup factorGroup = (FactorGroup)factor; + if (!factorGroup.equals(selectedFactorGroup)) { + factorGroup.removeAll(movedFactors); + } + } + } + sensitivityTabUI.setFactorModel(); + } catch (IllegalArgumentException ex) { + JOptionPane.showMessageDialog(sensitivityTabUI, _("isisfish.sensitivity.moveillegal"), + _("isisfish.sensitivity.title"), JOptionPane.ERROR_MESSAGE); + } + } + + /** + * Mouse click on factors tree. + * + * <ul> + * <li>normal click : factor edit</li> + * <li>right click : popup menu</li> + * </ul> + * + * @param sensitivityTabUI ui + * @param e mouse event + */ + public void factorsTreeMouseClicked(final SensitivityTabUI sensitivityTabUI, MouseEvent e) { + // clic droit + if (e.getButton() == MouseEvent.BUTTON3) { + JPopupMenu menu = new JPopupMenu(); + JMenuItem menuItemDelete = new JMenuItem(_("isisfish.common.delete")); + menuItemDelete.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + deleteSelectedFactors(sensitivityTabUI); + } + }); + menu.add(menuItemDelete); + menu.show(e.getComponent(), e.getX(), e.getY()); + } + else if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { + // autre double clic + factorSelected(sensitivityTabUI); + } + } + + /** + * Factor selection, display modification wizard. + * + * @param sensitivityTabUI + */ + protected void factorSelected(SensitivityTabUI sensitivityTabUI) { + // get selected factor + TreePath selectedPath = sensitivityTabUI.getFactorsTree().getSelectionPath(); + Object[] pathWay = selectedPath.getPath(); + Object selectedObject = pathWay[pathWay.length - 1]; + + if (selectedObject != null) { + if (!(selectedObject instanceof FactorGroup)) { + Factor selectedFactor = (Factor)selectedObject; + FactorWizardUI wizard = new FactorWizardUI(sensitivityTabUI); + + JComponent component = sensitivityTabUI.getSimulAction().getFactorComponent(selectedFactor); + if (component != null) { + wizard.initExisting(component, selectedFactor); + wizard.pack(); + wizard.setLocationRelativeTo(sensitivityTabUI); + wizard.setVisible(true); + } + 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) { + 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()); + } + } + } + } + } + } + + /** + * Delete selection factor. + */ + protected void deleteSelectedFactors(SensitivityTabUI sensitivityTabUI) { + // get selected factor + TreePath selectedPath = sensitivityTabUI.getFactorsTree().getSelectionPath(); + Object[] pathWay = selectedPath.getPath(); + Object selectedObject = pathWay[pathWay.length - 1]; + + if (selectedObject != null) { + if (selectedObject instanceof Factor) { + Factor selectedFactor = (Factor)selectedObject; + if (log.isDebugEnabled()) { + log.debug("Deleting factor " + selectedFactor.getName()); + } + sensitivityTabUI.getSimulAction().removeFactor(selectedFactor); + sensitivityTabUI.setFactorModel(); + } + } + } } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabUI.jaxx =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabUI.jaxx 2011-03-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityTabUI.jaxx 2011-03-22 14:57:49 UTC (rev 3194) @@ -36,9 +36,10 @@ fr.ifremer.isisfish.ui.input.InputAction; fr.ifremer.isisfish.ui.input.InputSaveVerifier; fr.ifremer.isisfish.ui.simulator.SimulAction; - fr.ifremer.isisfish.simulator.sensitivity.group.FactorGroup; + fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; fr.ifremer.isisfish.ui.sensitivity.model.FactorTreeModel; fr.ifremer.isisfish.ui.sensitivity.model.FactorTreeCellRenderer; + fr.ifremer.isisfish.ui.sensitivity.model.FactorTree javax.swing.JComponent java.awt.event.ActionListener javax.swing.JMenuItem @@ -49,13 +50,6 @@ <fr.ifremer.isisfish.entities.FisheryRegion id='fisheryRegion' javaBean='null'/> <script><![CDATA[ - - -protected void $afterCompleteSetup() { - // end code constructor - //getVerifier().setSensPanel(this); -} - protected InputAction getInputAction() { return getContextValue(InputAction.class); } @@ -72,67 +66,7 @@ return getContextValue(RegionStorage.class); } -/** - * Mouse click on factors tree. - * - * <ul> - * <li>normal click : factor edit</li> - * <li>right click : popup menu</li> - * </ul> - */ -public void factorsTreeMouseClicked(MouseEvent e) { - // clic droit - if (e.getButton() == MouseEvent.BUTTON3) { - JPopupMenu menu = new JPopupMenu(); - JMenuItem menuItemDelete = new JMenuItem(_("isisfish.common.delete")); - menuItemDelete.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - deleteSelectedFactors(); - } - }); - menu.add(menuItemDelete); - menu.show(e.getComponent(), e.getX(), e.getY()); - } - else { - // autre clic - factorSelected(); - } -} -protected void factorSelected() { - Object selectedObject = factorsTree.getSelectionValue(); - if (selectedObject != null) { - if (selectedObject instanceof Factor) { - Factor selectedFactor = (Factor)selectedObject; - FactorWizardUI wizard = new FactorWizardUI(this); - JComponent component = getSimulAction().getFactorComponent(selectedFactor); - if (component != null) { - wizard.initExisting(component, selectedFactor); - wizard.pack(); - wizard.setVisible(true); - } - else { - - // method 2 - JComponent component2 = EditorHelper.getEditorForFactor(selectedFactor, getFisheryRegion().getTopiaContext()); - if (component2 != null) { - if (log.isDebugEnabled()) { - log.debug("Component found is " + component2); - } - wizard.initExisting(component2, selectedFactor); - wizard.pack(); - wizard.setVisible(true); - } - else { - if (log.isDebugEnabled()) { - log.debug("No component found, skip edition of factor " + selectedFactor.getName()); - } - } - } - } - } -} public void setTreeModel() { if (getFisheryRegion() != null) { getCardlayoutPrincipal().show(inputPanePrincipal,"normale"); @@ -154,24 +88,8 @@ FactorGroup factorGroup = getSimulAction().getFactorGroup(); FactorTreeModel model = new FactorTreeModel(factorGroup); factorsTree.setModel(model); - factorsTree.setRootVisible(true); getParentContainer(SensitivityUI.class).getSensitivityChooserUI().setFactorCardinalityTableModel(); } - -protected void deleteSelectedFactors() { - Object selectedObject = factorsTree.getSelectionValue(); - - if (selectedObject != null) { - if (selectedObject instanceof Factor) { - Factor selectedFactor = (Factor)selectedObject; - if (log.isDebugEnabled()) { - log.debug("Deleting factor " + selectedFactor.getName()); - } - getSimulAction().removeFactor(selectedFactor); - setFactorModel(); - } - } -} ]]> </script> <JSplitPane oneTouchExpandable="true" dividerLocation="200" orientation="HORIZONTAL" constraints='BorderLayout.CENTER'> @@ -187,20 +105,19 @@ </JScrollPane> <Table> <row> - <cell> - <JButton icon="table.png" /> - </cell> <cell anchor='west' weightx='1.0'> - <JButton icon="table_multiple.png" /> + <JButton icon="table_multiple.png" toolTipText="isisfish.sensitivity.newfactorgroup.tip" + onActionPerformed="getHandler().addNewFactorGroup(this)"/> </cell> </row> <row> <cell columns='2' fill="both" weightx='1.0' weighty='1.0'> <JScrollPane> - <JAXXTree id="factorsTree" rootVisible="true" selectionRow='0' - model='{new DefaultTreeModel(null)}' + <FactorTree id="factorsTree" constructorParams='this' + rootVisible="true" selectionRow='0' + model='{new FactorTreeModel(getSimulAction().getFactorGroup())}' cellRenderer='{new FactorTreeCellRenderer()}' - onMouseClicked='factorsTreeMouseClicked(event)'/> + onMouseClicked='getHandler().factorsTreeMouseClicked(this, event)'/> </JScrollPane> </cell> </row> 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-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityUI.jaxx 2011-03-22 14:57:49 UTC (rev 3194) @@ -31,6 +31,12 @@ </import> <script><![CDATA[ + protected void $afterCompleteSetup() { + super.$afterCompleteSetup(); + // both ParamsUI and SensitivityTabUI + setContextValue(new SensitivityAction()); + } + /** * Refresh all simulation launch UI. */ @@ -60,14 +66,20 @@ public void setEnabledAnalysePlanTab(boolean selected) { // no analyse plan in AS } + + @Override + public void refreshFactorTree() { + sensitivityTabUI.setFactorModel(); + } ]]></script> <JTabbedPane id="bodyTabbedPane"> <tab title='isisfish.params.title'> - <fr.ifremer.isisfish.ui.simulator.ParamsUI id='paramsUI' sensitivity='{true}' regionStorage="{getRegionStorage()}" constructorParams='this'/> + <fr.ifremer.isisfish.ui.simulator.ParamsUI id='paramsUI' sensitivity='{true}' regionStorage="{getRegionStorage()}" + constructorParams='new JAXXInitialContext().add(new InputAction()).add(new InputSaveVerifier()).add("SimulationUI", this).add(this)'/> </tab> <tab title='isisfish.sensitivity.title' enabled="false"> <fr.ifremer.isisfish.ui.sensitivity.SensitivityTabUI id="sensitivityTabUI" - constructorParams='new JAXXInitialContext().add(new InputAction()).add(new SensitivityAction()).add(new InputSaveVerifier()).add(this)'/> + constructorParams='new JAXXInitialContext().add(new InputAction()).add(new InputSaveVerifier()).add("SimulationUI", this).add(this)'/> </tab> <tab title='isisfish.sensitivityChooser.title' enabled="false"> <SensitivityChooserUI id="sensitivityChooserUI" constructorParams='this'/> Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorCardinalityTableModel.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorCardinalityTableModel.java 2011-03-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorCardinalityTableModel.java 2011-03-22 14:57:49 UTC (rev 3194) @@ -1,20 +1,27 @@ -/* *##% - * Copyright (C) 2009 - 2010 Ifremer, Code Lutin - * - * 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. - * +/* + * #%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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * + * 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.model; Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTranferable.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTranferable.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTranferable.java 2011-03-22 14:57:49 UTC (rev 3194) @@ -0,0 +1,119 @@ +/* + * #%L + * Isis-Fish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2011 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.model; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import fr.ifremer.isisfish.simulator.sensitivity.Factor; + +/** + * Represent transfered data. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ By : $Author$ + */ +public class FactorTranferable implements Transferable { + + /** log */ + private static Log log = LogFactory.getLog(FactorTranferable.class); + + /** Data transfer mime type */ + protected static final String MIMETYPE = DataFlavor.javaJVMLocalObjectMimeType + + ";class=" + Factor.class.getName(); + + /** Data instance */ + protected static DataFlavor myData; + + /** Factors to transfer. Chosen implementation must be serializable. */ + protected List<Factor> factorsToTransfer; + + /** + * Constructor. + * + * @param factorsToTransfer factors to transfer + */ + public FactorTranferable(List<Factor> factorsToTransfer) { + + // save task + this.factorsToTransfer = factorsToTransfer; + + // build new DataFlavor + try { + myData = new DataFlavor(MIMETYPE); + } catch (ClassNotFoundException e) { + if (log.isErrorEnabled()) { + log.error("Class not found", e); + } + } + } + + /* + * @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor) + */ + @Override + public Object getTransferData(DataFlavor flavor) + throws UnsupportedFlavorException, IOException { + + List<Factor> factorsToTransfer = null; + + if (flavor == null) { + throw new IOException("flavor is null"); + } + + if (flavor.equals(myData)) { + factorsToTransfer = this.factorsToTransfer; + } else { + throw new UnsupportedFlavorException(flavor); + } + + return factorsToTransfer; + } + + /* + * @see java.awt.datatransfer.Transferable#getTransferDataFlavors() + */ + @Override + public DataFlavor[] getTransferDataFlavors() { + return new DataFlavor[] { myData }; + } + + /* + * @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor) + */ + @Override + public boolean isDataFlavorSupported(DataFlavor flavor) { + return flavor.equals(myData); + } +} Property changes on: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTranferable.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTransferHandler.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTransferHandler.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTransferHandler.java 2011-03-22 14:57:49 UTC (rev 3194) @@ -0,0 +1,173 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2011 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.model; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import javax.swing.JComponent; +import javax.swing.TransferHandler; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import fr.ifremer.isisfish.simulator.sensitivity.Factor; +import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; +import fr.ifremer.isisfish.ui.sensitivity.SensitivityTabUI; + +/** + * Transfer handler used to transfer tasks in table. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ By : $Author$ + */ +public class FactorTransferHandler extends TransferHandler { + + /** serialVersionUID. */ + private static final long serialVersionUID = 5433321973795969278L; + + /** log. */ + private static Log log = LogFactory.getLog(FactorTransferHandler.class); + + /** Associated ui */ + protected SensitivityTabUI sensitivityTabUI; + + /** + * Constructor. + * + * @param sensitivityTabUI associated ui + */ + public FactorTransferHandler(SensitivityTabUI sensitivityTabUI) { + this.sensitivityTabUI = sensitivityTabUI; + } + + @Override + public boolean canImport(JComponent cp, DataFlavor[] df) { + + for (DataFlavor dataFlavor : df) { + if (dataFlavor.equals(FactorTranferable.myData)) { + return true; + } + } + + return false; + } + + @Override + public boolean importData(JComponent component, Transferable transferable) { + + boolean confirmImport = false; + + /*if (transferable.isDataFlavorSupported(FactorTranferable.myData)) { + try { + + FactorTree factorTree = (FactorTree) component; + FactorGroup selectedFactorGroup = factorTree.getSelectedFactorGroup(); + + if (selectedFactorGroup != null) { + Object myObject = transferable.getTransferData(FactorTranferable.myData); + List<Factor> movedFactors = (List<Factor>) myObject; + } + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Exception while transfering task", e); + } + } catch (UnsupportedFlavorException e) { + if (log.isErrorEnabled()) { + log.error("Exception while transfering task", e); + } + } + }*/ + + confirmImport = true; + + return confirmImport; + + } + + /** + * Get selected task in tree, and build Transferable object for it. + * + * @param cp component + * @return transferable instance for selected task + */ + @Override + protected Transferable createTransferable(JComponent cp) { + + Transferable transferable = null; + + FactorTree factorTree = (FactorTree) cp; + // only task can be moved ! + List<Factor> selectedFactors = factorTree.getSelectedFactors(); + if (selectedFactors != null && !selectedFactors.isEmpty()) { + List<Factor> factors = new LinkedList<Factor>(selectedFactors); + transferable = new FactorTranferable(factors); + } + + return transferable; + } + + @Override + protected void exportDone(JComponent cp, Transferable transferable, int type) { + if (log.isDebugEnabled()) { + log.debug("Transfert done"); + } + + if (type == TransferHandler.MOVE) { + + try { + FactorTree factorTree = (FactorTree) cp; + // elements here, task can be move to task or projects + FactorGroup selectedFactorGroup = factorTree.getSelectedFactorGroup(); + + if (selectedFactorGroup != null) { + Object myObject = transferable.getTransferData(FactorTranferable.myData); + List<Factor> movedFactors = (List<Factor>) myObject; + sensitivityTabUI.getHandler().moveFactor(sensitivityTabUI, selectedFactorGroup, movedFactors); + } + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Exception while transfering task", e); + } + } catch (UnsupportedFlavorException e) { + if (log.isErrorEnabled()) { + log.error("Exception while transfering task", e); + } + } + } + } + + @Override + public int getSourceActions(JComponent component) { + return MOVE; + } +} Property changes on: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTransferHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTree.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTree.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTree.java 2011-03-22 14:57:49 UTC (rev 3194) @@ -0,0 +1,120 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 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.model; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JTree; +import javax.swing.tree.TreePath; + +import fr.ifremer.isisfish.simulator.sensitivity.Factor; +import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; +import fr.ifremer.isisfish.ui.sensitivity.SensitivityTabUI; + +/** + * Factor tree. + * + * Add drag and drop support. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class FactorTree extends JTree { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1999481128072081972L; + + /** + * Constructor (add drag and drop). + * + * @param sensitivityTabUI parent ui + */ + public FactorTree(SensitivityTabUI sensitivityTabUI) { + // enable drag n drop + setDragEnabled(true); + setTransferHandler(new FactorTransferHandler(sensitivityTabUI)); + } + + /** + * Return selected factor group. + * + * @return selected factor group + */ + public FactorGroup getSelectedFactorGroup() { + + FactorGroup factorGroup = null; + + TreePath[] selectedPaths = getSelectionModel().getSelectionPaths(); + if (selectedPaths != null) { + for (TreePath selectedPath : selectedPaths) { + if (selectedPath != null) { + Object[] pathWay = selectedPath.getPath(); + + if (pathWay[pathWay.length - 1] instanceof FactorGroup) { + if (factorGroup == null) { + factorGroup = (FactorGroup)pathWay[pathWay.length - 1]; + } + else { + // multiselection de factor group + // on retourne rien + factorGroup = null; + break; + } + } + } + } + } + + return factorGroup; + } + + /** + * Return selected factors. + * + * @return selected factors + */ + public List<Factor> getSelectedFactors() { + + List<Factor> factors = new ArrayList<Factor>(); + + TreePath[] selectedPaths = getSelectionModel().getSelectionPaths(); + if (selectedPaths != null) { + for (TreePath selectedPath : selectedPaths) { + if (selectedPath != null) { + Object[] pathWay = selectedPath.getPath(); + + if (!(pathWay[pathWay.length - 1] instanceof FactorGroup)) { + factors.add((Factor)pathWay[pathWay.length - 1]); + } + } + } + } + + return factors; + } +} Property changes on: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTree.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL 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-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTreeCellRenderer.java 2011-03-22 14:57:49 UTC (rev 3194) @@ -1,30 +1,47 @@ -/* *##% - * Copyright (C) 2009 - 2010 Ifremer, Code Lutin - * - * 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. - * +/* + * #%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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * + * 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.model; import java.awt.Component; +import java.util.HashMap; +import java.util.Map; +import javax.swing.Icon; import javax.swing.JLabel; import javax.swing.JTree; import javax.swing.tree.DefaultTreeCellRenderer; +import org.nuiton.util.Resource; + +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.EquationContinuousDomain; +import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain; /** * Factor tree cell renderer. @@ -40,6 +57,20 @@ /** serialVersionUID. */ private static final long serialVersionUID = 1686424876690392268L; + /** Icon cache. */ + protected Map<String, Icon> iconCache; + + public FactorTreeCellRenderer() { + iconCache = new HashMap<String, Icon>(); + iconCache.put("c", Resource.getIcon("/icons/factors/c.png")); // continuous + iconCache.put("ce", Resource.getIcon("/icons/factors/ce.png")); // continuous equation + iconCache.put("cm", Resource.getIcon("/icons/factors/cm.png")); // continuous matrix + iconCache.put("d", Resource.getIcon("/icons/factors/d.png")); // discrete + iconCache.put("dg", Resource.getIcon("/icons/factors/dg.png")); // group discrete + iconCache.put("cg", Resource.getIcon("/icons/factors/cg.png")); // group continuous + iconCache.put("xg", Resource.getIcon("/icons/factors/xg.png")); // group unknown + } + /* * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean) */ @@ -47,13 +78,51 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { - + JLabel c = (JLabel)super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); + String icon = null; + String text = null; if (value instanceof Factor) { Factor factor = (Factor)value; - c.setText(factor.getName()); + if (value instanceof FactorGroup) { + FactorGroup factorGroup = (FactorGroup)value; + if (!factorGroup.isMixed()) { // root + if (factorGroup.isDiscrete()) { + icon = "d"; + } + else if (factorGroup.isContinuous()) { + icon = "c"; + } + else { + icon = "x"; + } + icon +="g"; // group + } + } + else { + Domain domain = factor.getDomain(); + + // get factor type + if (domain instanceof ContinuousDomain) { + icon = "c"; + } + else { + icon = "d"; + } + + // get factor data type + if (domain instanceof EquationContinuousDomain) { + icon += "e"; + } + else if (domain instanceof MatrixContinuousDomain) { + icon += "m"; + } + } + text = factor.getName(); } + c.setIcon(iconCache.get(icon)); + c.setText(text); return c; } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTreeModel.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTreeModel.java 2011-03-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/FactorTreeModel.java 2011-03-22 14:57:49 UTC (rev 3194) @@ -1,20 +1,27 @@ -/* *##% - * Copyright (C) 2009 - 2010 Ifremer, Code Lutin - * - * 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. - * +/* + * #%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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * + * 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.model; @@ -25,8 +32,9 @@ import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; +import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.simulator.sensitivity.Factor; -import fr.ifremer.isisfish.simulator.sensitivity.group.FactorGroup; +import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; /** * Cette classe gere l'affichage d'une liste de facteurs dans l'arbre. @@ -143,7 +151,7 @@ */ @Override public void valueForPathChanged(TreePath path, Object newValue) { - throw new RuntimeException("Not implemented"); + throw new IsisFishRuntimeException("Not implemented"); } } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/package-info.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/package-info.java 2011-03-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/sensitivity/model/package-info.java 2011-03-22 14:57:49 UTC (rev 3194) @@ -1,3 +1,27 @@ +/* + * #%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% + */ /** * Sensitivity specifics swing models. */ Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2011-03-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2011-03-22 14:57:49 UTC (rev 3194) @@ -1,13 +1,27 @@ -<!-- #%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% --> +<!-- + #%L + IsisFish + + $Id$ + $HeadURL$ + %% + Copyright (C) 2005 - 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% + --> <Table> <fr.ifremer.isisfish.datastore.RegionStorage id="regionStorage" javaBean="null" /> @@ -59,8 +73,6 @@ javax.swing.ComboBoxModel </import> <script><![CDATA[ - - // instances variables déclaration SimulationServiceListener simulationListener; StorageChangeListener regionStorageListener; @@ -91,6 +103,7 @@ } } +SimulationService.getService().addSimulationServiceListener(simulationListener); public void refresh() { if (simulAction.getSimulationStorage() != null) { @@ -99,9 +112,6 @@ fieldSimulParamsDesc.setText(simulAction.getSimulationParameter().getDescription()); setListSimulParamsStrategiesItems(); setListSimulParamsPopulationsItems(); - - // rule component - ruleChooser.setRegionStorage(simulAction.getRegionStorage()); } /** @@ -268,58 +278,10 @@ int index = listSimulParamsPopulationsModel.indexOf(p); listSimulParamsPopulations.addSelectionInterval(index, index); } - populationSelected(); + simulAction.populationSelected(this); } } -/** - * Population selection changed. - * - * Fill matrix panel with population effectif of selected population. - */ -protected void populationSelected() { - CardLayout layout = (CardLayout)populationEffectivesPanel.getLayout(); - - Object[] selectedPopulationsValues = listSimulParamsPopulations.getSelectedValues(); - if (!ArrayUtils.isEmpty(selectedPopulationsValues)) { - populationEffectivesTabbedPane.removeAll(); - simulAction.setPopulations(selectedPopulationsValues); - - for (Object selectedPopulationValue : selectedPopulationsValues) { - Population selectedPopulation = (Population)selectedPopulationValue; - // TODO add change listener on matrix panel !!! - final MatrixPanelEditor matrixPanel = new MatrixPanelEditor(); - MatrixND populationEffectives = simulAction.getSimulationParameter().getNumberOf(selectedPopulation); - matrixPanel.setMatrix(populationEffectives); - - JPanel matrixPanelComponent = new JPanel(new BorderLayout()); - matrixPanelComponent.add(matrixPanel, BorderLayout.CENTER); - - // add addFactorButton with matrixPanel (just in sensitivity cas) - if (isSensitivity()) { - // TODO choose another name than "id" - matrixPanel.putClientProperty("id", selectedPopulation.getName()); - // TODO add another thing that action - JButton addFactorButton = new JButton(); - addFactorButton.setAction(new AbstractAction() { - public void actionPerformed(ActionEvent e) { - addFactorWithComponent(matrixPanel); - } - }); - addFactorButton.setIcon(SwingUtil.createImageIcon("building_add.png")); - matrixPanelComponent.add(addFactorButton, BorderLayout.EAST); - } - - populationEffectivesTabbedPane.add(matrixPanelComponent, _("isisfish.params.populationEffectives", selectedPopulation.getName())); - } - - layout.show(populationEffectivesPanel, "specific"); - } - else { - layout.show(populationEffectivesPanel, "default"); - } -} - protected void strategySelected(){ simulAction.setStrategies(listSimulParamsStrategies.getSelectedValues()); } @@ -361,47 +323,6 @@ simulAction.resetOldSimulatorNames(); fieldSimulParamsSelect.setModel(getSimulParamsSelectModel(false)); } - -/** - * Action appelée lors du clic sur les boutons a coté des composants factorisables. - * - * Contrairement à l'interface 'input', on edite ici des facteurs existants, - * (créé à la première demande). - * - * @param e l'event initial intersepté par le layer - */ -protected void addFactorWithComponent(JComponent source) { - - if (log.isDebugEnabled()) { - log.debug("Event intercepted on " + source); - } - - // redo this, here manage just two case - Factor selectedFactor = null; - if (source instanceof RuleChooser) { - selectedFactor = simulAction.getFactors().get("parameters.rules"); - if (selectedFactor == null) { - selectedFactor = new Factor("parameters.rules"); - selectedFactor.setPath("parameters.rules"); - } - } - else { - if (source instanceof MatrixPanelEditor) { - // id here is not coherent with all other attributes (bean, beanID, method) - String property = (String)source.getClientProperty("id"); - selectedFactor = simulAction.getFactors().get("parameters.population." + property); - selectedFactor.setPath("parameters.population." + property); - } - } - - if (selectedFactor != null) { - FactorWizardUI wizard = new FactorWizardUI(this); - wizard.initExisting(source, selectedFactor); - wizard.pack(); - SwingUtil.center(this, wizard); - wizard.setVisible(true); - } -} ]]> </script> <row> @@ -518,11 +439,9 @@ </cell> </row> <row> - <cell columns="4" fill="both" weightx="1.0" - weighty="0.6"> + <cell columns="4" fill="both" weightx="1.0" weighty="0.6"> <JTabbedPane id="parametersTabbedPane" enabled="{getRegionStorage() != null}"> - <tab - title='{_("isisfish.params.stategiesAndPopulations")}'> + <tab title='{_("isisfish.params.stategiesAndPopulations")}'> <Table> <row> <cell fill="horizontal"> @@ -538,6 +457,7 @@ <JScrollPane> <JList id="listSimulParamsStrategies" selectionMode="{javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION}" + selectionModel="{new jaxx.runtime.swing.OneClicListSelectionModel(listSimulParamsStrategies.getSelectionModel(), listSimulParamsStrategies.getModel())}" onValueChanged='strategySelected()' enabled="{getRegionStorage() != null}" /> </JScrollPane> @@ -547,16 +467,15 @@ <JScrollPane> <JList id="listSimulParamsPopulations" selectionMode="{javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION}" - onValueChanged='populationSelected()' + selectionModel="{new jaxx.runtime.swing.OneClicListSelectionModel(listSimulParamsPopulations.getSelectionModel(), listSimulParamsPopulations.getModel())}" + onValueChanged='simulAction.populationSelected(this)' enabled="{getRegionStorage() != null}" /> </JScrollPane> </cell> </row> <row> - <cell fill="both" weighty="1" - columns="2"> - <JPanel - id="populationEffectivesPanel" + <cell fill="both" weighty="1" columns="2"> + <JPanel id="populationEffectivesPanel" layout="{new CardLayout()}"> <JLabel text="isisfish.params.nopopulation" horizontalAlignment="center" @@ -575,16 +494,14 @@ <tab title='{_("isisfish.params.rules")}'> <Table> <row> - <cell fill="both" weightx="1" - weighty="1"> + <cell fill="both" weightx="1" weighty="1"> <RuleChooser id="ruleChooser" active="{getRegionStorage() != null}" /> </cell> <cell> - <JButton - id="addRuleFactorButton" + <JButton id="addRuleFactorButton" icon='{SwingUtil.createImageIcon("building_add.png")}' - onActionPerformed="addFactorWithComponent(ruleChooser)" + onActionPerformed="simulAction.addFactorWithComponent(this, ruleChooser)" visible="{isSensitivity()}" /> </cell> </row> @@ -601,8 +518,7 @@ <Table> <row> <cell fill="horizontal" weightx="0.3"> - <JCheckBox - text="isisfish.params.usePreSimulationScript" + <JCheckBox text="isisfish.params.usePreSimulationScript" id="fieldUseSimulPreScripts" selected='{simulAction.getSimulationParameter().getUsePreScript()}' visible='{!isSensitivity()}' Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooser.jaxx =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooser.jaxx 2011-03-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooser.jaxx 2011-03-22 14:57:49 UTC (rev 3194) @@ -21,6 +21,8 @@ License along with this program. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>. #L% + + @param : Region storage (context) --> <Table> <!-- Rules collection managed by current ui instance. --> @@ -29,9 +31,6 @@ <!-- Active enabled binding property --> <Boolean id="active" javaBean="true"/> - <!-- Storage to edit rule parameters. --> - <fr.ifremer.isisfish.datastore.RegionStorage id="regionStorage" javaBean="null"/> - <import> fr.ifremer.isisfish.IsisFishException; fr.ifremer.isisfish.datastore.RuleStorage; @@ -43,13 +42,13 @@ fr.ifremer.isisfish.ui.util.ErrorHelper; java.beans.PropertyChangeEvent; java.beans.PropertyChangeListener; + fr.ifremer.isisfish.datastore.RegionStorage; </import> - <script><![CDATA[ - + <script><![CDATA[ protected void $afterCompleteSetup() { // Manage rule list change - addPropertyChangeListener("rulesList", new PropertyChangeListener() { + addPropertyChangeListener(PROPERTY_RULES_LIST, new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getNewValue() == null) { selectedRulesList.setModel(new fr.ifremer.isisfish.ui.models.rule.RuleListModel()); @@ -115,7 +114,7 @@ RuleParametersTableModel model = new RuleParametersTableModel(selectedRule); selectedRuleParameterTable.setModel(model); RuleParametersTableCellEditor cellEditor = new RuleParametersTableCellEditor(selectedRule); - cellEditor.setRegion(getRegionStorage()); + cellEditor.setRegion(getContextValue(RegionStorage.class)); RuleParametersTableCellRenderer cellRenderer = new RuleParametersTableCellRenderer(selectedRule); selectedRuleParameterTable.getColumnModel().getColumn(0).setCellRenderer(cellRenderer); selectedRuleParameterTable.getColumnModel().getColumn(1).setCellEditor(cellEditor); 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-22 14:47:37 UTC (rev 3193) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java 2011-03-22 14:57:49 UTC (rev 3194) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2005 - 2010 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin + * Copyright (C) 2005 - 2011 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin, 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 @@ -27,6 +27,9 @@ import static org.nuiton.i18n.I18n._; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.event.ActionEvent; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -43,11 +46,18 @@ import java.util.SortedMap; import java.util.TreeMap; +import javax.swing.AbstractAction; +import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JPanel; +import jaxx.runtime.SwingUtil; + +import org.apache.commons.lang.ArrayUtils; 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 fr.ifremer.isisfish.IsisFish; @@ -62,7 +72,6 @@ import fr.ifremer.isisfish.datastore.SensitivityStorage; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.datastore.SimulatorStorage; -import fr.ifremer.isisfish.datastore.StorageException; import fr.ifremer.isisfish.entities.Population; import fr.ifremer.isisfish.entities.Species; import fr.ifremer.isisfish.entities.Strategy; @@ -77,14 +86,16 @@ import fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher; import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan; import fr.ifremer.isisfish.simulator.sensitivity.Factor; +import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; import fr.ifremer.isisfish.simulator.sensitivity.SensitivityCalculator; import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException; 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.group.FactorGroup; +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.util.ErrorHelper; /** @@ -104,16 +115,17 @@ private static Log log = LogFactory.getLog(SimulAction.class); private static final SimpleDateFormat DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd-HH-mm"); - + 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 SortedMap<String, Factor> factors; - + + protected FactorGroup factorGroup = new FactorGroup(_("isisfish.sensitivity.factors"), 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) @@ -160,9 +172,6 @@ } ErrorHelper.showErrorDialog(_("isisfish.error.simulation.initsimulaction"), eee); } - - // factors has been requested to be sorted - factors = new TreeMap<String, Factor>(); } protected void setName(String name) { @@ -823,20 +832,7 @@ * @return factor list */ public FactorGroup getFactorGroup() { - FactorGroup result = new FactorGroup(_("isisfish.sensitivity.factors"), true); - for (Factor value : factors.values()) { - result.addFactor(value); - } - - // sort factor on name (sorted on tree map now) - /*Collections.sort(result, new Comparator<Factor<?, ?>> (){ - @Override - public int compare(Factor<?, ?> o1, Factor<?, ?> o2) { - return o1.getName().compareTo(o2.getName()); - } - });*/ - - return result; + return factorGroup; } public SortedMap<String, Factor> getFactors() { @@ -847,6 +843,7 @@ 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()); @@ -1126,4 +1123,104 @@ return result; } + + /** + * Population selection changed. + * + * Fill matrix panel with population effectif of selected population. + * + * @param paramsUI paramsUI + */ + public void populationSelected(final ParamsUI paramsUI) { + CardLayout layout = (CardLayout)paramsUI.getPopulationEffectivesPanel().getLayout(); + + Object[] selectedPopulationsValues = paramsUI.getListSimulParamsPopulations().getSelectedValues(); + if (!ArrayUtils.isEmpty(selectedPopulationsValues)) { + paramsUI.getPopulationEffectivesTabbedPane().removeAll(); + setPopulations(selectedPopulationsValues); + + for (Object selectedPopulationValue : selectedPopulationsValues) { + Population selectedPopulation = (Population)selectedPopulationValue; + final MatrixPanelEditor matrixPanel = new MatrixPanelEditor(); + MatrixND populationEffectives = getSimulationParameter().getNumberOf(selectedPopulation); + matrixPanel.setMatrix(populationEffectives); + + JPanel matrixPanelComponent = new JPanel(new BorderLayout()); + matrixPanelComponent.add(matrixPanel, BorderLayout.CENTER); + + // add addFactorButton with matrixPanel (just in sensitivity cas) + if (paramsUI.isSensitivity()) { + matrixPanel.putClientProperty("sensitivityPopulation", selectedPopulation); + // TODO add another thing that action + JButton addFactorButton = new JButton(); + addFactorButton.setAction(new AbstractAction() { + + public void actionPerformed(ActionEvent e) { + addFactorWithComponent(paramsUI, matrixPanel); + } + }); + addFactorButton.setIcon(SwingUtil.createImageIcon("building_add.png")); + matrixPanelComponent.add(addFactorButton, BorderLayout.EAST); + } + + paramsUI.getPopulationEffectivesTabbedPane().add(matrixPanelComponent, _("isisfish.params.populationEffectives", selectedPopulation.getName())); + } + + layout.show(paramsUI.getPopulationEffectivesPanel(), "specific"); + } + else { + layout.show(paramsUI.getPopulationEffectivesPanel(), "default"); + } + } + + /** + * Action appelée lors du clic sur les boutons a coté des composants factorisables. + * + * Contrairement à l'interface 'input', on edite ici des facteurs existants, + * (créé à la première demande). + * + * @param paramsUI paramsUI + * @param source la source de l'event + */ + public void addFactorWithComponent(ParamsUI paramsUI, JComponent source) { + + if (log.isDebugEnabled()) { + log.debug("Event intercepted on " + source); + } + + Factor selectedFactor = null; + + // new factor with rule domain + if (source instanceof RuleChooser) { + selectedFactor = getFactors().get("parameters.rules"); + if (selectedFactor == null) { + selectedFactor = new Factor("parameters.rules"); + selectedFactor.setPath("parameters.rules"); + selectedFactor.setDomain(new RuleDomain()); + } + } + + // new factor with matrix continous domain + else if (source instanceof MatrixPanelEditor) { + Population population = (Population)source.getClientProperty("sensitivityPopulation"); + String factorName = "parameters.population." + population.getName(); + selectedFactor = getFactors().get(factorName); + if (selectedFactor == null) { + selectedFactor = new Factor(factorName); + selectedFactor.setPath(factorName); + MatrixContinuousDomain factorDomain = new MatrixContinuousDomain(); + MatrixND populationEffectives = getSimulationParameter().getNumberOf(population); + factorDomain.setMatrix(populationEffectives.copy()); + selectedFactor.setDomain(factorDomain); + } + } + + if (selectedFactor != null) { + FactorWizardUI wizard = new FactorWizardUI(paramsUI); + wizard.initExisting(source, selectedFactor); + wizard.pack(); + wizard.setLocationRelativeTo(paramsUI); + wizard.setVisible(true); + } + } }