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;
39 import javax.swing.event.ListSelectionEvent;
40 import javax.swing.event.ListSelectionListener;
50 import net.
sf.japi.swing.action.ActionBuilder;
51 import net.
sf.japi.swing.action.ActionBuilderFactory;
52 import net.
sf.japi.swing.action.ActionMethod;
53 import org.jetbrains.annotations.NotNull;
54 import org.jetbrains.annotations.Nullable;
62 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
68 private final JList<Plugin<G, A, R>>
scripts;
103 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) {
108 frame.getContentPane().setLayout(
new BorderLayout());
109 final ListModel<Plugin<G, A, R>> listModel =
new AbstractListModel<Plugin<G, A, R>>() {
114 private static final long serialVersionUID = 1L;
138 public void pluginUnregistered(@NotNull
final Plugin<G, A, R> plugin) {
155 public int getSize() {
160 scripts =
new JList<>(listModel);
161 scripts.addListSelectionListener(
new ListSelectionListener() {
164 public void valueChanged(
final ListSelectionEvent e) {
165 if (!e.getValueIsAdjusting()) {
170 scripts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
171 scripts.setBorder(
new LineBorder(Color.black, 1));
174 final Container bottomLeft =
new JPanel(
new GridLayout(2, 1));
175 bottomLeft.add(
new JButton(
ACTION_BUILDER.createAction(
false,
"pluginManagerNewScript",
this)));
176 bottomLeft.add(
new JButton(
ACTION_BUILDER.createAction(
false,
"pluginManagerRemoveScript",
this)));
178 final Container left =
new JPanel(
new BorderLayout());
179 left.add(
scripts, BorderLayout.CENTER);
180 left.add(bottomLeft, BorderLayout.SOUTH);
182 frame.getContentPane().add(left, BorderLayout.WEST);
185 frame.setLocationRelativeTo(parent);
196 if (plugin ==
null) {
201 if (pluginEditor ==
null) {
211 if (scriptEditor !=
null) {
221 frame.setVisible(
true);
235 if (plugin ==
null) {
238 JOptionPane.showMessageDialog(
scripts, message, title, JOptionPane.WARNING_MESSAGE);
251 if (plugin ==
null) {
257 if (JOptionPane.showConfirmDialog(
scripts, message, title, JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {