private static int progressLabelWidth = 72;
private void dropIsolatedPresets(final ContextPresetSelection ips, final Object[] destRowObjects) {
final Object progressOwner = new Object();
final Thread mt = new ZDBModifyThread("D&D: Transfer IsolatedPresets") {
public void run() {
final Zoeos z = Zoeos.getInstance();
z.beginProgressElement(progressOwner, ZUtilities.makeExactLengthString("Copying Presets", progressLabelWidth), destRowObjects.length * 2);
int errors = 0;
try {
final int j = destRowObjects.length;
for (int i = 0; i < j; i++) {
final int f_i = i;
final Object pobj = destRowObjects[i];
if (pobj instanceof ContextEditablePreset) {
final IsolatedPreset ip = ips.getIsolatedPreset(i);
z.updateProgressElement(progressOwner);
if (ip == null) {
z.updateProgressElement(progressOwner);
if (i >= j - 1)
z.endProgressElement(progressOwner);
errors++;
continue;
}
new ZDBModifyThread("D&D: New Presets from IsolatedPresets") {
public void run() {
// TODO!! should use a signal here to achieve correct ordering of threads
try {
z.updateProgressElementTitle(progressOwner, "Copying " + ip.getName() + " to " + ((ContextEditablePreset) pobj).getPresetDisplayName());
((ContextEditablePreset) pobj).newPreset(((ContextEditablePreset) pobj).getPresetNumber(), ip.getName(), ip);
} catch (NoSuchPresetException e) {
e.printStackTrace();
} finally {
z.updateProgressElement(progressOwner);
if (f_i >= j - 1)
z.endProgressElement(progressOwner);
}
}
}.start();
} else {
z.updateProgressElement(progressOwner);
z.updateProgressElement(progressOwner);
if (i >= j - 1)
z.endProgressElement(progressOwner);
errors++;
}
}
} finally {
if (errors == destRowObjects.length)
JOptionPane.showMessageDialog(ZoeosFrame.getInstance(), (destRowObjects.length > 1 ? "None of the source presets could be copied" : "The source preset could not be copied"), "Problem", JOptionPane.ERROR_MESSAGE);
else if (errors > 0)
JOptionPane.showMessageDialog(ZoeosFrame.getInstance(), errors + " of " + destRowObjects.length + " source presets could not be copied", "Problem", JOptionPane.ERROR_MESSAGE);
}
}
};
mt.start();
}