@Override
  public void start(Stage primaryStage) throws Exception {
    Cat cat = new Cat();
    CatInfo catInfo = fromCat(cat);

    CatInfoTreeItem treeItem = new CatInfoTreeItem();
    treeItem.setValue(catInfo);

    TreeView<CatInfo> treeView = new TreeView<>(treeItem);
    treeView.setCellFactory(
        new Callback<TreeView<CatInfo>, TreeCell<CatInfo>>() {
          @Override
          public TreeCell<CatInfo> call(TreeView<CatInfo> param) {
            TreeCell<CatInfo> catInfoCell =
                new TreeCell<CatInfo>() {
                  @Override
                  protected void updateItem(CatInfo item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                      System.out.println("aa:" + item.name);
                      setText(item.name);
                    }
                  }
                };
            return catInfoCell;
          }
        });

    Scene scene = new Scene(treeView);
    primaryStage.setScene(scene);
    primaryStage.show();
  }
  @Override
  public void initialize(URL url, ResourceBundle r) {
    modFuncContextMenu = new ModFuncContextMenu(dbgController);
    modulesTree
        .getSelectionModel()
        .selectedItemProperty()
        .addListener(
            (o, old, newItem) -> {
              modFuncContextMenu.selectedTreeItemProperty().set(newItem);
              if (newItem != null)
                modFuncContextMenu.selectedItemProperty().set(newItem.getValue());
            });

    sortedTreeModules.setComparator(treeItemModFuncComparator());

    SplitPane.setResizableWithParent(modulesBox, Boolean.FALSE);

    ErlyBerly.nodeAPI().connectedProperty().addListener(this::onConnected);

    modulesTree.setCellFactory(new ModFuncTreeCellFactory(dbgController));
    /*modulesTree.setOnKeyPressed(this::onKeyPressInModuleTree);*/
    modulesTree.setContextMenu(modFuncContextMenu);

    addModulesFloatySearchControl();

    dbgController.initialize(url, r);

    dbgSplitPane.getItems().add(new DbgTraceView(dbgController));
  }
  public TreeView<ProjectFile> buildTreeView(String workspacePath) {

    File workspaceRoot = new File(workspacePath);
    // TODO check existence
    ProjectFile workspaceRootProjectFile = new ProjectFile(workspaceRoot);

    TreeItem<ProjectFile> workspaceRootItem = buildTreeItem(workspaceRootProjectFile, 1);

    TreeView<ProjectFile> workspaceTreeView = new TreeView<ProjectFile>(workspaceRootItem);
    workspaceTreeView.setShowRoot(false);

    workspaceTreeView.setOnMouseClicked(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent mouseEvent) {
            if (mouseEvent.getClickCount() == 2) {
              TreeItem<ProjectFile> item = workspaceTreeView.getSelectionModel().getSelectedItem();
              File file = item.getValue().getFile();
              System.out.println("Double click on file : " + file.getAbsolutePath());
              if (file.isFile()) {
                _mainActions.showEditorView(file);
              }
            }
          }
        });
    return workspaceTreeView;
  }
  @Override
  public void initialize(URL arg0, ResourceBundle arg1) {
    storedPreferences = Preferences.userRoot().node(PrefsConstants.PREFS_NODE);
    // DynamiPrefs.Basic.prefs().read(preferences);
    TreeItem<PrefsItem> root = new TreeItem<PrefsItem>(new PrefsItem(null, "General", ""));
    for (DynamiPrefs p : prefsPages) {
      final Prefs prefsNode = p.prefs();
      prefsNode.read(storedPreferences);
      final Prefs.Panel panel = p.prefs().getClass().getAnnotation(Prefs.Panel.class);
      TreeItem<PrefsItem> child =
          new TreeItem<PrefsItem>(new PrefsItem(prefsNode, panel.name(), panel.description()));

      root.getChildren().add(child);
    }

    root.setExpanded(true);
    tree.setRoot(root);

    tree.getSelectionModel()
        .selectedItemProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              if (newValue.getValue().prefs != null) {
                main.detailNodeProperty().set(new PrefsPage(newValue.getValue().prefs).getNode());
              }
            });
  }
 @SuppressWarnings("rawtypes")
 @Test
 public void assertContent() {
   TreeView treeView = (TreeView) getPrimaryStage().getScene().getRoot().lookup(".tree-view");
   int expandedItemCount = treeView.getExpandedItemCount();
   TreeItem treeItem = treeView.getTreeItem(expandedItemCount - 1);
   treeItem.setExpanded(true);
   final Object[] content = new Object[] {null};
   Platform.runLater(
       new Runnable() {
         @Override
         public void run() {
           RFXTreeView rTreeView = new RFXTreeView(treeView, null, null, null);
           content[0] = rTreeView.getContent();
         }
       });
   new Wait("Waiting for contents.") {
     @Override
     public boolean until() {
       return content[0] != null;
     }
   };
   JSONArray a = new JSONArray(content[0]);
   Assert.assertEquals(
       "[[\"Root node\",\"Child Node 1\",\"Child Node 2\",\"Child Node 3\",\"Child Node 4\",\"Child Node 5\",\"Child Node 6\",\"Child Node 7\",\"Child Node 8\",\"Child Node 9\",\"Child Node 10\",\"Child Node 11\",\"Child Node 12\",\"Child Node 13\",\"Child Node 14\",\"Child Node 15\",\"Child Node 16\",\"Child Node 17\",\"Child Node 18\",\"Child Node 19\",\"Child Node 20\",\"Child Node 21\",\"Child Node 22\",\"Child Node 23\",\"Child Node 24\"]]",
       a.toString());
 }
