branch develop updated (856e849 -> b6c955c)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository tutti. See http://git.codelutin.com/tutti.git from 856e849 fixes #6610: [TECH] Mauvaise fermeture des bases new 45fd868 refs #6538 chargement du svg à chaque fois qu'on revient sur l'onglet new b6c955c refs #6538 better handle erors The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit b6c955c34d2e57f6f6fc71d648c6b8f07736aed2 Author: Kevin Morin <morin@codelutin.com> Date: Thu Feb 5 15:19:01 2015 +0100 refs #6538 better handle erors commit 45fd86826d7ed7fdff06567a61b9f89f641098b4 Author: Kevin Morin <morin@codelutin.com> Date: Thu Feb 5 12:09:00 2015 +0100 refs #6538 chargement du svg à chaque fois qu'on revient sur l'onglet Summary of changes: .../operation/catches/EditCatchesUIHandler.java | 953 ++++++++++++--------- .../util/AbstractTuttiTabContainerUIHandler.java | 55 +- 2 files changed, 579 insertions(+), 429 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit 45fd86826d7ed7fdff06567a61b9f89f641098b4 Author: Kevin Morin <morin@codelutin.com> Date: Thu Feb 5 12:09:00 2015 +0100 refs #6538 chargement du svg à chaque fois qu'on revient sur l'onglet --- .../operation/catches/EditCatchesUIHandler.java | 954 +++++++++++---------- .../util/AbstractTuttiTabContainerUIHandler.java | 55 +- 2 files changed, 571 insertions(+), 438 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java index 4956bd0..bd8dc22 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java @@ -23,6 +23,8 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches; */ import com.google.common.base.Function; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import fr.ifremer.tutti.TuttiConfiguration; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; @@ -52,7 +54,6 @@ import org.apache.batik.dom.svg.SVGOMTextElement; import org.apache.batik.swing.JSVGCanvas; import org.apache.batik.swing.gvt.GVTTreeRendererAdapter; import org.apache.batik.swing.gvt.GVTTreeRendererEvent; -import org.apache.batik.util.RunnableQueue; import org.apache.batik.util.XMLResourceDescriptor; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; @@ -161,6 +162,8 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } }; + protected Multimap<String, PropertyChangeListener> svgRelatedPropertyChangeListeners = HashMultimap.create(); + protected JSVGCanvas canvas; protected Document svgDocument; @@ -224,277 +227,6 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } }); - try { - initResumeSvg(); - - } catch (IOException err) { - if (log.isErrorEnabled()) { - log.error("error while initializing the resume background", err); - } - getContext().getErrorHelper().showErrorDialog(t("tutti.editCatchBatch.svgLoading.error"), err); - } - } - - public void initResumeSvg() throws IOException { - String parser = XMLResourceDescriptor.getXMLParserClassName(); - SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); - URL url = Resource.getURL("EcranResume.svg"); - svgDocument = f.createDocument(url.toString()); - - canvas = new JSVGCanvas(); - canvas.setSize(new Dimension(1, 1)); - canvas.setMySize(new Dimension(1, 1)); - - getUI().getSvgCanvasPanel().add(canvas, BorderLayout.CENTER); - - canvas.setRecenterOnResize(true); - - canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() { - @Override - public void gvtRenderingCompleted(GVTTreeRendererEvent gvtTreeRendererEvent) { - log.info("gvtRenderingCompleted"); - TuttiConfiguration config = getConfig(); - WeightUnit catchWeightUnit = WeightUnit.KG; - WeightUnit speciesWeightUnit = config.getSpeciesWeightUnit(); - WeightUnit benthosWeightUnit = config.getBenthosWeightUnit(); - WeightUnit marineLitterWeightUnit = config.getMarineLitterWeightUnit(); - - EditCatchesUIModel model = getModel(); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_WEIGHT, model.getCatchTotalComputedOrNotWeight(), catchWeightUnit); - - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, model.getCatchTotalRejectedComputedOrNotWeight(), catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, catchWeightUnit); - - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, model.getSpeciesTotalSortedComputedOrNotWeight(), speciesWeightUnit); - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, speciesWeightUnit); - - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, model.getBenthosTotalSortedComputedOrNotWeight(), benthosWeightUnit); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, benthosWeightUnit); - - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_UNSORTED_COMPUTED_WEIGHT, catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, speciesWeightUnit); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, benthosWeightUnit); - - model.addPropertyChangeListener(new ChangeElementBackgroundColorPropertyChangeListener( - CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, - Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), - canvas, - svgDocument, - new Function<EditCatchesUIModel, Color>() { - @Override - public Color apply(EditCatchesUIModel model) { - boolean warning = model.isSpeciesTotalUnsortedComputedWeightInWarning(); - return warning ? Color.ORANGE : Color.decode("#006bba"); - } - })); - - model.addPropertyChangeListener(new ChangeElementBackgroundColorPropertyChangeListener( - CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, - Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), - canvas, - svgDocument, - new Function<EditCatchesUIModel, Color>() { - @Override - public Color apply(EditCatchesUIModel model) { - boolean warning = model.isBenthosTotalUnsortedComputedWeightInWarning(); - return warning ? Color.ORANGE : Color.decode("#006bba"); - } - })); - - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, - speciesWeightUnit, - CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, - benthosWeightUnit, - CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); - initSvgField(CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT, - model.getMarineLitterTotalComputedOrNotWeight(), - marineLitterWeightUnit, - CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT); - - model.addPropertyChangeListener(new RatioPropertyChangeListener("ratioSpeciesSampleSortedOverSpeciesSortedWeightLabel", - CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, - canvas, - svgDocument)); - model.addPropertyChangeListener(new RatioPropertyChangeListener("ratioBenthosSampleSortedOverBenthosSortedWeightLabel", - CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, - canvas, - svgDocument)); - model.addPropertyChangeListener(new RatioPropertyChangeListener("ratioSortedSortedOverSortedWeightLabel", - CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, - canvas, - svgDocument)); - - initSpeciesCount(CatchBatch.PROPERTY_SPECIES_DISTINCT_SORTED_SPECIES_COUNT); - initSpeciesCount(CatchBatch.PROPERTY_BENTHOS_DISTINCT_SORTED_SPECIES_COUNT); - - initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_CAROUSSEL_WEIGHT, catchWeightUnit); - initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_TREMIS_WEIGHT, catchWeightUnit); - } - }); - - canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); - canvas.setDocument(svgDocument); - } - - protected void initSpeciesCount(final String property) { - - if (log.isDebugEnabled()) { - log.debug("init " + property + " field"); - } - - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { - @Override - public void run() { - Element labelElement = svgDocument.getElementById(property + "Label"); - labelElement.setTextContent(t("tutti.editCatchBatch.field." + property)); - } - }); - - getModel().addPropertyChangeListener(property, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Integer value = (Integer) evt.getNewValue(); - Element labelElement = svgDocument.getElementById(property + "Value"); - labelElement.setTextContent(JAXXUtil.getStringValue(value)); - } - }); - } - - protected void initTremieCarrouselField(final String property, final WeightUnit weightUnit) { - if (log.isDebugEnabled()) { - log.debug("init " + property + " field"); - } - - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { - @Override - public void run() { - Element labelElement = svgDocument.getElementById(property + "Label"); - labelElement.setTextContent(weightUnit.decorateLabel(t("tutti.editCatchBatch.field." + property))); - } - }); - - getModel().addPropertyChangeListener(property, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Float value = (Float) evt.getNewValue(); - Element valueElement = svgDocument.getElementById(property + "Value"); - String text; - if (value == null) { - text = ""; - } else { - text = Weights.getWeightStringValue(value) + " " + weightUnit.getShortLabel(); - } - valueElement.setTextContent(text); - } - }); - - getModel().addPropertyChangeListener(EditCatchesUIModel.PROPERTY_FISHING_OPERATION, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - EditCatchesUIModel model = (EditCatchesUIModel) evt.getSource(); - FishingOperation fishingOperation = model.getFishingOperation(); - if (fishingOperation != null) { - - boolean tremieCarrouselFieldsVisisble = fishingOperation.getVessel() != null - && fishingOperation.getVessel().getId().equals(getConfig().getTremieCarousselVesselId()); - - Element labelElement = svgDocument.getElementById(property + "Label"); - labelElement.setAttribute("visibility", tremieCarrouselFieldsVisisble ? "visible" : "hidden"); - - Element valueElement = svgDocument.getElementById(property + "Value"); - valueElement.setAttribute("visibility", tremieCarrouselFieldsVisisble ? "visible" : "hidden"); - - } - } - }); - } - - protected void initSvgField(String property, WeightUnit weightUnit, String... idsInGroup) { - initSvgField(property, null, weightUnit, idsInGroup); - } - - protected void initSvgField(final String property, - final ComputableData<Float> computableData, - final WeightUnit weightUnit, - final String... idsInGroup) { - - if (log.isDebugEnabled()) { - log.debug("init " + property + " field"); - } - - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { - @Override - public void run() { - Element rectElement = svgDocument.getElementById(property + "Rect"); - SVGOMRectElement rectElem = (SVGOMRectElement) rectElement; - SVGRect bbox = rectElem.getBBox(); - Float x = bbox.getX(); - - Element labelElement = svgDocument.getElementById(property + "Label"); - if (computableData == null) { - SVGStylable field = (SVGStylable) labelElement; - CSSStyleDeclaration style = field.getStyle(); - style.setProperty("font-style", "italic", null); - } - - SVGOMTextElement labelTextElem = (SVGOMTextElement) labelElement; - labelElement.setTextContent(weightUnit.decorateLabel(t("tutti.editCatchBatch.field." + property))); - bbox = labelTextElem.getBBox(); - float labelX = bbox.getX(); - float width = Math.abs(x - labelX) + 10; - - SVGOMRectElement labelRectElement = (SVGOMRectElement) svgDocument.getElementById(property + "LabelRect"); - float actualWidth = Math.abs(labelRectElement.getBBox().getX() - labelX) + 10; - - if (actualWidth < width) { - labelRectElement.setAttribute("width", Float.toString(width)); - labelRectElement.setAttribute("x", String.valueOf(labelX - 10)); - - for (String id : idsInGroup) { - Element el = svgDocument.getElementById(id + "LabelRect"); - el.setAttribute("width", Float.toString(width)); - el.setAttribute("x", String.valueOf(labelX - 10)); - } - } - } - }); - - Color colorComputedWeights = getConfig().getColorComputedWeights(); - if (computableData == null) { - - // computed data value - OnDataOrComputedDataValueChangedListener listener = new OnDataOrComputedDataValueChangedListener(property, weightUnit, true, canvas, svgDocument, colorComputedWeights, idsInGroup); - getModel().addPropertyChangeListener(property, listener); - - } else { - - // data or computed data value - Element element = svgDocument.getElementById(property); - EventTarget target = (EventTarget) element; - target.addEventListener("click", new OnValueClickListener(computableData, property, weightUnit), false); - - OnDataOrComputedDataValueChangedListener listener = new OnDataOrComputedDataValueChangedListener(property, weightUnit, false, canvas, svgDocument, colorComputedWeights, idsInGroup); - computableData.addPropertyChangeListener(listener); - } } public void closeAttachments() { @@ -528,6 +260,8 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi log.debug("closing: " + ui); } ui.getCatchesCaracteristicsAttachmentsButton().onCloseUI(); + clearSVG(); + // close batches tabs, then general tab closeUI(ui.getSpeciesTabContent()); closeUI(ui.getBenthosTabContent()); @@ -580,7 +314,27 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi ui.getCatchesCaracteristicsAttachmentsButton().onCloseUI(); ui.getComputeSpeciesBatchButton().setVisible(newIndex < 4); ui.getCleanSpeciesBatchButton().setVisible(newIndex < 3); - return super.onTabChanged(currentIndex, newIndex); + + boolean result = super.onTabChanged(currentIndex, newIndex); + + if (result && currentIndex != newIndex) { + if (currentIndex == 0) { + clearSVG(); + } + if (newIndex == 0 && getUI().isVisible()) { + try { + initResumeSvg(); + + } catch (IOException err) { + if (log.isErrorEnabled()) { + log.error("error while initializing the resume background", err); + } + getContext().getErrorHelper().showErrorDialog(t("tutti.editCatchBatch.svgLoading.error"), err); + } + } + } + + return result; } @Override @@ -642,12 +396,27 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi // model not modify, can change tab result = true; } + + if (result) { + clearSVG(); + } + return result; } @Override public void onShowTab(int currentIndex, int newIndex) { registerValidators(); + + try { + initResumeSvg(); + + } catch (IOException err) { + if (log.isErrorEnabled()) { + log.error("error while initializing the resume background", err); + } + getContext().getErrorHelper().showErrorDialog(t("tutti.editCatchBatch.svgLoading.error"), err); + } } @Override @@ -1013,163 +782,479 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi return result; } - private class OnValueClickListener implements EventListener { + //------------------------------------------------------------------------// + //-- Protected methods --// + //------------------------------------------------------------------------// - private final ComputableData<Float> computableData; + protected void initResumeSvg() throws IOException { + String parser = XMLResourceDescriptor.getXMLParserClassName(); + SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); + URL url = Resource.getURL("EcranResume.svg"); + svgDocument = f.createDocument(url.toString()); - private final String property; + canvas = new JSVGCanvas(); + canvas.setSize(new Dimension(1, 1)); + canvas.setMySize(new Dimension(1, 1)); - private final WeightUnit weightUnit; + canvas.setRecenterOnResize(true); - public OnValueClickListener(ComputableData<Float> computableData, String property, WeightUnit weightUnit) { - this.computableData = computableData; - this.property = property; - this.weightUnit = weightUnit; - } + canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() { + @Override + public void gvtRenderingCompleted(GVTTreeRendererEvent gvtTreeRendererEvent) { + if (log.isDebugEnabled()) { + log.debug("gvtRenderingCompleted"); + } + TuttiConfiguration config = getConfig(); + WeightUnit catchWeightUnit = WeightUnit.KG; + WeightUnit speciesWeightUnit = config.getSpeciesWeightUnit(); + WeightUnit benthosWeightUnit = config.getBenthosWeightUnit(); + WeightUnit marineLitterWeightUnit = config.getMarineLitterWeightUnit(); - public void handleEvent(org.w3c.dom.events.Event evt) { - log.info("element clicked"); - EnterWeightUI dialog = new EnterWeightUI(getContext()); - Float originalWeight = computableData.getData(); - Float weight = dialog.openAndGetWeightValue(t("tutti.editCatchBatch.field." + property), - originalWeight, - weightUnit); + EditCatchesUIModel model = getModel(); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, + model.getCatchTotalComputedOrNotWeight(), + catchWeightUnit); - if (!Objects.equals(originalWeight, weight)) { + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, + model.getCatchTotalRejectedComputedOrNotWeight(), + catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, catchWeightUnit); - computableData.setData(weight); + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, + model.getSpeciesTotalSortedComputedOrNotWeight(), + speciesWeightUnit); + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, speciesWeightUnit); + + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, + model.getBenthosTotalSortedComputedOrNotWeight(), + benthosWeightUnit); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, benthosWeightUnit); + + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_UNSORTED_COMPUTED_WEIGHT, catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, speciesWeightUnit); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, benthosWeightUnit); + + addSvgRelatedPropertyChangeListener(null, new ChangeElementBackgroundColorPropertyChangeListener( + CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, + Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), + new Function<EditCatchesUIModel, Color>() { + @Override + public Color apply(EditCatchesUIModel model) { + boolean warning = model.isSpeciesTotalUnsortedComputedWeightInWarning(); + return warning ? Color.ORANGE : Color.decode("#006bba"); + } + })); + + addSvgRelatedPropertyChangeListener(null, new ChangeElementBackgroundColorPropertyChangeListener( + CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, + Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), + new Function<EditCatchesUIModel, Color>() { + @Override + public Color apply(EditCatchesUIModel model) { + boolean warning = model.isBenthosTotalUnsortedComputedWeightInWarning(); + return warning ? Color.ORANGE : Color.decode("#006bba"); + } + })); + + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, + speciesWeightUnit, + CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, + benthosWeightUnit, + CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); + initSvgField(CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT, + CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_COMPUTED_WEIGHT, + model.getMarineLitterTotalComputedOrNotWeight(), + marineLitterWeightUnit, + CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT); + + addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioSpeciesSampleSortedOverSpeciesSortedWeightLabel", + CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT)); + addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioBenthosSampleSortedOverBenthosSortedWeightLabel", + CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT)); + addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioSortedSortedOverSortedWeightLabel", + CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT)); + + initSpeciesCount(CatchBatch.PROPERTY_SPECIES_DISTINCT_SORTED_SPECIES_COUNT); + initSpeciesCount(CatchBatch.PROPERTY_BENTHOS_DISTINCT_SORTED_SPECIES_COUNT); + + initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_CAROUSSEL_WEIGHT, catchWeightUnit); + initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_TREMIS_WEIGHT, catchWeightUnit); + + getUI().getSvgCanvasPanel().add(canvas, BorderLayout.CENTER); + } + }); + + canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); + canvas.setDocument(svgDocument); + } + + protected void initSpeciesCount(final String property) { + + if (log.isDebugEnabled()) { + log.debug("init " + property + " field"); + } + + canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { + @Override + public void run() { + Element labelElement = svgDocument.getElementById(property + "Label"); + labelElement.setTextContent(t("tutti.editCatchBatch.field." + property)); + + Element valueElement = svgDocument.getElementById(property + "Value"); + Integer value; + try { + String sValue = BeanUtils.getProperty(getModel(), property); + if (sValue != null) { + value = Integer.parseInt(sValue); + } else { + value = null; + } + + } catch (ReflectiveOperationException e) { + if (log.isErrorEnabled()) { + log.error("error on reading model's property " + property, e); + } + value = null; + } + valueElement.setTextContent(JAXXUtil.getStringValue(value)); } + }); + + addSvgRelatedPropertyChangeListener(property, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + Integer value = (Integer) evt.getNewValue(); + Element labelElement = svgDocument.getElementById(property + "Value"); + labelElement.setTextContent(JAXXUtil.getStringValue(value)); + } + }); + } + + protected void initTremieCarrouselField(final String property, final WeightUnit weightUnit) { + if (log.isDebugEnabled()) { + log.debug("init " + property + " field"); } + + canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { + @Override + public void run() { + Element labelElement = svgDocument.getElementById(property + "Label"); + labelElement.setTextContent(weightUnit.decorateLabel(t("tutti.editCatchBatch.field." + property))); + } + }); + + addSvgRelatedPropertyChangeListener(property, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + Float value = (Float) evt.getNewValue(); + updateValue(property, value, weightUnit, true); + } + }); + + Float value = getModelPropertyValue(property); + updateValue(property, value, weightUnit, true); + + addSvgRelatedPropertyChangeListener(EditCatchesUIModel.PROPERTY_FISHING_OPERATION, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + updateTremieCarrouselVisibility(property); + } + }); + updateTremieCarrouselVisibility(property); } - private static abstract class UpdateRunnableQueuePropertyChangeListener implements PropertyChangeListener { + protected void updateTremieCarrouselVisibility(String property) { + EditCatchesUIModel model = getModel(); + FishingOperation fishingOperation = model.getFishingOperation(); + if (fishingOperation != null) { + boolean tremieCarrouselFieldsVisisble = fishingOperation.getVessel() != null + && fishingOperation.getVessel().getId().equals(getConfig().getTremieCarousselVesselId()); - protected final JSVGCanvas canvas; - protected RunnableQueue updateRunnableQueue; - protected final Document svgDocument; + Element labelElement = svgDocument.getElementById(property + "Label"); + labelElement.setAttribute("visibility", tremieCarrouselFieldsVisisble ? "visible" : "hidden"); - public UpdateRunnableQueuePropertyChangeListener(JSVGCanvas canvas, - Document svgDocument) { - this.canvas = canvas; - this.svgDocument = svgDocument; + Element valueElement = svgDocument.getElementById(property + "Value"); + valueElement.setAttribute("visibility", tremieCarrouselFieldsVisisble ? "visible" : "hidden"); } + } - protected RunnableQueue getUpdateRunnableQueue() { - if (updateRunnableQueue == null) { - updateRunnableQueue = canvas.getUpdateManager().getUpdateRunnableQueue(); + protected void initSvgField(String computedProperty, WeightUnit weightUnit, String... idsInGroup) { + initSvgField(null, computedProperty, null, weightUnit, idsInGroup); + } + + protected void initSvgField(String property, + String computedProperty, + final ComputableData<Float> computableData, + final WeightUnit weightUnit, + final String... idsInGroup) { + + if (log.isDebugEnabled()) { + log.debug("init " + property + " field"); + } + + final String notNullProperty = property != null ? property : computedProperty; + + OnDataOrComputedDataValueChangedListener listener = new OnDataOrComputedDataValueChangedListener(notNullProperty, computableData, weightUnit, idsInGroup); + if (property != null) { + addSvgRelatedPropertyChangeListener(property, listener); + } + if (computedProperty != null) { + addSvgRelatedPropertyChangeListener(computedProperty, listener); + } + + if (computableData != null) { + // data or computed data value + Element element = svgDocument.getElementById(property); + EventTarget target = (EventTarget) element; + target.addEventListener("click", new OnValueClickListener(computableData, property, weightUnit), false); + } + + canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { + @Override + public void run() { + + SVGOMRectElement rectElement = (SVGOMRectElement) svgDocument.getElementById(notNullProperty + "Rect"); + SVGRect bbox = rectElement.getBBox(); + Float x = bbox.getX(); + Element labelElement = svgDocument.getElementById(notNullProperty + "Label"); + if (computableData == null) { + SVGStylable field = (SVGStylable) labelElement; + CSSStyleDeclaration style = field.getStyle(); + style.setProperty("font-style", "italic", null); + } + + SVGOMTextElement labelTextElem = (SVGOMTextElement) labelElement; + labelElement.setTextContent(weightUnit.decorateLabel(t("tutti.editCatchBatch.field." + notNullProperty))); + bbox = labelTextElem.getBBox(); + float labelX = bbox.getX(); + float width = Math.abs(x - labelX) + 10; + + SVGOMRectElement labelRectElement = (SVGOMRectElement) svgDocument.getElementById(notNullProperty + "LabelRect"); + float actualWidth = Math.abs(labelRectElement.getBBox().getX() - labelX) + 10; + + if (actualWidth < width) { + labelRectElement.setAttribute("width", Float.toString(width)); + labelRectElement.setAttribute("x", String.valueOf(labelX - 10)); + + for (String id : idsInGroup) { + Element el = svgDocument.getElementById(id + "LabelRect"); + el.setAttribute("width", Float.toString(width)); + el.setAttribute("x", String.valueOf(labelX - 10)); + } + } + + Float value; + boolean computed; + if (computableData == null) { + computed = true; + value = getModelPropertyValue(notNullProperty); + + } else if (computableData.getData() == null) { + computed = true; + value = computableData.getComputedData(); + + } else { + computed = false; + value = computableData.getData(); + } + + updateValue(notNullProperty, value, weightUnit, computed, idsInGroup); } - return updateRunnableQueue; + }); + + } + + protected Float getModelPropertyValue(String property) { + Float value; + try { + String sValue = BeanUtils.getProperty(getModel(), property); + if (sValue != null) { + value = Float.parseFloat(sValue); + } else { + value = null; + } + + } catch (ReflectiveOperationException e) { + if (log.isErrorEnabled()) { + log.error("error on reading model's property " + property, e); + } + value = null; } + return value; } - private static class OnDataOrComputedDataValueChangedListener extends UpdateRunnableQueuePropertyChangeListener { + protected void clearSVG() { + for (String property : svgRelatedPropertyChangeListeners.keySet()) { + for (PropertyChangeListener listener : svgRelatedPropertyChangeListeners.get(property)) { + if (property != null) { + getModel().removePropertyChangeListener(property, listener); + } else { + getModel().removePropertyChangeListener(listener); + } + } + } + svgRelatedPropertyChangeListeners.clear(); + + canvas.dispose(); + getUI().getSvgCanvasPanel().remove(canvas); + } + + protected void addSvgRelatedPropertyChangeListener(String property, PropertyChangeListener listener) { + svgRelatedPropertyChangeListeners.put(property, listener); + if (property != null) { + getModel().addPropertyChangeListener(property, listener); + } else { + getModel().addPropertyChangeListener(listener); + } + } + + protected void updateValue(final String property, + final Float value, + final WeightUnit weightUnit, + final boolean computed, + final String... idsInGroup) { + + canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater + (new Runnable() { + public void run() { + if (log.isDebugEnabled()) { + log.debug("update " + property + " field"); + } + + SVGOMTextElement valueElement = (SVGOMTextElement) svgDocument.getElementById(property + "Value"); + if (valueElement == null) { + return; + } + + //TODO i18n ? + String textContent; + if (value != null) { + textContent = Weights.getWeightStringValue(value) + " " + weightUnit.getShortLabel(); + } else { + textContent = null; + } + valueElement.setTextContent(textContent); + + CSSStyleDeclaration style = valueElement.getStyle(); + + Color colorComputedWeights = getConfig().getColorComputedWeights(); + String computedColor = "#" + Integer.toHexString(colorComputedWeights.getRGB()).substring(2); + style.setProperty("fill", computed ? computedColor : "#000000", null); + style.setProperty("font-style", computed ? "italic" : "normal", null); + + SVGRect bbox = valueElement.getBBox(); + SVGOMRectElement rectElement = (SVGOMRectElement) svgDocument.getElementById(property + "Rect"); + if (bbox != null && rectElement != null) { + float width = bbox.getWidth() + 15; + float actualWidth = rectElement.getBBox().getWidth(); + if (actualWidth < width) { + rectElement.setAttribute("width", Float.toString(width)); + for (String id : idsInGroup) { + Element el = svgDocument.getElementById(id + "Rect"); + el.setAttribute("width", Float.toString(width)); + } + } + } + } + }); + + } + + private class OnValueClickListener implements EventListener { + + private final ComputableData<Float> computableData; private final String property; + + private final WeightUnit weightUnit; + + public OnValueClickListener(ComputableData<Float> computableData, String property, WeightUnit weightUnit) { + this.computableData = computableData; + this.property = property; + this.weightUnit = weightUnit; + } + + public void handleEvent(org.w3c.dom.events.Event evt) { + log.info("element clicked"); + EnterWeightUI dialog = new EnterWeightUI(getContext()); + Float originalWeight = computableData.getData(); + Float weight = dialog.openAndGetWeightValue(t("tutti.editCatchBatch.field." + property), + originalWeight, + weightUnit); + + if (!Objects.equals(originalWeight, weight)) { + + computableData.setData(weight); + } + } + } + + private class OnDataOrComputedDataValueChangedListener implements PropertyChangeListener { + + private final String property; + private final ComputableData<Float> computableData; private final WeightUnit weightUnit; - private final boolean onlyReactOnComputedData; - private final Color colorComputedWeights; private final String[] idsInGroup; public OnDataOrComputedDataValueChangedListener(String property, + ComputableData<Float> computableData, WeightUnit weightUnit, - boolean onlyReactOnComputedData, - JSVGCanvas canvas, - Document svgDocument, - Color colorComputedWeights, String... idsInGroup) { - super(canvas, svgDocument); this.property = property; + this.computableData = computableData; this.weightUnit = weightUnit; - this.onlyReactOnComputedData = onlyReactOnComputedData; - this.colorComputedWeights = colorComputedWeights; this.idsInGroup = idsInGroup; } @Override public void propertyChange(PropertyChangeEvent evt) { - boolean computedData; - Float newValue; - if (onlyReactOnComputedData) { - + if (computableData == null) { computedData = true; newValue = (Float) evt.getNewValue(); } else { - - ComputableData<Float> computableData = (ComputableData<Float>) evt.getSource(); - if (computableData.getData() == null) { - computedData = true; newValue = computableData.getComputedData(); } else { - computedData = false; newValue = computableData.getData(); - } - } - updateValue(newValue, computedData); - + updateValue(property, newValue, weightUnit, computedData, idsInGroup); } - private void updateValue(final Float value, final boolean computed) { - - getUpdateRunnableQueue().invokeLater - (new Runnable() { - public void run() { - if (log.isDebugEnabled()) { - log.debug("update " + property + " field"); - } - - Element element = svgDocument.getElementById(property + "Value"); - if (element == null) { - return; - } - - //TODO i18n ? - String textContent; - if (value != null) { - textContent = Weights.getWeightStringValue(value) + " " + weightUnit.getShortLabel(); - } else { - textContent = null; - } - element.setTextContent(textContent); - - SVGStylable field = (SVGStylable) element; - CSSStyleDeclaration style = field.getStyle(); - - String computedColor = "#" + Integer.toHexString(colorComputedWeights.getRGB()).substring(2); - style.setProperty("fill", computed ? computedColor : "#000000", null); - style.setProperty("font-style", computed ? "italic" : "normal", null); - - SVGOMTextElement textElem = (SVGOMTextElement) element; - SVGRect bbox = textElem.getBBox(); - if (bbox != null) { - float width = bbox.getWidth() + 15; - SVGOMRectElement rectElement = (SVGOMRectElement) svgDocument.getElementById(property + "Rect"); - float actualWidth = rectElement.getBBox().getWidth(); - if (actualWidth < width) { - rectElement.setAttribute("width", Float.toString(width)); - for (String id : idsInGroup) { - Element el = svgDocument.getElementById(id + "Rect"); - el.setAttribute("width", Float.toString(width)); - } - } - } - } - }); - - } } - private static class ChangeElementBackgroundColorPropertyChangeListener extends UpdateRunnableQueuePropertyChangeListener { + private class ChangeElementBackgroundColorPropertyChangeListener implements PropertyChangeListener { private final String elementId; private Set<String> propertiesToListen; @@ -1177,42 +1262,42 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi public ChangeElementBackgroundColorPropertyChangeListener(String elementId, Set<String> propertiesToListen, - JSVGCanvas canvas, - Document svgDocument, Function<EditCatchesUIModel, Color> colorFunction) { - super(canvas, svgDocument); this.elementId = elementId; this.propertiesToListen = propertiesToListen; this.colorFunction = colorFunction; + + updateColor(); } @Override public void propertyChange(PropertyChangeEvent evt) { - EditCatchesUIModel model = (EditCatchesUIModel) evt.getSource(); - final Color background = colorFunction.apply(model); - if (propertiesToListen.contains(evt.getPropertyName())) { + updateColor(); + } + } - getUpdateRunnableQueue().invokeLater - (new Runnable() { - public void run() { - if (log.isDebugEnabled()) { - log.debug("update " + elementId + " field"); - } + protected void updateColor() { + canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater + (new Runnable() { + public void run() { + if (log.isDebugEnabled()) { + log.debug("update " + elementId + " field"); + } - Element rectElement = svgDocument.getElementById(elementId + "LabelRect"); - SVGStylable field = (SVGStylable) rectElement; - CSSStyleDeclaration style = field.getStyle(); + Element rectElement = svgDocument.getElementById(elementId + "LabelRect"); + SVGStylable field = (SVGStylable) rectElement; + CSSStyleDeclaration style = field.getStyle(); - String color = "#" + Integer.toHexString(background.getRGB()).substring(2); - style.setProperty("fill", color, null); - } - }); - } + final Color background = colorFunction.apply(getModel()); + String color = "#" + Integer.toHexString(background.getRGB()).substring(2); + style.setProperty("fill", color, null); + } + }); } } - private static class RatioPropertyChangeListener extends UpdateRunnableQueuePropertyChangeListener { + private class RatioPropertyChangeListener implements PropertyChangeListener { private final String elementId; private final String numeratorProperty; @@ -1223,14 +1308,13 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi public RatioPropertyChangeListener(String elementId, String numeratorProperty, String denominatorProperty, - String denominatorComputedProperty, - JSVGCanvas canvas, - Document svgDocument) { - super(canvas, svgDocument); + String denominatorComputedProperty) { this.elementId = elementId; this.numeratorProperty = numeratorProperty; this.denominatorProperty = denominatorProperty; this.denominatorComputedProperty = denominatorComputedProperty; + + updateRatioText(); } @Override @@ -1238,48 +1322,52 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi String propertyName = evt.getPropertyName(); if (propertyName.equals(numeratorProperty) || propertyName.equals(denominatorProperty)) { - EditCatchesUIModel model = (EditCatchesUIModel) evt.getSource(); + updateRatioText(); + } + } - try { - String numerator = BeanUtils.getProperty(model, numeratorProperty); - String denominator = BeanUtils.getProperty(model, denominatorProperty); - if (denominator == null) { - denominator = BeanUtils.getProperty(model, denominatorComputedProperty); - } + protected void updateRatioText() { + EditCatchesUIModel model = getModel(); - if (numerator != null && denominator != null) { - Float numeratorValue = Float.valueOf(numerator); - Float denominatorValue = Float.valueOf(denominator); + try { + String numerator = BeanUtils.getProperty(model, numeratorProperty); + String denominator = BeanUtils.getProperty(model, denominatorProperty); + if (denominator == null) { + denominator = BeanUtils.getProperty(model, denominatorComputedProperty); + } - if (denominatorValue != 0) { - ratio = (int) (100 * numeratorValue / denominatorValue); - } - } + if (numerator != null && denominator != null) { + Float numeratorValue = Float.valueOf(numerator); + Float denominatorValue = Float.valueOf(denominator); - } catch (ReflectiveOperationException e) { - if (log.isErrorEnabled()) { - log.error("Error while computing the ration", e); + if (denominatorValue != 0) { + ratio = (int) (100 * numeratorValue / denominatorValue); } } - getUpdateRunnableQueue().invokeLater - (new Runnable() { - public void run() { - if (log.isDebugEnabled()) { - log.debug("update " + elementId + " field"); - } + } catch (ReflectiveOperationException e) { + if (log.isErrorEnabled()) { + log.error("Error while computing the ration", e); + } + } - Element ratioElement = svgDocument.getElementById(elementId); - String textContent; - if (ratio != null) { - textContent = ratio + "%"; - } else { - textContent = null; - } - ratioElement.setTextContent(textContent); + canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater + (new Runnable() { + public void run() { + if (log.isDebugEnabled()) { + log.debug("update " + elementId + " field"); } - }); - } + + Element ratioElement = svgDocument.getElementById(elementId); + String textContent; + if (ratio != null) { + textContent = ratio + "%"; + } else { + textContent = null; + } + ratioElement.setTextContent(textContent); + } + }); } } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiTabContainerUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiTabContainerUIHandler.java index ca17c7e..4eb3144 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiTabContainerUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiTabContainerUIHandler.java @@ -22,11 +22,17 @@ package fr.ifremer.tutti.ui.swing.util; * #L% */ +import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler; +import org.nuiton.jaxx.application.swing.ApplicationUI; +import org.nuiton.jaxx.application.swing.tab.CustomTab; import org.nuiton.jaxx.application.swing.tab.DelegateTabContainerHandler; import org.nuiton.jaxx.application.swing.tab.TabContainerHandler; import org.nuiton.jaxx.application.swing.tab.TabContentModel; import org.nuiton.jaxx.application.swing.tab.TabHandler; +import javax.swing.*; +import java.awt.*; + /** * UI containing a tab panel. * @@ -48,29 +54,68 @@ public abstract class AbstractTuttiTabContainerUIHandler<M, UI extends TuttiUI<M */ @Override public TabHandler getTabHandler(int index) { - TabHandler tabHandler = delegateTabHandler.getTabHandler(index); + TabHandler tabHandler = null; + JTabbedPane tabPanel = getTabPanel(); + if (index >= 0 && index < tabPanel.getTabCount()) { + Component tab = tabPanel.getComponentAt(index); + if (ApplicationUI.class.isInstance(tab)) { + ApplicationUI tuttiTab = (ApplicationUI) tabPanel.getComponentAt(index); + AbstractApplicationUIHandler handler = tuttiTab.getHandler(); + if (TabHandler.class.isInstance(handler)) { + tabHandler = (TabHandler) handler; + } + } + } return tabHandler; } @Override public void setCustomTab(int index, TabContentModel model) { - delegateTabHandler.setCustomTab(index, model); + JTabbedPane tabPanel = getTabPanel(); + tabPanel.setTabComponentAt(index, new CustomTab(model, this)); } @Override protected void initUI(UI ui) { super.initUI(ui); delegateTabHandler = new DelegateTabContainerHandler(getTabPanel()); - delegateTabHandler.init(); + init(); } @Override public void init() { - delegateTabHandler.init(); + + getTabPanel().setModel(new DefaultSingleSelectionModel() { + + private static final long serialVersionUID = 1L; + + @Override + public void setSelectedIndex(int index) { + int currentIndex = getTabPanel().getSelectedIndex(); + boolean mustChangeTab = onTabChanged(currentIndex, index); + + if (mustChangeTab) { + super.setSelectedIndex(index); + } + } + + }); } @Override public boolean onTabChanged(int currentIndex, int newIndex) { - return delegateTabHandler.onTabChanged(currentIndex, newIndex); + boolean result = true; + if (currentIndex != newIndex) { + TabHandler handler = getTabHandler(currentIndex); + if (handler != null) { + result = handler.onHideTab(currentIndex, newIndex); + } + + handler = getTabHandler(newIndex); + if (handler != null) { + handler.onShowTab(currentIndex, newIndex); + } + } + return result; } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit b6c955c34d2e57f6f6fc71d648c6b8f07736aed2 Author: Kevin Morin <morin@codelutin.com> Date: Thu Feb 5 15:19:01 2015 +0100 refs #6538 better handle erors --- .../operation/catches/EditCatchesUIHandler.java | 411 +++++++++++---------- 1 file changed, 214 insertions(+), 197 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java index bd8dc22..e27cc5f 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java @@ -54,6 +54,7 @@ import org.apache.batik.dom.svg.SVGOMTextElement; import org.apache.batik.swing.JSVGCanvas; import org.apache.batik.swing.gvt.GVTTreeRendererAdapter; import org.apache.batik.swing.gvt.GVTTreeRendererEvent; +import org.apache.batik.swing.svg.SVGUserAgentAdapter; import org.apache.batik.util.XMLResourceDescriptor; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; @@ -168,6 +169,21 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi protected Document svgDocument; + protected final SVGUserAgentAdapter ua = new SVGUserAgentAdapter() { + @Override + public void displayError(String message) { + if (log.isErrorEnabled()) { + log.error("Canvas error: " + message); + } + } + @Override + public void displayError(Exception ex) { + if (log.isErrorEnabled()) { + log.error("Canvas error", ex); + } + } + }; + //------------------------------------------------------------------------// //-- AbstractTuttiUIHandler methods --// //------------------------------------------------------------------------// @@ -322,15 +338,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi clearSVG(); } if (newIndex == 0 && getUI().isVisible()) { - try { - initResumeSvg(); - - } catch (IOException err) { - if (log.isErrorEnabled()) { - log.error("error while initializing the resume background", err); - } - getContext().getErrorHelper().showErrorDialog(t("tutti.editCatchBatch.svgLoading.error"), err); - } + initResumeSvg(); } } @@ -407,16 +415,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi @Override public void onShowTab(int currentIndex, int newIndex) { registerValidators(); - - try { - initResumeSvg(); - - } catch (IOException err) { - if (log.isErrorEnabled()) { - log.error("error while initializing the resume background", err); - } - getContext().getErrorHelper().showErrorDialog(t("tutti.editCatchBatch.svgLoading.error"), err); - } + initResumeSvg(); } @Override @@ -786,129 +785,138 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi //-- Protected methods --// //------------------------------------------------------------------------// - protected void initResumeSvg() throws IOException { - String parser = XMLResourceDescriptor.getXMLParserClassName(); - SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); - URL url = Resource.getURL("EcranResume.svg"); - svgDocument = f.createDocument(url.toString()); - - canvas = new JSVGCanvas(); - canvas.setSize(new Dimension(1, 1)); - canvas.setMySize(new Dimension(1, 1)); + protected void initResumeSvg() { + try { + String parser = XMLResourceDescriptor.getXMLParserClassName(); + SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); + URL url = Resource.getURL("EcranResume.svg"); + svgDocument = f.createDocument(url.toString()); + + // redefine user agent to avoid displaying errors about css + canvas = new JSVGCanvas(ua, true, true); + canvas.setSize(new Dimension(1, 1)); + canvas.setMySize(new Dimension(1, 1)); + + canvas.setRecenterOnResize(true); + + canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() { + @Override + public void gvtRenderingCompleted(GVTTreeRendererEvent gvtTreeRendererEvent) { + if (log.isDebugEnabled()) { + log.debug("gvtRenderingCompleted"); + } + TuttiConfiguration config = getConfig(); + WeightUnit catchWeightUnit = WeightUnit.KG; + WeightUnit speciesWeightUnit = config.getSpeciesWeightUnit(); + WeightUnit benthosWeightUnit = config.getBenthosWeightUnit(); + WeightUnit marineLitterWeightUnit = config.getMarineLitterWeightUnit(); + + EditCatchesUIModel model = getModel(); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, + model.getCatchTotalComputedOrNotWeight(), + catchWeightUnit); + + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, + model.getCatchTotalRejectedComputedOrNotWeight(), + catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, catchWeightUnit); + + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, + model.getSpeciesTotalSortedComputedOrNotWeight(), + speciesWeightUnit); + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, speciesWeightUnit); + + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, + model.getBenthosTotalSortedComputedOrNotWeight(), + benthosWeightUnit); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, benthosWeightUnit); + + initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_UNSORTED_COMPUTED_WEIGHT, catchWeightUnit); + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, speciesWeightUnit); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, benthosWeightUnit); + + addSvgRelatedPropertyChangeListener(null, new ChangeElementBackgroundColorPropertyChangeListener( + CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, + Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), + new Function<EditCatchesUIModel, Color>() { + @Override + public Color apply(EditCatchesUIModel model) { + boolean warning = model.isSpeciesTotalUnsortedComputedWeightInWarning(); + return warning ? Color.ORANGE : Color.decode("#006bba"); + } + })); + + addSvgRelatedPropertyChangeListener(null, new ChangeElementBackgroundColorPropertyChangeListener( + CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, + Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), + new Function<EditCatchesUIModel, Color>() { + @Override + public Color apply(EditCatchesUIModel model) { + boolean warning = model.isBenthosTotalUnsortedComputedWeightInWarning(); + return warning ? Color.ORANGE : Color.decode("#006bba"); + } + })); + + initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, + speciesWeightUnit, + CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); + initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, + benthosWeightUnit, + CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); + initSvgField(CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT, + CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_COMPUTED_WEIGHT, + model.getMarineLitterTotalComputedOrNotWeight(), + marineLitterWeightUnit, + CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT); + + addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioSpeciesSampleSortedOverSpeciesSortedWeightLabel", + CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT)); + addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioBenthosSampleSortedOverBenthosSortedWeightLabel", + CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, + CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT)); + addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioSortedSortedOverSortedWeightLabel", + CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, + CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT)); + + initSpeciesCount(CatchBatch.PROPERTY_SPECIES_DISTINCT_SORTED_SPECIES_COUNT); + initSpeciesCount(CatchBatch.PROPERTY_BENTHOS_DISTINCT_SORTED_SPECIES_COUNT); + + initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_CAROUSSEL_WEIGHT, catchWeightUnit); + initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_TREMIS_WEIGHT, catchWeightUnit); + + getUI().getSvgCanvasPanel().add(canvas, BorderLayout.CENTER); + } + }); - canvas.setRecenterOnResize(true); + canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); + canvas.setDocument(svgDocument); - canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() { - @Override - public void gvtRenderingCompleted(GVTTreeRendererEvent gvtTreeRendererEvent) { - if (log.isDebugEnabled()) { - log.debug("gvtRenderingCompleted"); - } - TuttiConfiguration config = getConfig(); - WeightUnit catchWeightUnit = WeightUnit.KG; - WeightUnit speciesWeightUnit = config.getSpeciesWeightUnit(); - WeightUnit benthosWeightUnit = config.getBenthosWeightUnit(); - WeightUnit marineLitterWeightUnit = config.getMarineLitterWeightUnit(); - - EditCatchesUIModel model = getModel(); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, - model.getCatchTotalComputedOrNotWeight(), - catchWeightUnit); - - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, - model.getCatchTotalRejectedComputedOrNotWeight(), - catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, catchWeightUnit); - - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, - model.getSpeciesTotalSortedComputedOrNotWeight(), - speciesWeightUnit); - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, speciesWeightUnit); - - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, - model.getBenthosTotalSortedComputedOrNotWeight(), - benthosWeightUnit); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, benthosWeightUnit); - - initSvgField(CatchBatch.PROPERTY_CATCH_TOTAL_UNSORTED_COMPUTED_WEIGHT, catchWeightUnit); - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, speciesWeightUnit); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, benthosWeightUnit); - - addSvgRelatedPropertyChangeListener(null, new ChangeElementBackgroundColorPropertyChangeListener( - CatchBatch.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, - Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), - new Function<EditCatchesUIModel, Color>() { - @Override - public Color apply(EditCatchesUIModel model) { - boolean warning = model.isSpeciesTotalUnsortedComputedWeightInWarning(); - return warning ? Color.ORANGE : Color.decode("#006bba"); - } - })); - - addSvgRelatedPropertyChangeListener(null, new ChangeElementBackgroundColorPropertyChangeListener( - CatchBatch.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, - Sets.newHashSet(CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT), - new Function<EditCatchesUIModel, Color>() { - @Override - public Color apply(EditCatchesUIModel model) { - boolean warning = model.isBenthosTotalUnsortedComputedWeightInWarning(); - return warning ? Color.ORANGE : Color.decode("#006bba"); - } - })); - - initSvgField(CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, - speciesWeightUnit, - CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); - initSvgField(CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, - benthosWeightUnit, - CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); - initSvgField(CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT, - CatchBatch.PROPERTY_MARINE_LITTER_TOTAL_COMPUTED_WEIGHT, - model.getMarineLitterTotalComputedOrNotWeight(), - marineLitterWeightUnit, - CatchBatch.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT); - - addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioSpeciesSampleSortedOverSpeciesSortedWeightLabel", - CatchBatch.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT)); - addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioBenthosSampleSortedOverBenthosSortedWeightLabel", - CatchBatch.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - CatchBatch.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT)); - addSvgRelatedPropertyChangeListener(null, new RatioPropertyChangeListener("ratioSortedSortedOverSortedWeightLabel", - CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT, - CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_COMPUTED_WEIGHT)); - - initSpeciesCount(CatchBatch.PROPERTY_SPECIES_DISTINCT_SORTED_SPECIES_COUNT); - initSpeciesCount(CatchBatch.PROPERTY_BENTHOS_DISTINCT_SORTED_SPECIES_COUNT); - - initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_CAROUSSEL_WEIGHT, catchWeightUnit); - initTremieCarrouselField(CatchBatch.PROPERTY_CATCH_TOTAL_SORTED_TREMIS_WEIGHT, catchWeightUnit); - - getUI().getSvgCanvasPanel().add(canvas, BorderLayout.CENTER); + } catch (IOException err) { + if (log.isErrorEnabled()) { + log.error("error while initializing the resume background", err); } - }); - - canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); - canvas.setDocument(svgDocument); + getContext().getErrorHelper().showErrorDialog(t("tutti.editCatchBatch.svgLoading.error"), err); + } } protected void initSpeciesCount(final String property) { @@ -917,7 +925,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi log.debug("init " + property + " field"); } - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { + updateOnCanvas(new Runnable() { @Override public void run() { Element labelElement = svgDocument.getElementById(property + "Label"); @@ -958,7 +966,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi log.debug("init " + property + " field"); } - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { + updateOnCanvas(new Runnable() { @Override public void run() { Element labelElement = svgDocument.getElementById(property + "Label"); @@ -1032,7 +1040,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi target.addEventListener("click", new OnValueClickListener(computableData, property, weightUnit), false); } - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { + updateOnCanvas(new Runnable() { @Override public void run() { @@ -1088,6 +1096,18 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } + protected void updateOnCanvas(Runnable runnable) { + try { + canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(runnable); + } catch (IllegalStateException e) { + if (log.isErrorEnabled()) { + log.error("error while updating canvas, reload it"); + } + clearSVG(); + initResumeSvg(); + } + } + protected Float getModelPropertyValue(String property) { Float value; try { @@ -1138,49 +1158,48 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi final boolean computed, final String... idsInGroup) { - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater - (new Runnable() { - public void run() { - if (log.isDebugEnabled()) { - log.debug("update " + property + " field"); - } + updateOnCanvas(new Runnable() { + public void run() { + if (log.isDebugEnabled()) { + log.debug("update " + property + " field"); + } - SVGOMTextElement valueElement = (SVGOMTextElement) svgDocument.getElementById(property + "Value"); - if (valueElement == null) { - return; - } + SVGOMTextElement valueElement = (SVGOMTextElement) svgDocument.getElementById(property + "Value"); + if (valueElement == null) { + return; + } - //TODO i18n ? - String textContent; - if (value != null) { - textContent = Weights.getWeightStringValue(value) + " " + weightUnit.getShortLabel(); - } else { - textContent = null; - } - valueElement.setTextContent(textContent); - - CSSStyleDeclaration style = valueElement.getStyle(); - - Color colorComputedWeights = getConfig().getColorComputedWeights(); - String computedColor = "#" + Integer.toHexString(colorComputedWeights.getRGB()).substring(2); - style.setProperty("fill", computed ? computedColor : "#000000", null); - style.setProperty("font-style", computed ? "italic" : "normal", null); - - SVGRect bbox = valueElement.getBBox(); - SVGOMRectElement rectElement = (SVGOMRectElement) svgDocument.getElementById(property + "Rect"); - if (bbox != null && rectElement != null) { - float width = bbox.getWidth() + 15; - float actualWidth = rectElement.getBBox().getWidth(); - if (actualWidth < width) { - rectElement.setAttribute("width", Float.toString(width)); - for (String id : idsInGroup) { - Element el = svgDocument.getElementById(id + "Rect"); - el.setAttribute("width", Float.toString(width)); - } - } + //TODO i18n ? + String textContent; + if (value != null) { + textContent = Weights.getWeightStringValue(value) + " " + weightUnit.getShortLabel(); + } else { + textContent = null; + } + valueElement.setTextContent(textContent); + + CSSStyleDeclaration style = valueElement.getStyle(); + + Color colorComputedWeights = getConfig().getColorComputedWeights(); + String computedColor = "#" + Integer.toHexString(colorComputedWeights.getRGB()).substring(2); + style.setProperty("fill", computed ? computedColor : "#000000", null); + style.setProperty("font-style", computed ? "italic" : "normal", null); + + SVGRect bbox = valueElement.getBBox(); + SVGOMRectElement rectElement = (SVGOMRectElement) svgDocument.getElementById(property + "Rect"); + if (bbox != null && rectElement != null) { + float width = bbox.getWidth() + 15; + float actualWidth = rectElement.getBBox().getWidth(); + if (actualWidth < width) { + rectElement.setAttribute("width", Float.toString(width)); + for (String id : idsInGroup) { + Element el = svgDocument.getElementById(id + "Rect"); + el.setAttribute("width", Float.toString(width)); } } - }); + } + } + }); } @@ -1278,22 +1297,21 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } protected void updateColor() { - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater - (new Runnable() { - public void run() { - if (log.isDebugEnabled()) { - log.debug("update " + elementId + " field"); - } + updateOnCanvas(new Runnable() { + public void run() { + if (log.isDebugEnabled()) { + log.debug("update " + elementId + " field"); + } - Element rectElement = svgDocument.getElementById(elementId + "LabelRect"); - SVGStylable field = (SVGStylable) rectElement; - CSSStyleDeclaration style = field.getStyle(); + Element rectElement = svgDocument.getElementById(elementId + "LabelRect"); + SVGStylable field = (SVGStylable) rectElement; + CSSStyleDeclaration style = field.getStyle(); - final Color background = colorFunction.apply(getModel()); - String color = "#" + Integer.toHexString(background.getRGB()).substring(2); - style.setProperty("fill", color, null); - } - }); + final Color background = colorFunction.apply(getModel()); + String color = "#" + Integer.toHexString(background.getRGB()).substring(2); + style.setProperty("fill", color, null); + } + }); } } @@ -1351,8 +1369,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } } - canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater - (new Runnable() { + updateOnCanvas(new Runnable() { public void run() { if (log.isDebugEnabled()) { log.debug("update " + elementId + " field"); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm