Search in sources :

Example 1 with FileChangeWatcher

use of com.neuronrobotics.bowlerstudio.util.FileChangeWatcher in project BowlerStudio by CommonWealthRobotics.

the class BowlerStudioController method createFileTab.

// Custom function for creation of New Tabs.
public ScriptingFileWidget createFileTab(File file) {
    if (openFiles.get(file.getAbsolutePath()) != null && widgets.get(file.getAbsolutePath()) != null) {
        BowlerStudioModularFrame.getBowlerStudioModularFrame().setSelectedTab(openFiles.get(file.getAbsolutePath()));
        return widgets.get(file.getAbsolutePath()).getScripting();
    }
    Tab fileTab = new Tab(file.getName());
    openFiles.put(file.getAbsolutePath(), fileTab);
    try {
        System.err.println("Loading local file from: " + file.getAbsolutePath());
        LocalFileScriptTab t = new LocalFileScriptTab(file);
        new Thread() {

            public void run() {
                String gitRepo = t.getScripting().getGitRepo();
                if (gitRepo != null) {
                    String message = BowlerStudioMenu.gitURLtoMessage(gitRepo);
                    if (gitRepo.length() < 5 || (message == null))
                        message = "Project " + gitRepo;
                    BowlerStudioMenuWorkspace.add(gitRepo, message);
                }
            }
        }.start();
        String key = t.getScripting().getGitRepo() + ":" + t.getScripting().getGitFile();
        ArrayList<String> files = new ArrayList<>();
        files.add(t.getScripting().getGitRepo());
        files.add(t.getScripting().getGitFile());
        try {
            if (// catch degenerates
            key.length() > 3 && files.get(0).length() > 0 && files.get(1).length() > 0)
                ConfigurationDatabase.setObject("studio-open-git", key, files);
        } catch (java.lang.NullPointerException ex) {
        // file can not be opened
        }
        fileTab.setContent(t);
        fileTab.setGraphic(AssetFactory.loadIcon("Script-Tab-" + ScriptingEngine.getShellType(file.getName()) + ".png"));
        addTab(fileTab, true);
        widgets.put(file.getAbsolutePath(), t);
        fileTab.setOnCloseRequest(event -> {
            widgets.remove(file.getAbsolutePath());
            openFiles.remove(file.getAbsolutePath());
            ConfigurationDatabase.removeObject("studio-open-git", key);
            t.getScripting().close();
            System.out.println("Closing " + file.getAbsolutePath());
        });
        FileChangeWatcher watcher = FileChangeWatcher.watch(file);
        watcher.addIFileChangeListener(new IFileChangeListener() {

            @Override
            public void onFileDelete(File fileThatIsDeleted) {
                BowlerStudioModularFrame.getBowlerStudioModularFrame().closeTab(fileTab);
            }

            @Override
            public void onFileChange(File fileThatChanged, WatchEvent event) {
            }
        });
        t.setFontSize(size);
        return t.getScripting();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) FileChangeWatcher(com.neuronrobotics.bowlerstudio.util.FileChangeWatcher) IOException(java.io.IOException) LocalFileScriptTab(com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab) LocalFileScriptTab(com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab) Tab(javafx.scene.control.Tab) IFileChangeListener(com.neuronrobotics.bowlerstudio.util.IFileChangeListener) WatchEvent(java.nio.file.WatchEvent) File(java.io.File)

Example 2 with FileChangeWatcher

use of com.neuronrobotics.bowlerstudio.util.FileChangeWatcher in project bowler-script-kernel by CommonWealthRobotics.

the class MobileBaseCadManager method getConfigurationDisplay.

private static ICadGenerator getConfigurationDisplay() {
    if (cadEngineConfiguration == null) {
        try {
            File confFile = ScriptingEngine.fileFromGit("https://github.com/CommonWealthRobotics/DHParametersCadDisplay.git", "dhcad.groovy");
            cadEngineConfiguration = (ICadGenerator) ScriptingEngine.inlineFileScriptRun(confFile, null);
            FileChangeWatcher watcher = FileChangeWatcher.watch(confFile);
            watcher.addIFileChangeListener(new IFileChangeListener() {

                @Override
                public void onFileChange(File fileThatChanged, WatchEvent event) {
                    // TODO Auto-generated method stub
                    try {
                        cadEngineConfiguration = (ICadGenerator) ScriptingEngine.gitScriptRun("https://github.com/CommonWealthRobotics/DHParametersCadDisplay.git", "dhcad.groovy", null);
                        for (MobileBase manager : cadmap.keySet()) {
                            MobileBaseCadManager mobileBaseCadManager = cadmap.get(manager);
                            if (mobileBaseCadManager.autoRegen)
                                if (mobileBaseCadManager.configMode)
                                    mobileBaseCadManager.generateCad();
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            });
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return cadEngineConfiguration;
}
Also used : IFileChangeListener(com.neuronrobotics.sdk.util.IFileChangeListener) FileChangeWatcher(com.neuronrobotics.bowlerstudio.util.FileChangeWatcher) WatchEvent(java.nio.file.WatchEvent) File(java.io.File) MobileBase(com.neuronrobotics.sdk.addons.kinematics.MobileBase) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) TransportException(org.eclipse.jgit.api.errors.TransportException) InvalidRemoteException(org.eclipse.jgit.api.errors.InvalidRemoteException)

Aggregations

FileChangeWatcher (com.neuronrobotics.bowlerstudio.util.FileChangeWatcher)2 File (java.io.File)2 IOException (java.io.IOException)2 WatchEvent (java.nio.file.WatchEvent)2 LocalFileScriptTab (com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab)1 IFileChangeListener (com.neuronrobotics.bowlerstudio.util.IFileChangeListener)1 MobileBase (com.neuronrobotics.sdk.addons.kinematics.MobileBase)1 IFileChangeListener (com.neuronrobotics.sdk.util.IFileChangeListener)1 ArrayList (java.util.ArrayList)1 Tab (javafx.scene.control.Tab)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 InvalidRemoteException (org.eclipse.jgit.api.errors.InvalidRemoteException)1 TransportException (org.eclipse.jgit.api.errors.TransportException)1