Exemple #6
0
 public void initialize(TreeView<DbTreeValue> treeView, MainFrameController mainFrameController) {
   this.treeView = treeView;
   this.mainFrameController = mainFrameController;
   treeView.setRoot(new TreeItem<>());
   treeView.setCellFactory(tv -> new TreeDbCell());
   buildDbContextMenu();
   buildCollectionContextMenu();
   buildIndexContextMenu();
   buildConnectContextMenu();
 }
  /** Initialize the TreeView by adding in children nodes to a dummy root. Dummy root is hidden. */
  private void createTree(ArrayList<String> allTask) {
    dummyRoot = new TreeItem<>(TREE_ROOT);

    overdueNode = setupNode(overdueNode, TITLE_FLAG + TREE_OVERDUE);
    todayNode = setupNode(todayNode, TITLE_FLAG + TREE_TODAY);
    tomorrowNode = setupNode(tomorrowNode, TITLE_FLAG + TREE_TOMORROW);
    everythingElseNode = setupNode(everythingElseNode, TITLE_FLAG + TREE_EVERYTHING_ELSE);

    allTreeView.setRoot(dummyRoot);
    allTreeView.setShowRoot(false);
  }
 /**
  * TreeViewで板を選択する。
  *
  * <p>仮実装で二階層まで対応
  *
  * @param board
  */
 public void setSelection(Board board) {
   TreeItem<Board> root = boardTreeView.getRoot();
   for (TreeItem<Board> boardItem1 : root.getChildren()) {
     for (TreeItem<Board> boardItem2 : boardItem1.getChildren()) {
       if (boardItem2.getValue() != null
           && boardItem2.getValue().getId() != null
           && boardItem2.getValue().getId().equals(board.getId())) {
         boardTreeView.getSelectionModel().select(boardItem2);
       }
     }
   }
 }
  @Override
  public void initialize(URL location, ResourceBundle resources) {

    // dummy entries
    TreeItem<String> rootItem = new TreeItem<String>("Dummy");
    rootItem.setExpanded(true);
    for (int i = 1; i < 6; i++) {
      TreeItem<String> item = new TreeItem<String>("Sub Dummy " + i);
      rootItem.getChildren().add(item);
    }

    treeView = new TreeView<>(rootItem);

    treeView
        .getSelectionModel()
        .selectedItemProperty()
        .addListener(
            new ChangeListener<TreeItem>() {

              @Override
              public void changed(
                  ObservableValue<? extends TreeItem> observable,
                  TreeItem oldValue,
                  TreeItem newValue) {
                Logger.getLogger(SystemtreePresenter.class.getName())
                    .log(Level.INFO, "Tree selection changed: {0}", newValue);
                someLogic.doSomething();
              }
            });
    rootPane.getChildren().add(treeView);
  }
 private void refreshModules() {
   try {
     modulesTree.setShowRoot(false);
     dbgController.requestModFuncs(this::buildObjectTreeRoot);
   } catch (Exception e) {
     throw new RuntimeException("failed to build module/function tree", e);
   }
 }
  @SuppressWarnings("unchecked")
  @FXML
  private void handleButtonAction(ActionEvent event) {
    // createTree();
    // create root
    TreeItem<String> root = new TreeItem<>("Output Structure");

    // root.setExpanded(true);
    // create child
    TreeItem<String> item1 = new TreeItem<>("Data collect");
    TreeItem<String> item1c1 = new TreeItem<>("Data Base");
    TreeItem<String> item1c2 = new TreeItem<>("Field Trip");
    TreeItem<String> item1c3 = new TreeItem<>("Darwin01");
    item1.getChildren().addAll(item1c1, item1c2, item1c3);
    // item1.setExpanded(false);

    TreeItem<String> item2 = new TreeItem<>("Scanline");

    TreeItem<String> item2C1 = new TreeItem<>("Power Law");
    TreeItem<String> item2C2 = new TreeItem<>("New data");
    item2.getChildren().addAll(item2C1, item2C2);

    TreeItem<String> item3 = new TreeItem<>("Modeling");

    TreeItem<String> item3C1 = new TreeItem<>("2D");
    TreeItem<String> item3C2 = new TreeItem<>("3D");
    item3.getChildren().addAll(item3C1, item3C2);

    // itemChild2.setExpanded(false);
    // root is the parent of itemChild
    root.getChildren().addAll(item1, item2, item3);

    treeview_outs
        .getSelectionModel()
        .selectedItemProperty()
        .addListener(
            (v, oldvalue, newvalue) -> {
              if (newvalue != null) {
                System.out.println(newvalue.toString());
              }
            });

    treeview_outs.setRoot(root);
    grid_output_project.setDisable(true);
    check_output_newproject.setDisable(false);
  }
