From 8559fbe8e90c4baf21abf1c596633b02eac74a0f Mon Sep 17 00:00:00 2001
From: Florian Hoelzl <hoelzl@fortiss.org>
Date: Tue, 24 Mar 2020 14:47:53 +0100
Subject: [PATCH] Kernel: LWFXEF now provides a in-place help feature.

Issue-Ref: 3969
Issue-Url: https://af3-developer.fortiss.org/issues/3969
Signed-off-by: Florian Hoelzl <hoelzl@fortiss.org>
---
 .../build.properties                          |   3 +-
 org.fortiss.tooling.common.ui/icons/help.png  | Bin 0 -> 1095 bytes
 .../tooling/common/ui/javafx/lwfxef/.ratings  |   4 +-
 .../ui/javafx/lwfxef/DiagramViewer.java       |  62 +++++++++++++++++-
 .../javafx/lwfxef/DiagramViewerFeatures.java  |  12 ++++
 5 files changed, 77 insertions(+), 4 deletions(-)
 create mode 100644 org.fortiss.tooling.common.ui/icons/help.png

diff --git a/org.fortiss.tooling.common.ui/build.properties b/org.fortiss.tooling.common.ui/build.properties
index ab1e37fb1..15f0431a4 100644
--- a/org.fortiss.tooling.common.ui/build.properties
+++ b/org.fortiss.tooling.common.ui/build.properties
@@ -5,7 +5,8 @@ bin.includes = .,\
                lib/org.conqat.ide.commons.gef.jar,\
                lib/org.conqat.ide.commons.ui.jar,\
                lib/swt-grouplayout.jar,\
-               res/
+               res/,\
+               icons/
 jars.compile.order = .
 source.. = src/,\
            res/,\
diff --git a/org.fortiss.tooling.common.ui/icons/help.png b/org.fortiss.tooling.common.ui/icons/help.png
new file mode 100644
index 0000000000000000000000000000000000000000..e8d15197971a8222c74e29151085ef7024b61567
GIT binary patch
literal 1095
zcmV-N1i1T&P)<h;3K|Lk000e1NJLTq001BW001Be1^@s6b9#F8000CINkl<Zc-rk(
zOHWf#5O(3xg$tK1{0S~xxNzZ4V>B^BiAG~kuq_&6f{-8*bNf)yh>rk@FGK>0AQ%;&
zfQZV|2IY-B%d@4FmbO5F0^`iJ=Xy);?Ja0rd6F-^y=UfpbI#0}nY(7q|FMFhI>v2Q
zsr5;b8r|mzjlMrpqxT{JV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FniINpjl2id!<Nru4|^
zG$?vo1H<DkNuuSb{@w-ghTE%eO6A&ex}vwy|5Td0hHL^M8Aha!OF!`eEN;tbBmexv
z1WC>GVG^?cTg`~j7`M=;nM$Lp_16v`i*EWfi%{#+k$iVhp8r2WjGuW-(I{|I`}P0;
N002ovPDHLkV1mW14|M<l

literal 0
HcmV?d00001

diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/.ratings b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/.ratings
index 8f3c591ba..fbe218be6 100644
--- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/.ratings
+++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/.ratings
@@ -1,8 +1,8 @@
 DiagramCoordinate.java 6b00aec99054d4cd19003a72bd4e5e774ac6a641 GREEN
 DiagramLayers.java 155cbb47a5f0aaa0025320ae607e6777f3a2d2e8 GREEN
-DiagramViewer.java a96338d3d8e043564eb857920ade45f6e2d4ac18 GREEN
+DiagramViewer.java 07e59468c9279b6a2987daaf9ed1b7da9670bb18 YELLOW
 DiagramViewerDefaultTags.java 6230763252409c60009ab8887b4ef582cf883229 GREEN
-DiagramViewerFeatures.java 31e3fb61f915b0d8695005b083c47ce1c5be0b05 GREEN
+DiagramViewerFeatures.java 44f5315505d76ef8cb0b61b5a37d7d2501195788 YELLOW
 DiagramViewerSelection.java e833f592543bc97077907d980a39b123fc4044e6 GREEN
 EDragGesture.java 5cfa098d3877db11981c2750e5e103156d62fc5e GREEN
 FeedbackChange.java b088fa89af648f1674f2f9c1f7f99d585ce801ca GREEN
diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/DiagramViewer.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/DiagramViewer.java
index a96338d3d..07e59468c 100644
--- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/DiagramViewer.java
+++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/DiagramViewer.java
@@ -14,19 +14,23 @@ import static java.lang.Math.ceil;
 import static java.lang.Math.max;
 import static java.lang.Math.min;
 import static java.util.Objects.requireNonNull;
+import static javafx.geometry.VPos.TOP;
 import static javafx.scene.layout.GridPane.setHgrow;
 import static javafx.scene.layout.GridPane.setVgrow;
 import static javafx.scene.layout.Priority.ALWAYS;
 import static javafx.scene.paint.Color.ORANGERED;
+import static javafx.scene.paint.Color.grayRgb;
 import static org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_ALLOWED_TAG;
 import static org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_DENIED_TAG;
 import static org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_MAYBE_TAG;
+import static org.fortiss.tooling.common.ui.javafx.util.GraphicUtils.getFXImage;
 
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.function.Consumer;
 
