} 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).";