Utilizzare il codice seguente ed assegnare l'Action al pulsante "Refresh":
@Action
public Task refresh() {
return new RefreshTask(MyApp.getApplication());
}
private class RefreshTask extends Task {
RefreshTask(org.jdesktop.application.Application app) {
super(app);
}
@SuppressWarnings("unchecked")
@Override
protected Void doInBackground() {
setProgress(0, 0, 4);
setMessage("Rolling back the current changes...");
setProgress(1, 0, 4);
entityManager.getTransaction().rollback();
setProgress(2, 0, 4);
setMessage("Starting a new transaction...");
entityManager.getTransaction().begin();
setProgress(3, 0, 4);
setMessage("Fetching new data...");
java.util.Collection data = query.getResultList();
for (Object entity : data) {
entityManager.refresh(entity);
}
setProgress(4, 0, 4);
*masterTable.setVisible(false);
list.clear();
list.addAll(data);
return null;
}
@Override
protected void finished() {
setMessage("Done.");
setSaveNeeded(false);
masterTable.setVisible(true);
masterTable.revalidate();
masterTable.repaint();
}
}
Nessun commento:
Posta un commento