use of org.meteoinfo.lab.application.Application in project MeteoInfo by meteoinfo.
the class FrmAppsManager method readPyApp.
// GEN-LAST:event_formWindowClosed
public Application readPyApp(String path, String fileName) {
try {
Application plugin = new Application();
plugin.setPath(path);
plugin.setClassName("LoadApp");
PythonInterpreter interp = this.parent.getConsoleDockable().getInterpreter();
interp.exec("import " + path);
interp.exec("from " + path + ".loadApp import LoadApp");
PyObject loadClass = interp.get("LoadApp");
PyObject loadObj = loadClass.__call__();
IPlugin instance = (IPlugin) loadObj.__tojava__(IPlugin.class);
plugin.setPluginObject(instance);
return plugin;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.meteoinfo.lab.application.Application in project MeteoInfo by meteoinfo.
the class FrmAppsManager method jButton_UpdateListActionPerformed.
// GEN-LAST:event_checkBoxList_PluginMouseClicked
private void jButton_UpdateListActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_jButton_UpdateListActionPerformed
// TODO add your handling code here:
List<Application> plugins = new ArrayList<>();
String pluginPath = parent.getApplications().getPluginPath();
if (new File(pluginPath).isDirectory()) {
// List<String> fileNames = GlobalUtil.getFiles(pluginPath, ".jar");
// for (String fn : fileNames) {
// Application plugin = this.readApplication(fn);
// if (plugin != null) {
// plugins.add(plugin);
// }
// }
File f = new File(pluginPath);
if (f.isDirectory()) {
File[] fs = f.listFiles();
for (File ff : fs) {
if (ff.isDirectory()) {
Application plugin = this.readPyApp(ff.getName(), "loadApp.py");
if (plugin != null) {
plugins.add(plugin);
}
}
}
}
if (plugins.size() > 0) {
List<String> pluginNames = new ArrayList<>();
for (Application plugin : apps) {
pluginNames.add(plugin.getName());
}
List<String> newPluginNames = new ArrayList<>();
for (Application plugin : plugins) {
newPluginNames.add(plugin.getName());
}
for (int i = 0; i < apps.size(); i++) {
if (!newPluginNames.contains(apps.get(i).getName())) {
apps.remove(i);
i -= 1;
}
}
for (Application plugin : plugins) {
if (!pluginNames.contains(plugin.getName())) {
apps.add(plugin);
}
}
this.updatePluginCheckList();
}
}
}
use of org.meteoinfo.lab.application.Application in project MeteoInfo by meteoinfo.
the class FrmAppsManager method updatePluginCheckList.
private void updatePluginCheckList() {
DefaultListModel listModel = new DefaultListModel();
for (Application plugin : apps) {
listModel.addElement(new CheckBoxListEntry(plugin, plugin.isLoad()));
}
this.checkBoxList_Plugin.setModel(listModel);
}
use of org.meteoinfo.lab.application.Application in project MeteoInfo by meteoinfo.
the class FrmAppsManager method checkBoxList_PluginMouseClicked.
// </editor-fold>//GEN-END:initComponents
private void checkBoxList_PluginMouseClicked(java.awt.event.MouseEvent evt) {
// GEN-FIRST:event_checkBoxList_PluginMouseClicked
// TODO add your handling code here:
DefaultListModel listModel = (DefaultListModel) this.checkBoxList_Plugin.getModel();
int idx = this.checkBoxList_Plugin.getSelectedIndex();
CheckBoxListEntry item = (CheckBoxListEntry) listModel.getElementAt(idx);
Application plugin = (Application) item.getValue();
if (item.isSelected()) {
parent.loadApplication(plugin);
parent.validate();
} else {
parent.unloadApplication(plugin);
parent.validate();
}
String detailStr = "Name: " + plugin.getName() + System.getProperty("line.separator") + "Author: " + plugin.getAuthor() + System.getProperty("line.separator") + "Version: " + plugin.getVersion() + System.getProperty("line.separator") + "Description: " + plugin.getDescription() + System.getProperty("line.separator") + "Jar Path: " + plugin.getJarPath() + System.getProperty("line.separator") + "Class Name: " + plugin.getClassName();
this.jTextArea_PluginDetails.setText(detailStr);
}
use of org.meteoinfo.lab.application.Application in project MeteoInfo by meteoinfo.
the class FrmAppsManager method readApplication.
public Application readApplication(String jarFileName) {
try {
Application plugin = new Application();
plugin.setPath(jarFileName);
String className = GlobalUtil.getPluginClassName(jarFileName);
if (className == null) {
return null;
} else {
plugin.setClassName(className);
URL url = new URL("file:" + plugin.getPath());
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { url });
Class<?> clazz = urlClassLoader.loadClass(plugin.getClassName());
IPlugin instance = (IPlugin) clazz.newInstance();
plugin.setPluginObject(instance);
return plugin;
}
} catch (MalformedURLException ex) {
Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
Aggregations