@@ -769,7 +769,9 @@ private void fetchPermissions(final List<ExplorerNode> explorerNodes,
769
769
.fetchExplorerPermissions (explorerNodes );
770
770
}
771
771
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 ) {
773
775
final ExplorerNode primarySelection = getPrimarySelection ();
774
776
775
777
// 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
789
791
selectionModel .clear ();
790
792
})
791
793
.build ());
794
+ return true ;
792
795
}
796
+ return false ;
793
797
}
794
798
795
799
private void toggleFavourite (final DocRef docRef , final boolean isFavourite ) {
@@ -931,10 +935,8 @@ private void addModifyMenuItems(final List<Item> menuItems,
931
935
// Feeds are a special case so can't be copied, see https://github.com/gchq/stroom/issues/3048
932
936
final boolean isCopyEnabled = allowRead && !hasFeed ;
933
937
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 ) {
938
940
menuItems .add (new Separator (12 ));
939
941
}
940
942
@@ -944,15 +946,18 @@ private void addModifyMenuItems(final List<Item> menuItems,
944
946
menuItems .add (createRemoveTagsMenuItem (updatableItems , 22 , isRemoveTagsEnabled ));
945
947
}
946
948
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 ));
950
955
951
956
if (securityContext .hasAppPermission (PermissionNames .IMPORT_CONFIGURATION )) {
952
- menuItems .add (createImportMenuItem (27 ));
957
+ menuItems .add (createImportMenuItem (28 ));
953
958
}
954
959
if (securityContext .hasAppPermission (PermissionNames .EXPORT_CONFIGURATION )) {
955
- menuItems .add (createExportMenuItem (28 , readableItems ));
960
+ menuItems .add (createExportMenuItem (29 , readableItems ));
956
961
}
957
962
958
963
// Only allow users to change permissions if they have a single item selected.
@@ -1174,6 +1179,95 @@ private MenuItem createCopyMenuItem(final List<ExplorerNode> explorerNodeList,
1174
1179
.build ();
1175
1180
}
1176
1181
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
+
1177
1271
private MenuItem createMoveMenuItem (final List <ExplorerNode > explorerNodeList ,
1178
1272
final int priority ,
1179
1273
final boolean enabled ) {
0 commit comments