20 package net.sf.gridarta.gui.dialog.plugin;
22 import java.awt.BorderLayout;
23 import java.awt.CardLayout;
24 import java.awt.Color;
25 import java.awt.Component;
26 import java.awt.Container;
27 import java.awt.GridLayout;
28 import java.util.HashMap;
30 import javax.swing.AbstractListModel;
31 import javax.swing.JButton;
32 import javax.swing.JFrame;
33 import javax.swing.JList;
34 import javax.swing.JOptionPane;
35 import javax.swing.JPanel;
36 import javax.swing.ListModel;
37 import javax.swing.ListSelectionModel;
38 import javax.swing.border.LineBorder;
48 import net.
sf.japi.swing.action.ActionBuilder;
49 import net.
sf.japi.swing.action.ActionBuilderFactory;
50 import net.
sf.japi.swing.action.ActionMethod;
51 import org.jetbrains.annotations.NotNull;
52 import org.jetbrains.annotations.Nullable;
60 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
66 private final JList<Plugin<G, A, R>>
scripts;
101 public PluginManager(@NotNull
final Component parent, @NotNull
final PluginController<G, A, R> pluginController, @NotNull
final PluginModel<G, A, R> pluginModel, @NotNull
final PluginParameterViewFactory<G, A, R> pluginParameterViewFactory, @NotNull
final ResourceIcons resourceIcons) {
106 frame.getContentPane().setLayout(
new BorderLayout());
107 final ListModel<Plugin<G, A, R>> listModel =
new AbstractListModel<Plugin<G, A, R>>() {
112 private static final long serialVersionUID = 1L;
136 public void pluginUnregistered(@NotNull
final Plugin<G, A, R> plugin) {
153 public int getSize() {
158 scripts =
new JList<>(listModel);
159 scripts.addListSelectionListener(e -> {
160 if (!e.getValueIsAdjusting()) {
161 showScript(scripts.getSelectedValue());
164 scripts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
165 scripts.setBorder(
new LineBorder(Color.black, 1));
168 final Container bottomLeft =
new JPanel(
new GridLayout(2, 1));
169 bottomLeft.add(
new JButton(
ACTION_BUILDER.createAction(
false,
"pluginManagerNewScript",
this)));
170 bottomLeft.add(
new JButton(
ACTION_BUILDER.createAction(
false,
"pluginManagerRemoveScript",
this)));
172 final Container left =
new JPanel(
new BorderLayout());
173 left.add(
scripts, BorderLayout.CENTER);
174 left.add(bottomLeft, BorderLayout.SOUTH);
176 frame.getContentPane().add(left, BorderLayout.WEST);
179 frame.setLocationRelativeTo(parent);
190 if (plugin ==
null) {
195 if (pluginEditor ==
null) {
205 if (scriptEditor !=
null) {
215 frame.setVisible(
true);
229 if (plugin ==
null) {
232 JOptionPane.showMessageDialog(
scripts, message, title, JOptionPane.WARNING_MESSAGE);
245 if (plugin ==
null) {
251 if (JOptionPane.showConfirmDialog(
scripts, message, title, JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {