}
} catch (Exception e1) {}
}
GeneralDialog dia = new GeneralDialog(
this.myStarter,
null,
"Delete all plugins but the selected ones.",
GeneralDialog.OK_CANCEL_BUTT,
"Do you really want to delete all plugins (and master schedulers), but the selected ones, from the list of stored plugins?\n"
+ "You will not be able to use any other plugins after this. To get back to the complete list, use the button '"
+ Starter.FIND_NEW_PLUGINS_STRING + "'.\n\nThe selected plugins that will remain in the list are:\n\n"
+ pluginsNew.toString().replace("]", "").replace("[", "").replace(", ", "\n")
+ "\n\nWARNING: The program will be shut down to complete this procedure.");
dia.setVisible(true);
if (dia.getResult().equals(GeneralDialog.CANCEL)) {
return;
}
try {
PluginFactory.serializePlugins(pluginsNew, PluginFactory.PLUGIN_STORAGE_FILE_NAME);
GlobalVariables.getPrematureParameters().logInfo("List of plugins has been reduced to selected ones. Program is shutting down to complete procedure.");
System.exit(0);
} catch (IOException e1) {
GlobalVariables.getPrematureParameters().logError(
"List of plugins has NOT been reduced due to the following problem:\n"
+ e1.getStackTrace().toString().replace("]", "").replace("[", "").replace(", ", "\n"));
GeneralDialog dia2 = new GeneralDialog(
this.myStarter,
"The list of plugins has NOT been reduced. See log for details.",
"Error occured while reducing plugins list.",
GeneralDialog.OK_BUTT,
null);
dia2.setVisible(true);
}
}
// Export plugins.
if (e.getSource().equals(buttOK)) {
FileDialog dia = new FileDialog(this.myStarter, "Choose JAR file to store plugins", FileDialog.SAVE);
frame.dispose();
dia.setFilenameFilter(new FileNamePostfixFilter(".jar"));
dia.setVisible(true);
if (dia.getDirectory() == null || dia.getFile() == null) {
return;
}
File storeFile = new File(dia.getDirectory() + File.separator + dia.getFile());
@SuppressWarnings("deprecation")
Object[] selected = list.getSelectedValues();
String dirPrefixPlugin = dirPrefix;
StaticMethods.delDir(new File(dirPrefix));
for (Object o : selected) {
Class<Plugin<?>> c = (Class<Plugin<?>>) o;
try {
dirPrefixPlugin = dirPrefix + c.newInstance().id() + "/";
} catch (Exception e2) {
throw new RuntimeException("Plugin instance not created.");
}
File dir = new File(dirPrefixPlugin + "/" + c.getPackage().getName().replace('.', '/'));
File dirOwn = new File("./" + c.getPackage().getName().replace('.', '/'));
FileCopy copy = new FileCopy();
dir.mkdirs();
try {
copy.copyFolder(dirOwn, dir, true, false);
} catch (IOException e1) {
GlobalVariables.getPrematureParameters().logError("Could not copy directory '" + dirOwn + "':" + e1.getMessage() + "\n" + Arrays.deepToString(e1.getStackTrace()).replace(',', '\n'));
GlobalVariables.getPrematureParameters().logInfo("Plugin export aborted due to errors.");
return;
}
}
try {
ZipIt.createJARfromDirectory(dirPrefix, storeFile, null);
} catch (IOException e1) {
GlobalVariables.getPrematureParameters().logError("Could not create JAR file '" + storeFile + "'.");
}
StaticMethods.delDir(new File(dirPrefix));
GlobalVariables.getPrematureParameters().logInfo("Plugin JAR file '" + storeFile + "' exported.");
GeneralDialog dia2 = new GeneralDialog(
myStarter,
null,
"Export successful (" + selected.length + " plugins)",
GeneralDialog.OK_BUTT,
"Plugin JAR file '" + storeFile + "' exported:\n\n- " + Arrays.deepToString(selected).replace("[", "").replace("]", "").replace(", ", "\n- "));
dia2.setVisible(true);
return;
} else if (e.getSource().equals(buttCancel)) {
frame.dispose();
return;
}
myStarter.actionPerformed(e);
if (e.getActionCommand().equals(Starter.EXIT_STRING)) {
myStarter.dispose();
System.exit(0);
} else if (e.getActionCommand().equals(Starter.LOAD_STORED_SIMULATION)) {
if (loadSimState()) {
this.myStarter.dispose();
}
} else if (e.getActionCommand().equals(Starter.EXPORT_PLUGINS_STRING)) {
frame = new JDialog(myStarter, Starter.EXPORT_PLUGINS_STRING + " NOTE: all necessary classes have to be located in the package of the main plugin class.");
JPanel panel = new JPanel(new GridLayout(2, 1));
Object[] items = convertListToArray(getSharablePlugins());
list = new JList(items);
JScrollPane jScrollPane1 = new JScrollPane(list);
panel.add(jScrollPane1);
JPanel mainPanel = new JPanel();
JPanel panel1 = new JPanel(new GridLayout(1, 4));
panel1.add(buttOK);
panel1.add(buttCancel);
buttOK.addActionListener(this);
buttCancel.addActionListener(this);
panel.add(mainPanel);
mainPanel.add(panel1);
frame.getContentPane().add(panel);
frame.setSize(750, 400);
frame.setVisible(true);
} else if (e.getActionCommand().equals(Starter.IMPORT_PLUGINS_STRING)) {
// User selects file to import.
FileDialog dia = new FileDialog(this.myStarter, "Choose JAR file to store plugins", FileDialog.LOAD);
dia.setFilenameFilter(new FileNamePostfixFilter(".jar"));
dia.setVisible(true);
if (dia.getDirectory() == null || dia.getFile() == null) {
return;
}
// Delete temp dir if existing.
StaticMethods.delDir(new File(dirPrefix));
// Extract ZIP archive from JAR.
try {
ZipIt.extractZIPArchive(
new File(dia.getDirectory() + File.separator + dia.getFile()),
new File("."));
} catch (Exception e1) {
e1.printStackTrace();
}
// Create list of plugin ids.
LinkedList<Class<Plugin<?>>> list = PluginFactory.findAllNonAbstractPluginClasses(false);
LinkedList<String> listPlugStr = new LinkedList<String>();
for (Class<Plugin<?>> c : list) {
try {
listPlugStr.add(c.newInstance().id());
} catch (Exception e1) {
GlobalVariables.getPrematureParameters().logError("Plugin instance not created: " + c.getName());
}
}
// Check if some new plugin id already exists.
File[] files = new File(this.dirPrefix).listFiles();
String[] selected = new String[files.length];
int num = 0;
for (File f : files) {
boolean ignore = false;
if (listPlugStr.contains(f.getName())) {
GeneralDialog dia2 = new GeneralDialog(
this.myStarter,
"A Plugin with id '" + f.getName() + "' already exists in local class tree. Do you wish to continue?",
"Plugin id exists",
GeneralDialog.YES_NO,
null);
dia2.setVisible(true);
if (dia2.getResult().equals(GeneralDialog.NO)) {
ignore = true;
}
}
if (!ignore) {
// Import plugin.
selected[num] = f.getName();
String destDir = ".";
File destDirFile = new File(destDir);
try {
new FileCopy().copyFolder(f, destDirFile, true, true);
} catch (IOException e1) {
GlobalVariables.getPrematureParameters().logError("Could not copy directory '" + f + "':" + e1.getMessage() + "\n" + Arrays.deepToString(e1.getStackTrace()).replace(',', '\n'));
}
} else {
selected[num] = f.getName() + " (NOT IMPORTED).";
}
num++;
}
// Delete temp dir.
StaticMethods.delDir(new File(dirPrefix));
GeneralDialog dia2 = new GeneralDialog(
myStarter,
null,
"Import successful (" + files.length + " plugins)",
GeneralDialog.OK_BUTT,
"Plugin JAR file '"
+ dia.getDirectory()
+ dia.getFile()
+ "' imported:\n\n- "
+ Arrays.deepToString(selected).replace("[", "").replace("]", "").replace(", ", "\n- "));
dia2.setVisible(true);
// Find new plugins.
this.myStarter.findNewPlugins(GlobalVariables.getPrematureParameters().getAllParsArrayView());
}
}