From 57e057d2e329240ddbef6ac693327fc8e2831265 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Mon, 30 Sep 2019 10:59:25 +0300 Subject: [PATCH] Minor UI bug fixes for dynamic visualisations gitlab #59 Change-Id: I21c6467b898d2d724cf180758974567120cb7702 (cherry picked from commit 8ed34578950dcf8e59f85e3ceecf0f8f264f6208) --- .../network/ui/DistrictDiagramViewer.java | 40 ++++++++++++------ .../DynamicVisualisationsUI.java | 41 ++++++++----------- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java index d7f530df..7ee2f2fa 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java @@ -309,9 +309,13 @@ public class DistrictDiagramViewer extends DiagramViewer { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); Resource model = graph.syncRequest(new IndexRoot(parameter)); Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model); - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DistrictNetworkUtil.colorBarOptions(graph, activeVisualisation); + if (vf != null) { + Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); + if (activeVisualisation != null) { + return DistrictNetworkUtil.colorBarOptions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } return ColorBarOptions.useDefault(); } @@ -328,9 +332,13 @@ public class DistrictDiagramViewer extends DiagramViewer { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); Resource model = graph.syncRequest(new IndexRoot(parameter)); Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model); - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DistrictNetworkUtil.colorContributions(graph, activeVisualisation); + if (vf != null) { + Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); + if (activeVisualisation != null) { + return DistrictNetworkUtil.colorContributions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } return Collections.emptyMap(); } @@ -403,9 +411,13 @@ public class DistrictDiagramViewer extends DiagramViewer { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); Resource model = graph.syncRequest(new IndexRoot(parameter)); Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model); - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DistrictNetworkUtil.sizeBarOptions(graph, activeVisualisation); + if (vf != null) { + Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); + if (activeVisualisation != null) { + return DistrictNetworkUtil.sizeBarOptions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } return SizeBarOptions.useDefault(); } @@ -450,9 +462,13 @@ public class DistrictDiagramViewer extends DiagramViewer { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); Resource model = graph.syncRequest(new IndexRoot(parameter)); Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model); - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DistrictNetworkUtil.sizeContributions(graph, activeVisualisation); + if (vf != null) { + Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); + if (activeVisualisation != null) { + return DistrictNetworkUtil.sizeContributions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } return Collections.emptyMap(); } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java index c5be0451..bc055152 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java @@ -228,6 +228,19 @@ public class DynamicVisualisationsUI extends Composite { } } + private void persistCurrentVisualisationTemplateIfAvailable() { + if (visualisation != null) { + try { + persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); + } catch (Exception e1) { + LOGGER.error("Could not persist visualisation template", e1); + ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); + } + } else { + LOGGER.info("No current visualisation template selected for saving"); + } + } + private void persistVisualisationTemplate(String templateName, Optional existing) throws Exception { List> colorCollect = colorSuppliers.stream().map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList()); @@ -880,12 +893,7 @@ public class DynamicVisualisationsUI extends Composite { @Override public void widgetSelected(SelectionEvent e) { - try { - persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); - } catch (Exception e1) { - LOGGER.error("Could not persist visualisation template", e1); - ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); - } + persistCurrentVisualisationTemplateIfAvailable(); } }); } else if (widget instanceof Combo) { @@ -893,12 +901,7 @@ public class DynamicVisualisationsUI extends Composite { @Override public void widgetSelected(SelectionEvent e) { - try { - persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); - } catch (Exception e1) { - LOGGER.error("Could not persist visualisation template", e1); - ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); - } + persistCurrentVisualisationTemplateIfAvailable(); } }); } else if (widget instanceof Text) { @@ -906,12 +909,7 @@ public class DynamicVisualisationsUI extends Composite { @Override public void focusLost(FocusEvent e) { - try { - persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); - } catch (Exception e1) { - LOGGER.error("Could not persist visualisation template", e1); - ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); - } + persistCurrentVisualisationTemplateIfAvailable(); } }); ((Text) widget).addKeyListener(new KeyAdapter() { @@ -919,12 +917,7 @@ public class DynamicVisualisationsUI extends Composite { @Override public void keyReleased(KeyEvent e) { if(e.keyCode == SWT.CR || e.keyCode == SWT.LF) { - try { - persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); - } catch (Exception e1) { - LOGGER.error("Could not persist visualisation template", e1); - ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); - } + persistCurrentVisualisationTemplateIfAvailable(); } } }); -- 2.47.1