Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Parent class
- /**
- * Initialize background services.
- */
- private void initServices() {
- this.dtModel = (DefaultTableModel) tblHistory.getModel(); // Default data model of the jTable
- this.updateTimer = new Timer(1000, new ActionListener() { // I don't know if this is right, I use Timer to loop the Swingworker
- @Override
- public void actionPerformed(ActionEvent e) {
- new CallHistoryWatcherService(CallHistory.this, updateTimer, dtModel).execute();
- }
- });
- updateTimer.setRepeats(false);
- updateTimer.start();
- }
- // Watcher class
- /**
- * Watch the CallInformations if any update has been made.
- * This will check every seconds.
- * @param history
- * @param updateTimer
- * @param dtModel
- */
- public CallHistoryWatcherService(CallHistory history, javax.swing.Timer updateTimer, DefaultTableModel dtModel) {
- // Initialize values
- }
- @Override
- protected Collection<Vector> doInBackground() throws Exception {
- Collection<Vector> chunks = new ArrayList<>();
- for (CallInformations info : CallInformations.getCallInformations(OrderBy.Ascending)) {
- Vector v = new Vector();
- // Get from data from Database then place it to Vector
- chunks.add(v);
- }
- return chunks;
- }
- @Override
- protected void done() {
- try {
- history.updateTableData(get()); // From parent class, manually update the data based on new Collection of data
- System.out.println("Call History refreshed...");
- } catch (ExecutionException | InterruptedException e) {
- e.printStackTrace();
- }
- COLUMN_NAMES.clear();
- updateTimer.restart(); // Again, I don't know if this is right, restart the timer to execute the SwingWorker
- }
Advertisement
Add Comment
Please, Sign In to add comment