use of com.revolsys.swing.map.layer.record.table.model.RecordLayerErrors in project com.revolsys.open by revolsys.
the class AbstractUpdateField method finish.
private void finish() {
if (this.recordCount > 100) {
final int confirm = JOptionPane.showConfirmDialog(this, "<html>Update <b style='color:#32CD32'>" + this.recordCountString + "</b> records? This may take a long time or fail if there are many records.</html>", "Update Records?", JOptionPane.OK_CANCEL_OPTION);
if (confirm != JOptionPane.OK_OPTION) {
setVisible(false);
return;
}
}
final ProgressMonitor progressMonitor = new ProgressMonitor(this, getProgressMonitorTitle(), "Updated 0 of " + this.recordCountString, 0, 100);
progressMonitor.setProgress(0);
setVisible(false);
final AtomicInteger progress = new AtomicInteger();
final SwingWorker<?, ?> task = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
final Set<String> fieldNames = new LinkedHashSet<>();
fieldNames.add(AbstractUpdateField.this.fieldDefinition.getName());
fieldNames.addAll(AbstractUpdateField.this.layer.getFieldNames());
final RecordLayerErrors errors = new RecordLayerErrors("Setting Field Values", AbstractUpdateField.this.layer, fieldNames);
AbstractUpdateField.this.tableModel.forEachRecord((record) -> {
if (progressMonitor.isCanceled()) {
throw new CancellationException();
} else {
try {
updateRecord(record);
} catch (final WrappedException e) {
errors.addRecord(record, e.getCause());
} catch (final Throwable e) {
errors.addRecord(record, e);
}
final int updateCount = progress.incrementAndGet();
if (updateCount < AbstractUpdateField.this.recordCount) {
final int updatePercent = (int) Math.floor(updateCount * 100 / (double) AbstractUpdateField.this.recordCount);
if (updatePercent < 100) {
setProgress(updatePercent);
}
}
}
});
setProgress(100);
if (!isCancelled()) {
errors.showErrorDialog();
}
return null;
}
@Override
protected void done() {
}
};
task.addPropertyChangeListener((event) -> {
if ("progress" == event.getPropertyName()) {
final int percent = (Integer) event.getNewValue();
progressMonitor.setProgress(percent);
progressMonitor.setNote("Updated " + progress + " of " + this.recordCountString);
}
});
Invoke.worker(task);
}
use of com.revolsys.swing.map.layer.record.table.model.RecordLayerErrors in project com.revolsys.open by revolsys.
the class AbstractRecordLayer method saveChanges.
public final boolean saveChanges(final LayerRecord record) {
// Includes two types of validation of record. The first checks field
// types before interacting with the record store. The second is any
// errors on the actual saving of data.
final Set<Boolean> allSaved = new HashSet<>();
//
RecordValidationDialog.validateRecords(//
"Save Changes", //
this, record, (validator) -> {
// Success
// Save the valid records
final List<LayerRecord> validRecords = validator.getValidRecords();
if (!validRecords.isEmpty()) {
final RecordLayerErrors errors = new RecordLayerErrors("Saving Changes", this);
try (BaseCloseable eventsEnabled = eventsDisabled()) {
synchronized (this.getSync()) {
try {
final boolean saved = internalSaveChanges(errors, record);
if (!saved) {
errors.addRecord(record, "Unknown error");
}
} catch (final Throwable t) {
errors.addRecord(record, t);
}
}
cleanCachedRecords();
record.fireRecordUpdated();
} finally {
if (!errors.showErrorDialog()) {
allSaved.add(false);
}
}
}
final List<LayerRecord> invalidRecords = validator.getInvalidRecords();
if (!invalidRecords.isEmpty()) {
allSaved.add(false);
}
}, (validator) -> {
allSaved.add(false);
});
return allSaved.isEmpty();
}
use of com.revolsys.swing.map.layer.record.table.model.RecordLayerErrors in project com.revolsys.open by revolsys.
the class AbstractRecordLayer method saveChanges.
public final boolean saveChanges(final Collection<? extends LayerRecord> records) {
try {
if (records.isEmpty()) {
return true;
} else {
// Includes two types of validation of record. The first checks field
// types before interacting with the record store. The second is any
// errors on the actual saving of data.
final Set<Boolean> allSaved = new HashSet<>();
//
RecordValidationDialog.validateRecords(//
"Save Changes", //
this, records, (validator) -> {
// Success
// Save the valid records
final List<LayerRecord> validRecords = validator.getValidRecords();
if (!validRecords.isEmpty()) {
final RecordLayerErrors errors = new RecordLayerErrors("Saving Changes", this);
try (BaseCloseable eventsEnabled = eventsDisabled()) {
for (final LayerRecord record : validRecords) {
synchronized (this.getSync()) {
try {
final boolean saved = internalSaveChanges(errors, record);
if (!saved) {
errors.addRecord(record, "Unknown error");
}
} catch (final Throwable t) {
errors.addRecord(record, t);
}
}
}
cleanCachedRecords();
} finally {
if (!errors.showErrorDialog()) {
allSaved.add(false);
}
}
fireRecordsChanged();
}
final List<LayerRecord> invalidRecords = validator.getInvalidRecords();
if (!invalidRecords.isEmpty()) {
allSaved.add(false);
}
}, (validator) -> {
allSaved.add(false);
});
return allSaved.isEmpty();
}
} finally {
fireSelected();
fireHasChangedRecords();
}
}
Aggregations