예제 #1
0
 private void setupTooltip(DbTreeValue item) {
   TreeValueType valueType = item.getValueType();
   if (valueType == TreeValueType.COLLECTION) {
     setTooltip(uiBuilder.loadDBCollectionInfoTooltip(item.getCollectionDetails()));
   } else {
     setTooltip(null);
   }
 }
예제 #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));
 }
예제 #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();
           });
 }
예제 #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();
            });
  }
예제 #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));
            });
  }
예제 #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));
            });
  }
예제 #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());
 }
예제 #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();
            });
  }
예제 #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);
   }
 }
예제 #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));
            });
  }
예제 #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);
      }
    }
예제 #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());
  }