~ubuntu-branches/ubuntu/utopic/eclipse-linuxtools/utopic

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.structures/src/org/eclipse/linuxtools/systemtap/ui/structures/UpdateManager.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2014-05-12 18:11:40 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140512181140-w237r3vsah1tmybz
Tags: 2.2.1-1
* New upstream release.
* Refreshed d/patches.
* Removed eclipse-cdt-valgrind-remote package, all its functionality
  is now provided by eclipse-cdt-profiling-framework-remote.
* Added remove-license-feature.patch.
* Bump Standards-Version to 3.9.5.
* Enable eclipse-changelog package.
* Enable eclipse-rpm-editor package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2006 IBM Corporation.
3
 
 * All rights reserved. This program and the accompanying materials
4
 
 * are made available under the terms of the Eclipse Public License v1.0
5
 
 * which accompanies this distribution, and is available at
6
 
 * http://www.eclipse.org/legal/epl-v10.html
7
 
 *
8
 
 * Contributors:
9
 
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
10
 
 *******************************************************************************/
11
 
 
12
 
package org.eclipse.linuxtools.systemtap.ui.structures;
13
 
 
14
 
import java.util.ArrayList;
15
 
import java.util.Timer;
16
 
import java.util.TimerTask;
17
 
 
18
 
import org.eclipse.linuxtools.systemtap.ui.structures.listeners.IUpdateListener;
19
 
 
20
 
 
21
 
 
22
 
public class UpdateManager {
23
 
        public UpdateManager(int delay) {
24
 
                updateListeners = new ArrayList<IUpdateListener>();
25
 
                stopped = false;
26
 
                disposed = false;
27
 
                timer = new Timer("Update Manager", true);
28
 
                timer.scheduleAtFixedRate(new Notify(), delay, delay);
29
 
        }
30
 
        
31
 
        /**
32
 
         * Terminates the timer and removes all update listeners.
33
 
         */
34
 
        public void stop() {
35
 
                if(!stopped) {
36
 
                        stopped = true;
37
 
                        timer.cancel();
38
 
                        for(int i=0; i<updateListeners.size(); i++)
39
 
                                removeUpdateListener(updateListeners.get(i));
40
 
                }
41
 
        }
42
 
        
43
 
        public void addUpdateListener(IUpdateListener l) {
44
 
                if(!updateListeners.contains(l))
45
 
                        updateListeners.add(l);
46
 
        }
47
 
        public void removeUpdateListener(IUpdateListener l) {
48
 
                if(updateListeners.contains(l))
49
 
                        updateListeners.remove(l);
50
 
        }
51
 
        
52
 
        public boolean isRunning() {
53
 
                return !stopped;
54
 
        }
55
 
        
56
 
        public void dispose() {
57
 
                if(!disposed) {
58
 
                        disposed = true;
59
 
                        stop();
60
 
                        timer = null;
61
 
                        updateListeners = null;
62
 
                }
63
 
        }
64
 
        
65
 
        /**
66
 
         * Handle any events that are timed to occur.
67
 
         */
68
 
        private class Notify extends TimerTask {
69
 
                @Override
70
 
                public void run() {
71
 
                        try{
72
 
                        if(!stopped) {
73
 
                                for(int i = 0; i < updateListeners.size(); i++)
74
 
                                        (updateListeners.get(i)).handleUpdateEvent();
75
 
                        }
76
 
                        }catch(Exception e) {}
77
 
                }
78
 
                        
79
 
        }
80
 
        
81
 
        private Timer timer;
82
 
        private ArrayList<IUpdateListener> updateListeners;
83
 
        private boolean stopped;
84
 
        private boolean disposed;
85
 
}