Exemple #12
0
  public void onDisconnectDb(ActionEvent ev) {
    TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem();
    if (selectedItem == null) {
      return;
    }

    selectedItem.getValue().getMongoConnection().close();
    removeFromRoot(selectedItem);
  }
 /** Initialize the TreeView by populating it with custom TreeCell class */
 private void setupTreeCell() {
   allTreeView.setCellFactory(
       new Callback<TreeView<String>, TreeCell<String>>() {
         @Override
         public TreeCell<String> call(TreeView<String> treeView) {
           return new TaskTreeCell();
         }
       });
 }
Exemple #14
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();
           });
 }
  public void initTreeView() {
    TreeItem<TreeObj> rootItem1 = new TreeItem<TreeObj>(new TreeObj("root", 123));

    for (DbConfiguration dbc : Context.DbList.getDbConfigurations()) {

      TreeNode<TreeObj> leaf1 = new TreeNode<TreeObj>(new TreeObj(dbc.getName(), new ConnObj(dbc)));
      leaf1.setGraphic(new ImageView(Context.Icon_Connector));
      leaf1.setExpanded(true);

      rootItem1.getChildren().add(leaf1);
    }
    rootItem1.setExpanded(true);

    treeView.setRoot(rootItem1);
    treeView.setEditable(false);
    treeView.setCellFactory(
        new Callback<TreeView<TreeObj>, TreeCell<TreeObj>>() {
          @Override
          public TreeCell<TreeObj> call(TreeView<TreeObj> p) {
            return new TextFieldTreeCellImpl();
          }
        });
  }
  /** *************************Set Tree************************** */
  private void setTree(CheckBoxTreeItem<StrucTree> treeItem, int id) throws SQLException {
    CheckBoxTreeItem<StrucTree> treeRoot = new CheckBoxTreeItem<>();
    if (treeItem == null) {
      treeRoot.setValue(new StrucTree("p", currProjectName, currPID));
      String query = "SELECT * FROM PDirs WHERE pid LIKE '" + currPID + "' AND parentid IS NULL";
      Statement st = conn.createStatement();
      ResultSet rs = st.executeQuery(query);
      while (rs.next()) {
        CheckBoxTreeItem<StrucTree> temptreeItem = new CheckBoxTreeItem<>();
        temptreeItem.setValue(
            new StrucTree("d", rs.getString("pdname"), rs.getInt("pdid"), rs.getInt("parentid")));
        treeRoot.getChildren().add(temptreeItem);
        setTree(temptreeItem, rs.getInt("pdid"));
      }
      query = "SELECT * FROM PFiles WHERE pid LIKE '" + currPID + "' AND pdid IS NULL";
      rs = st.executeQuery(query);
      while (rs.next()) {
        CheckBoxTreeItem<StrucTree> temptreeItem = new CheckBoxTreeItem<>();
        temptreeItem.setValue(
            new StrucTree("f", rs.getString("pfname"), rs.getInt("pfid"), rs.getInt("pdid")));
        getIniLine(temptreeItem);
        treeRoot.getChildren().add(temptreeItem);
      }
      structure_tree.setRoot(treeRoot);
      treeRoot.setExpanded(true);
      selected = treeRoot;
    } else {
      String query =
          "SELECT * FROM PDirs WHERE pid LIKE '" + currPID + "' AND parentid like '" + id + "'";
      Statement st = conn.createStatement();
      ResultSet rs = st.executeQuery(query);
      while (rs.next()) {
        CheckBoxTreeItem<StrucTree> temptreeItem = new CheckBoxTreeItem<>();
        temptreeItem.setValue(
            new StrucTree("d", rs.getString("pdname"), rs.getInt("pdid"), rs.getInt("parentid")));
        treeItem.getChildren().add(temptreeItem);
        setTree(temptreeItem, rs.getInt("pdid"));
      }

      query = "SELECT * FROM PFiles WHERE pid LIKE '" + currPID + "' AND pdid LIKE '" + id + "'";
      rs = st.executeQuery(query);
      while (rs.next()) {
        CheckBoxTreeItem<StrucTree> temptreeItem = new CheckBoxTreeItem<>();
        temptreeItem.setValue(
            new StrucTree("f", rs.getString("pfname"), rs.getInt("pfid"), rs.getInt("pdid")));
        getIniLine(temptreeItem);
        treeItem.getChildren().add(temptreeItem);
      }
    }
  }
