Skip to content

Commit 1dc5064

Browse files
committed
Merge branch 'master' of github.com:gchq/stroom
2 parents ed5ba07 + e17a708 commit 1dc5064

File tree

2 files changed

+123
-10
lines changed

2 files changed

+123
-10
lines changed

stroom-core-client/src/main/java/stroom/document/client/DocumentPluginEventManager.java

+104-10
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,9 @@ private void fetchPermissions(final List<ExplorerNode> explorerNodes,
769769
.fetchExplorerPermissions(explorerNodes);
770770
}
771771

772-
private void addFavouritesMenuItem(final List<Item> menuItems, final boolean singleSelection, final int priority) {
772+
private boolean addFavouritesMenuItem(final List<Item> menuItems,
773+
final boolean singleSelection,
774+
final int priority) {
773775
final ExplorerNode primarySelection = getPrimarySelection();
774776

775777
// Add the favourites menu item if an item is selected, and it's not a root-level node or a favourite folder
@@ -789,7 +791,9 @@ private void addFavouritesMenuItem(final List<Item> menuItems, final boolean sin
789791
selectionModel.clear();
790792
})
791793
.build());
794+
return true;
792795
}
796+
return false;
793797
}
794798

795799
private void toggleFavourite(final DocRef docRef, final boolean isFavourite) {
@@ -931,10 +935,8 @@ private void addModifyMenuItems(final List<Item> menuItems,
931935
// Feeds are a special case so can't be copied, see https://github.com/gchq/stroom/issues/3048
932936
final boolean isCopyEnabled = allowRead && !hasFeed;
933937

934-
addFavouritesMenuItem(menuItems, singleSelection, 10);
935-
if (singleSelection && getPrimarySelection() != null &&
936-
!DocumentTypes.isSystem(getPrimarySelection().getType())) {
937-
menuItems.add(createCopyLinkMenuItem(getPrimarySelection(), 11));
938+
final boolean wasAdded = addFavouritesMenuItem(menuItems, singleSelection, 10);
939+
if (wasAdded) {
938940
menuItems.add(new Separator(12));
939941
}
940942

@@ -944,15 +946,18 @@ private void addModifyMenuItems(final List<Item> menuItems,
944946
menuItems.add(createRemoveTagsMenuItem(updatableItems, 22, isRemoveTagsEnabled));
945947
}
946948
menuItems.add(createCopyMenuItem(readableItems, 23, isCopyEnabled));
947-
menuItems.add(createMoveMenuItem(updatableItems, 24, allowUpdate));
948-
menuItems.add(createRenameMenuItem(updatableItems, 25, isRenameEnabled));
949-
menuItems.add(createDeleteMenuItem(deletableItems, 26, allowDelete));
949+
950+
menuItems.add(createCopyAsMenuItem(readableItems, 24));
951+
952+
menuItems.add(createMoveMenuItem(updatableItems, 25, allowUpdate));
953+
menuItems.add(createRenameMenuItem(updatableItems, 26, isRenameEnabled));
954+
menuItems.add(createDeleteMenuItem(deletableItems, 27, allowDelete));
950955

951956
if (securityContext.hasAppPermission(PermissionNames.IMPORT_CONFIGURATION)) {
952-
menuItems.add(createImportMenuItem(27));
957+
menuItems.add(createImportMenuItem(28));
953958
}
954959
if (securityContext.hasAppPermission(PermissionNames.EXPORT_CONFIGURATION)) {
955-
menuItems.add(createExportMenuItem(28, readableItems));
960+
menuItems.add(createExportMenuItem(29, readableItems));
956961
}
957962

958963
// Only allow users to change permissions if they have a single item selected.
@@ -1174,6 +1179,95 @@ private MenuItem createCopyMenuItem(final List<ExplorerNode> explorerNodeList,
11741179
.build();
11751180
}
11761181

1182+
private MenuItem createCopyAsMenuItem(final List<ExplorerNode> explorerNodes,
1183+
final int priority) {
1184+
List<Item> children = createCopyAsChildMenuItems(explorerNodes);
1185+
1186+
return new IconParentMenuItem.Builder()
1187+
.priority(priority)
1188+
.icon(SvgImage.COPY)
1189+
.text("Copy As")
1190+
.children(children)
1191+
.enabled(true)
1192+
.build();
1193+
}
1194+
1195+
private List<Item> createCopyAsChildMenuItems(final List<ExplorerNode> explorerNodes) {
1196+
final List<Item> children = new ArrayList<>();
1197+
final int count = explorerNodes.size();
1198+
int priority = 1;
1199+
if (count == 1) {
1200+
children.add(new IconMenuItem.Builder()
1201+
.priority(priority++)
1202+
.icon(SvgImage.COPY)
1203+
.text("Copy Name to Clipboard")
1204+
.enabled(true)
1205+
.command(() -> copyAs(explorerNodes, ExplorerNode::getName, "\n"))
1206+
.build());
1207+
1208+
children.add(new IconMenuItem.Builder()
1209+
.priority(priority++)
1210+
.icon(SvgImage.COPY)
1211+
.text("Copy UUID to Clipboard")
1212+
.enabled(true)
1213+
.command(() -> copyAs(explorerNodes, ExplorerNode::getUuid, "\n"))
1214+
.build());
1215+
} else if (count > 1) {
1216+
children.add(new IconMenuItem.Builder()
1217+
.priority(priority++)
1218+
.icon(SvgImage.COPY)
1219+
.text("Copy Names to Clipboard (lines)")
1220+
.enabled(true)
1221+
.command(() -> copyAs(explorerNodes, ExplorerNode::getName, "\n"))
1222+
.build());
1223+
children.add(new IconMenuItem.Builder()
1224+
.priority(priority++)
1225+
.icon(SvgImage.COPY)
1226+
.text("Copy Names to Clipboard (comma delimited)")
1227+
.enabled(true)
1228+
.command(() -> copyAs(explorerNodes, ExplorerNode::getName, ","))
1229+
.build());
1230+
children.add(new IconMenuItem.Builder()
1231+
.priority(priority++)
1232+
.icon(SvgImage.COPY)
1233+
.text("Copy UUIDs to Clipboard (lines)")
1234+
.enabled(true)
1235+
.command(() -> copyAs(explorerNodes, ExplorerNode::getUuid, "\n"))
1236+
.build());
1237+
children.add(new IconMenuItem.Builder()
1238+
.priority(priority++)
1239+
.icon(SvgImage.COPY)
1240+
.text("Copy UUIDs to Clipboard (comma delimited)")
1241+
.enabled(true)
1242+
.command(() -> copyAs(explorerNodes, ExplorerNode::getUuid, ","))
1243+
.build());
1244+
}
1245+
1246+
if (explorerNodes.size() == 1) {
1247+
children.add(createCopyLinkMenuItem(explorerNodes.get(0), priority++));
1248+
}
1249+
1250+
return children;
1251+
}
1252+
1253+
private void copyAs(final List<ExplorerNode> nodes,
1254+
final Function<ExplorerNode, String> extractor,
1255+
final String delimter) {
1256+
final String value;
1257+
if (nodes.isEmpty()) {
1258+
value = "";
1259+
} else if (nodes.size() == 1) {
1260+
value = GwtNullSafe.getOrElse(nodes.get(0), extractor, "");
1261+
} else {
1262+
value = nodes.stream()
1263+
.map(extractor)
1264+
.collect(Collectors.joining(delimter));
1265+
}
1266+
if (!GwtNullSafe.isBlankString(value)) {
1267+
ClipboardUtil.copy(value);
1268+
}
1269+
}
1270+
11771271
private MenuItem createMoveMenuItem(final List<ExplorerNode> explorerNodeList,
11781272
final int priority,
11791273
final boolean enabled) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
* Create a 'Copy As' explorer tree context menu sub-menu containing 'Copy (Name|UUID|Link) to Clipboard'.
2+
3+
4+
```sh
5+
# ONLY the top line will be included as a change entry in the CHANGELOG.
6+
# The entry should be in GitHub flavour markdown and should be written on a SINGLE
7+
# line with no hard breaks. You can have multiple change files for a single GitHub issue.
8+
# The entry should be written in the imperative mood, i.e. 'Fix nasty bug' rather than
9+
# 'Fixed nasty bug'.
10+
#
11+
# Examples of acceptable entries are:
12+
#
13+
#
14+
# * Issue **123** : Fix bug with an associated GitHub issue in this repository
15+
#
16+
# * Issue **namespace/other-repo#456** : Fix bug with an associated GitHub issue in another repository
17+
#
18+
# * Fix bug with no associated GitHub issue.
19+
```

0 commit comments

Comments
 (0)