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;
}
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;
}
Aggregations