Exemple #17
0
 public void addDbConnect(MongoDbConnection mongoDbConnection) {
   DbTreeValue connectTreeValue =
       new DbTreeValue(mongoDbConnection, mongoDbConnection.getConnectionSettings().getHost());
   DynamicTreeItem item =
       new DynamicTreeItem(
           connectTreeValue,
           new FontAwesomeIconView(FontAwesomeIcon.SERVER),
           executor,
           popupService,
           tv -> buildDbList(tv.getHostConnect().getMongoConnection()));
   item.setOnFiled(() -> removeFromRoot(item));
   item.setExpanded(true);
   treeView.getRoot().getChildren().add(item);
 }
  /** 板一覧を表示 */
  public void showBoardList(List<Board> boards) {
    boardTreeView.setRoot(rootNode);
    boardTreeView.setShowRoot(false);
    rootNode.getValue().setTitle("root");
    rootNode.getValue().setId("root_");
    rootNode.setExpanded(true);

    // 履歴
    TreeItem<Board> userTree = new TreeItem<Board>(new Board());
    userTree.getValue().setTitle("ユーザ");
    userTree.getValue().setId("user_");
    userTree.setExpanded(true);
    rootNode.getChildren().add(userTree);

    TreeItem<Board> history = new TreeItem<Board>(new Board());
    history.getValue().setTitle("履歴");
    history.getValue().setId("history_");
    history.setExpanded(true);
    userTree.getChildren().add(history);

    TreeItem<Board> favorite = new TreeItem<Board>(new Board());
    favorite.getValue().setTitle("お気に入り");
    favorite.getValue().setId("favorite_");
    favorite.setExpanded(true);
    userTree.getChildren().add(favorite);

    TreeItem<Board> nichanBoard = new TreeItem<Board>(new Board());
    nichanBoard.getValue().setTitle("2ch");
    nichanBoard.getValue().setId("2ch_");
    nichanBoard.setExpanded(true);
    rootNode.getChildren().add(nichanBoard);

    for (Board board : boards) {
      setupTreeItem(nichanBoard, board);
    }
  }
