Ejemplo n.º 1
0
 private StringBuilder printpath(TreeItem<StrucTree> item, StringBuilder temp) {
   if (item.getParent() != null && !item.getParent().getValue().isProject()) {
     printpath(item.getParent(), temp);
   }
   if (!Objects.equals(currProjectName, "")) {
     temp.append("/");
   }
   temp.append(item.getValue().toString());
   return temp;
 }
Ejemplo n.º 2
0
  /**
   * Restores the mapping of the tree items from the internal dictionary of expanded items.
   *
   * @param tree The tree to restore the mapping of
   */
  public static void restoreMap(TreeViewWithItems<SaharaItem> tree) {
    /*for (TreeItem<SaharaItem> item : tree.getTreeItems()) {
        item.setExpanded(isExpanded(item.getValue()));
    }*/

    for (TreeItem<SaharaItem> item : tree.getTreeItems()) {
      TreeEntry entry;
      if (item.getParent() != null && item.getParent().getValue() != null) {
        entry = new TreeEntry(item.getValue(), item.getParent().getValue());
      } else {
        entry = new TreeEntry(item.getValue(), null);
      }
      item.setExpanded(isExpanded(entry));
    }
  }
Ejemplo n.º 3
0
  private void selectFileTreeItemForSelectedFile(final File file) {
    if (updatingSelectedFiles) return;

    updatingSelectedFiles = true;
    try {
      final FileTreeItem<?> fileTreeItem = rootFileTreeItem.findFirst(file);
      if (fileTreeItem == null) {
        IllegalStateException x =
            new IllegalStateException("File does not have corresponding FileTreeItem: " + file);
        logger.warn("selectFileTreeItemForSelectedFile: " + x, x);
      } else {
        TreeItem<?> ti = fileTreeItem.getParent();
        while (ti != null) {
          ti.setExpanded(true);
          ti = ti.getParent();
        }

        // TODO maybe, instead of scrolling here (after each single item is selected), immediately,
        // we should wait (=> Timer) and scroll to the *first* selection, later?!
        treeTableView.getSelectionModel().select(fileTreeItem);
        int row = treeTableView.getRow(fileTreeItem);
        if (row >= 0) treeTableView.scrollTo(row);
      }
    } finally {
      updatingSelectedFiles = false;
    }
  }
Ejemplo n.º 4
0
  /**
   * Expands all items in the tree by mapping all of the items inside of it to true, and then
   * restoring the map state from the dictionary
   *
   * @param tree The tree to expand all items of
   */
  public static void expandAll(TreeViewWithItems<SaharaItem> tree) {
    /*for (TreeItem<SaharaItem> item : tree.getTreeItems()) {
        collapseMap.put(item.getValue(), Boolean.TRUE);
    }*/

    for (TreeItem<SaharaItem> item : tree.getTreeItems()) {
      TreeEntry entry;
      if (item.getParent() != null && item.getParent().getValue() != null) {
        entry = new TreeEntry(item.getValue(), item.getParent().getValue());
      } else {
        entry = new TreeEntry(item.getValue(), null);
      }
      collapseParentMap.put(entry, Boolean.TRUE);
    }

    restoreMap(tree);
  }
Ejemplo n.º 5
0
  /**
   * Refreshes the mapping of the tree items and if they are expanded or not.
   *
   * @param tree The tree to map items for
   */
  public static void refreshMap(TreeViewWithItems<SaharaItem> tree) {
    /*for (TreeItem<SaharaItem> item : tree.getTreeItems()) {
        //System.out.println(item + " " + item.isExpanded());
        collapseMap.put(item.getValue(), item.isExpanded());
    }*/

    for (TreeItem<SaharaItem> item : tree.getTreeItems()) {

      TreeEntry entry;
      if (item.getParent() != null && item.getParent().getValue() != null) {
        entry = new TreeEntry(item.getValue(), item.getParent().getValue());
      } else {
        entry = new TreeEntry(item.getValue(), null);
      }

      collapseParentMap.put(entry, item.isExpanded());
    }
  }
