Author: dlanglais Date: 2010-03-04 00:30:50 +0100 (Thu, 04 Mar 2010) New Revision: 179 Added: trunk/plugins/ Modified: trunk/msm/src/main/java/org/nuiton/mapstoragemanager/core/BigTableLoader.java trunk/msm/src/main/java/org/nuiton/mapstoragemanager/ui/MainUI.jaxx trunk/msm/src/main/java/org/nuiton/mapstoragemanager/ui/gui/ApplicationEngine.java Log: Au d?\195?\169marrage de msm : - Chargement des plugins se trouvant dans le dossier "plugins" ?\195?\160 la racine du projet. En cours d'utilisation : - Possibilit?\195?\169 de charger un plugin. Modified: trunk/msm/src/main/java/org/nuiton/mapstoragemanager/core/BigTableLoader.java =================================================================== --- trunk/msm/src/main/java/org/nuiton/mapstoragemanager/core/BigTableLoader.java 2010-03-03 22:09:37 UTC (rev 178) +++ trunk/msm/src/main/java/org/nuiton/mapstoragemanager/core/BigTableLoader.java 2010-03-03 23:30:50 UTC (rev 179) @@ -49,13 +49,7 @@ classLoader); for (File file : new File(pluginsFolderPath).listFiles()) { - if (file.getAbsolutePath().endsWith(".jar")) { - try { - this.addURL(file.toURI().toURL()); - } catch (MalformedURLException e) { - LOG.error(e.toString(), e); - } - } + loadPlugin(file); } bigTableSetLoader = ServiceLoader.load(BigTable.class, this); @@ -66,6 +60,21 @@ } /** + * Load a plugin. + * @param file the plugin file. + */ + public void loadPlugin(final File file) { + LOG.info("Load plugin : " + file.getAbsolutePath()); + if (file.getAbsolutePath().endsWith(".jar")) { + try { + this.addURL(file.toURI().toURL()); + } catch (MalformedURLException e) { + LOG.error(e.toString(), e); + } + } + } + + /** * Returns a string displaying all the available BigTable implementations. * @return a string displaying all the available BigTable implementations */ Modified: trunk/msm/src/main/java/org/nuiton/mapstoragemanager/ui/MainUI.jaxx =================================================================== --- trunk/msm/src/main/java/org/nuiton/mapstoragemanager/ui/MainUI.jaxx 2010-03-03 22:09:37 UTC (rev 178) +++ trunk/msm/src/main/java/org/nuiton/mapstoragemanager/ui/MainUI.jaxx 2010-03-03 23:30:50 UTC (rev 179) @@ -4,98 +4,106 @@ <!-- include java files for treatment --> <script> <![CDATA[ - import org.nuiton.mapstoragemanager.ui.gui.ApplicationEngine; - import javax.swing.tree.*; - import static org.nuiton.i18n.I18n.n_; - import static org.nuiton.i18n.I18n._; - import javax.swing.JLabel; - import org.nuiton.mapstoragemanager.MsmConfig; - import org.nuiton.mapstoragemanager.ui.gui.MessageThread; + import org.nuiton.mapstoragemanager.ui.gui.ApplicationEngine; + import org.nuiton.mapstoragemanager.core.BigTableLoader; + import javax.swing.tree.*; + import static org.nuiton.i18n.I18n.n_; + import static org.nuiton.i18n.I18n._; + import javax.swing.JLabel; + import org.nuiton.mapstoragemanager.MsmConfig; + import org.nuiton.mapstoragemanager.plugins.BigTable; + import org.nuiton.mapstoragemanager.ui.gui.MessageThread; - ApplicationEngine engine = ApplicationEngine.getInstance(); + ApplicationEngine engine = ApplicationEngine.getInstance(); - /** - * classe instance (singleton pattern). - */ - private static MainUI instance = null; + /** + * classe instance (singleton pattern). + */ + private static MainUI instance = null; - /** - * getInstance method (singleton pattern). - * @return instance of the class - */ - public static MainUI getInstance() { - if (instance == null){ - instance = new MainUI(); - } - return instance; + /** + * getInstance method (singleton pattern). + * @return instance of the class + */ + public static MainUI getInstance() { + if (instance == null){ + instance = new MainUI(); + for (BigTable btPlugin : instance.getEngine().getBigTableLoader().getAllBigTable()) { + String btName = btPlugin.getPluginName(); + jaxx.runtime.swing.Item bigTableItem = + new jaxx.runtime.swing.Item(btName, null, btName, true); + instance.getNameBase().addItem(bigTableItem); + } } + return instance; + } - /** - * Access to the engine. - * @return instance of the class - */ - public ApplicationEngine getEngine(){ - return engine; - } + /** + * Access to the engine. + * @return instance of the class + */ + public ApplicationEngine getEngine(){ + return engine; + } - /** - * Access to the config. - * @return instance of the class - */ - public MsmConfig getConfig() { - return getContextValue(MsmConfig.class); - } + /** + * Access to the config. + * @return instance of the class + */ + public MsmConfig getConfig() { + return getContextValue(MsmConfig.class); + } - /** - * Dispose UI. - */ - public void dispose(){ - instance = null; - engine.dispose(); - this.setVisible(false); + /** + * Dispose UI. + */ + public void dispose(){ + instance = null; + engine.dispose(); + this.setVisible(false); + } + + /** + * Display the appropriate message. + * @param message the message to display. + * @param code code error (for images). + */ + public void displayMessage(String message, int code){ + + //clear the message panel + this.getMessagesPanel().removeAll(); + + //display message + if (code==0){ + String icon ="ok_16"; + }else if (code==1){ + String icon ="warning_16.png"; + }else if (code==2){ + String icon ="cancel_16.png"; } - /** - * Display the appropriate message. - * @param message the message to display. - * @param code code error (for images). - */ - public void displayMessage(String message, int code){ - - //clear the message panel - this.getMessagesPanel().removeAll(); + JLabel label = new JLabel(message); + label.setIcon(jaxx.runtime.SwingUtil.getUIManagerActionIcon("ok_16")); + this.getMessagesPanel().add(label); + this.getMessagesPanel().repaint(); + this.getMessagesPanel().revalidate(); - //display message - if (code==0){ - String icon ="ok_16"; - }else if (code==1){ - String icon ="warning_16.png"; - }else if (code==2){ - String icon ="cancel_16.png"; - } + //remove message after a short time + MessageThread m = new MessageThread(); + m.start(); - JLabel label = new JLabel(message); - label.setIcon(jaxx.runtime.SwingUtil.getUIManagerActionIcon("ok_16")); - this.getMessagesPanel().add(label); - this.getMessagesPanel().repaint(); - this.getMessagesPanel().revalidate(); + } - //remove message after a short time - MessageThread m = new MessageThread(); - m.start(); - - } + /** + * Test. + */ + public DefaultTreeModel getModelTree(){ + n_("Empty"); + return new DefaultTreeModel(new DefaultMutableTreeNode(_("Empty"))); + } - /** - * Test. - */ - public DefaultTreeModel getModelTree(){ - n_("Empty"); - return new DefaultTreeModel(new DefaultMutableTreeNode(_("Empty"))); - } - ]]> </script> Modified: trunk/msm/src/main/java/org/nuiton/mapstoragemanager/ui/gui/ApplicationEngine.java =================================================================== --- trunk/msm/src/main/java/org/nuiton/mapstoragemanager/ui/gui/ApplicationEngine.java 2010-03-03 22:09:37 UTC (rev 178) +++ trunk/msm/src/main/java/org/nuiton/mapstoragemanager/ui/gui/ApplicationEngine.java 2010-03-03 23:30:50 UTC (rev 179) @@ -22,8 +22,6 @@ import org.nuiton.mapstoragemanager.MsmConfig; import org.nuiton.mapstoragemanager.core.BigTableLoader; import org.nuiton.mapstoragemanager.plugins.BigTable; -//import org.nuiton.mapstoragemanager.plugins.bighashmapv2.BigHashMapV2; -//import org.nuiton.mapstoragemanager.plugins.OurHashMap2; import org.nuiton.mapstoragemanager.plugins.OurHashMap2; import org.nuiton.mapstoragemanager.ui.MainUI; import static org.nuiton.i18n.I18n._; @@ -52,12 +50,27 @@ /** * BigtableLoader. */ - private static BigTableLoader bigTableLoader; + private static BigTableLoader btl; /** * Constructor. */ private ApplicationEngine() { + try { + String basedir = new File("").getAbsolutePath(); + File msnBasedir = new File(basedir).getParentFile(); + String toPlugin = "plugins/"; + String pluginsFolderPath = new File(msnBasedir, toPlugin).getPath(); + + LOG.info("basedir : " + basedir + '\n' + + "msnBasedir : " + msnBasedir + '\n' + + "pluginsFolderPath : " + pluginsFolderPath); + + btl = new BigTableLoader(pluginsFolderPath, + this.getClass().getClassLoader()); + } catch (MalformedURLException ex) { + LOG.error(ex, ex); + } } /** @@ -73,38 +86,38 @@ String basedir = new File("").getAbsolutePath(); File msnBasedir = new File(basedir).getParentFile(); +// String toPlugin = "msm-bighashmapV2/target/"; JFileChooser jfc = new javax.swing.JFileChooser(msnBasedir); - String toPlugin = "msm-bighashmapV2/target/"; jfc.getSelectedFiles(); // File pluginPath = new File(msnBasedir, toPlugin); jfc.showOpenDialog(MainUI.getFrames()[0]); - File pluginPath = jfc.getSelectedFile().getParentFile(); + File pluginPath = jfc.getSelectedFile(); // BigTableLoader btl = null; LOG.info("basedir : " + basedir + '\n' - + "msnBbasedir : " + msnBasedir + '\n' - + "pluginPath : " + pluginPath.getPath()); + + "msnBasedir : " + msnBasedir + '\n' + + "pluginPath : " + pluginPath.getAbsolutePath()); - try { - bigTableLoader = - new BigTableLoader(pluginPath.getPath(), - this.getClass().getClassLoader()); - } catch (MalformedURLException ex) { - LOG.fatal(ex, ex); - } +// try { + btl.loadPlugin(pluginPath); +// bigTableLoader = +// new BigTableLoader(pluginPath.getPath(), +// this.getClass().getClassLoader()); +// } catch (MalformedURLException ex) { +// LOG.fatal(ex, ex); +// } - LOG.info("getBigtable() : " + bigTableLoader.getBigTable()); + LOG.info("getBigtable() : " + btl.getBigTable()); MainUI ui = MainUI.getInstance(); - for (BigTable btPlugin : bigTableLoader.getAllBigTable()) { + for (BigTable btPlugin : btl.getAllBigTable()) { String btName = btPlugin.getPluginName(); jaxx.runtime.swing.Item bigTableItem = new jaxx.runtime.swing.Item(btName, null, btName, true); ui.getNameBase().addItem(bigTableItem); ui.getNameBase().setSelectedItem(bigTableItem); - } // ui.getNameBase().re @@ -192,7 +205,7 @@ if (nameBase.equals("OurHashMap")) { bigTable = new OurHashMap2(); } else { - bigTable = bigTableLoader.getBigTable(nameBase); + bigTable = btl.getBigTable(nameBase); } // bigTable = new OurHashMap2(); { @@ -273,7 +286,7 @@ */ public static ApplicationEngine getInstance() { if (instance == null) { - instance = new ApplicationEngine(); + instance = new ApplicationEngine(); } return instance; } @@ -352,4 +365,7 @@ this.bigTable = bigTable; } + public BigTableLoader getBigTableLoader(){ + return btl; + } }