Exemple #19
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();
            });
  }
Exemple #20
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));
            });
  }
Exemple #21
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));
            });
  }
  private void buildObjectTreeRoot(OtpErlangList requestFunctions) {
    boolean isExported;

    for (OtpErlangObject e : requestFunctions) {
      OtpErlangTuple tuple = (OtpErlangTuple) e;

      OtpErlangAtom moduleNameAtom = (OtpErlangAtom) tuple.elementAt(0);
      OtpErlangList exportedFuncs = (OtpErlangList) tuple.elementAt(1);
      OtpErlangList localFuncs = (OtpErlangList) tuple.elementAt(2);

      TreeItem<ModFunc> moduleItem;

      moduleItem = new TreeItem<ModFunc>(ModFunc.toModule(moduleNameAtom));
      moduleItem.setGraphic(treeIcon(AwesomeIcon.CUBE));

      ObservableList<TreeItem<ModFunc>> modFuncs = FXCollections.observableArrayList();

      SortedList<TreeItem<ModFunc>> sortedFuncs = new SortedList<TreeItem<ModFunc>>(modFuncs);

      FilteredList<TreeItem<ModFunc>> filteredFuncs =
          new FilteredList<TreeItem<ModFunc>>(sortedFuncs);

      sortedFuncs.setComparator(treeItemModFuncComparator());

      isExported = true;
      addTreeItems(toModFuncs(moduleNameAtom, exportedFuncs, isExported), modFuncs);

      isExported = false;
      addTreeItems(toModFuncs(moduleNameAtom, localFuncs, isExported), modFuncs);
      functionLists.add(filteredFuncs);

      Bindings.bindContentBidirectional(moduleItem.getChildren(), filteredFuncs);

      treeModules.add(moduleItem);
    }

    TreeItem<ModFunc> root;

    root = new TreeItem<ModFunc>();
    root.setExpanded(true);

    Bindings.bindContentBidirectional(root.getChildren(), filteredTreeModules);

    modulesTree.setRoot(root);
  }
 public void filter(ActionEvent e) {
   final String newValue = searchText.getText();
   ObservableList<TreeItem<PrefsItem>> items = tree.getRoot().getChildren();
   if (newValue != null && !newValue.trim().equals("")) {
     items.forEach(
         n -> {
           if (newValue.contains(n.getValue().name)) {
             //					node.getGraphic().setVisible(true);
           } else {
             //					node.getGraphic().setVisible(false);
           }
         });
   } else {
     items.forEach(
         node -> {
           //				node.getGraphic().setVisible(true);
         });
   }
 }
Exemple #24
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();
            });
  }