Ejemplo n.º 6
0
 private Optional<DynamicTreeItem> findParentOfType(
     TreeItem<DbTreeValue> selectedItem, Class<DynamicTreeItem> class1) {
   if (selectedItem == null) {
     return Optional.empty();
   }
   if (class1.isAssignableFrom(selectedItem.getClass())) {
     return Optional.of((DynamicTreeItem) selectedItem);
   }
   return findParentOfType(selectedItem.getParent(), class1);
 }
  @Override
  public void changeType(List<Node> nodes, NodeTransform transform) {
    if (nodes != null && !nodes.isEmpty() && transform != null) {
      for (Node node : nodes) {
        controller.getDomainProfileService().transformNode(node, transform);
      }

      displayPackageTree();

      // Resort the tree if necessary
      TreeItem<Node> selectedItem =
          view.getArtifactTreeView().getSelectionModel().getSelectedItem();
      if (selectedItem != null) {
        // This should never be the case since we don't show the root but just to be safe
        if (selectedItem.getParent() != null) {
          sortChildren(selectedItem.getParent().getChildren());
        }
      }
    }
  }
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 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.º 10
0
  /** *************************File Creation************************** */
  @FXML
  private void CreateFile() throws SQLException {
    boolean isExist = false;

    if (Objects.equals(currProjectName, "") || selected == null) {
      warning("Can't create file under the main project");
    } else if (selected.getValue().isProject()) {
      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Create File");
      dialog.setHeaderText("File");
      dialog.setContentText("Please enter the file name:");
      Optional<String> result = dialog.showAndWait();

      if (result.isPresent()) {
        final String inputFileName = result.get();

        String query =
            "SELECT pfname FROM PFiles WHERE pid like '" + currPID + "' AND pdid IS NULL";
        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 =
              "INSERT INTO PFiles(pfname, pid,creatorID) VALUE('"
                  + inputFileName
                  + "','"
                  + currPID
                  + "','"
                  + MyuserID
                  + "')";
          st = conn.createStatement();
          st.executeUpdate(query);
          query = "SELECT LAST_INSERT_ID()";
          rs = st.executeQuery(query);
          if (rs.next()) {
            int currID = rs.getInt("LAST_INSERT_ID()");
            CheckBoxTreeItem<StrucTree> temptreeItem = new CheckBoxTreeItem<>();
            temptreeItem.setValue(new StrucTree("f", inputFileName, currID));
            selected.getChildren().add(temptreeItem);
            selected.setExpanded(true);
            iniFile(temptreeItem);
          }
        }
      }
    } else if (selected.getValue().isFile()) {

      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Create File");
      dialog.setHeaderText("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 {
          if (selected.getParent().getValue().isProject()) {
            query =
                "INSERT INTO PFiles(pfname, pid,creatorID) VALUE('"
                    + inputFileName
                    + "','"
                    + currPID
                    + "','"
                    + MyuserID
                    + "')";
          } else {
            query =
                "INSERT INTO PFiles(pfname, pid, pdid,creatorID) VALUE('"
                    + inputFileName
                    + "','"
                    + currPID
                    + "','"
                    + selected.getParent().getValue().getID()
                    + "','"
                    + MyuserID
                    + "')";
          }
          st = conn.createStatement();
          st.executeUpdate(query);
          query = "SELECT LAST_INSERT_ID()";
          rs = st.executeQuery(query);
          if (rs.next()) {
            int currID = rs.getInt("LAST_INSERT_ID()");
            CheckBoxTreeItem<StrucTree> temptreeItem = new CheckBoxTreeItem<>();
            if (selected.getParent().getValue().isProject()) {
              temptreeItem.setValue(new StrucTree("f", inputFileName, currID));
            } else {
              temptreeItem.setValue(
                  new StrucTree(
                      "f", inputFileName, currID, selected.getParent().getValue().getID()));
            }
            selected.getParent().getChildren().add(temptreeItem);
            selected.getParent().setExpanded(true);
            iniFile(temptreeItem);
          }
        }
      }
    } else if (selected.getValue().isDirectory()) {
      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Create File");
      dialog.setHeaderText("File");
      dialog.setContentText("Please enter the file name:");
      Optional<String> result = dialog.showAndWait();

      if (result.isPresent()) {
        final String inputFileName = result.get();
        String query =
            "SELECT pfname FROM PFiles where pid like '"
                + currPID
                + "' AND pdid LIKE '"
                + selected.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 =
              "INSERT INTO PFiles(pfname, pid, pdid,creatorID) VALUE('"
                  + inputFileName
                  + "','"
                  + currPID
                  + "','"
                  + selected.getValue().getID()
                  + "','"
                  + MyuserID
                  + "')";
          st = conn.createStatement();
          st.executeUpdate(query);
          query = "SELECT LAST_INSERT_ID()";
          rs = st.executeQuery(query);
          if (rs.next()) {
            int currID = rs.getInt("LAST_INSERT_ID()");
            CheckBoxTreeItem<StrucTree> temptreeItem = new CheckBoxTreeItem<>();
            temptreeItem.setValue(
                new StrucTree("f", inputFileName, currID, selected.getValue().getID()));
            selected.getChildren().add(temptreeItem);
            selected.setExpanded(true);
            iniFile(temptreeItem);
          }
        }
      }
    }
  }
