2323import com .owlplug .core .utils .FileUtils ;
2424import com .owlplug .core .utils .PlatformUtils ;
2525import com .owlplug .plugin .controllers .dialogs .DisablePluginDialogController ;
26+ import com .owlplug .plugin .model .IPlugin ;
2627import com .owlplug .plugin .model .Plugin ;
2728import com .owlplug .plugin .model .PluginFormat ;
2829import com .owlplug .plugin .model .PluginState ;
@@ -63,9 +64,9 @@ public class PluginTableController extends BaseController {
6364 private PluginService pluginService ;
6465
6566 private final SimpleStringProperty search = new SimpleStringProperty ();
66- private final TableView <Plugin > tableView ;
67+ private final TableView <IPlugin > tableView ;
6768
68- private final ObservableList <Plugin > pluginList ;
69+ private final ObservableList <IPlugin > pluginList ;
6970
7071
7172 public PluginTableController () {
@@ -75,7 +76,7 @@ public PluginTableController() {
7576 createColumns ();
7677
7778 tableView .setRowFactory (tv -> {
78- TableRow <Plugin > row = new TableRow <>();
79+ TableRow <IPlugin > row = new TableRow <>();
7980 row .itemProperty ().addListener ((obs , oldItem , newItem ) -> {
8081 if (newItem != null ) {
8182 row .setContextMenu (createPluginContextMenu (newItem ));
@@ -88,7 +89,7 @@ public PluginTableController() {
8889 pluginList = FXCollections .observableArrayList ();
8990 // Wraps an ObservableList and filters its content using the provided Predicate.
9091 // All changes in the ObservableList are propagated immediately to the FilteredList.
91- FilteredList <Plugin > filteredPluginList = new FilteredList <>(pluginList );
92+ FilteredList <IPlugin > filteredPluginList = new FilteredList <>(pluginList );
9293
9394 filteredPluginList .predicateProperty ().bind (Bindings .createObjectBinding (() -> {
9495 if (search .getValue () == null || search .getValue ().isEmpty ()) {
@@ -99,17 +100,17 @@ public PluginTableController() {
99100 search .getValue ().toLowerCase ()));
100101 }, search ));
101102
102- SortedList <Plugin > sortedPluginList = new SortedList <>(filteredPluginList );
103+ SortedList <IPlugin > sortedPluginList = new SortedList <>(filteredPluginList );
103104 tableView .setItems (sortedPluginList );
104105 sortedPluginList .comparatorProperty ().bind (tableView .comparatorProperty ());
105106
106107 }
107108
108109 private void createColumns () {
109- TableColumn <Plugin , String > nameColumn = new TableColumn <>("Name" );
110+ TableColumn <IPlugin , String > nameColumn = new TableColumn <>("Name" );
110111 nameColumn .setCellValueFactory (cellData -> new SimpleStringProperty (cellData .getValue ().getName ()));
111- TableColumn <Plugin , PluginFormat > formatColumn = new TableColumn <>("Format" );
112- formatColumn .setCellValueFactory (cellData -> new SimpleObjectProperty <>(cellData .getValue ().getFormat ()));
112+ TableColumn <IPlugin , PluginFormat > formatColumn = new TableColumn <>("Format" );
113+ formatColumn .setCellValueFactory (cellData -> new SimpleObjectProperty <>(cellData .getValue ().asPlugin (). getFormat ()));
113114 formatColumn .setCellFactory (e -> new TableCell <>() {
114115 @ Override
115116 public void updateItem (PluginFormat item , boolean empty ) {
@@ -123,17 +124,17 @@ public void updateItem(PluginFormat item, boolean empty) {
123124 }
124125 }
125126 });
126- TableColumn <Plugin , String > manufacturerColumn = new TableColumn <>("Manufacturer" );
127+ TableColumn <IPlugin , String > manufacturerColumn = new TableColumn <>("Manufacturer" );
127128 manufacturerColumn .setCellValueFactory (cellData ->
128129 new SimpleStringProperty (cellData .getValue ().getManufacturerName ()));
129- TableColumn <Plugin , String > versionColumn = new TableColumn <>("Version" );
130+ TableColumn <IPlugin , String > versionColumn = new TableColumn <>("Version" );
130131 versionColumn .setCellValueFactory (cellData -> new SimpleStringProperty (cellData .getValue ().getVersion ()));
131- TableColumn <Plugin , String > categoryColumn = new TableColumn <>("Category" );
132+ TableColumn <IPlugin , String > categoryColumn = new TableColumn <>("Category" );
132133 categoryColumn .setCellValueFactory (cellData -> new SimpleStringProperty (cellData .getValue ().getCategory ()));
133134 // Directory Column
134- TableColumn <Plugin , String > directoryColumn = new TableColumn <>("Directory" );
135+ TableColumn <IPlugin , String > directoryColumn = new TableColumn <>("Directory" );
135136 directoryColumn .setCellValueFactory (cellData -> new SimpleStringProperty (
136- FileUtils .getParentDirectoryName (cellData .getValue ().getPath ())));
137+ FileUtils .getParentDirectoryName (cellData .getValue ().asPlugin (). getPath ())));
137138 directoryColumn .setCellFactory (e -> new TableCell <>() {
138139 @ Override
139140 public void updateItem (String item , boolean empty ) {
@@ -148,9 +149,9 @@ public void updateItem(String item, boolean empty) {
148149 }
149150 });
150151 // Scan Directory Column
151- TableColumn <Plugin , String > scanDirectoryColumn = new TableColumn <>("Scan Dir." );
152+ TableColumn <IPlugin , String > scanDirectoryColumn = new TableColumn <>("Scan Dir." );
152153 scanDirectoryColumn .setCellValueFactory (cellData -> new SimpleStringProperty (
153- FileUtils .getFilename (cellData .getValue ().getScanDirectoryPath ())));
154+ FileUtils .getFilename (cellData .getValue ().asPlugin (). getScanDirectoryPath ())));
154155 scanDirectoryColumn .setCellFactory (e -> new TableCell <>() {
155156 @ Override
156157 public void updateItem (String item , boolean empty ) {
@@ -165,9 +166,9 @@ public void updateItem(String item, boolean empty) {
165166 }
166167 });
167168 // Plugin State Column
168- TableColumn <Plugin , PluginState > stateColumn = new TableColumn <>("State" );
169+ TableColumn <IPlugin , PluginState > stateColumn = new TableColumn <>("State" );
169170 stateColumn .setCellValueFactory (cellData -> new SimpleObjectProperty <>(
170- pluginService .getPluginState (cellData .getValue ())));
171+ pluginService .getPluginState (cellData .getValue (). asPlugin () )));
171172 stateColumn .setCellFactory (e -> new TableCell <>() {
172173 @ Override
173174 public void updateItem (PluginState item , boolean empty ) {
@@ -188,10 +189,16 @@ public void updateItem(PluginState item, boolean empty) {
188189
189190 public void setPlugins (Iterable <Plugin > plugins ) {
190191 pluginList .clear ();
191- plugins .forEach (pluginList ::add );
192+ plugins .forEach (p -> {
193+ pluginList .add (p );
194+ if (p .getComponents ().size () > 1 ) {
195+ pluginList .addAll (p .getComponents ());
196+ }
197+ });
198+
192199 }
193200
194- public TableView <Plugin > getTableView () {
201+ public TableView <IPlugin > getTableView () {
195202 return tableView ;
196203 }
197204
@@ -201,7 +208,8 @@ public void setNodeManaged(boolean isManaged) {
201208 }
202209
203210 public void selectPluginById (long id ) {
204- for (Plugin plugin : pluginList ) {
211+ for (IPlugin p : pluginList ) {
212+ Plugin plugin = p .asPlugin (); // Get plugin or component parent
205213 if (plugin .getId ().equals (id )) {
206214 tableView .getSelectionModel ().select (plugin );
207215 break ;
@@ -217,37 +225,39 @@ public void refresh() {
217225 tableView .refresh ();
218226 }
219227
220- private ContextMenu createPluginContextMenu (Plugin plugin ) {
228+ private ContextMenu createPluginContextMenu (IPlugin plugin ) {
221229
222230 ContextMenu menu = new ContextMenu ();
223231 MenuItem openDirItem = new MenuItem ("Reveal in File Explorer" );
224232 openDirItem .setOnAction (e -> {
225- File pluginFile = new File (plugin .getPath ());
233+ File pluginFile = new File (plugin .asPlugin (). getPath ());
226234 PlatformUtils .openFromDesktop (pluginFile .getParentFile ());
227235 });
228236
229237 menu .getItems ().addAll (openDirItem , new SeparatorMenuItem ());
230238
231- if (plugin .isDisabled ()) {
232- MenuItem enableItem = new MenuItem ("Enable plugin" );
233- enableItem .setOnAction (e -> {
234- Async .run (() -> pluginService .enablePlugin (plugin ));
235- });
236- menu .getItems ().add (enableItem );
237- } else {
238- MenuItem disableItem = new MenuItem ("Disable plugin" );
239- disableItem .setOnAction (e -> {
240- if (this .getPreferences ().getBoolean (ApplicationDefaults .SHOW_DIALOG_DISABLE_PLUGIN_KEY , true )) {
241- this .disableController .setPlugin (plugin );
242- this .disableController .show ();
243- } else {
244- this .disableController .disablePluginWithoutPrompt (plugin );
245- }
246- });
247- menu .getItems ().add (disableItem );
248- }
239+ if (plugin instanceof Plugin p ) {
240+ if (p .isDisabled ()) {
241+ MenuItem enableItem = new MenuItem ("Enable plugin" );
242+ enableItem .setOnAction (e -> {
243+ Async .run (() -> pluginService .enablePlugin (p ));
244+ });
245+ menu .getItems ().add (enableItem );
246+ } else {
247+ MenuItem disableItem = new MenuItem ("Disable plugin" );
248+ disableItem .setOnAction (e -> {
249+ if (this .getPreferences ().getBoolean (ApplicationDefaults .SHOW_DIALOG_DISABLE_PLUGIN_KEY , true )) {
250+ this .disableController .setPlugin (p );
251+ this .disableController .show ();
252+ } else {
253+ this .disableController .disablePluginWithoutPrompt (p );
254+ }
255+ });
256+ menu .getItems ().add (disableItem );
257+ }
249258
250- menu .getItems ().add (new SeparatorMenuItem ());
259+ menu .getItems ().add (new SeparatorMenuItem ());
260+ }
251261
252262 MenuItem infoDisplayItem = new MenuItem ("Toggle info display" );
253263 menu .getItems ().add (infoDisplayItem );
0 commit comments