private void onReanameCollection(ActionEvent actionEvent) { TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem(); if (selectedItem == null) { return; } DbTreeValue value = selectedItem.getValue(); TextInputDialog dialog = new TextInputDialog(value.getDisplayValue()); dialog.setContentText("New collection name:"); dialog.setHeaderText("Rename collection"); dialog .showAndWait() .ifPresent( targetCollection -> { MongoCollection<Document> collection = value.getMongoDatabase().getMongoDb().getCollection(value.getDisplayValue()); collection.renameCollection( new MongoNamespace(value.getMongoDatabase().getName(), targetCollection)); ((DynamicTreeItem) selectedItem.getParent()).reload(); }); }
private List<TreeItem<DbTreeValue>> buildIndexes(DbTreeValue value) { MongoCollection<Document> collection = value.getMongoDatabase().getMongoDb().getCollection(value.getCollectionName()); return StreamSupport.stream(collection.listIndexes().spliterator(), false) .map( d -> { DbTreeValue val = new DbTreeValue( value.getMongoDatabase(), (String) d.get("name"), TreeValueType.INDEX); val.setCollectionName(value.getDisplayValue()); return new TreeItem<>(val, new FontAwesomeIconView(FontAwesomeIcon.ASTERISK)); }) .collect(Collectors.toList()); }
private void onDropIndex(ActionEvent ev) { DbTreeValue value = treeView.getSelectionModel().getSelectedItem().getValue(); String indexName = value.getDisplayValue(); Alert alert = new Alert(AlertType.CONFIRMATION); alert.setHeaderText("Drop index " + indexName); alert.setContentText("Are you sure?"); alert .showAndWait() .filter(r -> r == ButtonType.OK) .ifPresent( r -> { value.getMongoDatabase().dropIndex(value.getCollectionName(), indexName); reloadSelectedTreeItem(); }); }
private void onDropDB(ActionEvent ev) { DbTreeValue value = treeView.getSelectionModel().getSelectedItem().getValue(); String dbName = value.getDisplayValue(); Alert alert = new Alert(AlertType.CONFIRMATION); alert.setHeaderText("Drop database " + dbName); alert.setContentText("Are you sure?"); alert .showAndWait() .filter(r -> r == ButtonType.OK) .ifPresent( r -> { value.getMongoDatabase().drop(); reloadSelectedTreeItem(); popupService.showInfo(String.format("Database '%s' dropped", dbName)); }); }
private void onRemoveAllDocuments(ActionEvent ev) { DbTreeValue value = treeView.getSelectionModel().getSelectedItem().getValue(); String collectionName = value.getDisplayValue(); Alert alert = new Alert(AlertType.CONFIRMATION); alert.setHeaderText("Remove all documents form " + collectionName); alert.setContentText("Are you sure?"); alert .showAndWait() .filter(r -> r == ButtonType.OK) .ifPresent( r -> { value.getMongoDatabase().removeAllDocuments(collectionName); popupService.showInfo( String.format("All documents from collection '%s' removed", collectionName)); }); }
private void onCopyCollection(ActionEvent actionEvent) { TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem(); if (selectedItem == null) { return; } DbTreeValue value = selectedItem.getValue(); String sourceCollectionName = value.getDisplayValue(); TextInputDialog dialog = new TextInputDialog(sourceCollectionName + "_copy"); dialog.setContentText("New collection name:"); dialog.setHeaderText("Copy collection"); dialog .showAndWait() .ifPresent( targetCollection -> { new CopyCollectionHelper( value.getMongoDatabase(), sourceCollectionName, targetCollection) .copy(); ((DynamicTreeItem) selectedItem.getParent()).reload(); popupService.showInfo( String.format( "Collection %s copied to %s", sourceCollectionName, targetCollection)); }); }