From 2eaaa3685614be85066f173067bdeeaca240637a Mon Sep 17 00:00:00 2001 From: Max Schenkelberg Date: Mon, 24 Sep 2012 14:42:32 -0500 Subject: [PATCH] Issue #1214 Made VizGlobalsManager check for null window before calling getPage() since getInstance() still returns succesfully when null window is passed in. Change TimeMatchingJob to be shutdown when core plugin stops and cancels existing jobs. Amend: Removed println Change-Id: I3559b13074eb025e9bf931685cda3e804037baff Former-commit-id: 8a9ba0178b5c87b7bd33568b9a2feae10554ecc3 [formerly 51e565c6ff9f2d55a1e2962ee79f5b0df17fe815] [formerly 4b2467e6396db89a673e95b2705cbbd1b395d227] [formerly edfd7fd22ff3391c0587df24a05463b799c90133 [formerly 4b2467e6396db89a673e95b2705cbbd1b395d227 [formerly fc617c1392d9585d2e91e371af74aad4b24acfbb]]] Former-commit-id: edfd7fd22ff3391c0587df24a05463b799c90133 Former-commit-id: 6c26ac1dfaab3d2a090ad759e28fbd78f175087c [formerly 63c30eafc23e06a8fc2f6fbeeb3cdca65e37a9cd] Former-commit-id: f0376e02409a1cbe66d6ac8a69afe11e9f63841f --- .../viz/core/globals/VizGlobalsManager.java | 9 +++- .../uf/viz/core/time/TimeMatchingJob.java | 48 ++++++++++++++----- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/globals/VizGlobalsManager.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/globals/VizGlobalsManager.java index 7f1b0f1be6..9b15e56bc6 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/globals/VizGlobalsManager.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/globals/VizGlobalsManager.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; @@ -163,8 +164,12 @@ public class VizGlobalsManager { */ public void updateUI(IDisplayPaneContainer editor, IRenderableDisplay display) { - if (window.getActivePage().getActiveEditor() != editor) { - return; + if (window != null) { + // Check the active editor on the window + IWorkbenchPage page = window.getActivePage(); + if (page != null && page.getActiveEditor() != editor) { + return; + } } if (editor != null && display != null) { Map globals = display.getGlobalsMap(); diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/time/TimeMatchingJob.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/time/TimeMatchingJob.java index 82c3a7594f..fec658cd9b 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/time/TimeMatchingJob.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/time/TimeMatchingJob.java @@ -27,6 +27,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.services.IDisposable; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; @@ -57,6 +58,17 @@ public class TimeMatchingJob extends Job { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(TimeMatchingJob.class); + static { + Activator.getDefault().registerDisposable(new IDisposable() { + @Override + public void dispose() { + shutdown(); + } + }); + } + + private static boolean running = true; + private static Map map = new ConcurrentHashMap(); private IDescriptor request; @@ -68,20 +80,35 @@ public class TimeMatchingJob extends Job { this.request = desc; } - public static synchronized void scheduleTimeMatch(IDescriptor desc) { - if (desc != null && desc.getTimeMatcher() != null) { - TimeMatchingJob job = map.get(desc); - if (job == null) { - job = new TimeMatchingJob(desc); - job.setSystem(true); - } else { - job.keepAround = true; + public static void scheduleTimeMatch(IDescriptor desc) { + synchronized (TimeMatchingJob.class) { + if (running == false) { + return; + } + if (desc != null && desc.getTimeMatcher() != null) { + TimeMatchingJob job = map.get(desc); + if (job == null) { + job = new TimeMatchingJob(desc); + job.setSystem(true); + } else { + job.keepAround = true; + } + map.put(desc, job); + job.schedule(); } - map.put(desc, job); - job.schedule(); } } + private static void shutdown() { + synchronized (TimeMatchingJob.class) { + running = false; + } + for (TimeMatchingJob job : map.values()) { + job.cancel(); + } + map.clear(); + } + /* * (non-Javadoc) * @@ -111,7 +138,6 @@ public class TimeMatchingJob extends Job { } }); } - } catch (Throwable e) { statusHandler.handle(Priority.CRITICAL, "Error redoing time matching", e);