+import org.fortiss.tooling.common.ui.ToolingCommonUIActivator;
 import org.fortiss.tooling.common.ui.javafx.lwfxef.change.Change;
 import org.fortiss.tooling.common.ui.javafx.lwfxef.change.ChangeSet;
 import org.fortiss.tooling.common.ui.javafx.lwfxef.change.DefaultModelModifier;
@@ -54,6 +58,8 @@ import javafx.scene.control.ContextMenu;
 import javafx.scene.control.Label;
 import javafx.scene.control.MenuItem;
 import javafx.scene.control.ScrollBar;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
 import javafx.scene.input.KeyEvent;
 import javafx.scene.input.ScrollEvent;
 import javafx.scene.layout.GridPane;
@@ -62,6 +68,7 @@ import javafx.scene.paint.Color;
 import javafx.scene.paint.Paint;
 import javafx.scene.shape.Line;
 import javafx.scene.shape.Rectangle;
+import javafx.scene.text.Text;
 
 /**
  * This class represents the diagram viewer node, which manages the grid
@@ -87,6 +94,12 @@ public class DiagramViewer {
 	private final DiagramLayers layers;
 	/** The viewer main pane. */
 	private final Pane viewerPane;
+	/** The help label. */
+	private final Label helpLabel = new Label("");
+	/** The help display. */
+	private Text helpText = null;
+	/** The help shadowed background. */
+	private final Rectangle helpShadow = new Rectangle(0, 0);
 	/** The mouse drag multi-selection feedback rectangle. */
 	private final Rectangle mouseDragRectangle = new Rectangle(0, 0);
 	/** The initial location where the selection rectangle was started. */
@@ -178,12 +191,24 @@ public class DiagramViewer {
 		debugLabel.setLayoutY(20);
 		debugLabel.setTextFill(ORANGERED);
 
+		viewerPane.getChildren().add(helpLabel);
+		Image helpImage = getFXImage(ToolingCommonUIActivator.PLUGIN_ID, "/icons/help.png");
+		ImageView view = new ImageView(helpImage);
+		helpLabel.setGraphic(view);
+		helpLabel.setLayoutX(viewerPane.getWidth() - helpLabel.getWidth());
+		helpLabel.setLayoutY(0);
+		helpLabel.setOnMouseClicked(evt -> {
+			toggleHelp();
+		});
+
 		// clipping rectangle for the viewer pane
 		Rectangle viewerClip = new Rectangle();
 		viewerPane.setClip(viewerClip);
 		viewerPane.layoutBoundsProperty().addListener((obs, ov, nv) -> {
-			viewerClip.setWidth(nv.getWidth());
+			double width = nv.getWidth();
+			viewerClip.setWidth(width);
 			viewerClip.setHeight(nv.getHeight());
+			helpLabel.setLayoutX(width - helpLabel.getWidth());
 		});
 
 		// update the viewer content
@@ -676,6 +701,41 @@ public class DiagramViewer {
 		return getLayers().getMouseState().getDragExtent();
 	}
 
+	/** Toggles the in-place help. */
+	private void toggleHelp() {
+		if(helpText == null) {
+			// enable help
+			String txt = features.getHelpText();
+			if(txt == null || "".equals(txt)) {
+				txt = "No in-place help available.";
+			}
+			helpText = new Text(txt);
+			helpText.setFill(Color.WHITE);
+			helpText.setLayoutY(0);
+			double lw = viewerPane.getWidth() - helpLabel.getWidth();
+			// 20% of the width with 3 pixel inset
+			helpText.setLayoutX(lw * .2 + 3);
+			helpText.setLayoutY(3);
+			helpText.setTextOrigin(TOP);
+			helpText.setWrappingWidth(lw * .8 - 6);
+			helpText.setOnMouseClicked(evt -> toggleHelp());
+			helpShadow.setX(lw * .2);
+			helpShadow.setY(0);
+			helpShadow.setWidth(lw * .8);
+			helpShadow.setHeight(viewerPane.getHeight());
+			helpShadow.setFill(grayRgb(32, .66));
+			helpShadow.setOnMouseClicked(evt -> toggleHelp());
+
+			viewerPane.getChildren().add(helpShadow);
+			viewerPane.getChildren().add(helpText);
+		} else {
+			// disable help
+			viewerPane.getChildren().remove(helpText);
+			viewerPane.getChildren().remove(helpShadow);
+			helpText = null;
+		}
+	}
+
 	/**
 	 * Creates a drag controller for the given bundle, gesture, mouse location and source node also
 	 * considering the current selection.
diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/DiagramViewerFeatures.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/DiagramViewerFeatures.java
index 31e3fb61f..44f531550 100644
--- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/DiagramViewerFeatures.java
+++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/DiagramViewerFeatures.java
@@ -47,6 +47,8 @@ public final class DiagramViewerFeatures {
 	private IndicatorType indicatorType = IndicatorType.CROSS;
 	/** The background color. */
 	private Color backgroundColor = LIGHTGRAY;
+	/** The help text for the diagram viewer in-place help */
+	private String helpText = null;
 
 	/** Constructor. */
 	public DiagramViewerFeatures(DiagramViewer diagramViewer) {
@@ -280,4 +282,14 @@ public final class DiagramViewerFeatures {
 	public double getMaximumSpacing() {
 		return max(getVerticalSpacing(), getHorizontalSpacing());
 	}
+
+	/** Returns the help text. */
+	public String getHelpText() {
+		return helpText;
+	}
+
+	/** Sets help text. */
+	public void setHelpText(String helpText) {
+		this.helpText = helpText;
+	}
 }
-- 
GitLab