Author: chatellier Date: 2011-04-18 16:43:02 +0000 (Mon, 18 Apr 2011) New Revision: 3269 Log: Fix population node creation Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java 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/PopulationBasicsUI.jaxx isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/tree/FisheryTreeHelper.java Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java 2011-04-18 15:47:36 UTC (rev 3268) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java 2011-04-18 16:43:02 UTC (rev 3269) @@ -522,21 +522,8 @@ return null; } - // Population - public Species getSpeciesByTopiaId(TopiaContext context, String topiaId) { - Species result = null; - try { - SpeciesDAO dao = IsisFishDAOHelper.getSpeciesDAO(context); - result = dao.findByTopiaId(topiaId); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Can't get species", e); - } - } - return result; - } - public Population createPopulation(TopiaContext context, Species species) { + Population pop = null; if (log.isTraceEnabled()) { log.trace("createPopulation called"); } @@ -544,25 +531,17 @@ String name = "Population_new"; PopulationDAO dao = IsisFishDAOHelper.getPopulationDAO(context); - Population pop = dao.create(); + pop = dao.create(); pop.setName(name); species.addPopulation(pop); pop.setSpecies(species); species.update(); pop.update(); - // EC-20091112 : commit() twice cause hibernate error: - // Found two representations of same collection: - //context.commitTransaction(); - return pop; - } catch (Exception eee) { - if (log.isErrorEnabled()) { - log.error("Can't create Population", eee); - } - ErrorHelper.showErrorDialog(_("isisfish.error.input.addentity", - "Population"), eee); + } catch (TopiaException eee) { + throw new IsisFishRuntimeException(_("isisfish.error.input.addentity", "Population"), eee); } - return null; + return pop; } public PopulationSeasonInfo createPopulationSeasonInfo(Population pop) { 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-04-18 15:47:36 UTC (rev 3268) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputHandler.java 2011-04-18 16:43:02 UTC (rev 3269) @@ -55,6 +55,7 @@ import org.nuiton.topia.persistence.TopiaEntityContextable; import org.nuiton.util.FileUtil; +import fr.ifremer.isisfish.IsisFishDAOHelper; import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.datastore.RegionStorage; import fr.ifremer.isisfish.datastore.SimulationStorage; @@ -68,6 +69,7 @@ import fr.ifremer.isisfish.entities.Port; import fr.ifremer.isisfish.entities.SetOfVessels; import fr.ifremer.isisfish.entities.Species; +import fr.ifremer.isisfish.entities.SpeciesDAO; import fr.ifremer.isisfish.entities.Strategy; import fr.ifremer.isisfish.entities.TripType; import fr.ifremer.isisfish.entities.VesselType; @@ -670,9 +672,17 @@ selectedNode = selectedNode.getParent(); } + // must use loador to properly load species node FisheryTreeNodeLoador typeNodeLoador = fisheryTreeHelper.getLoadorFor(nodeClass); - // must use loador to properly load species node - FisheryTreeNode newNode = (FisheryTreeNode)typeNodeLoador.createNode(topiaEntity, null); + FisheryTreeNode newNode = null; + if (newNode != null) { + newNode = (FisheryTreeNode)typeNodeLoador.createNode(topiaEntity, null); + } + else { + // FIXME echatellier 20110418 cas non résolu du node "population" + // pour lequel on n'a pas le loador + newNode = new FisheryTreeNode(nodeClass, topiaEntity.getTopiaId(), null, null); + } fisheryTreeHelper.insertNode(selectedNode, newNode); fisheryTreeHelper.selectNode(newNode); } @@ -728,35 +738,12 @@ } 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); - }*/ + FactorWizardUI factorWizardUI = new FactorWizardUI(inputContentUI); + SensitivityInputHandler handler = factorWizardUI.getHandler(); + handler.initNewFactor(factorWizardUI, bean, sensitivityMethod); + factorWizardUI.pack(); + factorWizardUI.setLocationRelativeTo(inputContentUI); + factorWizardUI.setVisible(true); } else { if (log.isErrorEnabled()) { @@ -764,4 +751,47 @@ } } } + + /** + * Dans le cas d'une creation de population, on doit la creer dans + * une espèce. On doit rechercher celle qui est sélectionnée dans l'arbre. + * + * @param inputUI input ui + * @return selected species + */ + public Species findSpecies(InputUI inputUI) { + // get selected node + FisheryTreeHelper treeHelper = inputUI.getContextValue(FisheryTreeHelper.class); + FisheryTreeNode selectedNode = treeHelper.getSelectedNode(); + if (selectedNode == null) { + throw new IsisFishRuntimeException("Not selected tree node"); + } + + // look for parent node (Species type) + String speciesId = null; + FisheryTreeNode parentNode = selectedNode.getParent(); + if (parentNode.getInternalClass().equals(Species.class)) { + // cas selection du noeud type "Population" + speciesId = parentNode.getId(); + } + else if (parentNode.getParent().getInternalClass().equals(Species.class)) { + // cas où on est deja sur une population + speciesId = parentNode.getParent().getId(); + } + else { + throw new IsisFishRuntimeException("Not selected tree node"); + } + + // look for entities + TopiaContext topiaContext = inputUI.getContextValue(TopiaContext.class); + Species result = null; + try { + SpeciesDAO dao = IsisFishDAOHelper.getSpeciesDAO(topiaContext); + result = dao.findByTopiaId(speciesId); + } catch (TopiaException e) { + throw new IsisFishRuntimeException("Can't find "); + } + + return result; + } } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/PopulationBasicsUI.jaxx =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/PopulationBasicsUI.jaxx 2011-04-18 15:47:36 UTC (rev 3268) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/PopulationBasicsUI.jaxx 2011-04-18 16:43:02 UTC (rev 3269) @@ -34,7 +34,6 @@ fr.ifremer.isisfish.entities.PopulationGroup; fr.ifremer.isisfish.entities.Population; javax.swing.table.DefaultTableModel; - org.nuiton.topia.persistence.TopiaEntity; java.beans.PropertyChangeEvent; java.beans.PropertyChangeListener; javax.swing.JOptionPane @@ -102,7 +101,8 @@ wizard.init(this); wizardFrame.add(wizard, BorderLayout.CENTER); wizardFrame.setTitle(_("isisfish.wizardGroupCreation.title")); - wizard.setAgeType(getBean().getSpecies().getAgeGroupType()); + Species species = getBean().getSpecies(); + wizard.setAgeType(species.getAgeGroupType()); if (wizard.isAgeType()) { wizard.setCard("singleGroupAge"); } else { @@ -138,15 +138,12 @@ } protected void create() { - Species species = null; //getAction().getSpeciesByTopiaId(getSaveVerifier().getIsisContext(), getSaveVerifier().getCurrentNode().getParent().getNavigationPath()); - if (species == null){ - species = null; //getAction().getSpeciesByTopiaId(getSaveVerifier().getIsisContext(), getSaveVerifier().getCurrentNode().getParent().getParent().getNavigationPath()); - } - - TopiaEntity topia = getContextValue(InputAction.class).createPopulation(getTopiaContext(), species); - // FIXME echatellier 20110306 use new tree api - //getParentContainer(InputUI.class).setTreeModel(); - //getParentContainer(InputUI.class).setTreeSelection("$root/$species/"+ species.getTopiaId() +"/$populations/"+topia.getTopiaId()); + // find species node + InputUI inputUI = getContextValue(InputUI.class, JAXXUtil.PARENT); + Species species = inputUI.getHandler().findSpecies(inputUI); + // create node and select it + Population population = getContextValue(InputAction.class).createPopulation(getTopiaContext(), species); + inputUI.getHandler().insertTreeNode(inputUI, Population.class, population); setInfoText(_("isisfish.message.creation.finished")); } ]]> @@ -276,7 +273,7 @@ <JButton id='create' decorator='boxed' text="isisfish.common.new" enabled="{!validator.isChanged()}" - onActionPerformed="getSaveVerifier().create(Population.class)"/> + onActionPerformed="create()"/> </cell> <cell fill='horizontal' weightx='0.5'> <JButton id='delete' decorator='boxed' Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/tree/FisheryTreeHelper.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/tree/FisheryTreeHelper.java 2011-04-18 15:47:36 UTC (rev 3268) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/tree/FisheryTreeHelper.java 2011-04-18 16:43:02 UTC (rev 3269) @@ -141,7 +141,7 @@ FisheryTreeNode strategiesChild = new FisheryTreeNode(Strategy.class, n_("isisfish.input.tree.strategies"), null, strategiesNodeLoador); loadorCache.put(Strategy.class, strategiesNodeLoador); - + root.add(cellsChild); root.add(zonesChild); root.add(portsChild);
participants (1)
-
chatellier@users.labs.libre-entreprise.org