0

Please help me to add item from addproject controller to project controller. I want to add item from addprojects controller to projectscontroller method. Please guide me to resolve this. please guide to dynamically change the right side split pane view and add tree item in treeview and show to user.

    package com.define.controller;

    import java.io.File;
    import java.io.IOException;
    import java.net.URL;

    import java.util.ResourceBundle;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javafx.event.Event;

    //import org.apache.commons.io.FileUtils;

    import javafx.fxml.FXML;
    import javafx.fxml.Initializable;

    import javafx.scene.Node;
    import javafx.scene.control.CheckBox;
    import javafx.scene.control.Tab;
    import javafx.scene.control.TreeItem;
    import javafx.scene.control.TreeView;
    import javafx.scene.image.Image;
    import javafx.scene.image.ImageView;
    import javafx.scene.layout.AnchorPane;
    import javafx.scene.layout.HBox;

    import javafx.stage.DirectoryChooser;
    import javax.naming.Context;
    import testapp.TestApp;

    public class ProjectsController implements Initializable{

        // @FXML private HBox fileList;
        @FXML TreeView<String> Maintree ;
        @FXML private AnchorPane Anchorpane;

         File destinationFolder;



         //Image img = new Image();
         //private final Node rootIcon = new ImageView(img);
    /*  private final Node rootIcon = new ImageView(
                    new Image(getClass().getResourceAsStream("G:\\workspace\\DefineApp\\src\\images\\folder.png")));*/
         File file = new File("D:\\DefineApp\\src\\images\\folder.png");
            Image image = new Image(file.toURI().toString(),20,20,false,false);
            private  Node rootIcon = new ImageView(image);    


         @Override
            public void initialize(URL location, ResourceBundle resources) {
             File currentDir = new File("D:\\DefineApp\\src\\Documents"); // current directory
                 rootItem.setExpanded(true);
             Maintree.setShowRoot(false);
                     Maintree.setRoot(rootItem);
                     findFiles(currentDir);
                 try {
                     changeView();
                 } catch (IOException ex) {
                     Logger.getLogger(ProjectsController.class.getName()).log(Level.SEVERE, null, ex);
                 }
            }


        public void UploadFiles() throws IOException{
            DirectoryChooser directory = new DirectoryChooser();
            directory.setTitle("Choose Directory");

             final File selectedDirectory = directory.showDialog(null);
             File sourcefolder = new File(selectedDirectory.getAbsolutePath());
             String projectName = "Symbiance";
             String studyName = "study1";
             destinationFolder = new File("G:\\workspace\\DefineApp\\src\\"+projectName+"\\"+studyName);

                if(!destinationFolder.exists()){
                    destinationFolder.mkdirs();

                        if(destinationFolder.isDirectory()){
                            // FileUtils.copyDirectory(sourcefolder, destinationFolder);
                             System.out.println("Files Copied Successfully");
                        }
                }else{

                    if(destinationFolder.isDirectory()){
                     //FileUtils.copyDirectory(sourcefolder, destinationFolder);
                     System.out.println("Files Copied Successfully");
                    }

                }
                    //Method call for list the files
                listFiles();
        }

        public void listFiles(){
             //fileList.setPadding(new Insets(15, 12, 15, 12));
             //fileList.setSpacing(10);
            File[] listOfFiles = destinationFolder.listFiles();
            CheckBox[] cbs = new CheckBox[listOfFiles.length];
             int i=0;
            for (File file : listOfFiles) {
                CheckBox cbox = cbs[i]= new CheckBox(file.getName());
                i++;

            }

            //fileList.getChildren().addAll(cbs);
        }

        TreeItem<String> rootItem = new TreeItem<String>("Root");

        public void findFiles(File currentDir){

             //rootItem.setGraphic(rootIcon);;
            TreeItem<String> subfolder;
             // parent = new TreeItem<String> (parent.getValue(),rootIcon);

            System.out.println("1");
             File folder = new File(currentDir.getAbsolutePath());
                File[] listOfFiles = folder.listFiles();
                for (File file:listOfFiles) {           

                    if(file.isDirectory()){
                         subfolder = new TreeItem<String> (file.getName());
                        rootItem.getChildren().add(subfolder);
                        File subFolderName = new File(file.getAbsolutePath());
                        File[] subFolderFiles = subFolderName.listFiles();

                        for(File f:subFolderFiles){
                            TreeItem<String> it= new TreeItem<String>(f.getName());
                            subfolder.getChildren().add(it);
                        }

                    }


                }





        }

        public void changeView() throws IOException{
        System.out.println("change view is called");

                Anchorpane.getChildren().add(TestApp.getInstance().designChooser("com/define/views/AddProject.fxml"));


            //setContent();
        }

     public void addProject(String name,Event e){
         rootItem.getChildren().add(new TreeItem(name));
         System.out.println("test check");
     }

    }

another controller;

package com.define.controller;

import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.TreeItem;
import javafx.scene.text.Text;

public class AddProjectController implements Initializable{
    @FXML Button yesbutton;
    @FXML RadioButton projectYesRadio;
    @FXML RadioButton projectNORadio;
    @FXML TextField projectId;
    @FXML TextField projectName;

    final ToggleGroup Projectgroup = new ToggleGroup();
    final File baseFolder = new File("D:\\DefineApp\\src\\Documents");
    File projectFolder;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        projectYesRadio.setToggleGroup(Projectgroup);
        projectNORadio.setToggleGroup(Projectgroup);
        projectYesRadio.setSelected(true);

    }

     public void addProject(ActionEvent e){

             projectFolder = new File("D:\\DefineApp\\src\\Documents\\"+projectName.getText());
             projectFolder.mkdir();
                         ProjectsController pt = new ProjectsController();
                         pt.addProject(projectName.getText(),e);
                          //System.out.println(projectController.Maintree.getRoot());
             //.rootItem.getChildren().add(new TreeItem(projectName.getText()));


         //projectController.findFiles(baseFolder);
         System.out.println("test check");
     }

     public void radiocalled(){
         //yesbutton.setVisible(false);
     }  
}
SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
  • Please post your code. – grael Aug 27 '16 at 09:47
  • http://stackoverflow.com/questions/32342864/applying-mvc-with-javafx asks something different, but the solution there has an example of the selection in a `ListView` in one FXML being used in another FXML, which is pretty much identical to what you are asking. – James_D Aug 27 '16 at 11:13

0 Answers0