From: jsimomaa Date: Mon, 30 Sep 2019 07:59:25 +0000 (+0300) Subject: Minor UI bug fixes for dynamic visualisations X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=57e057d2e329240ddbef6ac693327fc8e2831265;p=simantics%2Fdistrict.git Minor UI bug fixes for dynamic visualisations gitlab #59 Change-Id: I21c6467b898d2d724cf180758974567120cb7702 (cherry picked from commit 8ed34578950dcf8e59f85e3ceecf0f8f264f6208) --- 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(); } } });