Skip to content

Commit 9fc2097

Browse files
committed
Merge commit 'refs/pull/5081/head' of github.com:gchq/stroom
2 parents 1ecd48f + 9f2e090 commit 9fc2097

File tree

19 files changed

+392
-117
lines changed

19 files changed

+392
-117
lines changed

stroom-core-client-widget/src/main/java/stroom/data/grid/client/MyDataGrid.java

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import stroom.svg.shared.SvgImage;
2222
import stroom.task.client.DefaultTaskMonitorFactory;
2323
import stroom.widget.menu.client.presenter.IconMenuItem;
24+
import stroom.widget.menu.client.presenter.IconMenuItem.Builder;
2425
import stroom.widget.menu.client.presenter.Item;
2526
import stroom.widget.menu.client.presenter.ShowMenuEvent;
2627
import stroom.widget.popup.client.presenter.PopupPosition;
@@ -43,6 +44,7 @@
4344
import com.google.gwt.dom.client.TableSectionElement;
4445
import com.google.gwt.event.shared.HandlerRegistration;
4546
import com.google.gwt.event.shared.HasHandlers;
47+
import com.google.gwt.http.client.URL;
4648
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
4749
import com.google.gwt.user.cellview.client.Column;
4850
import com.google.gwt.user.cellview.client.DataGrid;
@@ -253,34 +255,33 @@ private void showContextMenu(final int x, final int y, final int rowIndex,
253255
}
254256
}
255257

