Skip to content

Commit 4de8d13

Browse files
authored
Merge pull request #4137 from gchq/gh-4132-docref-hover-button-tooltips
PR for #4132 - Tooltip for new Open/Copy options in stream browser please
2 parents e3aac2a + e82a586 commit 4de8d13

File tree

5 files changed

+355
-158
lines changed

5 files changed

+355
-158
lines changed

stroom-core-client/src/main/java/stroom/data/client/presenter/CopyTextUtil.java

+21-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import stroom.svg.shared.SvgImage;
44
import stroom.util.client.ClipboardUtil;
5+
import stroom.util.shared.GwtNullSafe;
56
import stroom.widget.util.client.ElementUtil;
67
import stroom.widget.util.client.MouseUtil;
78
import stroom.widget.util.client.SvgImageUtil;
@@ -20,6 +21,7 @@ public class CopyTextUtil {
2021
public static final String ICON_NAME = "svgIcon";
2122
public static final String COPY_CLASS_NAME = "docRefLinkCopy";
2223
private static final Template TEMPLATE;
24+
private static final int TRUNCATE_THRESHOLD = 30;
2325

2426
static {
2527
TEMPLATE = GWT.create(Template.class);
@@ -41,10 +43,16 @@ public static void render(final String value, final SafeHtmlBuilder sb) {
4143
sb.appendHtmlConstant("<div class=\"docRefLinkContainer\">");
4244
sb.append(textSafeHtml);
4345

44-
if (value.trim().length() > 0) {
46+
GwtNullSafe.consumeNonBlankString(value, str -> {
4547
final SafeHtml copy = SvgImageUtil.toSafeHtml(SvgImage.COPY, ICON_NAME, COPY_CLASS_NAME);
46-
sb.append(copy);
47-
}
48+
// Cell values could be huge so truncate big ones
49+
final String truncatedStr = str.length() > TRUNCATE_THRESHOLD
50+
? (str.substring(0, TRUNCATE_THRESHOLD) + "...")
51+
: str;
52+
sb.append(TEMPLATE.divWithToolTip(
53+
"Copy value '" + truncatedStr + "' to clipboard.",
54+
copy));
55+
});
4856

4957
sb.appendHtmlConstant("</div>");
5058
}
@@ -56,11 +64,11 @@ public static void onClick(final NativeEvent e) {
5664
final Element copy =
5765
ElementUtil.findMatching(element, CopyTextUtil.COPY_CLASS_NAME, 0, 5);
5866
if (copy != null) {
59-
final Element container =
60-
ElementUtil.findMatching(element, "docRefLinkContainer", 0, 5);
61-
if (container != null && container.getInnerText().trim().length() > 0) {
62-
ClipboardUtil.copy(container.getInnerText().trim());
63-
}
67+
final Element container = ElementUtil.findMatching(
68+
element, "docRefLinkContainer", 0, 5);
69+
70+
GwtNullSafe.consumeNonBlankString(container, Element::getInnerText, text ->
71+
ClipboardUtil.copy(text.trim()));
6472
}
6573
}
6674
}
@@ -69,9 +77,14 @@ public static SafeHtml div(String className, SafeHtml content) {
6977
return TEMPLATE.div(className, content);
7078
}
7179

80+
// --------------------------------------------------------------------------------
81+
7282
interface Template extends SafeHtmlTemplates {
7383

7484
@Template("<div class=\"{0}\">{1}</div>")
7585
SafeHtml div(String className, SafeHtml content);
86+
87+
@Template("<div title=\"{0}\">{1}</div>")
88+
SafeHtml divWithToolTip(String title, SafeHtml content);
7689
}
7790
}

stroom-core-client/src/main/java/stroom/data/client/presenter/DocRefCell.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,15 @@ public void render(final Context context, final DocRef value, final SafeHtmlBuil
111111
sb.append(textSafeHtml);
112112

113113
final SafeHtml copy = SvgImageUtil.toSafeHtml(SvgImage.COPY, ICON_NAME, COPY_CLASS_NAME);
114-
sb.append(copy);
114+
sb.append(template.divWithToolTip(
115+
"Copy name '" + value.getName() + "' to clipboard.",
116+
copy));
115117

116118
if (value.getUuid() != null || allowLinkByName) {
117119
final SafeHtml open = SvgImageUtil.toSafeHtml(SvgImage.OPEN, ICON_NAME, OPEN_CLASS_NAME);
118-
sb.append(open);
120+
sb.append(template.divWithToolTip(
121+
"Open " + value.getType() + " " + value.getName() + " in new tab.",
122+
open));
119123
}
120124

121125
sb.appendHtmlConstant("</div>");
@@ -132,9 +136,16 @@ private String getText(final DocRef docRef) {
132136
return null;
133137
}
134138

139+
140+
// --------------------------------------------------------------------------------
141+
142+
135143
interface Template extends SafeHtmlTemplates {
136144

137145
@Template("<div class=\"{0}\">{1}</div>")
138146
SafeHtml div(String expanderClass, SafeHtml icon);
147+
148+
@Template("<div title=\"{0}\">{1}</div>")
149+
SafeHtml divWithToolTip(String title, SafeHtml content);
139150
}
140151
}

