Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'systemtap/org.eclipse.linuxtools.systemtap.ui.structures/src/org/eclipse/linuxtools/systemtap/ui/structures/UpdateManager.java')
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.structures/src/org/eclipse/linuxtools/systemtap/ui/structures/UpdateManager.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.structures/src/org/eclipse/linuxtools/systemtap/ui/structures/UpdateManager.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.structures/src/org/eclipse/linuxtools/systemtap/ui/structures/UpdateManager.java
new file mode 100644
index 0000000000..f9adbb5a1a
--- /dev/null
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.structures/src/org/eclipse/linuxtools/systemtap/ui/structures/UpdateManager.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.systemtap.ui.structures;
+
+import java.util.ArrayList;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.eclipse.linuxtools.systemtap.ui.structures.listeners.IUpdateListener;
+
+
+
+public class UpdateManager {
+ public UpdateManager(int delay) {
+ updateListeners = new ArrayList<IUpdateListener>();
+ stopped = false;
+ disposed = false;
+ timer = new Timer("Update Manager", true);
+ timer.scheduleAtFixedRate(new Notify(), delay, delay);
+ }
+
+ /**
+ * Terminates the timer and removes all update listeners.
+ */
+ public void stop() {
+ if(!stopped) {
+ stopped = true;
+ timer.cancel();
+ for(int i=0; i<updateListeners.size(); i++)
+ removeUpdateListener((IUpdateListener)updateListeners.get(i));
+ }
+ }
+
+ public void addUpdateListener(IUpdateListener l) {
+ if(!updateListeners.contains(l))
+ updateListeners.add(l);
+ }
+ public void removeUpdateListener(IUpdateListener l) {
+ if(updateListeners.contains(l))
+ updateListeners.remove(l);
+ }
+
+ public boolean isRunning() {
+ return !stopped;
+ }
+
+ public void dispose() {
+ if(!disposed) {
+ disposed = true;
+ stop();
+ timer = null;
+ updateListeners = null;
+ }
+ }
+
+ /**
+ * Handle any events that are timed to occur.
+ */
+ private class Notify extends TimerTask {
+ public void run() {
+ try{
+ if(!stopped) {
+ for(int i = 0; i < updateListeners.size(); i++)
+ ((IUpdateListener)(updateListeners.get(i))).handleUpdateEvent();
+ }
+ }catch(Exception e) {;}
+ }
+
+ }
+
+ private Timer timer;
+ private ArrayList<IUpdateListener> updateListeners;
+ private boolean stopped;
+ private boolean disposed;
+}

Back to the top