256-
if (!specialItems) {
257-
Element linkElement = target;
258-
while (linkElement != null && !"a".equalsIgnoreCase(linkElement.getTagName())) {
259-
linkElement = linkElement.getParentElement();
260-
}
258+
Element linkElement = target;
259+
while (linkElement != null && !"a".equalsIgnoreCase(linkElement.getTagName())) {
260+
linkElement = linkElement.getParentElement();
261+
}
261262

262-
if (linkElement != null) {
263-
final String href = linkElement.getAttribute("href");
264-
if (href != null && !href.isEmpty() && !href.startsWith("javascript")) {
265-
hyperlink = new Hyperlink(
266-
normalizeWhitespace(linkElement.getInnerText()),
267-
href,
268-
null,
269-
null);
270-
}
263+
if (linkElement != null) {
264+
final String href = linkElement.getAttribute("href");
265+
if (href != null && !href.isEmpty() && !href.startsWith("javascript")) {
266+
hyperlink = new Hyperlink(
267+
normalizeWhitespace(linkElement.getInnerText()),
268+
URL.decodeQueryString(href),
269+
null,
270+
null,
271+
null);
271272
}
273+
}
272274

273-
if (hyperlink == null) {
274-
Element customLinkElement = target;
275-
while (customLinkElement != null && !customLinkElement.hasAttribute("link")) {
276-
customLinkElement = customLinkElement.getParentElement();
277-
}
275+
if (hyperlink == null) {
276+
Element customLinkElement = target;
277+
while (customLinkElement != null && !customLinkElement.hasAttribute("link")) {
278+
customLinkElement = customLinkElement.getParentElement();
279+
}
278280

279-
if (customLinkElement != null) {
280-
final String linkAttr = customLinkElement.getAttribute("link");
281-
if (linkAttr != null) {
282-
hyperlink = Hyperlink.create(linkAttr);
283-
}
281+
if (customLinkElement != null) {
282+
final String linkAttr = customLinkElement.getAttribute("link");
283+
if (linkAttr != null) {
284+
hyperlink = Hyperlink.create(linkAttr);
284285
}
285286
}
286287
}
@@ -290,6 +291,9 @@ private void showContextMenu(final int x, final int y, final int rowIndex,
290291
if (hyperlink != null) {
291292
isLink = true;
292293
final Hyperlink finalHyperlink = hyperlink;
294+
if (!menuItems.isEmpty()) {
295+
menuItems.add(new stroom.widget.menu.client.presenter.Separator(1));
296+
}
293297
menuItems.add(new IconMenuItem.Builder()
294298
.icon(SvgImage.COPY)
295299
.text("Copy Link URL")
@@ -303,6 +307,28 @@ private void showContextMenu(final int x, final int y, final int rowIndex,
303307
finalHyperlink,
304308
new DefaultTaskMonitorFactory(globalEventBus)))
305309
.build());
310+
311+
if ("dashboard".equals(hyperlink.getType())) {
312+
if ("self".equals(hyperlink.getTarget())) {
313+
menuItems.add(new Builder()
314+
.icon(SvgImage.OPEN)
315+
.text("Open In New Tab")
316+
.command(() -> HyperlinkEvent.fire(
317+
globalEventBus,
318+
finalHyperlink.copy().target("tab").build(),
319+
new DefaultTaskMonitorFactory(globalEventBus)))
320+
.build());
321+
} else {
322+
menuItems.add(new Builder()
323+
.icon(SvgImage.OPEN)
324+
.text("Open In This Tab")
325+
.command(() -> HyperlinkEvent.fire(
326+
globalEventBus,
327+
finalHyperlink.copy().target("self").build(),
328+
new DefaultTaskMonitorFactory(globalEventBus)))
329+
.build());
330+
}
331+
}
306332
}
307333

308334
if (rowIndex >= 0 && colIndex >= 0) {

stroom-core-client-widget/src/main/java/stroom/hyperlink/client/Hyperlink.java

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ public class Hyperlink {
1818
private final String href;
1919
private final String type;
2020
private final SvgImage icon;
21+
private final String target;
2122

2223
public Hyperlink(final String text,
2324
final String href,
2425
final String type,
25-
final SvgImage icon) {
26+
final SvgImage icon,
27+
final String target) {
2628
this.text = text;
2729
this.href = href;
2830
this.type = type;
2931
this.icon = icon;
32+
this.target = target;
3033
}
3134

3235
/**
@@ -56,10 +59,15 @@ public static Hyperlink create(final String value, final int pos) {
5659
if (href != null) {
5760
index = index + href.length() + 2;
5861
final String type = nextToken(value, index, '{', '}');
62+
if (type != null) {
63+
index = index + type.length() + 2;
64+
}
65+
final String target = nextToken(value, index, '<', '>');
5966
hyperlink = new Builder()
6067
.text(text)
61-
.href(href)
68+
.href(decode(href))
6269
.type(type)
70+
.target(target)
6371
.build();
6472
}
6573
}
@@ -113,30 +121,53 @@ private static String nextToken(final String value,
113121

114122
public String getText() {
115123
// Why are we decoding the plain text part?
116-
return decode(text);
124+
return text;
117125
// return text;
118126
}
119127

120128
public String getHref() {
121-
return decode(href);
129+
return href;
122130
}
123131

124132
public String getType() {
125-
// Why are we decoding the type part?
126-
return decode(type);
133+
return type;
134+
}
135+
136+
public String getTarget() {
137+
return target;
127138
}
128139

129140
public SvgImage getIcon() {
130141
return icon;
131142
}
132143

133-
private String decode(final String string) {
144+
public HyperlinkTargetType getTargetType() {
145+
try {
146+
return HyperlinkTargetType.valueOf(target.toUpperCase());
147+
} catch (final RuntimeException ignored) {
148+
return null;
149+
}
150+
}
151+
152+
153+
private static String decode(final String string) {
134154
// Hyperlink values are URLEncoded within the link dashboard function, so they need to be decoded when used.
135155
if (string == null) {
136156
return null;
137157
}
138158
if (GWT.isClient()) {
139-
return URL.decode(string);
159+
return URL.decodeQueryString(string);
160+
}
161+
return string;
162+
}
163+
164+
private static String encode(final String string) {
165+
// Hyperlink values are URLEncoded within the link dashboard function, so they need to be decoded when used.
166+
if (string == null) {
167+
return null;
168+
}
169+
if (GWT.isClient()) {
170+
return URL.encodeQueryString(string);
140171
}
141172
return string;
142173
}
@@ -152,12 +183,13 @@ public boolean equals(final Object o) {
152183
final Hyperlink hyperlink = (Hyperlink) o;
153184
return Objects.equals(text, hyperlink.text) &&
154185
Objects.equals(href, hyperlink.href) &&
155-
Objects.equals(type, hyperlink.type);
186+
Objects.equals(type, hyperlink.type) &&
187+
Objects.equals(target, hyperlink.target);
156188
}
157189

158190
@Override
159191
public int hashCode() {
160-
return Objects.hash(text, href, type);
192+
return Objects.hash(text, href, type, target);
161193
}
162194

163195
@Override
@@ -170,14 +202,19 @@ public String toString() {
170202
}
171203
if (href != null) {
172204
sb.append("(");
173-
sb.append(href);
205+
sb.append(encode(href));
174206
sb.append(")");
175207
}
176208
if (type != null) {
177209
sb.append("{");
178210
sb.append(type);
179211
sb.append("}");
180212
}
213+
if (target != null) {
214+
sb.append("<");
215+
sb.append(target);
216+
sb.append(">");
217+
}
181218
return sb.toString();
182219
}
183220

@@ -199,6 +236,7 @@ public static final class Builder {
199236
private String href;
200237
private String type;
201238
private SvgImage icon;
239+
private String target;
202240

203241
private Builder() {
204242
}
@@ -208,6 +246,7 @@ private Builder(final Hyperlink hyperlink) {
208246
this.href = hyperlink.href;
209247
this.type = hyperlink.type;
210248
this.icon = hyperlink.icon;
249+
this.target = hyperlink.target;
211250
}
212251

213252
public Builder text(final String text) {
@@ -230,12 +269,18 @@ public Builder icon(final SvgImage icon) {
230269
return this;
231270
}
232271

272+
public Builder target(final String target) {
273+
this.target = target;
274+
return this;
275+
}
276+
233277
public Hyperlink build() {
234278
return new Hyperlink(
235279
text,
236280
href,
237281
type,
238-
icon);
282+
icon,
283+
target);
239284
}
240285
}
241286
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package stroom.hyperlink.client;
2+
3+
public enum HyperlinkTargetType {
4+
SELF,
5+
TAB
6+
}

stroom-core-client-widget/src/main/java/stroom/widget/tab/client/event/RequestCloseTabEvent.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,31 @@ public class RequestCloseTabEvent extends GwtEvent<RequestCloseTabEvent.Handler>
2727
private static Type<Handler> TYPE;
2828
private final TabData tabData;
2929
private final boolean force;
30+
private final Runnable runOnClose;
31+
private final boolean resizeTabBar;
3032

31-
private RequestCloseTabEvent(final TabData tabData, final boolean force) {
33+
private RequestCloseTabEvent(final TabData tabData, final boolean force, final Runnable runOnClose,
34+
final boolean resizeTabBar) {
3235
this.tabData = tabData;
3336
this.force = force;
37+
this.runOnClose = runOnClose;
38+
this.resizeTabBar = resizeTabBar;
3439
}
3540

3641
public static void fire(final HasHandlers handlers, final TabData tabData) {
37-
handlers.fireEvent(new RequestCloseTabEvent(tabData, false));
42+
handlers.fireEvent(new RequestCloseTabEvent(tabData, false, () -> {}, true));
3843
}
3944

4045
/**
4146
* @param force If true the tab will be closed even if dirty.
4247
*/
4348
public static void fire(final HasHandlers handlers, final TabData tabData, final boolean force) {
44-
handlers.fireEvent(new RequestCloseTabEvent(tabData, force));
49+
handlers.fireEvent(new RequestCloseTabEvent(tabData, force, () -> {}, true));
50+
}
51+
52+
public static void fire(final HasHandlers handlers, final TabData tabData, final Runnable runOnClose,
53+
final boolean resizeTabBar) {
54+
handlers.fireEvent(new RequestCloseTabEvent(tabData, false, runOnClose, resizeTabBar));
4555
}
4656

4757
public static Type<Handler> getType() {
@@ -69,6 +79,13 @@ protected void dispatch(final Handler handler) {
6979
handler.onCloseTab(this);
7080
}
7181

82+
public Runnable runOnClose() {
83+
return runOnClose;
84+
}
85+
86+
public boolean resizeTabBar() {
87+
return resizeTabBar;
88+
}
7289

7390
// --------------------------------------------------------------------------------
7491

stroom-core-client-widget/src/main/java/stroom/widget/tab/client/presenter/CurveTabLayoutPresenter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,17 @@ public void clear() {
8080
}
8181

8282
public void remove(final TabData tabData) {
83+
remove(tabData, true);
84+
}
85+
86+
public void remove(final TabData tabData, final boolean resizeTabBar) {
8387
final Layer layer = tabContentMap.remove(tabData);
8488
if (layer != null) {
85-
getView().getTabBar().removeTab(tabData);
89+
getView().getTabBar().removeTab(tabData, resizeTabBar);
8690
layer.removeLayer();
87-
fireSelectedTabChange(getSelectedTab());
91+
if (resizeTabBar) {
92+
fireSelectedTabChange(getSelectedTab());
93+
}
8894
}
8995
}
9096

stroom-core-client-widget/src/main/java/stroom/widget/tab/client/presenter/TabBar.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public interface TabBar extends
3535

3636
void removeTab(TabData tab);
3737

38+
void removeTab(TabData tab, boolean resize);
39+
3840
void moveTab(TabData tabData, int tabPos);
3941

4042
void clear();

0 commit comments

Comments
 (0)