Exemple #25
0
  public void onCreateNewDb(ActionEvent ev) {
    TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem();
    if (selectedItem == null
        || selectedItem.getValue().getValueType() != TreeValueType.CONNECTION) {
      return;
    }

    TextInputDialog dialog = new TextInputDialog();
    dialog.setContentText("Enter Name:");
    dialog.setHeaderText("Create new db");
    dialog
        .showAndWait()
        .ifPresent(
            r ->
                selectedItem
                    .getChildren()
                    .add(
                        createDbItem(
                            selectedItem
                                .getValue()
                                .getMongoConnection()
                                .createMongoDB(dialog.getResult()))));
  }
  public void IniTree() {
    CheckBoxTreeItem<StrucTree> treeRoot = new CheckBoxTreeItem<>();
    treeRoot.setValue(new StrucTree("sQuire Project"));
    treeRoot.setExpanded(true);
    Node graphic = new ImageView(new Image("https://duke.kenai.com/iconSized/duke4.gif"));

    try {
      String query = "SELECT * FROM ProjectAccess WHERE userID like '" + MyuserID + "'";
      Statement st = conn.createStatement();
      ResultSet rs = st.executeQuery(query);
      while (rs.next()) {
        int PID = rs.getInt("PID");
        //	        	System.out.println(PID);
        query = "SELECT * FROM Projects WHERE PID like '" + PID + "'";
        Statement st1 = conn.createStatement();
        ResultSet rs1 = st1.executeQuery(query);

        rs1.next();
        String ProjectName = rs1.getString("pname");
        int ProjectID = rs1.getInt("PID");
        CheckBoxTreeItem<StrucTree> treeItem = new CheckBoxTreeItem<>();
        treeItem.setValue(new StrucTree("p", ProjectName, ProjectID));

        treeRoot.getChildren().add(treeItem);
      }
      structure_tree.setRoot(treeRoot);
    } catch (SQLException e) {
      e.printStackTrace();
    }
    currPID = 0;
    selected = null;
    selectedFile = null;
    currProjectName = "";
    tempFileId = 0;
    tempFileData = "";
    fileData.setText("");
  }
