Search in sources :

Example 1 with Application

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;
}
Also used : PythonInterpreter(org.python.util.PythonInterpreter) Application(org.meteoinfo.lab.application.Application) PyObject(org.python.core.PyObject) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IPlugin(org.meteoinfo.ui.plugin.IPlugin)

Example 2 with Application

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();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Application(org.meteoinfo.lab.application.Application) File(java.io.File)

Example 3 with Application

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);
}
Also used : DefaultListModel(javax.swing.DefaultListModel) Application(org.meteoinfo.lab.application.Application) CheckBoxListEntry(org.meteoinfo.ui.CheckBoxListEntry)

Example 4 with Application

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);
}
Also used : DefaultListModel(javax.swing.DefaultListModel) Application(org.meteoinfo.lab.application.Application) CheckBoxListEntry(org.meteoinfo.ui.CheckBoxListEntry)

Example 5 with Application

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) URLClassLoader(java.net.URLClassLoader) Application(org.meteoinfo.lab.application.Application) URL(java.net.URL) IPlugin(org.meteoinfo.ui.plugin.IPlugin)

Aggregations

Application (org.meteoinfo.lab.application.Application)5 MalformedURLException (java.net.MalformedURLException)2 DefaultListModel (javax.swing.DefaultListModel)2 CheckBoxListEntry (org.meteoinfo.ui.CheckBoxListEntry)2 IPlugin (org.meteoinfo.ui.plugin.IPlugin)2 File (java.io.File)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 PyObject (org.python.core.PyObject)1 PythonInterpreter (org.python.util.PythonInterpreter)1