Ejemplo n.º 1
0
 private void setupTooltip(DbTreeValue item) {
   TreeValueType valueType = item.getValueType();
   if (valueType == TreeValueType.COLLECTION) {
     setTooltip(uiBuilder.loadDBCollectionInfoTooltip(item.getCollectionDetails()));
   } else {
     setTooltip(null);
   }
 }
Ejemplo n.º 2
0
 private void buildCollectionDetail(MongoDatabase db, TreeItem<DbTreeValue> ti) {
   DbTreeValue indexCategory = new DbTreeValue(db, "Indexes", TreeValueType.CATEGORY);
   indexCategory.setCollectionName(ti.getValue().getDisplayValue());
   ti.getChildren()
       .add(
           new DynamicTreeItem(
               indexCategory,
               new FontAwesomeIconView(FontAwesomeIcon.FOLDER),
               executor,
               popupService,
               this::buildIndexes));
 }
Ejemplo n.º 3
0
 private void onCreateNewCollection(ActionEvent ev) {
   TextInputDialog dialog = new TextInputDialog();
   dialog.setContentText("Enter Name:");
   dialog.setHeaderText("Create new collection");
   dialog
       .showAndWait()
       .ifPresent(
           r -> {
             DbTreeValue value = treeView.getSelectionModel().getSelectedItem().getValue();
             value.getMongoDatabase().createCollection(dialog.getResult());
             reloadSelectedTreeItem();
           });
 }
Ejemplo n.º 4
0
  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();
            });
  }
Ejemplo n.º 5
0
  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));
            });
  }
Ejemplo n.º 6
0
  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));
            });
  }
Ejemplo n.º 7
0
 private List<TreeItem<DbTreeValue>> buildDbChilds(DbTreeValue value) {
   MongoDatabase db = value.getMongoDatabase();
   return db.listCollectionDetails()
       .stream()
       .map(
           cd ->
               new TreeItem<>(
                   new DbTreeValue(db, cd, TreeValueType.COLLECTION),
                   new FontAwesomeIconView(FontAwesomeIcon.TABLE)))
       .peek(ti -> buildCollectionDetail(db, ti))
       .collect(Collectors.toList());
 }
Ejemplo n.º 8
0
  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();
            });
  }
Ejemplo n.º 9
0
 private void setupContextMenu(DbTreeValue item) {
   TreeValueType valueType = item.getValueType();
   if (valueType == TreeValueType.CONNECTION) {
     setContextMenu(connectContextMenu);
   } else if (valueType == TreeValueType.DATABASE) {
     setContextMenu(dbContextMenu);
   } else if (valueType == TreeValueType.COLLECTION) {
     setContextMenu(collectionContextMenu);
   } else if (valueType == TreeValueType.INDEX) {
     setContextMenu(indexContextMenu);
   } else {
     setContextMenu(null);
   }
 }
Ejemplo n.º 10
0
  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));
            });
  }
Ejemplo n.º 11
0
    @Override
    protected void updateItem(DbTreeValue item, boolean empty) {
      super.updateItem(item, empty);

      setupGraphic();
      setOnMouseClicked(this::treeViewClicked);

      if (!empty) {
        setText(item.toString());
        setupContextMenu(item);
        setupTooltip(item);
      } else {
        setText(null);
        setContextMenu(null);
        setTooltip(null);
      }
    }
Ejemplo n.º 12
0
  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());
  }