stroom-util-shared/src/main/java/stroom/util/shared/GwtNullSafe.java

+52-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ private GwtNullSafe() {
3232

3333
/**
3434
* Allows you to safely compare a child property of val1 to other.
35+
*
3536
* @return False if val1 is null else whether the child property of val1 is equal to other
3637
*/
3738
public static <T1, T2> boolean equals(final T1 val1,
@@ -47,6 +48,7 @@ public static <T1, T2> boolean equals(final T1 val1,
4748

4849
/**
4950
* Allows you to safely compare a grandchild property of val1 to other.
51+
*
5052
* @return False if val1 is null or if val1's child property is null,
5153
* else whether the grandchild property of val1 is equal to other
5254
*/
@@ -161,6 +163,34 @@ public static boolean isBlankString(final String str) {
161163
return true;
162164
}
163165

166+
/**
167+
* @return str if it is not null/empty/blank, else other.
168+
*/
169+
public static String nonBlankStringElse(final String str, final String other) {
170+
return isBlankString(str)
171+
? Objects.requireNonNull(other)
172+
: str;
173+
}
174+
175+
/**
176+
* @return str if it is not null/empty/blank, else result of calling otherSupplier.
177+
*/
178+
public static String nonBlankStringElseGet(final String str, final Supplier<String> otherSupplier) {
179+
return isBlankString(str)
180+
? Objects.requireNonNull(Objects.requireNonNull(otherSupplier).get())
181+
: str;
182+
}
183+
184+
/**
185+
* If str is not null/empty/blank then pass it to consumer (if that is not null).
186+
*/
187+
public static void consumeNonBlankString(final String str, final Consumer<String> consumer) {
188+
// GWT doesn't emulate String::isBlank
189+
if (!isBlankString(str) && consumer != null) {
190+
consumer.accept(str);
191+
}
192+
}
193+
164194
/**
165195
* @return True if str is null or empty
166196
*/
@@ -228,7 +258,7 @@ public static <T> boolean isEmptyString(final T value,
228258
}
229259

230260
/**
231-
* @return True if value is null or the string property is null or empty
261+
* @return True if value is null or the string property is null/empty/blank
232262
*/
233263
public static <T> boolean isBlankString(final T value,
234264
final Function<T, String> stringGetter) {
@@ -240,6 +270,22 @@ public static <T> boolean isBlankString(final T value,
240270
}
241271
}
242272

273+
/**
274+
* If str is not null/empty/blank then pass it to consumer (if that is not null).
275+
*/
276+
public static <T> void consumeNonBlankString(final T value,
277+
final Function<T, String> stringGetter,
278+
final Consumer<String> consumer) {
279+
// GWT doesn't emulate String::isBlank
280+
if (value != null && stringGetter != null && consumer != null) {
281+
final String str = stringGetter.apply(value);
282+
283+
if (!isBlankString(str)) {
284+
Objects.requireNonNull(consumer).accept(str);
285+
}
286+
}
287+
}
288+
243289
/**
244290
* @return True if value is null or the collection is null or empty
245291
*/
@@ -373,6 +419,7 @@ public static <T> Stream<T> stream(final T... items) {
373419
/**
374420
* Returns the passed array of items or varargs items as a non-null list.
375421
* Does not support null items in the list.
422+
*
376423
* @return A non-null list of items. List should be assumed to be immutable.
377424
*/
378425
public static <T> List<T> asList(final T... items) {
@@ -384,6 +431,7 @@ public static <T> List<T> asList(final T... items) {
384431
/**
385432
* Returns the passed array of items or varargs items as a non-null set.
386433
* Does not support null items in the array.
434+
*
387435
* @return A non-null unmodifiable set of items.
388436
*/
389437
public static <T> Set<T> asSet(final T... items) {
@@ -971,7 +1019,9 @@ private static String convertToString(final Object value, final String other) {
9711019
* GWT currently doesn't emulate requireNonNullElse
9721020
*/
9731021
public static <T> T requireNonNullElse(T obj, T other) {
974-
return (obj != null) ? obj : Objects.requireNonNull(other, "other");
1022+
return (obj != null)
1023+
? obj
1024+
: Objects.requireNonNull(other, "other");
9751025
}
9761026

9771027
/**

0 commit comments

Comments
 (0)