Exemple #27
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));
            });
  }
  /** *************************Rename Function************************** */
  @FXML
  public void Rename() throws SQLException {
    boolean isExist = false;

    if (selected == null) {
      warning("No project or file selected.");
    } else if (selected.getValue().isProject()) {
      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Rename");
      dialog.setHeaderText("Rename Project");
      dialog.setContentText("Please enter the project name:");
      Optional<String> result = dialog.showAndWait();
      Statement st = conn.createStatement();
      String currProjName = "";

      if (result.isPresent()) {
        currProjName = result.get();
        String query = "SELECT PID FROM ProjectAccess where userID like '" + MyuserID + "'";
        ResultSet rs = st.executeQuery(query);
        while (rs.next()) {

          int myPid = rs.getInt("PID");

          String query2 = "SELECT pname FROM Projects where PID like '" + myPid + "'";
          Statement st1 = conn.createStatement();
          ResultSet re1 = st1.executeQuery(query2);
          if (re1.next()) {
            String projName = re1.getString("pname");
            if (Objects.equals(projName, currProjName)) {
              isExist = true;
              warning("Project name already exist.");
              break;
            }
          }
        }

        if (isExist == false) {
          String sql =
              "UPDATE Projects SET pname='"
                  + currProjName
                  + "' WHERE PID='"
                  + selected.getValue().getID()
                  + "'";
          st.executeUpdate(sql);
          selected.getValue().setName(currProjName);
          structure_tree.refresh();
        }
      }

    } else if (selected.getValue().isDirectory()) {
      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Rename");
      dialog.setHeaderText("Rename Folder");
      dialog.setContentText("Please enter the folder name:");
      Optional<String> result = dialog.showAndWait();

      if (result.isPresent()) {
        final String inputFolderName = result.get();
        String query = "";
        if (selected.getParent().getValue().isProject()) {
          query = "SELECT pdname FROM PDirs where pid like '" + currPID + "' AND parentid IS NULL";
        } else {
          query =
              "SELECT pdname FROM PDirs where pid like '"
                  + currPID
                  + "' AND parentid like '"
                  + selected.getParent().getValue().getID()
                  + "'";
        }
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);

        while (rs.next()) {
          String tempName = rs.getString("pdname");
          if (Objects.equals(tempName, inputFolderName)) {
            isExist = true;
            break;
          }
        }

        if (isExist == true) {
          warning("Directory name already exist.");
        } else {
          query =
              "UPDATE PDirs SET pdname='"
                  + inputFolderName
                  + "' WHERE pdid='"
                  + selected.getValue().getID()
                  + "'";

          st = conn.createStatement();
          st.executeUpdate(query);
          selected.getValue().setName(inputFolderName);
          structure_tree.refresh();
        }
      }

    } else if (selected.getValue().isFile) {
      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Rename");
      dialog.setHeaderText("Rename File");
      dialog.setContentText("Please enter the file name:");
      Optional<String> result = dialog.showAndWait();

      if (result.isPresent()) {
        final String inputFileName = result.get();
        String query = "";
        if (selected.getParent().getValue().isProject()) {
          query = "SELECT pfname FROM PFiles where pid like '" + currPID + "' AND pdid IS NULL";
        } else {
          query =
              "SELECT pfname FROM PFiles where pid like '"
                  + currPID
                  + "' AND pdid LIKE '"
                  + selected.getParent().getValue().getID()
                  + "'";
        }

        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);

        while (rs.next()) {
          String tempName = rs.getString("pfname");
          if (Objects.equals(tempName, inputFileName)) {
            isExist = true;
            break;
          }
        }
        if (isExist == true) {
          warning("File name already exist.");

        } else {
          query =
              "UPDATE PFiles SET pfname='"
                  + inputFileName
                  + "' WHERE pfid='"
                  + selected.getValue().getID()
                  + "'";

          st = conn.createStatement();
          st.executeUpdate(query);
          selected.getValue().setName(inputFileName);
          structure_tree.refresh();
        }
      }
    }
  }
  public void assignSampleData(FXOMObject startObject) {
    assert startObject != null;

    final Object sceneGraphObject = startObject.getSceneGraphObject();
    final AbstractSampleData currentData = sampleDataMap.get(startObject);
    final AbstractSampleData newData;

    if (sceneGraphObject == null) {
      // startObject is unresolved
      newData = null;
    } else {
      final Class<?> sceneGraphClass = sceneGraphObject.getClass();
      if (sceneGraphClass == ChoiceBox.class) {
        final ChoiceBox<?> choiceBox = (ChoiceBox) sceneGraphObject;
        if (choiceBox.getItems().isEmpty()) {
          if (currentData instanceof ChoiceBoxSampleData) {
            newData = currentData;
          } else {
            newData = new ChoiceBoxSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == ComboBox.class) {
        final ComboBox<?> comboBox = (ComboBox) sceneGraphObject;
        if (comboBox.getItems().isEmpty()) {
          if (currentData instanceof ComboBoxSampleData) {
            newData = currentData;
          } else {
            newData = new ComboBoxSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == ListView.class) {
        final ListView<?> listView = (ListView) sceneGraphObject;
        if (listView.getItems().isEmpty()) {
          if (currentData instanceof ListViewSampleData) {
            newData = currentData;
          } else {
            newData = new ListViewSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == TreeView.class) {
        final TreeView<?> treeView = (TreeView) sceneGraphObject;
        if (treeView.getRoot() == null) {
          if (currentData instanceof TreeViewSampleData) {
            newData = currentData;
          } else {
            newData = new TreeViewSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == TableView.class) {
        final TableView<?> treeView = (TableView) sceneGraphObject;
        if (TableViewSampleData.canApplyTo(treeView)) {
          if (currentData instanceof TableViewSampleData) {
            newData = currentData;
          } else {
            newData = new TableViewSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == TreeTableView.class) {
        final TreeTableView<?> treeTableView = (TreeTableView) sceneGraphObject;
        if (treeTableView.getRoot() == null) {
          if (currentData instanceof TreeTableViewSampleData) {
            newData = currentData;
          } else {
            newData = new TreeTableViewSampleData();
          }
        } else {
          newData = null;
        }
      } else if (sceneGraphClass == PieChart.class) {
        final PieChart pieChart = (PieChart) sceneGraphObject;
        if (pieChart.getData().isEmpty()) {
          if (currentData instanceof PieChartSampleData) {
            newData = currentData;
          } else {
            newData = new PieChartSampleData();
          }
        } else {
          newData = null;
        }
      } else if (XYChartSampleData.isKnownXYChart(sceneGraphObject)) {
        final XYChart<?, ?> xyChart = (XYChart) sceneGraphObject;
        if (xyChart.getData().isEmpty()) {
          if (currentData instanceof XYChartSampleData) {
            newData = currentData;
          } else {
            newData = new XYChartSampleData();
          }
        } else {
          newData = null;
        }
      } else {
        newData = null;
      }
    }

    if (newData == null) {
      if (currentData != null) {
        sampleDataMap.remove(startObject);
      }
    } else {
      newData.applyTo(sceneGraphObject);
      sampleDataMap.put(startObject, newData);
    }

    if (startObject instanceof FXOMInstance) {
      final FXOMInstance fxomInstance = (FXOMInstance) startObject;
      for (FXOMProperty p : fxomInstance.getProperties().values()) {
        if (p instanceof FXOMPropertyC) {
          final FXOMPropertyC pc = (FXOMPropertyC) p;
          for (FXOMObject v : pc.getValues()) {
            assignSampleData(v);
          }
        }
      }
    } else if (startObject instanceof FXOMCollection) {
      final FXOMCollection fxomCollection = (FXOMCollection) startObject;
      for (FXOMObject i : fxomCollection.getItems()) {
        assignSampleData(i);
      }
    }
  }
  /** *************************Selection Tasks************************** */
  @FXML
  private void file_select(MouseEvent mouse) throws SQLException {
    TreeItem<StrucTree> item = structure_tree.getSelectionModel().getSelectedItem();

    if (mouse.getClickCount() == 1 && item != null) {
      selected = item;

      if (item.getValue().isProject()) {
        info.setText(
            " [Project: "
                + item.getValue().toString()
                + "]  [ID: "
                + item.getValue().getID()
                + "]");
      } else if (item.getValue().isDirectory()) {
        info.setText(
            " [Directory: "
                + item.getValue().toString()
                + "]   [ID: "
                + item.getValue().getID()
                + "]  [Parent ID: "
                + item.getValue().getPID()
                + "]");
      } else if (item.getValue().isFile()) {
        String query = "SELECT * FROM PFiles WHERE pfid like '" + item.getValue().getID() + "'";
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);
        if (rs.next()) {
          if (rs.getInt("creatorID") == 0) {
            info.setText(
                " [File: "
                    + item.getValue().toString()
                    + "]  [ID: "
                    + item.getValue().getID()
                    + "]  [Created Time: "
                    + rs.getTimestamp("timeCreated")
                    + "]");
          } else {
            query = "SELECT userName from Users WHERE userID like '" + rs.getInt("creatorID") + "'";
            Statement st1 = conn.createStatement();
            ResultSet rs1 = st1.executeQuery(query);
            if (rs1.next()) {
              info.setText(
                  " [File: "
                      + item.getValue().toString()
                      + "]  [ID: "
                      + item.getValue().getID()
                      + "]  [Creator: "
                      + rs1.getString("userName")
                      + "]  [Created Time: "
                      + rs.getTimestamp("timeCreated")
                      + "]");
            }
          }
        }
      } else {
        info.setText(" *sQuire Project Menu*");
      }

      if (Objects.equals(currProjectName, "")) {
        curr_position.setText(item.getValue().toString());
      } else {
        curr_position.setText(getCurrPosition(item));
      }
    }
    if (mouse.getClickCount() == 2 && item != null) {
      selected = item;
      curr_position.setText(item.getValue().toString());

      if (currPID == 0 && !Objects.equals(item.getValue().toString(), "sQuire Project")) {
        currProjectName = item.getValue().toString();

        currPID = item.getValue().getID();
        setTree(null, 0);
      } else {
        curr_position.setText(getCurrPosition(item));
      }

      if (item.getValue().isFile()) {
        selectedFile = item;
        readFile(selectedFile);
      }
    }
  }