44import com .xwintop .xJavaFxTool .model .PluginJarInfo ;
55import com .xwintop .xJavaFxTool .utils .Config ;
66import com .xwintop .xcore .javafx .dialog .FxAlerts ;
7+ import com .xwintop .xcore .plugin .PluginEvent ;
78import javafx .fxml .FXMLLoader ;
9+ import javafx .scene .Node ;
810import org .apache .commons .lang3 .StringUtils ;
911
1012import java .io .IOException ;
@@ -21,6 +23,8 @@ public class PluginContainer {
2123
2224 private final PluginJarInfo pluginJarInfo ;
2325
26+ private Node rootNode ;
27+
2428 public PluginContainer (PluginJarInfo pluginJarInfo ) {
2529 this (ClassLoader .getSystemClassLoader (), pluginJarInfo );
2630 }
@@ -30,6 +34,10 @@ public PluginContainer(ClassLoader parentClassLoader, PluginJarInfo pluginJarInf
3034 this .pluginClassLoader = PluginClassLoader .create (parentClassLoader , pluginJarInfo .getFile ());
3135 }
3236
37+ public void setRootNode (Node rootNode ) {
38+ this .rootNode = rootNode ;
39+ }
40+
3341 public <T > T createInstance (Class <T > type ) {
3442 try {
3543 return type .getDeclaredConstructor ().newInstance ();
@@ -79,9 +87,18 @@ public FXMLLoader createFXMLLoader() {
7987 */
8088 public void unload () {
8189 try {
90+ if (this .rootNode != null ) {
91+ this .rootNode .fireEvent (new PluginEvent (this .rootNode , PluginEvent .PLUGIN_UNLOADING ));
92+ }
8293 this .pluginClassLoader .close ();
8394 } catch (IOException e ) {
8495 throw new AppException (e );
8596 }
8697 }
98+
99+ public void onPluginInitialized () {
100+ if (this .rootNode != null ) {
101+ this .rootNode .fireEvent (new PluginEvent (this .rootNode , PluginEvent .PLUGIN_INITIALIZED ));
102+ }
103+ }
87104}
0 commit comments