Ejemplo n.º 11
0
  /** *************************Delete Function************************** */
  @FXML
  private void DeleteButton() throws SQLException {

    /*
        	else if(selected.getParent()==null || Objects.equals(selected.getParent().getValue().toString(),"sQuire Project")){
        		String query = "SELECT PID FROM Projects where pname like '" + selected.getValue().toString() + "'";
        	    Statement st = conn.createStatement();
        	    ResultSet rs = st.executeQuery(query);
        	    while(rs.next()){
        	    	int tempPID = rs.getInt("PID");
    //    	    	System.out.println(tempPID);
        	    	query = "SELECT PID FROM ProjectAccess WHERE PID LIKE '" + tempPID +"' AND userID like '" + MyuserID + "' LIMIT 1";
            	    Statement st1 = conn.createStatement();
            	    ResultSet rs1 = st1.executeQuery(query);
            	    if(rs1.next()){ deletePID = rs1.getInt("PID");}
        	    }
        	    if(deletePID != 0){
        	    	String deleteProj = "DELETE FROM ProjectAccess WHERE PID LIKE '" + deletePID + "' AND userID like '" + MyuserID + "' LIMIT 1";
        	    	Statement st2 = conn.createStatement();
        	    	st2.executeUpdate(deleteProj);

        	    	Statement st3 = conn.createStatement();
        	    	String deleteProj2 = "DELETE FROM Projects WHERE PID LIKE '" + deletePID + "'";
        	    	st3.executeUpdate(deleteProj2);
        	    }
            	IniTree();
            	curr_position.setText("sQuire Project");
            	selected = null;
            	currPID = 0;
    /*        	query = "SELECT PID FROM ProjectAccess where userID like '" + MyuserID + "'";

        		String deleteProj = "DELETE FROM Projects WHERE pname LIKE '" + selected.getValue() + "'";
        		Statement s = conn.createStatement();
                s.executeUpdate(deleteProj);
            	IniTree();
            	curr_position.setText("sQuire Project");
            	selected = null;

        	}
    */
    if (selected == null) {
      warning("No project or file selected.");
    } else if (selected.getValue().isProject()) {

      int pid = selected.getValue().getID();

      String query1 = "SELECT * FROM Projects WHERE PID LIKE '" + pid + "'";
      Statement st1 = conn.createStatement();
      ResultSet rs1 = st1.executeQuery(query1);
      if (rs1.next()) {
        if (rs1.getInt("projectOwnerID") == MyuserID) {

          Statement st = conn.createStatement();
          String query = "DELETE FROM ProjectAccess WHERE PID LIKE '" + pid + "'";
          st.executeUpdate(query);

          query = "SELECT * FROM PFiles WHERE pid LIKE '" + pid + "' AND pdid IS NULL";
          st = conn.createStatement();
          ResultSet rs = st.executeQuery(query);
          while (rs.next()) {
            query = "DELETE FROM PFiles WHERE pfid LIKE '" + rs.getInt("pfid") + "'";
            Statement st2 = conn.createStatement();
            st2.executeUpdate(query);
            deleteFileLine(rs.getInt("pflhead"));
          }

          query = "SELECT pdid FROM PDirs WHERE pid like '" + pid + "' AND parentid is NULL";
          rs = st.executeQuery(query);
          while (rs.next()) {
            deleteDirectory(rs.getInt("pdid"));
          }
          query = "DELETE FROM Projects WHERE pid LIKE '" + pid + "'";
          st.executeUpdate(query);
          IniTree();

        } else {
          warning("You are not the owner of this project.");
        }
      }

    } else if (selected.getValue().isDirectory()) {
      System.out.println(selected.getValue().getID());
      deleteDirectory(selected.getValue().getID());
      System.out.println(currPID);
      selected.getParent().getChildren().remove(selected);
    } else if (selected.getValue().isFile()) {
      int pfid = selected.getValue().getID();
      String deleteFile = "DELETE FROM PFiles WHERE pfid LIKE '" + pfid + "'";
      Statement st = conn.createStatement();
      st.executeUpdate(deleteFile);
      deleteFileLine(selected.getValue().getLine());
      selected.getParent().getChildren().remove(selected);
    }
  }
Ejemplo n.º 12
0
  /** *************************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();
        }
      }
    }
  }