private static int progressLabelWidth = 72;
private void dropIsolatedSamples(final ContextSampleSelection ips, final Object[] destRowObjects) {
final Object progressOwner = new Object();
final Thread mt = new ZDBModifyThread("D&D: Transfer IsolatedSamples") {
public void run() {
final Zoeos z = Zoeos.getInstance();
z.beginProgressElement(progressOwner, ZUtilities.makeExactLengthString("Copying Samples", progressLabelWidth), destRowObjects.length * 2);
int errors = 0;
try {
final int j = destRowObjects.length;
for (int i = j - 1; i >= 0; i--) {
final int f_i = i;
final Object sobj = destRowObjects[i];
if (sobj instanceof ContextEditableSample) {
IsolatedSample is = null;
try {
if (i == 0)
is = ips.getIsolatedSample(i);
else
is = ips.getIsolatedSample(i);
is.doAssert();
} catch (IsolatedSampleUnavailableException e) {
e.printStackTrace();
} finally {
z.updateProgressElement(progressOwner);
if (is == null) {
z.updateProgressElement(progressOwner);
if (i >= j - 1)
z.endProgressElement(progressOwner);
errors++;
continue;
}
}
final IsolatedSample f_is = is;
// new ZDBModifyThread("D&D: New Samples from IsolatedSamples") {
// public void run() {
// TODO!! should use a signal here to achieve correct ordering of threads
try {
z.setProgressElementIndeterminate(progressOwner, true);
z.updateProgressElementTitle(progressOwner, "Copying " + f_is.getName() + " to " + ((ContextEditableSample) sobj).getSampleDisplayName());
((ContextEditableSample) sobj).newSample(f_is, f_is.getName());
f_is.zDispose();
} catch (NoSuchSampleException e) {
JOptionPane.showMessageDialog(ZoeosFrame.getInstance(), e.getMessage(), "Problem", JOptionPane.ERROR_MESSAGE);
errors++;
continue;
} catch (IsolatedSampleUnavailableException e) {
JOptionPane.showMessageDialog(ZoeosFrame.getInstance(), e.getMessage(), "Problem", JOptionPane.ERROR_MESSAGE);
errors++;
continue;
} finally {
z.setProgressElementIndeterminate(progressOwner, false);
z.updateProgressElement(progressOwner);
if (f_i >= j - 1)
z.endProgressElement(progressOwner);
}
// }
// }.stateStart();
} 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 samples could be copied" : "The source sample could not be copied"), "Problem", JOptionPane.ERROR_MESSAGE);
else if (errors > 0)
JOptionPane.showMessageDialog(ZoeosFrame.getInstance(), errors + " of " + destRowObjects.length + " source samples could not be copied", "Problem", JOptionPane.ERROR_MESSAGE);
}
}
};
mt.start();
}