diff --git a/cave/build/static/common/cave/etc/gfe/utility/PngWriter.py b/cave/build/static/common/cave/etc/gfe/utility/PngWriter.py index 634c5d68ae..09ec1ae8aa 100644 --- a/cave/build/static/common/cave/etc/gfe/utility/PngWriter.py +++ b/cave/build/static/common/cave/etc/gfe/utility/PngWriter.py @@ -42,7 +42,6 @@ from com.raytheon.viz.gfe.core.parm import ParmDisplayAttributes_VisMode as VisM class PngWriter: def __init__(self, conf="testIFPImage", userName="", baseTime=None, timeRange=None, usrTimeRange=None): - from com.raytheon.viz.gfe.core import DataManager from com.raytheon.uf.viz.core.localization import LocalizationManager self.site = LocalizationManager.getInstance().getCurrentSite() @@ -54,7 +53,9 @@ class PngWriter: self.baseTime = baseTime - self.dm = DataManager.getInstance(None) + # Create GFEPainter first and get DataManager from painter + self.viz = self.createPainter() + self.dm = self.viz.getDataManager(); LogStream.logEvent("Configuration File: ", conf) @@ -222,27 +223,36 @@ class PngWriter: else: return default - def paint(self, dir): - #mmgr = self.dm.mapMgr() - mv = [] - mids = [] + def createPainter(self): + # Extract properties needed to construct painter height = self.getConfig('Png_height', None, int) width = self.getConfig('Png_width', None, int) - localFlag = self.getConfig('Png_localTime', 0, int) - snapshotTime = self.getConfig('Png_snapshotTime', 0, int) - useLegend = self.getConfig('Png_legend', 1, int) - maps = self.getConfig('MapBackgrounds_default', []) leftExpand = self.getConfig('OfficeDomain_expandLeft', 10, int) rightExpand = self.getConfig('OfficeDomain_expandRight', 10, int) topExpand = self.getConfig('OfficeDomain_expandTop', 10, int) bottomExpand = self.getConfig('OfficeDomain_expandBottom', 10, int) + mask = self.getConfig(self.site + '_mask', None) + wholeDomain = self.getConfig('Png_wholeDomain', 0, int) + + #TODO handle transparent background + bgColor, trans = self.getBG() + + return GFEPainter.GFEPainter(width, height, leftExpand, rightExpand, topExpand, bottomExpand, mask, wholeDomain, bgColor) + + def paint(self, dir): + #mmgr = self.dm.mapMgr() + mv = [] + mids = [] + localFlag = self.getConfig('Png_localTime', 0, int) + snapshotTime = self.getConfig('Png_snapshotTime', 0, int) + useLegend = self.getConfig('Png_legend', 1, int) + maps = self.getConfig('MapBackgrounds_default', []) fitToDataArea = self.getConfig('Png_fitToDataArea', None) omitColorbar = self.getConfig('Png_omitColorBar', 0, int) showLogo = self.getConfig('Png_logo', None) logoString = self.getConfig('Png_logoString', None) smooth = self.getConfig('Png_smoothImage', 0, int) fexten = self.getFileType() - mask = self.getConfig(self.site + '_mask', None) # get the fit to data edit area, and set the active edit area if fitToDataArea is not None: @@ -255,12 +265,8 @@ class PngWriter: self.dm.getRefManager().setActiveRefSet(refdata) maskBasedOnHistory = self.getConfig('Png_historyMask', 0, int) - wholeDomain = self.getConfig('Png_wholeDomain', 0, int) - #TODO handle transparent background - bgColor, trans = self.getBG() - - viz = GFEPainter.GFEPainter(width, height, leftExpand, rightExpand, topExpand, bottomExpand, mask, wholeDomain, bgColor) + viz = self.viz if not omitColorbar: viz.enableColorbar() @@ -270,39 +276,18 @@ class PngWriter: # allow user to specify precise interval for creation of images # rather than the automatically generated set paintInterval = self.getConfig('Png_interval', None, int) - if paintInterval is None: - parmList = ArrayList(); - for p in prms: - parmList.add(p) - jtimes = self.dm.getParmManager().calcStepTimes(parmList, - self.dm.getParmManager().getSystemTimeRange()) - times = [] - for i in xrange(jtimes.size()): - times.append(AbsTime.AbsTime(jtimes.get(i))) - else: + if paintInterval is not None: + # Interval specified, create interval time matcher paintIntervalOffset = self.getConfig('Png_intervalOffset', 0, int) if paintInterval < 0: paintInterval = 1 if paintInterval > 24: paintInterval = 24 - paintInterval = paintInterval * 3600 # into seconds - paintIntervalOffset = paintIntervalOffset * 3600 - systemTime = TimeRange.TimeRange(self.dm.getParmManager().getSystemTimeRange()) - firstTime = systemTime.startTime() - lastTime = systemTime.endTime() - times = [] - unixT = firstTime.unixTime() - t = int(int(unixT)/int(paintInterval))*paintInterval\ - + paintIntervalOffset - t = AbsTime.AbsTime(t) - while t <= lastTime: - if t >= firstTime: - times.append(t) - t = t + paintInterval - - if len(times) == 0: - LogStream.logEvent("No grids to generate") - + from com.raytheon.viz.gfe.core import GFEIntervalTimeMatcher + tm = GFEIntervalTimeMatcher() + tm.setTimeMatchingInterval(paintInterval, paintIntervalOffset, self.dm.getParmManager().getSystemTimeRange()) + viz.getDescriptor().setTimeMatcher(tm) + if useLegend: snapshotTime = self.getConfig('Png_snapshotTime', 1, int) descName = self.getConfig('Png_descriptiveWeName', 'SHORT') @@ -369,14 +354,18 @@ class PngWriter: self.initSamples() + # Verify all resources are time matched before painting + desc = viz.getDescriptor() + desc.redoTimeMatching() + times = desc.getFramesInfo().getFrameTimes() + # paint once to get map retrieval started if len(times) > 0: viz.paint(times[0]) - for t in times: - paintTime = t - if paintTime and self.overlapsWithGrids(prms, paintTime): - self.dm.getSpatialDisplayManager().setSpatialEditorTime(paintTime.javaDate()) + for frame in times: + paintTime = AbsTime.AbsTime(frame.getRefTime()) + if self.overlapsWithGrids(prms, paintTime.javaDate()): visualInfo = [] for p in prms: griddata = p.overlappingGrid(paintTime.javaDate()) @@ -401,12 +390,12 @@ class PngWriter: RGBColors.getColorName(p.getDisplayAttributes().getBaseColor()), p.getDisplayAttributes().getVisMode().toString() == 'Image') visualInfo.append(info) - viz.paint(paintTime) - fname = self.getFileName(dir, t) + '.' + fexten + viz.paint(frame) + fname = self.getFileName(dir, paintTime) + '.' + fexten viz.outputFiles(fname, showLogo, logoString) self.writeInfo(dir, paintTime, visualInfo) else: - LogStream.logEvent("No grids to generate for ", `t`) + LogStream.logEvent("No grids to generate for ", `paintTime`) visuals = None mv = None @@ -415,20 +404,13 @@ class PngWriter: # return true if there is grid data that overlaps with time t def overlapsWithGrids(self, prms, t): - totalTR = None for p in prms: - grid = p.overlappingGrid(t.javaDate()) + grid = p.overlappingGrid(t) if grid is not None: gridTime = TimeRange.TimeRange(grid.getGridTime()) - if totalTR is None: - totalTR = gridTime - else: - totalTR.combineWith(gridTime) - if totalTR is not None and totalTR.contains(t) and \ - self.pngTimeRange.overlaps(totalTR): - return 1 - else: - return 0 + if self.pngTimeRange.overlaps(gridTime): + return 1 + return 0 def usage(): msg = """ diff --git a/cave/build/static/common/cave/etc/pyViz/GFEPainter.py b/cave/build/static/common/cave/etc/pyViz/GFEPainter.py index 8389f62ea1..3a702fd554 100644 --- a/cave/build/static/common/cave/etc/pyViz/GFEPainter.py +++ b/cave/build/static/common/cave/etc/pyViz/GFEPainter.py @@ -23,7 +23,7 @@ from com.raytheon.uf.viz.core.map import MapDescriptor from com.raytheon.uf.viz.core.rsc.capabilities import ColorableCapability,\ OutlineCapability, LabelableCapability, MagnificationCapability, ColorMapCapability from com.raytheon.viz.core import ColorUtil -from com.raytheon.viz.gfe.core import DataManager, GFEMapRenderableDisplay +from com.raytheon.viz.gfe.core import DataManagerOffscreenFactory, GFEMapRenderableDisplay from com.raytheon.viz.gfe.ifpimage import GfeImageUtil, ImageLegendResource from com.raytheon.viz.gfe.rsc import GFEResource, GFESystemResource from com.raytheon.viz.gfe.core.parm import ParmDisplayAttributes_EditorType as EditorType @@ -56,7 +56,9 @@ import VizPainter class GFEPainter(VizPainter.VizPainter): def __init__(self, imageWidth=None, imageHeight=None, expandLeft=25.0, expandRight=25.0, expandTop=25.0, expandBottom=25.0, mask=None, wholeDomain=0, bgColor=None): - self.dataMgr = DataManager.getInstance(None) + # Create empty display and data manager for display + display = GFEMapRenderableDisplay() + self.dataMgr = DataManagerOffscreenFactory.getInstance(display) self.refId = None envelope = None gloc = self.dataMgr.getParmManager().compositeGridLocation() @@ -70,10 +72,10 @@ class GFEPainter(VizPainter.VizPainter): if imageHeight is not None: imageHeight = Integer(int(imageHeight)) geom = GfeImageUtil.getLocationGeometry(gloc, envelope, imageWidth, imageHeight, expandLeft / 100.0, expandRight / 100.0, expandTop / 100.0, expandBottom / 100.0) - display = GFEMapRenderableDisplay(MapDescriptor(geom)) - display.setDataManager(self.dataMgr) - desc = display.getDescriptor() - self.dataMgr.getSpatialDisplayManager().setDescriptor(desc) + + # Create descriptor for display + desc = MapDescriptor(geom) + display.setDescriptor(desc) VizPainter.VizPainter.__init__(self, display, backgroundColor=bgColor) gfeSystem = GFESystemResource(self.dataMgr) @@ -201,6 +203,3 @@ class GFEPainter(VizPainter.VizPainter): self.outputImage(finalBuf, filename) else: self.outputImage(rendered, filename) - - def _changeTime(self, time): - pass diff --git a/cave/com.raytheon.viz.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject b/cave/com.raytheon.viz.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject index 9bdfe2ec83..c92a40e573 100644 --- a/cave/com.raytheon.viz.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject +++ b/cave/com.raytheon.viz.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject @@ -1,4 +1,6 @@ com.raytheon.viz.gfe.core.GFEMapRenderableDisplay +com.raytheon.viz.gfe.core.GFETimeMatcher +com.raytheon.viz.gfe.core.GFEIntervalTimeMatcher com.raytheon.viz.gfe.rsc.GFELegendResourceData com.raytheon.viz.gfe.rsc.GFEResourceData com.raytheon.uf.common.site.xml.AdjacentWfoXML diff --git a/cave/com.raytheon.viz.gfe/plugin.xml b/cave/com.raytheon.viz.gfe/plugin.xml index 9ba667331d..171e37d05f 100644 --- a/cave/com.raytheon.viz.gfe/plugin.xml +++ b/cave/com.raytheon.viz.gfe/plugin.xml @@ -605,13 +605,6 @@ - - - - - - diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/GridManagerView.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/GridManagerView.java index eadc85eb1e..1b08f40d78 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/GridManagerView.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/GridManagerView.java @@ -33,6 +33,7 @@ import org.eclipse.ui.part.ViewPart; import com.raytheon.uf.viz.core.RGBColors; import com.raytheon.viz.gfe.core.DataManager; +import com.raytheon.viz.gfe.core.DataManagerUIFactory; import com.raytheon.viz.gfe.core.parm.Parm; import com.raytheon.viz.gfe.dialogs.KillJobsOnExitDialog; import com.raytheon.viz.gfe.dialogs.SaveParameterDialog; @@ -91,7 +92,7 @@ public class GridManagerView extends ViewPart implements ISaveablePart2 { window = this.getSite().getWorkbenchWindow(); view = parent; - dataManager = DataManager.getInstance(window); + dataManager = DataManagerUIFactory.getInstance(window); if (dataManager == null) { return; } @@ -107,7 +108,6 @@ public class GridManagerView extends ViewPart implements ISaveablePart2 { .setColor(BGColorMode.EDITOR, RGBColors.getRGBColor(colorName)); // Causes the GridManger to redraw on initialization. - DataManager.fireChangeListener(); refresh(); } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/actions/ShowAutoSaveIntervalDialog.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/actions/ShowAutoSaveIntervalDialog.java index 994663a5a9..49746c9c93 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/actions/ShowAutoSaveIntervalDialog.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/actions/ShowAutoSaveIntervalDialog.java @@ -25,9 +25,11 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import com.raytheon.viz.gfe.core.DataManager; +import com.raytheon.viz.gfe.core.DataManagerUIFactory; import com.raytheon.viz.gfe.dialogs.AutoSaveIntervalDialog; import com.raytheon.viz.gfe.jobs.AutoSaveJob; import com.raytheon.viz.ui.dialogs.ICloseCallback; @@ -69,8 +71,9 @@ public class ShowAutoSaveIntervalDialog extends AbstractHandler { public Object execute(ExecutionEvent arg0) throws ExecutionException { if (dialog == null || dialog.getShell() == null || dialog.isDisposed()) { - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() - .getShell(); + final IWorkbenchWindow window = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow(); + Shell shell = window.getShell(); int interval = AutoSaveJob.getInterval(); boolean autoSaveEnabled = interval > 0; @@ -87,14 +90,22 @@ public class ShowAutoSaveIntervalDialog extends AbstractHandler { if (returnValue instanceof Integer) { int returnCode = (Integer) returnValue; if (returnCode == Window.OK) { + DataManager dm = DataManagerUIFactory + .findInstance(window); // update if (dialog.isAutoSaveEnabled()) { int interval = dialog.getCurrentInterval(); AutoSaveJob.setInterval(interval); - DataManager.enableAutoSave(); + if (dm != null) { + dm.enableAutoSave(); + } + DataManagerUIFactory.findInstance(window) + .enableAutoSave(); } else { AutoSaveJob.setInterval(0); - DataManager.disableAutoSave(); + if (dm != null) { + dm.disableAutoSave(); + } } } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManager.java index 43028b5d9d..f004158788 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManager.java @@ -25,20 +25,14 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import jep.JepException; -import org.apache.commons.lang.Validate; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.ui.IWindowListener; import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ICommandService; import com.raytheon.uf.common.activetable.ActiveTableRecord; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; @@ -62,15 +56,12 @@ import com.raytheon.viz.core.mode.CAVEMode; import com.raytheon.viz.gfe.GFEServerException; import com.raytheon.viz.gfe.core.internal.DataMgrInitStatus; import com.raytheon.viz.gfe.core.internal.GFEParmCacheInitJob; -import com.raytheon.viz.gfe.core.internal.GFESpatialDisplayManager; import com.raytheon.viz.gfe.core.internal.GFETopoManager; import com.raytheon.viz.gfe.core.internal.IFPClient; import com.raytheon.viz.gfe.core.internal.NotificationRouter; -import com.raytheon.viz.gfe.core.internal.OffscreenSpatialDisplayManager; import com.raytheon.viz.gfe.core.internal.ParmManager; import com.raytheon.viz.gfe.core.internal.ReferenceSetManager; import com.raytheon.viz.gfe.core.internal.WEGroupManager; -import com.raytheon.viz.gfe.core.msgs.ICurrentDataManagerChangedListener; import com.raytheon.viz.gfe.core.msgs.ISCSendStatusChangedMsg; import com.raytheon.viz.gfe.core.parm.ParmOp; import com.raytheon.viz.gfe.gridmanager.IGridManager; @@ -83,7 +74,6 @@ import com.raytheon.viz.gfe.smarttool.EditActionProcessor; import com.raytheon.viz.gfe.smarttool.GridCycler; import com.raytheon.viz.gfe.smarttool.script.SmartToolFactory; import com.raytheon.viz.gfe.smarttool.script.SmartToolUIController; -import com.raytheon.viz.ui.VizWorkbenchManager; /** * DataManager is the central singleton in GFE upon which other managers are @@ -108,49 +98,33 @@ import com.raytheon.viz.ui.VizWorkbenchManager; */ public class DataManager { + private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(DataManager.class); - private static class DataManagerKey { - private final IWorkbenchWindow window; - - private DataManagerKey(IWorkbenchWindow window) { - this.window = window; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return (window == null ? 0 : window.hashCode()); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (obj instanceof DataManagerKey) { - IWorkbenchWindow otherWindow = ((DataManagerKey) obj).window; - if (window == null) { - return otherWindow == null; - } - return window.equals(otherWindow); - } - return false; - } + /** + * Use {@link DataManagerUIFactory#getCurrentInstance()} + */ + @Deprecated + public static DataManager getCurrentInstance() { + return DataManagerUIFactory.getCurrentInstance(); } - private static Map instanceMap = new ConcurrentHashMap();; + /** + * Use {@link DataManagerUIFactory#findInstance(IWorkbenchWindow)} + */ + @Deprecated + public static DataManager findInstance(IWorkbenchWindow window) { + return DataManagerUIFactory.findInstance(window); + } - private static Set listeners; - - private static IWindowListener windowListener; + /** + * Use {@link DataManagerUIFactory#getInstance(IWorkbenchWindow)} + */ + @Deprecated + public static DataManager getInstance(IWorkbenchWindow window) { + return DataManagerUIFactory.getInstance(window); + } private final IParmManager parmManager; @@ -212,29 +186,22 @@ public class DataManager { private List allSites; + public IISCDataAccess getIscDataAccess() { + return iscDataAccess; + } + /** - * Not to be instantiated directly. + * Constructs a DataManager, passes in factory for creation of + * {@link ISpatialDisplayManager} for this instance. * - * Use getCurrentInstance() or getInstance(IWorkbenchWindow) instead. - * - * @param window + * @param factory + * @param discriminator * @throws GFEServerException */ - private DataManager(IWorkbenchWindow window) throws GFEServerException { - if (window != null) { - // When window is null, this is assumed to be a JUnit test case or - // the GFEClient - - // This is a separate if statement from below due to ordering issues - // which prevent putting them in the same if block. - - this.spatialDisplayManager = new GFESpatialDisplayManager(window, - this); - } else { - this.spatialDisplayManager = new OffscreenSpatialDisplayManager( - window, this); - } - + DataManager(DataManagerFactory factory, Object discriminator) + throws GFEServerException { + this.spatialDisplayManager = factory.createSpatialDisplayManager(this, + discriminator); this.client = new IFPClient(VizApp.getWsId(), this); this.router = new NotificationRouter(this.getSiteID()); @@ -293,209 +260,26 @@ public class DataManager { new ParmEvictor(); } - public IISCDataAccess getIscDataAccess() { - return iscDataAccess; + /** + * Start auto save jobs + */ + public void enableAutoSave() { + autoSaveJob.cancel(); + autoSaveJob.reSchedule(); } /** - * Default constructor to subclass for test. Intentionally left - * package-private for safety. - * - * @throws GFEServerException + * Stop auto save jobs */ - DataManager() throws GFEServerException { - this(null); + public void disableAutoSave() { + autoSaveJob.cancel(); } /** - * Get the DataManager associated with the currently active workbench - * window. - * - * If no workbench window is active, or the GFE perspective has not been - * activated in the active window, this method will return null. - * - * @return the active DataManager + * Disposes the DataManager object, should only be called through + * {@link DataManagerFactory#dispose(Object)} */ - public static DataManager getCurrentInstance() { - final IWorkbenchWindow[] window = new IWorkbenchWindow[1]; - - window[0] = VizWorkbenchManager.getInstance().getCurrentWindow(); - - if (window[0] == null && PlatformUI.isWorkbenchRunning()) { - VizApp.runSync(new Runnable() { - - @Override - public void run() { - window[0] = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow(); - } - - }); - } - if (window[0] != null) { - return findInstance(window[0]); - } else { - return findInstance(null); - } - } - - /** - * Add a change listener to subscribe to a change of data managers - * - * - * @param listener - * the listener to add - * - */ - public static void addChangeListener( - ICurrentDataManagerChangedListener listener) { - Validate.notNull(listener, "Attempting to add null listener"); - synchronized (DataManager.class) { - if (listeners == null) { - listeners = new HashSet(); - } - } - listeners.add(listener); - } - - /** - * Internal Method that is fired to indicate that the datamanager has - * changed - */ - public static void fireChangeListener() { - DataManager dm = null; - - dm = getCurrentInstance(); - - // kludge to get combine mode menu item updated - ICommandService service = (ICommandService) PlatformUI.getWorkbench() - .getService(ICommandService.class); - - service.refreshElements("com.raytheon.viz.gfe.actions.setCombineMode", - null); - - if (dm != null && listeners != null) { - for (ICurrentDataManagerChangedListener listener : listeners) { - listener.currentDataManagerChanged(dm); - } - } - } - - /** - * Find the DataManager associated with a specific workbench window - * - * If it does not exist, return null. - * - * @param window - * the workbench window - * @return the DataManager associated with the specified window - */ - public static DataManager findInstance(IWorkbenchWindow window) { - return instanceMap.get(new DataManagerKey(window)); - } - - /** - * Get the DataManager associated with a specific workbench window - * - * If it does not exist, create one. - * - * @param window - * the window the DataManager is associated with - * @return a DataManager associated to a specific window - */ - public static DataManager getInstance(IWorkbenchWindow window) { - if (window != null && windowListener == null) { - windowListener = new IWindowListener() { - - @Override - public void windowActivated(IWorkbenchWindow window) { - // do nothing - } - - @Override - public void windowClosed(IWorkbenchWindow window) { - DataManager.dispose(window); - } - - @Override - public void windowDeactivated(IWorkbenchWindow window) { - // do nothing - } - - @Override - public void windowOpened(IWorkbenchWindow window) { - // do nothing - } - - }; - PlatformUI.getWorkbench().addWindowListener(windowListener); - } - DataManager dm = findInstance(window); - if (dm == null) { - synchronized (instanceMap) { - // verify it hasn't been loaded by another - dm = findInstance(window); - if (dm == null) { - try { - dm = new DataManager(window); - instanceMap.put(new DataManagerKey(window), dm); - waitForJobs(dm); - if (window != null) { - postInitialize(dm); - } - } catch (GFEServerException e) { - statusHandler.handle(Priority.PROBLEM, - e.getLocalizedMessage(), e); - } - } - } - } - return dm; - } - - /** - * Check to see if any DataManagers are active - * - * @return true if any DataManagers are active - */ - public static boolean anyActive() { - return !instanceMap.isEmpty(); - } - - /** - * Start all auto save jobs - */ - public static void enableAutoSave() { - for (DataManager dm : instanceMap.values()) { - dm.autoSaveJob.cancel(); - dm.autoSaveJob.reSchedule(); - } - } - - /** - * Stop all auto save jobs - */ - public static void disableAutoSave() { - for (DataManager dm : instanceMap.values()) { - dm.autoSaveJob.cancel(); - } - } - - /** - * Dispose an instance of the DataManager associated with a particular - * window - * - * @param window - */ - public static void dispose(IWorkbenchWindow window) { - DataManager dm = instanceMap.remove(new DataManagerKey(window)); - - if (dm != null) { - dm.dispose(); - } - } - - private void dispose() { + void dispose() { selectTimeRangeManager.dispose(); refManager.dispose(); parmManager.dispose(); @@ -629,36 +413,6 @@ public class DataManager { return this.router; } - private static void postInitialize(DataManager dataManager) { - // Tell ParmManager which parms to load initially - IParmManager parmMgr = dataManager.getParmManager(); - ParmID[] parmIDs = dataManager.getWEGroupManager().getParmIDs( - dataManager.getWEGroupManager().getDefaultGroup(), - parmMgr.getAllAvailableParms()); - - parmMgr.setDisplayedParms(parmIDs); - - } - - /** - * @param dataManager - */ - protected static void waitForJobs(DataManager dataManager) { - // wait to ensure init jobs are done - long waitForJobs = 0; - while (!dataManager.getInitStatus().isDone()) { - try { - waitForJobs += 10; - Thread.sleep(10); - } catch (InterruptedException e) { - statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), - e); - } - } - System.out.println("Waiting on Jobs: " + waitForJobs); - - } - /** * Return the inventory for a parm * diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManagerFactory.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManagerFactory.java new file mode 100644 index 0000000000..22172a584b --- /dev/null +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManagerFactory.java @@ -0,0 +1,178 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.gfe.core; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.viz.gfe.GFEServerException; + +/** + * Factory class for construct {@link DataManager} objects for an arbitrary Object + * discriminator. Manages {@link DataManager}s so only one per discriminator exists. + * Takes instance of this class when constructing {@link DataManager} to for + * construction of {@link ISpatialDisplayManager} for the {@link DataManager} + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 27, 2012            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public abstract class DataManagerFactory { + + protected static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(DataManagerUIFactory.class); + + private static class DataManagerKey { + + private final Object discriminator; + + DataManagerKey(Object discriminator) { + this.discriminator = discriminator; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return (discriminator == null ? 0 : discriminator.hashCode()); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof DataManagerKey) { + Object otherDiscriminator = ((DataManagerKey) obj).discriminator; + if (discriminator == null) { + return otherDiscriminator == null; + } + return discriminator.equals(otherDiscriminator); + } + return false; + } + } + + private static Map instanceMap = new ConcurrentHashMap();; + + /** + * Find the DataManager associated with a discriminator + * + * If it does not exist, return null. + * + * @param discriminator + * the discriminator + * @return the DataManager associated with the specified discriminator + */ + static DataManager findInstance(Object discriminator) { + return instanceMap.get(new DataManagerKey(discriminator)); + } + + /** + * Gets an instance of the DataManager for the given discriminator, factory + * will be used to create display manager + * + * @param factory + * @param discriminator + * @return + */ + public static DataManager getInstance(DataManagerFactory factory, + Object discriminator) { + synchronized (DataManagerKey.class) { + DataManagerKey key = new DataManagerKey(discriminator); + DataManager dm = instanceMap.get(key); + if (dm == null) { + try { + dm = new DataManager(factory, discriminator); + instanceMap.put(key, dm); + waitForJobs(dm); + } catch (GFEServerException e) { + statusHandler.handle(Priority.PROBLEM, + e.getLocalizedMessage(), e); + } + } + return dm; + } + } + + /** + * @param dataManager + */ + private static void waitForJobs(DataManager dataManager) { + // wait to ensure init jobs are done + long waitForJobs = 0; + while (!dataManager.getInitStatus().isDone()) { + try { + waitForJobs += 10; + Thread.sleep(10); + } catch (InterruptedException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + } + } + System.out.println("Waiting on Jobs: " + waitForJobs); + } + + /** + * Dispose an instance of the DataManager associated with a particular + * discriminator + * + * @param window + */ + public static void dispose(Object discriminator) { + synchronized (DataManagerKey.class) { + DataManager dm = instanceMap.remove(new DataManagerKey( + discriminator)); + + if (dm != null) { + dm.dispose(); + } + } + } + + /** + * Create an {@link ISpatialDisplayManager} for the {@link DataManager} and + * discriminator + * + * @param dm + * @param discriminator + * @return + */ + protected abstract ISpatialDisplayManager createSpatialDisplayManager( + DataManager dm, Object discriminator); +} diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManagerOffscreenFactory.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManagerOffscreenFactory.java new file mode 100644 index 0000000000..29ef586f4b --- /dev/null +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManagerOffscreenFactory.java @@ -0,0 +1,73 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.gfe.core; + +import com.raytheon.uf.viz.core.drawables.IRenderableDisplay; +import com.raytheon.viz.gfe.core.internal.OffscreenSpatialDisplayManager; + +/** + * Manages windowless DataManagers for {@link IRenderableDisplay}s. Mostly used + * for offscreen rendering applications + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 27, 2012            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public class DataManagerOffscreenFactory extends DataManagerFactory { + + private static DataManagerOffscreenFactory instance = new DataManagerOffscreenFactory(); + + /** + * Gets (will create if none) the DataManager for the given display + * + * @param display + * @return + */ + public static DataManager getInstance(GFEMapRenderableDisplay display) { + DataManager dm = DataManagerFactory.getInstance(instance, display); + display.setDataManager(dm); + return dm; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.gfe.core.DataManagerFactory#createSpatialDisplayManager + * (com.raytheon.viz.gfe.core.DataManager, java.lang.Object) + */ + @Override + protected ISpatialDisplayManager createSpatialDisplayManager( + DataManager dm, Object discriminator) { + return new OffscreenSpatialDisplayManager( + (GFEMapRenderableDisplay) discriminator, dm); + } + +} diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManagerUIFactory.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManagerUIFactory.java new file mode 100644 index 0000000000..b5714e61b3 --- /dev/null +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManagerUIFactory.java @@ -0,0 +1,140 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.gfe.core; + +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; +import com.raytheon.uf.viz.core.VizApp; +import com.raytheon.viz.gfe.core.internal.GFESpatialDisplayManager; +import com.raytheon.viz.ui.VizWorkbenchManager; + +/** + * UI based {@link DataManager} factory. Uses {@link IWorkbenchWindow} objects + * as the discriminator for keeping track of instances + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 27, 2012            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * + * + * @version 1.0 + */ + +public class DataManagerUIFactory extends DataManagerFactory { + + private static DataManagerUIFactory instance = new DataManagerUIFactory(); + + /** + * Find the DataManager associated with a specific workbench window + * + * If it does not exist, return null. + * + * @param window + * the workbench window + * @return the DataManager associated with the specified window + */ + public static DataManager findInstance(IWorkbenchWindow window) { + return DataManagerFactory.findInstance(window); + } + + /** + * Get the DataManager associated with the currently active workbench + * window. + * + * If no workbench window is active, or the GFE perspective has not been + * activated in the active window, this method will return null. + * + * @return the active DataManager + */ + public static DataManager getCurrentInstance() { + final IWorkbenchWindow[] window = new IWorkbenchWindow[1]; + + window[0] = VizWorkbenchManager.getInstance().getCurrentWindow(); + + if (window[0] == null && PlatformUI.isWorkbenchRunning()) { + VizApp.runSync(new Runnable() { + + @Override + public void run() { + window[0] = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow(); + } + + }); + } + + return findInstance(window[0]); + } + + /** + * Get the DataManager associated with a specific workbench window + * + * If it does not exist, create one. + * + * @param window + * the window the DataManager is associated with + * @return a DataManager associated to a specific window + */ + public static DataManager getInstance(IWorkbenchWindow window) { + DataManager dm = DataManagerFactory.getInstance(instance, window); + if (window != null) { + postInitialize(dm); + } + return dm; + } + + /** + * Tell ParmManager which parms to load initially + * + * @param dataManager + */ + private static void postInitialize(DataManager dataManager) { + IParmManager parmMgr = dataManager.getParmManager(); + ParmID[] parmIDs = dataManager.getWEGroupManager().getParmIDs( + dataManager.getWEGroupManager().getDefaultGroup(), + parmMgr.getAllAvailableParms()); + + parmMgr.setDisplayedParms(parmIDs); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.gfe.core.DataManagerFactory#createSpatialDisplayManager + * (com.raytheon.viz.gfe.core.DataManager, java.lang.Object) + */ + @Override + protected ISpatialDisplayManager createSpatialDisplayManager( + DataManager dm, Object discriminator) { + return new GFESpatialDisplayManager(dm); + } + +} diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/GFEIntervalTimeMatcher.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/GFEIntervalTimeMatcher.java new file mode 100644 index 0000000000..d08fe6fa47 --- /dev/null +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/GFEIntervalTimeMatcher.java @@ -0,0 +1,99 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.gfe.core; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.common.time.TimeRange; +import com.raytheon.uf.viz.core.drawables.IDescriptor; +import com.raytheon.uf.viz.core.drawables.IDescriptor.FramesInfo; +import com.raytheon.viz.gfe.rsc.GFEResource; + +/** + * Time matcher that uses a set interval/offset and start/end time to calculate + * DataTimes for a descriptor + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 28, 2012            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public class GFEIntervalTimeMatcher extends GFETimeMatcher { + + private static final long HRS_TO_MILLIS = 3600 * 1000; + + private DataTime[] dataTimes = new DataTime[0]; + + /** + * Set the time matching interval data used to calculate the data times + * + * @param intervalInHrs + * @param intervalOffsetInHrs + * @param timeRange + */ + public void setTimeMatchingInterval(int intervalInHrs, + int intervalOffsetInHrs, TimeRange timeRange) { + long intervalInMillis = intervalInHrs * HRS_TO_MILLIS; + long intervalOffsetInMillis = intervalOffsetInHrs * HRS_TO_MILLIS; + + List times = new ArrayList(); + long firstTime = timeRange.getStart().getTime(); + long lastTime = timeRange.getEnd().getTime(); + + long time = ((firstTime / intervalInMillis) * intervalInMillis) + + intervalOffsetInMillis; + while (time <= lastTime) { + if (time >= firstTime) { + times.add(new DataTime(new Date(time))); + } + time += intervalInMillis; + } + dataTimes = times.toArray(new DataTime[0]); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.gfe.core.GFETimeMatcher#calculateDescriptorTimes(com + * .raytheon.uf.viz.core.drawables.IDescriptor, + * com.raytheon.uf.viz.core.drawables.IDescriptor.FramesInfo, java.util.Set) + */ + @Override + protected DataTime[] calculateDescriptorTimes(IDescriptor descriptor, + FramesInfo currInfo, Set tmbResources) { + return Arrays.copyOf(dataTimes, dataTimes.length); + } + +} diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/GFEMapRenderableDisplay.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/GFEMapRenderableDisplay.java index 79ee3d329a..7c33c268f7 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/GFEMapRenderableDisplay.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/GFEMapRenderableDisplay.java @@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.viz.core.drawables.IDescriptor; import com.raytheon.uf.viz.core.drawables.PaintProperties; import com.raytheon.uf.viz.core.drawables.ResourcePair; import com.raytheon.uf.viz.core.map.MapDescriptor; @@ -75,6 +76,21 @@ public class GFEMapRenderableDisplay extends PlainMapRenderableDisplay super(desc); } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.drawables.AbstractRenderableDisplay#setDescriptor + * (com.raytheon.uf.viz.core.drawables.IDescriptor) + */ + @Override + public void setDescriptor(IDescriptor desc) { + super.setDescriptor(desc); + if (desc.getTimeMatcher() == null) { + desc.setTimeMatcher(new GFETimeMatcher()); + } + } + @SuppressWarnings("unchecked") public void setDataManager(DataManager dataManager) { if (this.dataMgr != null) { @@ -102,9 +118,9 @@ public class GFEMapRenderableDisplay extends PlainMapRenderableDisplay protected PaintProperties calcPaintDataTime(PaintProperties paintProps, AbstractVizResource rsc) { if (dataMgr != null) { - Date date = dataMgr.getSpatialDisplayManager() - .getSpatialEditorTime(); - paintProps.setDataTime(new DataTime(date)); + // Get time for resource from FramesInfo + paintProps.setDataTime(paintProps.getFramesInfo() + .getTimeForResource(rsc)); } GFEPaintProperties gfeProps = new GFEPaintProperties(paintProps); diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/GFETimeMatcher.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/GFETimeMatcher.java new file mode 100644 index 0000000000..b7d28e0176 --- /dev/null +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/GFETimeMatcher.java @@ -0,0 +1,270 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.gfe.core; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.common.time.TimeRange; +import com.raytheon.uf.viz.core.AbstractTimeMatcher; +import com.raytheon.uf.viz.core.drawables.IDescriptor; +import com.raytheon.uf.viz.core.drawables.IDescriptor.FramesInfo; +import com.raytheon.uf.viz.core.drawables.ResourcePair; +import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.uf.viz.core.rsc.AbstractVizResource; +import com.raytheon.uf.viz.core.rsc.LoadProperties; +import com.raytheon.viz.gfe.core.griddata.IGridData; +import com.raytheon.viz.gfe.core.parm.Parm; +import com.raytheon.viz.gfe.rsc.GFEResource; + +/** + * GFE Time matcher, uses the union of visible resources available times to + * create set of descriptor times. Has notion of a selected time which is added + * to set of descriptor times + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 14, 2012            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public class GFETimeMatcher extends AbstractTimeMatcher { + + /** The selected date, added as a extra frame if not null */ + private Date selectedDate; + + /** Set of resources used in calculating the descriptor times */ + private Set tmbResources = new HashSet(); + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.AbstractTimeMatcher#redoTimeMatching(com.raytheon + * .uf.viz.core.rsc.AbstractVizResource) + */ + @Override + public void redoTimeMatching(AbstractVizResource resource) { + // Noop + } + + /** + * Time matches a single resource against the set of descriptorTimes and + * adds times into the timeMap + * + * @param descriptorTimes + * @param timeMap + * @param resource + */ + private void redoTimeMatching(DataTime[] descriptorTimes, + Map, DataTime[]> timeMap, + AbstractVizResource resource) { + if (resource instanceof GFEResource) { + GFEResource rsc = (GFEResource) resource; + Parm parm = rsc.getParm(); + DataTime[] rscTimes = new DataTime[descriptorTimes.length]; + for (int i = 0; i < descriptorTimes.length; ++i) { + IGridData overlapping = parm.overlappingGrid(descriptorTimes[i] + .getRefTime()); + if (overlapping != null) { + TimeRange tr = overlapping.getGridTime(); + rscTimes[i] = new DataTime(tr.getStart().getTime(), + new TimeRange(tr.getStart(), tr.getEnd())); + } + } + if (timeMap != null) { + timeMap.put(rsc, rscTimes); + } + } + } + + protected DataTime[] calculateDescriptorTimes(IDescriptor descriptor, + FramesInfo currInfo, Set tmbResources) { + DataTime currTime = currInfo.getCurrentFrame(); + List rscs = descriptor.getResourceList() + .getResourcesByTypeAsType(GFEResource.class); + + // Figure list of parms from visible GFEResources + List parms = new ArrayList(rscs.size()); + for (GFEResource rsc : rscs) { + if (rsc.getProperties().isVisible()) { + parms.add(rsc.getParm()); + tmbResources.add(rsc); + } + } + + // calculate time steps from parms + SortedSet dateSet = new TreeSet(); + for (Date stepTime : calcTimeSteps(parms)) { + dateSet.add(new DataTime(stepTime)); + } + + if (currTime != null && selectedDate == null + && dateSet.contains(currTime) == false) { + selectedDate = currTime.getRefTime(); + } + + // Add special selected time + if (selectedDate != null) { + currTime = new DataTime(selectedDate); + dateSet.add(currTime); + } + return dateSet.toArray(new DataTime[0]); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.AbstractTimeMatcher#redoTimeMatching(com.raytheon + * .uf.viz.core.drawables.IDescriptor) + */ + @Override + public synchronized void redoTimeMatching(IDescriptor descriptor) + throws VizException { + Set tmbResources = new HashSet(); + FramesInfo currInfo = descriptor.getFramesInfo(); + int currIdx = currInfo.getFrameIndex(); + DataTime currTime = currInfo.getCurrentFrame(); + + // Create descriptor times, for each resource, time match against them + DataTime[] descriptorTimes = calculateDescriptorTimes(descriptor, + currInfo, tmbResources); + Map, DataTime[]> rscTimeMap = new HashMap, DataTime[]>(); + for (ResourcePair rp : descriptor.getResourceList()) { + redoTimeMatching(descriptorTimes, rscTimeMap, rp.getResource()); + } + + // Update current displayed index + if (descriptorTimes.length == 0) { + currIdx = -1; + } else if (currTime != null) { + currIdx = Arrays.binarySearch(descriptorTimes, currTime); + if (currIdx < 0) { + // Fix Arrays.binarySearch returning -insertionIndex-1 + currIdx = -currIdx - 1; + } + } else { + currIdx = 0; + } + + FramesInfo newInfo = new FramesInfo(descriptorTimes, currIdx, + rscTimeMap); + descriptor.setFramesInfo(newInfo); + + this.tmbResources = tmbResources; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.AbstractTimeMatcher#handleRemove(com.raytheon + * .uf.viz.core.rsc.AbstractVizResource, + * com.raytheon.uf.viz.core.drawables.IDescriptor) + */ + @Override + public void handleRemove(AbstractVizResource resource, + IDescriptor descriptor) { + if (tmbResources.contains(resource)) { + // This was a time match basis resource, need to redo time matching + try { + redoTimeMatching(resource.getDescriptor()); + } catch (VizException e) { + // Do not like this handle, should throw exception? + UFStatus.getHandler().handle(Priority.PROBLEM, + e.getLocalizedMessage(), e); + } + } + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.AbstractTimeMatcher#initialLoad(com.raytheon + * .uf.viz.core.rsc.LoadProperties, com.raytheon.uf.common.time.DataTime[], + * com.raytheon.uf.viz.core.drawables.IDescriptor) + */ + @Override + public DataTime[] initialLoad(LoadProperties loadProps, + DataTime[] availableTimes, IDescriptor descriptor) + throws VizException { + // Should we support this? Would need to figure out a simple time + // matching method (would be same as how non GFEResources are handled in + // redoTimeMatching) + return new DataTime[0]; + } + + /** + * @param selectedDate + * the selectedDate to set + */ + public void setSelectedDate(Date selectedDate) { + this.selectedDate = selectedDate; + } + + /** + * Given a list of parms, calculate the time steps between them + * + * @param parms + * @return + */ + public static List calcTimeSteps(List parms) { + SortedSet dateSet = new TreeSet(); + for (Parm pi : parms) { + IGridData[] inv = pi.getGridInventory(); + for (IGridData grid : inv) { + dateSet.add(grid.getGridTime().getStart()); + + if (!dateSet.contains(grid.getGridTime().getEnd())) { + for (Parm pk : parms) { + if (pi != pk + && pk.overlappingGrid(grid.getGridTime() + .getEnd()) != null) { + dateSet.add(grid.getGridTime().getEnd()); + break; + } + } + } + } + } + return new ArrayList(dateSet); + } +} diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/IParmManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/IParmManager.java index cd428ddc14..0465a0b832 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/IParmManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/IParmManager.java @@ -19,7 +19,6 @@ **/ package com.raytheon.viz.gfe.core; -import java.util.Date; import java.util.List; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; @@ -551,6 +550,4 @@ public interface IParmManager extends IParmInventoryChangedListener, public JobPool getNotificationPool(); public VCModuleJobPool getVCModulePool(); - - public abstract List calcStepTimes(List parms, TimeRange dspTR); } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/ISpatialDisplayManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/ISpatialDisplayManager.java index a7c0a76841..215c1783ce 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/ISpatialDisplayManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/ISpatialDisplayManager.java @@ -22,7 +22,6 @@ package com.raytheon.viz.gfe.core; import java.util.Date; import com.raytheon.uf.common.time.TimeRange; -import com.raytheon.uf.viz.core.PixelExtent; import com.raytheon.uf.viz.core.drawables.ColorMapParameters; import com.raytheon.uf.viz.core.drawables.IDescriptor; import com.raytheon.uf.viz.core.drawables.ResourcePair; @@ -71,8 +70,7 @@ public interface ISpatialDisplayManager { public void setSpatialEditorTime(Date date); /** - * Activate a certain parm on the spatial editor. This will also disable all - * other parms + * Activate the specified parm for the display manager. * * @param parmToActivate * the parm to activate @@ -246,14 +244,6 @@ public interface ISpatialDisplayManager { */ public Parm[] getCurrentlyEnabledParms(); - /** - * Return the area of the screen (if any) that the colorbar is currently - * occupying. - * - * @return the colorbar coverage, or null if no colorbar displayed. - */ - public PixelExtent getColorbarExtent(); - /** * Return the GFE System Resource * diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/AbstractParmManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/AbstractParmManager.java index cf20e10bc4..821357e690 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/AbstractParmManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/AbstractParmManager.java @@ -2103,31 +2103,4 @@ public abstract class AbstractParmManager implements IParmManager { return vcModulePool; } - // Now construct the step times. - // All startTimes are included. - // EndTimes which are contained in another TR are included. - @Override - public List calcStepTimes(List parms, TimeRange dspTR) { - SortedSet dateSet = new TreeSet(); - - for (Parm pi : parms) { - IGridData[] inv = pi.getGridInventory(); - for (IGridData grid : inv) { - dateSet.add(grid.getGridTime().getStart()); - - if (!dateSet.contains(grid.getGridTime().getEnd())) { - for (Parm pk : parms) { - if (pi != pk - && pi.overlappingGrid(grid.getGridTime() - .getEnd()) != null) { - dateSet.add(grid.getGridTime().getEnd()); - break; - } - } - } - } - } - - return new ArrayList(dateSet); - } } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/AbstractSpatialDisplayManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/AbstractSpatialDisplayManager.java index 5cf8744df7..26aa80b964 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/AbstractSpatialDisplayManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/AbstractSpatialDisplayManager.java @@ -22,7 +22,6 @@ package com.raytheon.viz.gfe.core.internal; import java.util.ArrayList; import java.util.Date; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; @@ -30,10 +29,14 @@ import org.apache.commons.lang.Validate; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.ICommandService; -import com.raytheon.uf.common.time.SimulatedTime; -import com.raytheon.uf.viz.core.PixelExtent; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.common.time.TimeRange; +import com.raytheon.uf.viz.core.AbstractTimeMatcher; import com.raytheon.uf.viz.core.drawables.ColorMapParameters; import com.raytheon.uf.viz.core.drawables.IDescriptor; +import com.raytheon.uf.viz.core.drawables.IDescriptor.FramesInfo; import com.raytheon.uf.viz.core.drawables.ResourcePair; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.rsc.AbstractVizResource; @@ -44,6 +47,7 @@ import com.raytheon.viz.gfe.Activator; import com.raytheon.viz.gfe.GFEOperationFailedException; import com.raytheon.viz.gfe.actions.ShowISCMarkersAction; import com.raytheon.viz.gfe.core.DataManager; +import com.raytheon.viz.gfe.core.GFETimeMatcher; import com.raytheon.viz.gfe.core.ISpatialDisplayManager; import com.raytheon.viz.gfe.core.msgs.IActivatedParmChangedListener; import com.raytheon.viz.gfe.core.msgs.IDisplayModeChangedListener; @@ -58,7 +62,6 @@ import com.raytheon.viz.gfe.core.parm.ParmDisplayAttributes.VisMode; import com.raytheon.viz.gfe.edittool.AbstractGFEEditTool; import com.raytheon.viz.gfe.rsc.GFEResource; import com.raytheon.viz.gfe.rsc.GFESystemResource; -import com.raytheon.viz.gfe.rsc.colorbar.GFEColorbarResource; /** * Abstract Spatial Display Manager for GFE. Most of the implemented methods @@ -83,6 +86,8 @@ public abstract class AbstractSpatialDisplayManager implements protected final DataManager dataManager; + private TimeRange globalTimeRange; + protected Date seTime; protected Parm activeParm; @@ -117,7 +122,7 @@ public abstract class AbstractSpatialDisplayManager implements protected AbstractSpatialDisplayManager(DataManager dataMgr) { this.dataManager = dataMgr; - this.seTime = SimulatedTime.getSystemTime().getTime(); + this.globalTimeRange = new TimeRange(0, 0); this.activatedParmChangedListeners = new HashSet(); this.gridVisibilityChangedListeners = new HashSet(); this.globalSelectionTRChangedListeners = new HashSet(); @@ -146,6 +151,12 @@ public abstract class AbstractSpatialDisplayManager implements .getBoolean("ShowISCOfficialSymbol")); } + /** + * Gets any descriptors to be kept in sync with the display manager (can be + * empty) + * + * @return + */ protected abstract IDescriptor[] getDescriptors(); /* @@ -311,13 +322,10 @@ public abstract class AbstractSpatialDisplayManager implements IDescriptor[] descriptors = getDescriptors(); for (IDescriptor desc : descriptors) { ResourceList rl = desc.getResourceList(); - synchronized (rl) { - for (ResourcePair rp : rl) { - AbstractVizResource rsc = rp.getResource(); - if (rsc instanceof GFESystemResource) { - ((GFESystemResource) rsc).addEditTool(editTool); - } - } + List rscs = rl + .getResourcesByTypeAsType(GFESystemResource.class); + for (GFESystemResource rsc : rscs) { + rsc.addEditTool(editTool); } } } @@ -332,16 +340,11 @@ public abstract class AbstractSpatialDisplayManager implements @Override public void removeEditTool(AbstractGFEEditTool editTool) throws VizException { - IDescriptor[] descriptors = getDescriptors(); - for (IDescriptor desc : descriptors) { - ResourceList rl = desc.getResourceList(); - synchronized (rl) { - for (ResourcePair rp : rl) { - AbstractVizResource rsc = rp.getResource(); - if (rsc instanceof GFESystemResource) { - ((GFESystemResource) rsc).removeEditTool(editTool); - } - } + for (IDescriptor desc : getDescriptors()) { + List rscs = desc.getResourceList() + .getResourcesByTypeAsType(GFESystemResource.class); + for (GFESystemResource rsc : rscs) { + rsc.removeEditTool(editTool); } } } @@ -356,14 +359,13 @@ public abstract class AbstractSpatialDisplayManager implements @Override public ColorMapParameters getColorMapParameters(Parm p) throws GFEOperationFailedException { - IDescriptor[] descriptors = getDescriptors(); - if (descriptors.length == 0) { - throw new GFEOperationFailedException( - "Unable to get colormap from parm because spatial editor is not active"); + for (IDescriptor descriptor : getDescriptors()) { + ColorMapParameters cmap = getColorMapParameters(p, descriptor); + if (cmap != null) { + return cmap; + } } - - IDescriptor descriptor = descriptors[0]; - return getColorMapParameters(p, descriptor); + return null; } /* @@ -389,32 +391,6 @@ public abstract class AbstractSpatialDisplayManager implements return null; } - /* - * (non-Javadoc) - * - * @see com.raytheon.viz.gfe.core.ISpatialDisplayManager#getColorbarExtent() - */ - @Override - public PixelExtent getColorbarExtent() { - IDescriptor[] descriptors = getDescriptors(); - if (descriptors.length == 0) { - return null; - } - - IDescriptor descriptor = descriptors[0]; - ResourceList rscList = descriptor.getResourceList(); - synchronized (rscList) { - for (ResourcePair rp : rscList) { - AbstractVizResource rsc = rp.getResource(); - if (rsc instanceof GFEColorbarResource) { - return ((GFEColorbarResource) rsc).getExtent(); - } - } - } - - return null; - } - /* * (non-Javadoc) * @@ -425,30 +401,17 @@ public abstract class AbstractSpatialDisplayManager implements */ @Override public void setDisplayMode(Parm parm, VisMode mode) { - IDescriptor[] descriptors = getDescriptors(); - if (descriptors.length == 0) { - return; - } - - for (IDescriptor descriptor : descriptors) { - ResourceList resourceList = descriptor.getResourceList(); - synchronized (resourceList) { - Iterator iterator = resourceList.iterator(); - - while (iterator.hasNext()) { - ResourcePair resourcePair = iterator.next(); - AbstractVizResource rsc = resourcePair.getResource(); - if (rsc instanceof GFEResource) { - Parm p = ((GFEResource) rsc).getParm(); - if (p.equals(parm)) { - p.getDisplayAttributes().setVisMode(mode); - ((GFEResource) rsc).reset(); - } else if (mode.equals(VisMode.IMAGE)) { - p.getDisplayAttributes() - .setVisMode(VisMode.GRAPHIC); - ((GFEResource) rsc).reset(); - } - } + for (IDescriptor descriptor : getDescriptors()) { + List rscs = descriptor.getResourceList() + .getResourcesByTypeAsType(GFEResource.class); + for (GFEResource rsc : rscs) { + Parm p = rsc.getParm(); + if (p.equals(parm)) { + p.getDisplayAttributes().setVisMode(mode); + rsc.reset(); + } else if (mode.equals(VisMode.IMAGE)) { + p.getDisplayAttributes().setVisMode(VisMode.GRAPHIC); + rsc.reset(); } } } @@ -465,16 +428,11 @@ public abstract class AbstractSpatialDisplayManager implements */ @Override public GFESystemResource getSystemResource() throws VizException { - IDescriptor[] descriptors = getDescriptors(); - if (descriptors.length == 0) { - return null; - } - - ResourceList rl = descriptors[0].getResourceList(); - - for (ResourcePair rp : rl) { - if (rp.getResource() instanceof GFESystemResource) { - return (GFESystemResource) rp.getResource(); + for (IDescriptor descriptor : getDescriptors()) { + List rscs = descriptor.getResourceList() + .getResourcesByTypeAsType(GFESystemResource.class); + for (GFESystemResource rsc : rscs) { + return rsc; } } @@ -492,21 +450,16 @@ public abstract class AbstractSpatialDisplayManager implements */ @Override public ResourcePair getResourcePair(Parm parm) { - IDescriptor[] descriptors = getDescriptors(); - if (descriptors.length == 0 || descriptors[0] == null) { - return null; - } + for (IDescriptor descriptor : getDescriptors()) { + ResourceList resourceList = descriptor.getResourceList(); - IDescriptor descriptor = descriptors[0]; - - ResourceList resourceList = descriptor.getResourceList(); - - for (ResourcePair resourcePair : resourceList) { - AbstractVizResource rsc = resourcePair.getResource(); - if (rsc instanceof GFEResource) { - GFEResource grsc = (GFEResource) rsc; - if (grsc.getParm().equals(parm)) { - return resourcePair; + for (ResourcePair resourcePair : resourceList) { + AbstractVizResource rsc = resourcePair.getResource(); + if (rsc instanceof GFEResource) { + GFEResource grsc = (GFEResource) rsc; + if (grsc.getParm().equals(parm)) { + return resourcePair; + } } } } @@ -522,60 +475,57 @@ public abstract class AbstractSpatialDisplayManager implements */ @Override public Parm[] getCurrentlyEnabledParms() { - IDescriptor[] descriptors = getDescriptors(); - if (descriptors.length == 0) { - return new Parm[0]; - } - - IDescriptor descriptor = descriptors[0]; - List parmList = new ArrayList(); - ResourceList rscList = descriptor.getResourceList(); - synchronized (rscList) { - for (ResourcePair rp : rscList) { - AbstractVizResource rsc = rp.getResource(); - ResourceProperties props = rp.getProperties(); - if (rsc instanceof GFEResource && props.isVisible()) { - GFEResource grsc = (GFEResource) rsc; - parmList.add(grsc.getParm()); + for (IDescriptor descriptor : getDescriptors()) { + List parmList = new ArrayList(); + List rscs = descriptor.getResourceList() + .getResourcesByTypeAsType(GFEResource.class); + for (GFEResource rsc : rscs) { + if (rsc.getProperties().isVisible()) { + parmList.add(rsc.getParm()); } } + if (parmList.size() > 0) { + return parmList.toArray(new Parm[parmList.size()]); + } } - return parmList.toArray(new Parm[parmList.size()]); + return new Parm[0]; } @Override public void makeVisible(Parm parm, boolean visible, boolean makeOnlyVisible) { - IDescriptor[] descriptors = getDescriptors(); - if (descriptors.length == 0) { - return; + for (IDescriptor descriptor : getDescriptors()) { + makeVisible(descriptor, parm, visible, makeOnlyVisible); } - for (IDescriptor descriptor : descriptors) { - ResourceList resourceList = descriptor.getResourceList(); - synchronized (resourceList) { - Iterator iterator = resourceList.iterator(); - - while (iterator.hasNext()) { - ResourcePair resourcePair = iterator.next(); - AbstractVizResource rsc = resourcePair.getResource(); - if (rsc instanceof GFEResource) { - ResourceProperties props = resourcePair.getProperties(); - Parm p = ((GFEResource) rsc).getParm(); - if (p.equals(parm)) { - props.setVisible(visible); - } else if (makeOnlyVisible) { - props.setVisible(false); - } - } - } - } - } for (IGridVisibilityChangedListener listener : this.gridVisibilityChangedListeners) { listener.gridVisibilityChanged(parm, visible, makeOnlyVisible); } } + private void makeVisible(IDescriptor descriptor, Parm parm, + boolean visible, boolean makeOnlyVisible) { + List rscs = descriptor.getResourceList() + .getResourcesByTypeAsType(GFEResource.class); + for (GFEResource rsc : rscs) { + ResourceProperties props = rsc.getProperties(); + Parm p = rsc.getParm(); + if (p.equals(parm)) { + props.setVisible(visible); + } else if (makeOnlyVisible) { + props.setVisible(false); + } + } + + try { + // Parm visibility affects GFE time matching + descriptor.redoTimeMatching(); + } catch (VizException e) { + UFStatus.getHandler().handle(Priority.PROBLEM, + e.getLocalizedMessage(), e); + } + } + /* * (non-Javadoc) * @@ -585,47 +535,36 @@ public abstract class AbstractSpatialDisplayManager implements */ public void activateParm(Parm parmToActivate) throws GFEOperationFailedException { - IDescriptor[] descriptors = getDescriptors(); - if (descriptors.length == 0) { - throw new GFEOperationFailedException( - "Unable to activate parm because spatial editor is not active"); + // Keep any resources on descriptors in sync + for (IDescriptor descriptor : getDescriptors()) { + ResourceList resourceList = descriptor.getResourceList(); + List rscs = resourceList + .getResourcesByTypeAsType(GFEResource.class); + for (GFEResource rsc : rscs) { + ResourceProperties props = rsc.getProperties(); + // skip the quick view resource + if (props.isSystemResource()) { + continue; + } + Parm parm = ((GFEResource) rsc).getParm(); + if (parm.equals(parmToActivate)) { + props.setVisible(true); + } + ((GFEResource) rsc).reset(); + } } - for (IDescriptor descriptor : descriptors) { - ResourceList resourceList = descriptor.getResourceList(); - synchronized (resourceList) { - Iterator iterator = resourceList.iterator(); - - while (iterator.hasNext()) { - ResourcePair resourcePair = iterator.next(); - AbstractVizResource rsc = resourcePair.getResource(); - if (rsc instanceof GFEResource) { - ResourceProperties props = resourcePair.getProperties(); - // skip the quick view resource - if (props.isSystemResource()) { - continue; - } - Parm parm = ((GFEResource) rsc).getParm(); - if (parm.equals(parmToActivate)) { - props.setVisible(true); - } - ((GFEResource) rsc).reset(); - } - } - - this.activeParm = parmToActivate; - if (activeParm != null) { - if (Message.inquireLastMessage( - SetImageOnActiveChangedMsg.class).isEnabled()) { - setDisplayMode(parmToActivate, VisMode.IMAGE); - } - this.lastActiveParm = parmToActivate; - } - - for (IActivatedParmChangedListener listener : this.activatedParmChangedListeners) { - listener.activatedParmChanged(parmToActivate); - } + this.activeParm = parmToActivate; + if (activeParm != null) { + if (Message.inquireLastMessage(SetImageOnActiveChangedMsg.class) + .isEnabled()) { + setDisplayMode(parmToActivate, VisMode.IMAGE); } + this.lastActiveParm = parmToActivate; + } + + for (IActivatedParmChangedListener listener : this.activatedParmChangedListeners) { + listener.activatedParmChanged(parmToActivate); } } @@ -712,13 +651,51 @@ public abstract class AbstractSpatialDisplayManager implements } @Override - public void setSpatialEditorTime(Date date) { - seTime = date; + public Date getSpatialEditorTime() { + // Check descriptors first for current time + IDescriptor[] descs = getDescriptors(); + for (IDescriptor desc : descs) { + FramesInfo fi = desc.getFramesInfo(); + DataTime dt = fi.getCurrentFrame(); + if (dt != null) { + return dt.getRefTime(); + } + } + // No descriptors or no set time, use seTime + return seTime; } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.gfe.core.ISpatialDisplayManager#setSpatialEditorTime + * (java.util.Date) + */ @Override - public Date getSpatialEditorTime() { - return seTime; + public void setSpatialEditorTime(Date date) { + this.seTime = date; + // Keep descriptors in sync + for (IDescriptor desc : getDescriptors()) { + setSpatialEditorTime(desc, date); + } + } + + protected void setSpatialEditorTime(IDescriptor descriptor, Date date) { + AbstractTimeMatcher matcher = descriptor.getTimeMatcher(); + if (matcher instanceof GFETimeMatcher) { + ((GFETimeMatcher) matcher).setSelectedDate(date); + try { + // Selected spatial editor time affects GFE time matching + matcher.redoTimeMatching(descriptor); + } catch (VizException e) { + UFStatus.getHandler().handle(Priority.PROBLEM, + "Error redoing time matching", e); + } + } + if (date != null) { + descriptor.getFrameCoordinator().changeFrame(date); + } } private void updateElement(String commandId, boolean state) { @@ -729,4 +706,65 @@ public abstract class AbstractSpatialDisplayManager implements service.refreshElements(commandId, null); } } + + @Override + public void toggleVisibility(Parm parm) { + Boolean visible = null; + // Check for parm on any descriptor, use visiblity of first found + for (IDescriptor descriptor : getDescriptors()) { + ResourceList resourceList = descriptor.getResourceList(); + List rscs = resourceList + .getResourcesByTypeAsType(GFEResource.class); + for (GFEResource rsc : rscs) { + Parm p = rsc.getParm(); + if (p.equals(parm)) { + visible = rsc.getProperties().isVisible(); + break; + } + } + if (visible != null) { + break; + } + } + + if (visible != null) { + // Only if resource visibilty was found do we toggle and notify + visible = !visible; + for (IDescriptor descriptor : getDescriptors()) { + makeVisible(descriptor, parm, visible, false); + } + + for (IGridVisibilityChangedListener listener : this.gridVisibilityChangedListeners) { + listener.gridVisibilityChanged(parm, visible, false); + } + } + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.gfe.core.ISpatialDisplayManager#setGlobalTimeRange(com + * .raytheon.edex.plugin.time.TimeRange) + */ + @Override + public void setGlobalTimeRange(TimeRange timeRange) { + this.globalTimeRange = timeRange; + + for (IGlobalSelectionTRChangedListener listener : this.globalSelectionTRChangedListeners) { + listener.globalSelectionTRChanged(timeRange); + } + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.gfe.core.ISpatialDisplayManager#getGlobalTimeRange() + */ + @Override + public TimeRange getGlobalTimeRange() { + return this.globalTimeRange; + } + } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/GFESpatialDisplayManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/GFESpatialDisplayManager.java index 1fab7da2db..8f725b3865 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/GFESpatialDisplayManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/GFESpatialDisplayManager.java @@ -19,24 +19,23 @@ **/ package com.raytheon.viz.gfe.core.internal; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.HashSet; -import java.util.Iterator; +import java.util.List; import java.util.Set; import org.eclipse.swt.graphics.RGB; -import org.eclipse.ui.IWorkbenchWindow; import org.geotools.coverage.grid.GridGeometry2D; import org.geotools.geometry.GeneralEnvelope; import org.opengis.geometry.Envelope; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation; import com.raytheon.uf.common.geospatial.MapUtil; -import com.raytheon.uf.common.time.TimeRange; +import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.drawables.IDescriptor; -import com.raytheon.uf.viz.core.drawables.IRenderableDisplay; +import com.raytheon.uf.viz.core.drawables.IDescriptor.IFrameChangedListener; import com.raytheon.uf.viz.core.drawables.ResourcePair; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.map.MapDescriptor; @@ -51,17 +50,13 @@ import com.raytheon.viz.gfe.core.DataManager; import com.raytheon.viz.gfe.core.IParmManager; import com.raytheon.viz.gfe.core.ISampleSetManager; import com.raytheon.viz.gfe.core.msgs.IDisplayedParmListChangedListener; -import com.raytheon.viz.gfe.core.msgs.IGlobalSelectionTRChangedListener; -import com.raytheon.viz.gfe.core.msgs.IGridVisibilityChangedListener; import com.raytheon.viz.gfe.core.msgs.ISampleSetChangedListener; import com.raytheon.viz.gfe.core.msgs.ISpatialEditorTimeChangedListener; import com.raytheon.viz.gfe.core.parm.Parm; -import com.raytheon.viz.gfe.perspective.GFEPerspective; import com.raytheon.viz.gfe.rsc.GFEReferenceSetResource; import com.raytheon.viz.gfe.rsc.GFEResource; import com.raytheon.viz.gfe.rsc.GFESystemResource; import com.raytheon.viz.gfe.rsc.colorbar.GFEColorbarResource; -import com.raytheon.viz.ui.UiUtil; import com.raytheon.viz.ui.editor.AbstractEditor; /** @@ -85,31 +80,29 @@ import com.raytheon.viz.ui.editor.AbstractEditor; */ public class GFESpatialDisplayManager extends AbstractSpatialDisplayManager - implements IDisplayedParmListChangedListener { - - private final IWorkbenchWindow window; - - private TimeRange globalTimeRange; - - private static final String GFE_PERSPECTIVE = GFEPerspective.ID_PERSPECTIVE; + implements IDisplayedParmListChangedListener, IFrameChangedListener { private final ISampleSetChangedListener sampleSetListener = new ISampleSetChangedListener() { - @Override + @Override public void sampleSetChanged(ISampleSetManager sampleSetMgr) { GFESpatialDisplayManager.this.refresh(); } }; - private boolean isPopulated; + private boolean isRegistered; public final static String GFE_STATUS_GROUP = "GFE_STATUS_GROUP"; private static final String WXD_SETTING = "WxDiscrete_Description"; - public GFESpatialDisplayManager(IWorkbenchWindow window, DataManager mgr) { + /** + * Editors managed by this display manager, use + * {@link #populate(AbstractEditor)} to add editor + */ + private List managedEditors = new ArrayList(); + + public GFESpatialDisplayManager(DataManager mgr) { super(mgr); - this.window = window; - this.globalTimeRange = new TimeRange(0, 0); PythonPreferenceStore prefs = Activator.getDefault() .getPreferenceStore(); boolean wxd_val = true; @@ -132,12 +125,13 @@ public class GFESpatialDisplayManager extends AbstractSpatialDisplayManager @Override protected IDescriptor[] getDescriptors() { - AbstractEditor[] editors = UiUtil.getEditors(window, GFE_PERSPECTIVE); - IDescriptor[] descriptors = new IDescriptor[editors.length]; - for (int i = 0; i < editors.length; i++) { - descriptors[i] = editors[i].getActiveDisplayPane().getDescriptor(); + List descriptors = new ArrayList(); + for (AbstractEditor editor : managedEditors) { + for (IDisplayPane pane : editor.getDisplayPanes()) { + descriptors.add(pane.getDescriptor()); + } } - return descriptors; + return descriptors.toArray(new IDescriptor[descriptors.size()]); } /** @@ -149,98 +143,107 @@ public class GFESpatialDisplayManager extends AbstractSpatialDisplayManager */ public void populate(AbstractEditor editor) throws VizException { synchronized (this) { - if (isPopulated) { + if (isRegistered == false) { + // First time called, register listeners + this.dataManager.getParmManager() + .addDisplayedParmListChangedListener(this); + this.dataManager.getSampleSetManager() + .addSampleSetChangedListener(sampleSetListener); + isRegistered = true; + } + + if (managedEditors.contains(editor)) { + // Editor already managed return; } IParmManager parmManager = this.dataManager.getParmManager(); - parmManager.addDisplayedParmListChangedListener(this); - Parm[] parms = parmManager.getDisplayedParms(); - - IDisplayPane pane = editor.getActiveDisplayPane(); - MapDescriptor descriptor = (MapDescriptor) pane.getDescriptor(); - - GridLocation gloc = parmManager.compositeGridLocation(); - GridGeometry2D gridGeometry = MapUtil.getGridGeometry(gloc); - Envelope envelope = gridGeometry.getEnvelope(); - double colorBarHeight = GFEColorbarResource.HEIGHT - * envelope.getSpan(1) / pane.getBounds().height; - - PythonPreferenceStore prefs = Activator.getDefault() - .getPreferenceStore(); - - double expandLeft = 10; - if (prefs.contains("OfficeDomain_expandLeft")) { - expandLeft = prefs.getDouble("OfficeDomain_expandLeft"); - } - double expandRight = 0.1; - if (prefs.contains("OfficeDomain_expandRight")) { - expandRight = prefs.getDouble("OfficeDomain_expandRight"); - } - double expandTop = 0.1; - if (prefs.contains("OfficeDomain_expandTop")) { - expandTop = prefs.getDouble("OfficeDomain_expandTop"); - } - double expandBottom = 0.1; - if (prefs.contains("OfficeDomain_expandBottom")) { - expandBottom = prefs.getDouble("OfficeDomain_expandBottom"); - } - - double dxLeft = (envelope.getSpan(0) * expandLeft / 100.0); - double dxRight = (envelope.getSpan(0) * expandRight / 100.0); - double dyTop = (envelope.getSpan(1) * expandTop / 100.0); - double dyBottom = (envelope.getSpan(1) * expandBottom / 100.0); - - GeneralEnvelope newEnvelope = new GeneralEnvelope( - envelope.getCoordinateReferenceSystem()); - newEnvelope.setRange(0, envelope.getMinimum(0) - dxLeft, - envelope.getMaximum(0) + dxRight); - newEnvelope.setRange(1, envelope.getMinimum(1) - dyBottom, - envelope.getMaximum(1) + colorBarHeight + dyTop); - GridGeometry2D newGridGeometry = new GridGeometry2D( - gridGeometry.getGridRange(), newEnvelope); - descriptor.setGridGeometry(newGridGeometry); - pane.getRenderableDisplay().scaleToClientArea(pane.getBounds()); - - // Stop any looping - editor.getLoopProperties().setLooping(false); - - // Construct a new gfe time match resource which is used to help - // establish gfe time matching - GFESystemResource basis = new GFESystemResource(this.dataManager); - basis.setDescriptor(descriptor); - descriptor.getResourceList().add(basis); - descriptor.getResourceList().getProperties(basis) - .setSystemResource(true); - descriptor.setNumberOfFrames(Integer.MAX_VALUE); - - // create the gfe color bar - GFEColorbarResource colorBar = new GFEColorbarResource( - this.dataManager); - colorBar.setDescriptor(descriptor); - descriptor.getResourceList().add(colorBar); - descriptor.getResourceList().getProperties(colorBar) - .setSystemResource(true); - - // create the gfe reference set - GFEReferenceSetResource refSetRsc = new GFEReferenceSetResource( - this.dataManager.getRefManager()); - refSetRsc.setDescriptor(descriptor); - descriptor.getResourceList().add(refSetRsc); - descriptor.getResourceList().getProperties(refSetRsc) - .setSystemResource(true); - Arrays.sort(parms); - for (int i = parms.length - 1; i >= 0; i--) { - createResourceFromParm(descriptor, parms[i], false); + for (IDisplayPane pane : editor.getDisplayPanes()) { + MapDescriptor descriptor = (MapDescriptor) pane.getDescriptor(); + descriptor.addFrameChangedListener(this); + + GridLocation gloc = parmManager.compositeGridLocation(); + GridGeometry2D gridGeometry = MapUtil.getGridGeometry(gloc); + Envelope envelope = gridGeometry.getEnvelope(); + double colorBarHeight = GFEColorbarResource.HEIGHT + * envelope.getSpan(1) / pane.getBounds().height; + + PythonPreferenceStore prefs = Activator.getDefault() + .getPreferenceStore(); + + double expandLeft = 10; + if (prefs.contains("OfficeDomain_expandLeft")) { + expandLeft = prefs.getDouble("OfficeDomain_expandLeft"); + } + double expandRight = 0.1; + if (prefs.contains("OfficeDomain_expandRight")) { + expandRight = prefs.getDouble("OfficeDomain_expandRight"); + } + double expandTop = 0.1; + if (prefs.contains("OfficeDomain_expandTop")) { + expandTop = prefs.getDouble("OfficeDomain_expandTop"); + } + double expandBottom = 0.1; + if (prefs.contains("OfficeDomain_expandBottom")) { + expandBottom = prefs.getDouble("OfficeDomain_expandBottom"); + } + + double dxLeft = (envelope.getSpan(0) * expandLeft / 100.0); + double dxRight = (envelope.getSpan(0) * expandRight / 100.0); + double dyTop = (envelope.getSpan(1) * expandTop / 100.0); + double dyBottom = (envelope.getSpan(1) * expandBottom / 100.0); + + GeneralEnvelope newEnvelope = new GeneralEnvelope( + envelope.getCoordinateReferenceSystem()); + newEnvelope.setRange(0, envelope.getMinimum(0) - dxLeft, + envelope.getMaximum(0) + dxRight); + newEnvelope.setRange(1, envelope.getMinimum(1) - dyBottom, + envelope.getMaximum(1) + colorBarHeight + dyTop); + GridGeometry2D newGridGeometry = new GridGeometry2D( + gridGeometry.getGridRange(), newEnvelope); + descriptor.setGridGeometry(newGridGeometry); + pane.getRenderableDisplay().scaleToClientArea(pane.getBounds()); + + // Stop any looping + editor.getLoopProperties().setLooping(false); + + // Construct a new gfe time match resource which is used to help + // establish gfe time matching + GFESystemResource basis = new GFESystemResource( + this.dataManager); + basis.setDescriptor(descriptor); + descriptor.getResourceList().add(basis); + descriptor.getResourceList().getProperties(basis) + .setSystemResource(true); + descriptor.setNumberOfFrames(Integer.MAX_VALUE); + + // create the gfe color bar + GFEColorbarResource colorBar = new GFEColorbarResource( + this.dataManager); + colorBar.setDescriptor(descriptor); + descriptor.getResourceList().add(colorBar); + descriptor.getResourceList().getProperties(colorBar) + .setSystemResource(true); + + // create the gfe reference set + GFEReferenceSetResource refSetRsc = new GFEReferenceSetResource( + this.dataManager.getRefManager()); + refSetRsc.setDescriptor(descriptor); + descriptor.getResourceList().add(refSetRsc); + descriptor.getResourceList().getProperties(refSetRsc) + .setSystemResource(true); + + for (int i = parms.length - 1; i >= 0; i--) { + createResourceFromParm(descriptor, parms[i], false); + } + + setSpatialEditorTime(descriptor, getSpatialEditorTime()); } - this.dataManager.getSampleSetManager().addSampleSetChangedListener( - sampleSetListener); - - this.isPopulated = true; + managedEditors.add(editor); } } @@ -315,59 +318,16 @@ public class GFESpatialDisplayManager extends AbstractSpatialDisplayManager * * @throws VizException */ - public void depopulate() throws VizException { + public void dispose() throws VizException { synchronized (this) { - this.dataManager.getSampleSetManager() - .removeSampleSetChangedListener(sampleSetListener); - this.dataManager.getParmManager() - .removeDisplayedParmListChangedListener(this); - this.isPopulated = false; + if (isRegistered) { + this.dataManager.getSampleSetManager() + .removeSampleSetChangedListener(sampleSetListener); + this.dataManager.getParmManager() + .removeDisplayedParmListChangedListener(this); + isRegistered = false; + } } - - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.viz.gfe.core.ISpatialDisplayManager#setSpatialEditorTime - * (java.util.Date) - */ - @Override - public void setSpatialEditorTime(Date date) { - super.setSpatialEditorTime(date); - - for (ISpatialEditorTimeChangedListener listener : spatialEditorTimeChangedListeners) { - listener.spatialEditorTimeChanged(date); - } - - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.viz.gfe.core.ISpatialDisplayManager#setGlobalTimeRange(com - * .raytheon.edex.plugin.time.TimeRange) - */ - @Override - public void setGlobalTimeRange(TimeRange timeRange) { - this.globalTimeRange = timeRange; - - for (IGlobalSelectionTRChangedListener listener : this.globalSelectionTRChangedListeners) { - listener.globalSelectionTRChanged(timeRange); - } - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.viz.gfe.core.ISpatialDisplayManager#getGlobalTimeRange() - */ - @Override - public TimeRange getGlobalTimeRange() { - return this.globalTimeRange; } /* @@ -376,84 +336,53 @@ public class GFESpatialDisplayManager extends AbstractSpatialDisplayManager * @see com.raytheon.viz.gfe.core.ISpatialDisplayManager#refresh() */ private void refresh() { - for (AbstractEditor editor : UiUtil.getEditors(window, GFE_PERSPECTIVE)) { - editor.refresh(); + for (IDescriptor desc : getDescriptors()) { + if (desc.getRenderableDisplay() != null) { + desc.getRenderableDisplay().refresh(); + } } } @Override public void displayedParmListChanged(Parm[] parms, Parm[] deletions, Parm[] additions) { - - AbstractEditor[] editors = UiUtil.getEditors(window, GFE_PERSPECTIVE); - for (AbstractEditor e : editors) { - IRenderableDisplay disp = e.getActiveDisplayPane() - .getRenderableDisplay(); - IDescriptor descriptor = disp.getDescriptor(); - - // put parms to delete in set for easy look up - Set parmsToDelete = new HashSet(); - for (Parm p : deletions) { - parmsToDelete.add(p); - } - - for (ResourcePair rp : descriptor.getResourceList()) { - AbstractVizResource rsc = rp.getResource(); - if (rsc instanceof GFEResource) { - GFEResource gfeRsc = (GFEResource) rsc; - - if (parmsToDelete.contains(gfeRsc.getParm())) { - descriptor.getResourceList().remove(rp); - } + Set toDelete = new HashSet(Arrays.asList(deletions)); + for (IDescriptor desc : getDescriptors()) { + ResourceList list = desc.getResourceList(); + List rscs = list + .getResourcesByTypeAsType(GFEResource.class); + for (GFEResource rsc : rscs) { + if (toDelete.contains(rsc.getParm())) { + list.removeRsc(rsc); } } for (Parm addParm : additions) { - createResourceFromParm(descriptor, addParm, false); + createResourceFromParm(desc, addParm, false); } } } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.drawables.IDescriptor.IFrameChangedListener# + * frameChanged(com.raytheon.uf.viz.core.drawables.IDescriptor, + * com.raytheon.uf.common.time.DataTime, + * com.raytheon.uf.common.time.DataTime) + */ @Override - public void toggleVisibility(Parm parm) { - AbstractEditor[] editors = UiUtil.getEditors(window, GFE_PERSPECTIVE); - if (editors.length == 0) { - return; + public void frameChanged(IDescriptor descriptor, DataTime oldTime, + DataTime newTime) { + if (newTime != null && oldTime != null && seTime != null + && oldTime.getRefTime().equals(seTime)) { + // time was set to seTime, frame changed, set seTime to null + setSpatialEditorTime(null); } - - for (AbstractEditor editor : editors) { - IDescriptor descriptor = editor.getActiveDisplayPane() - .getDescriptor(); - boolean needRefresh = false; - - ResourceList resourceList = descriptor.getResourceList(); - synchronized (resourceList) { - Iterator iterator = resourceList.iterator(); - - while (iterator.hasNext()) { - ResourcePair resourcePair = iterator.next(); - AbstractVizResource rsc = resourcePair.getResource(); - if (rsc instanceof GFEResource) { - Parm p = ((GFEResource) rsc).getParm(); - if (p.equals(parm)) { - ResourceProperties props = resourcePair - .getProperties(); - boolean visible = !props.isVisible(); - props.setVisible(visible); - needRefresh = true; - - for (IGridVisibilityChangedListener listener : gridVisibilityChangedListeners) { - listener.gridVisibilityChanged(p, visible, - false); - } - } - } - } - } - - if (needRefresh) { - editor.refresh(); - } + for (ISpatialEditorTimeChangedListener subListener : spatialEditorTimeChangedListeners) { + subListener.spatialEditorTimeChanged(newTime != null ? newTime + .getRefTime() : null); } } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/OffscreenSpatialDisplayManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/OffscreenSpatialDisplayManager.java index 16137c49ff..3fb03eefd6 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/OffscreenSpatialDisplayManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/OffscreenSpatialDisplayManager.java @@ -19,12 +19,9 @@ **/ package com.raytheon.viz.gfe.core.internal; -import org.eclipse.ui.IWorkbenchWindow; - -import com.raytheon.uf.common.time.TimeRange; -import com.raytheon.uf.viz.core.map.MapDescriptor; +import com.raytheon.uf.viz.core.drawables.IDescriptor; +import com.raytheon.uf.viz.core.drawables.IRenderableDisplay; import com.raytheon.viz.gfe.core.DataManager; -import com.raytheon.viz.gfe.core.parm.Parm; /** * Spatial display manager for working offscreen without a display, i.e. with @@ -46,58 +43,17 @@ import com.raytheon.viz.gfe.core.parm.Parm; public class OffscreenSpatialDisplayManager extends AbstractSpatialDisplayManager { - private MapDescriptor descriptor; + private IRenderableDisplay display; - public OffscreenSpatialDisplayManager(IWorkbenchWindow window, + public OffscreenSpatialDisplayManager(IRenderableDisplay display, DataManager mgr) { super(mgr); + this.display = display; } @Override - protected MapDescriptor[] getDescriptors() { - return new MapDescriptor[] { descriptor }; - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.viz.gfe.core.ISpatialDisplayManager#getGlobalTimeRange() - */ - @Override - public TimeRange getGlobalTimeRange() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.viz.gfe.core.ISpatialDisplayManager#toggleVisibility(com - * .raytheon .viz.gfe.core.parm.Parm) - */ - @Override - public void toggleVisibility(Parm parm) { - // TODO Auto-generated method stub - - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.viz.gfe.core.ISpatialDisplayManager#setGlobalTimeRange(com - * .raytheon.uf.common.time.TimeRange) - */ - @Override - public void setGlobalTimeRange(TimeRange timeRange) { - // TODO Auto-generated method stub - - } - - public void setDescriptor(MapDescriptor desc) { - descriptor = desc; + protected IDescriptor[] getDescriptors() { + return new IDescriptor[] { display.getDescriptor() }; } } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/msgs/ICurrentDataManagerChangedListener.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/msgs/ICurrentDataManagerChangedListener.java deleted file mode 100644 index bb110ce333..0000000000 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/msgs/ICurrentDataManagerChangedListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.viz.gfe.core.msgs; - -/** - * - * Defines a listener that is called when the current datamanager changes - * - *
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * 03/12/2008              chammack    Initial Creation.
- * 
- * 
- * - * @author chammack - * @version 1.0 - */ - -public interface ICurrentDataManagerChangedListener { - - public void currentDataManagerChanged( - com.raytheon.viz.gfe.core.DataManager newDataManager); -} diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridBar.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridBar.java index 558e5f1cbb..f738e338d8 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridBar.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridBar.java @@ -1469,7 +1469,6 @@ public class GridBar implements IMessageClient, IParmInventoryChangedListener, @Override public void parmInventoryChanged(Parm parm, TimeRange timeRange) { // System.out.println("parmInventoryChanged for " + this); - canvas.calcStepTimes(); if (this.parm.equals(parm) && this.gridManager.checkVisibility(timeRange)) { redraw(); @@ -1510,7 +1509,6 @@ public class GridBar implements IMessageClient, IParmInventoryChangedListener, if (desiredVisiblity != parmVisible) { parmVisible = desiredVisiblity; // System.out.println("gridVisibilityChanged for " + this); - canvas.calcStepTimes(); redraw(); } } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridCanvas.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridCanvas.java index 9aa7856b45..fb3813d64f 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridCanvas.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridCanvas.java @@ -272,8 +272,6 @@ public class GridCanvas extends Canvas implements IMessageClient { private int separatorPosition = 0; - private List stepTimes; - private boolean quickviewMode; private GridID quickviewGrid; @@ -736,8 +734,6 @@ public class GridCanvas extends Canvas implements IMessageClient { } } - calcStepTimes(); - resize(); } @@ -908,96 +904,6 @@ public class GridCanvas extends Canvas implements IMessageClient { } } - public void nextSelectedGrid() { - Date seTime = gridManager.getSelectedTime(); - Date time = null; - for (Date stepTime : stepTimes) { - if (seTime.before(stepTime)) { - time = stepTime; - break; - } - } - - if (time == null && stepTimes.size() > 0) { - time = stepTimes.get(0); - } - - if (time != null) { - gridManager.setSelectedTime(time); - gridManager.syncSelectTR(time); - } - } - - public void previousSelectedGrid() { - - Date seTime = gridManager.getSelectedTime(); - Date time = null; - for (int i = stepTimes.size() - 1; i >= 0; i--) { - Date stepTime = stepTimes.get(i); - if (seTime.after(stepTime)) { - time = stepTime; - break; - } - } - - if (time == null && stepTimes.size() > 0) { - time = stepTimes.get(stepTimes.size() - 1); - } - - if (time != null) { - gridManager.setSelectedTime(time); - gridManager.syncSelectTR(time); - } - - return; - } - - public void firstSelectedGrid() { - Date time = null; - - if (time == null && stepTimes.size() > 0) { - time = stepTimes.get(0); - } - - if (time != null) { - gridManager.setSelectedTime(time); - gridManager.syncSelectTR(time); - } - } - - public void lastSelectedGrid() { - Date time = null; - - if (time == null && stepTimes.size() > 0) { - time = stepTimes.get(stepTimes.size() - 1); - } - - if (time != null) { - gridManager.setSelectedTime(time); - gridManager.syncSelectTR(time); - } - } - - public void calcStepTimes() { - ArrayList parms = new ArrayList(); - for (GridBar gridBar : gridBarList) { - if (gridBar.isParmVisible()) { - Parm p = gridBar.getParm(); - if (!parms.contains(p)) { - parms.add(p); - } - - // TODO ISC? - // p = view.iscGridID().parm(); - // if (!parms.contains(p)) { - // parms.add(p); - // } - } - } - stepTimes = dataMgr.getParmManager().calcStepTimes(parms, - new TimeRange()); - } - /** * @param e */ diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridManager.java index 1daf497a0d..efd3ea9c45 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/GridManager.java @@ -52,6 +52,7 @@ import com.raytheon.uf.viz.core.VizApp; import com.raytheon.viz.gfe.Activator; import com.raytheon.viz.gfe.core.DataManager; import com.raytheon.viz.gfe.core.griddata.IGridData; +import com.raytheon.viz.gfe.core.msgs.ISpatialEditorTimeChangedListener; import com.raytheon.viz.gfe.core.msgs.ISystemTimeRangeChangedListener; import com.raytheon.viz.gfe.core.parm.Parm; import com.raytheon.viz.gfe.edittool.GridID; @@ -73,7 +74,8 @@ import com.raytheon.viz.gfe.temporaleditor.TemporalEditor; * @version 1.0 */ -public class GridManager implements IGridManager { +public class GridManager implements IGridManager, + ISpatialEditorTimeChangedListener { /** * Job to scroll the grid manager horizontally */ @@ -234,15 +236,6 @@ public class GridManager implements IGridManager { private ScrolledComposite teScrolledComp; - private Date selectedTime; - - /** - * @return the selectedTime - */ - public Date getSelectedTime() { - return selectedTime; - } - private DataManager dataManager; private int widthIncrement; @@ -554,6 +547,9 @@ public class GridManager implements IGridManager { if (updateJob.getState() == Job.NONE) { updateJob.schedule(); } + + dataManager.getSpatialDisplayManager() + .addSpatialEditorTimeChangedListener(this); } public TimeRange getVisibleTimeRange() { @@ -652,26 +648,6 @@ public class GridManager implements IGridManager { } } - @Override - public void nextSelectedGrid() { - gridCanvas.nextSelectedGrid(); - } - - @Override - public void previousSelectedGrid() { - gridCanvas.previousSelectedGrid(); - } - - @Override - public void firstSelectedGrid() { - gridCanvas.firstSelectedGrid(); - } - - @Override - public void lastSelectedGrid() { - gridCanvas.lastSelectedGrid(); - } - protected void startScrolling(int i) { scrollJob.setIncrement(i); scrollJob.schedule(); @@ -751,12 +727,18 @@ public class GridManager implements IGridManager { @Override public void setSelectedTime(Date selectedTime) { - this.selectedTime = selectedTime; dataManager.getSpatialDisplayManager().setSpatialEditorTime( selectedTime); redraw(); } + /** + * @return the selectedTime + */ + public Date getSelectedTime() { + return dataManager.getSpatialDisplayManager().getSpatialEditorTime(); + } + protected void syncSelectTR(Date t) { // Use a selection tr of 1 hour duration if no active parm, // if active parm and no grid, use the parm's time constraint, @@ -809,4 +791,16 @@ public class GridManager implements IGridManager { service.refreshElements( "com.raytheon.viz.gfe.actions.SelectGridsWhenStepping", null); } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.gfe.core.msgs.ISpatialEditorTimeChangedListener# + * spatialEditorTimeChanged(java.util.Date) + */ + @Override + public void spatialEditorTimeChanged(Date date) { + syncSelectTR(date); + redraw(); + } } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/IGridManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/IGridManager.java index 81fdc4969f..2e8c77fa47 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/IGridManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/IGridManager.java @@ -59,32 +59,6 @@ public interface IGridManager { */ public void contractTimeScale(); - /** - * Moves the selected grid to the next selected grid or if at the end of the - * list selects the first grid in the list. - * - */ - public void nextSelectedGrid(); - - /** - * Moves the selected grid to the previous selected grid or if at the - * beginning of the list selects the last grid in the list. - * - */ - public void previousSelectedGrid(); - - /** - * Moves the selected grid to the first selected grid. - * - */ - public void firstSelectedGrid(); - - /** - * Moves the selected grid to the last selected grid. - * - */ - public void lastSelectedGrid(); - /** * Paints the TimeScale and all of the GridBars. */ diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/action/GFEFrameTool.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/action/GFEFrameTool.java deleted file mode 100644 index da1b8157a8..0000000000 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/gridmanager/action/GFEFrameTool.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.viz.gfe.gridmanager.action; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; - -import com.raytheon.uf.viz.core.drawables.IFrameCoordinator.FrameChangeOperation; -import com.raytheon.viz.gfe.core.DataManager; -import com.raytheon.viz.gfe.gridmanager.IGridManager; -import com.raytheon.viz.ui.tools.AbstractTool; - -/** - * Implements the frame tool events for GFE - * - * GFE only defines single step frame operations in forward and reverse, the - * rest of the operations are no-op. - * - *
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * 03/26/2008              chammack    Initial Creation.
- * 
- * 
- * - * @author chammack - * @version 1.0 - */ - -public class GFEFrameTool extends AbstractTool { - /* - * (non-Javadoc) - * - * @see - * com.raytheon.viz.ui.tools.AbstractTool#execute(org.eclipse.core.commands - * .ExecutionEvent) - */ - @Override - public Object execute(ExecutionEvent arg0) throws ExecutionException { - - String operationStr = arg0.getParameter("operation"); - FrameChangeOperation operation = FrameChangeOperation - .valueOf(operationStr); - - IGridManager gm = DataManager.getCurrentInstance().getGridManager(); - - switch (operation) { - case PREVIOUS: - gm.previousSelectedGrid(); - break; - case NEXT: - gm.nextSelectedGrid(); - break; - case FIRST: - gm.firstSelectedGrid(); - break; - case LAST: - gm.lastSelectedGrid(); - break; - } - - gm.redraw(); - - return null; - - } - -} diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/ifpimage/ImageLegendResource.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/ifpimage/ImageLegendResource.java index b6d756aeae..9ef5676f0c 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/ifpimage/ImageLegendResource.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/ifpimage/ImageLegendResource.java @@ -21,7 +21,7 @@ package com.raytheon.viz.gfe.ifpimage; import java.util.ArrayList; import java.util.Calendar; -import java.util.Date; +import java.util.Collection; import java.util.Formatter; import java.util.HashMap; import java.util.List; @@ -35,6 +35,7 @@ import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.common.time.TimeRange; import com.raytheon.uf.viz.core.RGBColors; import com.raytheon.uf.viz.core.drawables.IDescriptor; +import com.raytheon.uf.viz.core.drawables.IDescriptor.FramesInfo; import com.raytheon.uf.viz.core.drawables.ResourcePair; import com.raytheon.uf.viz.core.rsc.ResourceProperties; import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability; @@ -99,13 +100,9 @@ public class ImageLegendResource extends GFELegendResource { @Override public LegendEntry[] getLegendData(IDescriptor descriptor) { - Date date = this.dataManager.getSpatialDisplayManager() - .getSpatialEditorTime(); - DataTime dt = new DataTime(date); - - Parm[] parms = orderParms(descriptor); - - LegendData[] data = makeLegend(parms, dt); + Map parmRscMap = new HashMap(); + Collection parms = getLegendOrderedParms(descriptor, parmRscMap); + LegendData[] data = makeLegend(parms, parmRscMap); LegendEntry[] entries = new LegendEntry[data.length]; for (int i = 0; i < entries.length; ++i) { @@ -116,18 +113,23 @@ public class ImageLegendResource extends GFELegendResource { return entries; } - private LegendData[] makeLegend(Parm[] parms, DataTime curTime) { + private LegendData[] makeLegend(Collection parms, + Map parmRscMap) { + FramesInfo currInfo = descriptor.getFramesInfo(); + DataTime curTime = currInfo.getCurrentFrame(); + // loop through the grids List legendData = new ArrayList(); - for (int i = parms.length - 1; i >= 0; i--) { - Parm parm = parms[i]; - String parmName = parm.getParmID().getParmName(); - ResourcePair rp = this.parmToRscMap.get(parm); + for (Parm parm : parms) { + ResourcePair rp = parmRscMap.get(parm); GFEResource rsc = (GFEResource) rp.getResource(); + String parmName = parm.getParmID().getParmName(); ResourceProperties props = rp.getProperties(); LegendData data = new LegendData(); data.resource = rp; + DataTime curRscTime = currInfo.getTimeForResource(rsc); + // color for the text if ((props.isVisible()) && (parm.getDisplayAttributes().getVisMode() == VisMode.IMAGE)) { @@ -175,36 +177,32 @@ public class ImageLegendResource extends GFELegendResource { snap.setTimeZone(TimeZone.getTimeZone(tz)); formatter.format(snapshotFormat.replaceAll("\\%", "%1\\$t"), snap); - } else { - // get the valid time for the grid, get the time format - gd = rsc.getParm().getGridInventory(curTime.getValidPeriod()); - if (gd.length > 0) { - TimeRange tr = gd[0].getGridTime(); - if (durationFormat != null) { - timeString += durationString(tr); - } - if (startFormat != null) { - Calendar start = Calendar.getInstance(); - start.setTimeZone(TimeZone.getTimeZone(tz)); - start.setTime(tr.getStart()); - formatter.format( - startFormat.replaceAll("\\%", "%1\\$t"), start); - } - if (endFormat != null) { - Calendar end = Calendar.getInstance(); - end.setTimeZone(TimeZone.getTimeZone(tz)); - end.setTime(tr.getEnd()); - formatter.format(endFormat.replaceAll("\\%", "%1\\$t"), - end); - } - + } else if (curRscTime != null) { + TimeRange tr = curRscTime.getValidPeriod(); + if (durationFormat != null) { + timeString += durationString(tr); } + if (startFormat != null) { + Calendar start = Calendar.getInstance(); + start.setTimeZone(TimeZone.getTimeZone(tz)); + start.setTime(tr.getStart()); + formatter.format(startFormat.replaceAll("\\%", "%1\\$t"), + start); + } + if (endFormat != null) { + Calendar end = Calendar.getInstance(); + end.setTimeZone(TimeZone.getTimeZone(tz)); + end.setTime(tr.getEnd()); + formatter + .format(endFormat.replaceAll("\\%", "%1\\$t"), end); + } + } timeString += formatter.toString(); timeString = timeString.replaceAll("\\[UNITS\\]", units); - if (snapshotTime || gd.length > 0) { + if (snapshotTime || curRscTime != null) { // now prefix the parameter name String name = null; diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/perspective/GFEPerspectiveManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/perspective/GFEPerspectiveManager.java index 712f93f141..9902f4f472 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/perspective/GFEPerspectiveManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/perspective/GFEPerspectiveManager.java @@ -46,8 +46,6 @@ import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.IDisplayPaneContainer; -import com.raytheon.uf.viz.core.IExtent; -import com.raytheon.uf.viz.core.PixelExtent; import com.raytheon.uf.viz.core.RGBColors; import com.raytheon.uf.viz.core.drawables.IRenderableDisplay; import com.raytheon.uf.viz.core.drawables.ResourcePair; @@ -58,6 +56,7 @@ import com.raytheon.viz.gfe.Activator; import com.raytheon.viz.gfe.PythonPreferenceStore; import com.raytheon.viz.gfe.actions.FormatterlauncherAction; import com.raytheon.viz.gfe.core.DataManager; +import com.raytheon.viz.gfe.core.DataManagerUIFactory; import com.raytheon.viz.gfe.core.GFEMapRenderableDisplay; import com.raytheon.viz.gfe.core.ISpatialDisplayManager; import com.raytheon.viz.gfe.core.internal.GFESpatialDisplayManager; @@ -144,7 +143,7 @@ public class GFEPerspectiveManager extends AbstractCAVEPerspectiveManager { keybindingsCreated = true; } - DataManager dm = DataManager.getInstance(perspectiveWindow); + DataManager dm = DataManagerUIFactory.getInstance(perspectiveWindow); IRenderableDisplay display = pane.getRenderableDisplay(); if (display instanceof GFEMapRenderableDisplay) { ((GFEMapRenderableDisplay) display).setDataManager(dm); @@ -176,16 +175,12 @@ public class GFEPerspectiveManager extends AbstractCAVEPerspectiveManager { + GFESpatialDisplayManager.class.getName()); } } - - DataManager.fireChangeListener(); } @Override public void activate() { super.activate(); - DataManager.fireChangeListener(); - // Hack to disable editor closing IWorkbenchPage activePage = perspectiveWindow.getActivePage(); if (activePage != null) { @@ -220,11 +215,12 @@ public class GFEPerspectiveManager extends AbstractCAVEPerspectiveManager { super.close(); try { - DataManager dm = DataManager.findInstance(perspectiveWindow); + DataManager dm = DataManagerUIFactory + .findInstance(perspectiveWindow); if (dm != null) { ISpatialDisplayManager mgr = dm.getSpatialDisplayManager(); if (mgr instanceof GFESpatialDisplayManager) { - ((GFESpatialDisplayManager) mgr).depopulate(); + ((GFESpatialDisplayManager) mgr).dispose(); } else { throw new IllegalStateException(this.getClass().getName() + " must be used with " @@ -237,7 +233,7 @@ public class GFEPerspectiveManager extends AbstractCAVEPerspectiveManager { e); } - DataManager.dispose(perspectiveWindow); + DataManagerUIFactory.dispose(perspectiveWindow); // Put on own thread so close is not slowed down. new Thread(new Runnable() { @@ -408,30 +404,6 @@ public class GFEPerspectiveManager extends AbstractCAVEPerspectiveManager { public void addContextMenuItems(IMenuManager menuManager, IDisplayPaneContainer container, IDisplayPane pane) { super.addContextMenuItems(menuManager, container, pane); - - DataManager dataManager = DataManager.getCurrentInstance(); - if (dataManager != null) { - // Don't add menu items for the resource if mouse is in the colorbar - - // code for corrected mouse X and Y copied from - // GFEColorbarResource - IDisplayPane displayPane = container.getActiveDisplayPane(); - int x = displayPane.getLastClickX(); - int y = displayPane.getLastClickY(); - org.eclipse.swt.graphics.Rectangle bounds = displayPane.getBounds(); - IExtent extent = displayPane.getRenderableDisplay().getExtent(); - double correctedX = x * (extent.getMaxX() - extent.getMinX()) - / bounds.width + extent.getMinX(); - double correctedY = y * (extent.getMaxY() - extent.getMinY()) - / bounds.height + extent.getMinY(); - - PixelExtent colorBarExtent = dataManager.getSpatialDisplayManager() - .getColorbarExtent(); - if (colorBarExtent != null - && colorBarExtent.contains(correctedX, correctedY)) { - return; - } - } menuManager.add(new ZoomMenuAction(container)); } } diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/GFELegendResource.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/GFELegendResource.java index 8a6fd10cb1..ce10249422 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/GFELegendResource.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/GFELegendResource.java @@ -21,24 +21,22 @@ package com.raytheon.viz.gfe.rsc; import static com.raytheon.viz.gfe.core.parm.ParmDisplayAttributes.VisMode.IMAGE; -import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TimeZone; -import java.util.WeakHashMap; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.RGB; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; -import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -48,6 +46,7 @@ import com.raytheon.uf.viz.core.IDisplayPaneContainer; import com.raytheon.uf.viz.core.IGraphicsTarget; import com.raytheon.uf.viz.core.RGBColors; import com.raytheon.uf.viz.core.drawables.IDescriptor; +import com.raytheon.uf.viz.core.drawables.IDescriptor.FramesInfo; import com.raytheon.uf.viz.core.drawables.IFont; import com.raytheon.uf.viz.core.drawables.ResourcePair; import com.raytheon.uf.viz.core.exception.VizException; @@ -74,9 +73,9 @@ import com.raytheon.viz.gfe.edittool.GridID; import com.raytheon.viz.ui.input.InputAdapter; /** - * + * * Port of SELegendVisual from AWIPS I GFE - * + * *
  * SOFTWARE HISTORY
  * Date         Ticket#    Engineer    Description
@@ -85,7 +84,7 @@ import com.raytheon.viz.ui.input.InputAdapter;
  * 08/19/2009   2547       rjpeter     Implement Test/Prac database display.
  * 07/10/2012   15186      ryu         Clean up initInternal per Ron
  * 
- * + * * @author chammack * @version 1.0 */ @@ -107,7 +106,7 @@ public class GFELegendResource extends /* * (non-Javadoc) - * + * * @see java.lang.Enum#toString() */ @Override @@ -222,8 +221,6 @@ public class GFELegendResource extends protected IGraphicsTarget lastTarget; - protected Map parmToRscMap; - private GridID qvGrid; private IInputHandler handler = new GFELegendInputHandler(); @@ -252,7 +249,6 @@ public class GFELegendResource extends resourceDateFormat = new SimpleDateFormat("E HH'Z' dd-MMM-yy"); resourceDateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); this.dataManager = dataManager; - parmToRscMap = new WeakHashMap(); String s = Activator.getDefault().getPreferenceStore() .getString("LegendMode"); @@ -273,7 +269,7 @@ public class GFELegendResource extends /* * (non-Javadoc) - * + * * @see java.lang.Object#finalize() */ @SuppressWarnings("unchecked") @@ -290,7 +286,7 @@ public class GFELegendResource extends /* * (non-Javadoc) - * + * * @see * com.raytheon.viz.core.legend.ILegendDecorator#getLegendData(com.raytheon * .viz.core.drawables.IDescriptor) @@ -322,27 +318,55 @@ public class GFELegendResource extends } + /** + * Gets an ordered collection of Parms to display for the legend. + * + * @param descriptor + * @param parmRscMap + * optional map to create Parm->ResourcePair mapping for parms + * returned + * @return + */ + protected Collection getLegendOrderedParms(IDescriptor descriptor, + Map parmRscMap) { + List parms = new ArrayList(); + for (ResourcePair rp : descriptor.getResourceList()) { + if (rp.getResource() instanceof GFEResource) { + Parm parm = ((GFEResource) rp.getResource()).getParm(); + if (qvGrid == null + || (qvGrid != null && qvGrid.getParm() == parm)) { + parms.add(parm); + if (parmRscMap != null) { + parmRscMap.put(parm, rp); + } + if (qvGrid != null) { + break; + } + } + } + } + + Collections.sort(parms); + Collections.reverse(parms); + return parms; + } + private LegendData[] getLegendDataGrids(IDescriptor descriptor) { int lengthOfTime = "144h Tue 19Z 12-Sep-06".length(); List legendDataList = new ArrayList(); - Date date = this.dataManager.getSpatialDisplayManager() - .getSpatialEditorTime(); - DataTime dt = new DataTime(date); + FramesInfo currInfo = descriptor.getFramesInfo(); Parm activeParm = dataManager.getSpatialDisplayManager() .getActivatedParm(); StringBuilder labelBuilder = new StringBuilder(); - Parm[] parms; + Map parmRscMap = new HashMap(); + Collection parms = getLegendOrderedParms(descriptor, parmRscMap); Parm qvParm = null; - if (qvGrid == null) { - parms = orderParms(descriptor); - } else { + if (qvGrid != null) { qvParm = qvGrid.getParm(); - parms = new Parm[] { qvParm }; - dt = new DataTime(qvGrid.getDate()); } int[] lengths = getLongestFields(parms); @@ -350,12 +374,11 @@ public class GFELegendResource extends ParmID topoID = dataManager.getTopoManager().getCompositeParmID(); // Topmost resources: GFE Parms - for (int i = parms.length - 1; i >= 0; i--) { - Parm parm = parms[i]; + for (Parm parm : parms) { ParmID parmId = parm.getParmID(); DatabaseID dbId = parmId.getDbId(); StringBuilder sb = new StringBuilder(); - ResourcePair rp = parmToRscMap.get(parm); + ResourcePair rp = parmRscMap.get(parm); GFEResource rsc = (GFEResource) rp.getResource(); LegendData ld = new LegendData(); ResourceProperties props = rp.getProperties(); @@ -450,25 +473,19 @@ public class GFELegendResource extends addSpaces(sb, diff + 3); labelBuilder.setLength(0); - if (dt != null) { - IGridData[] gd = parm.getGridInventory(dt.getValidPeriod()); - if ((gd == null) || (gd.length == 0)) { - labelBuilder.append(" "); - } else if (!parm.getGridInfo().isTimeIndependentParm()) { - TimeRange tr = gd[0].getGridTime(); + if (parm.getGridInfo().isTimeIndependentParm()) { + labelBuilder.append(" Persistent"); + } else { + DataTime currRscTime = currInfo.getTimeForResource(rsc); + if (currRscTime != null) { + TimeRange tr = currRscTime.getValidPeriod(); labelBuilder.append(String.format("%3d", tr.getDuration() / 3600000)); labelBuilder.append("h "); labelBuilder.append(resourceDateFormat.format(tr .getStart())); } else { - labelBuilder.append(" Persistent"); - } - - } - if (labelBuilder.length() == 0) { - if (parm.getGridInfo().isTimeIndependentParm()) { - labelBuilder.append(" Persistent"); + labelBuilder.append(" "); } } @@ -528,7 +545,7 @@ public class GFELegendResource extends /** * Get the legend mode - * + * * @return the legend mode */ public LegendMode getLegendMode() { @@ -538,14 +555,14 @@ public class GFELegendResource extends /** * Works in a single pass to perform the operations performed in AWIPS I * getLargestLevelName, etc. - * + * * The fields in order:
  • FieldName
  • LevelName
  • Units
  • ModelName - * - * + * + * * @param descriptor * @return */ - private int[] getLongestFields(Parm[] parms) { + private int[] getLongestFields(Collection parms) { // Iterator rl = descriptor.getResourceList().iterator(); int[] sz = new int[4]; StringBuilder labelBuilder = new StringBuilder(); @@ -604,34 +621,6 @@ public class GFELegendResource extends return sz; } - /** - * Create a map between parms and gfe resources. This will avoid expensive - * searching - * - * @param descriptor - * @return - */ - protected Parm[] orderParms(IDescriptor descriptor) { - Iterator rl = descriptor.getResourceList().iterator(); - - parmToRscMap.clear(); - while (rl.hasNext()) { - ResourcePair rp = rl.next(); - if (rp.getResource() instanceof GFEResource) { - GFEResource gfeRsc = (GFEResource) rp.getResource(); - parmToRscMap.put(gfeRsc.getParm(), rp); - } - } - - // Now sort the parms in the proper order - // This will put them in the desired order, even if the actual order has - // been changed to facilitate proper rendering order - Parm[] parms = parmToRscMap.keySet().toArray( - new Parm[parmToRscMap.size()]); - Arrays.sort(parms); - return parms; - } - @Override protected void disposeInternal() { super.disposeInternal(); @@ -677,7 +666,7 @@ public class GFELegendResource extends /** * Set the legend mode - * + * * @param mode * the legend mode */ @@ -688,7 +677,7 @@ public class GFELegendResource extends /* * (non-Javadoc) - * + * * @see * com.raytheon.viz.gfe.core.msgs.Message.IMessageClient#receiveMessage( * com.raytheon.viz.gfe.core.msgs.Message) diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/GFEResource.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/GFEResource.java index 2dd9895521..2cd4701aec 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/GFEResource.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/GFEResource.java @@ -105,6 +105,7 @@ import com.raytheon.uf.viz.core.rsc.capabilities.ImagingCapability; import com.raytheon.uf.viz.core.rsc.capabilities.MagnificationCapability; import com.raytheon.uf.viz.core.rsc.capabilities.OutlineCapability; import com.raytheon.uf.viz.core.style.LabelingPreferences; +import com.raytheon.uf.viz.core.time.TimeMatchingJob; import com.raytheon.viz.core.contours.rsc.displays.GriddedContourDisplay; import com.raytheon.viz.core.contours.rsc.displays.GriddedVectorDisplay; import com.raytheon.viz.core.rsc.displays.GriddedImageDisplay; @@ -253,6 +254,7 @@ public class GFEResource extends @Override public void parmInventoryChanged(Parm parm, TimeRange timeRange) { resetFrame(timeRange); + TimeMatchingJob.scheduleTimeMatch(getDescriptor()); } }; @@ -309,7 +311,6 @@ public class GFEResource extends lastIscMode = dataManager.getParmManager().iscMode(); updateRightClickMenu(); - } public void reset() { diff --git a/cave/com.raytheon.viz.gfe/tests/com/raytheon/viz/gfe/core/FakeDataManager.java b/cave/com.raytheon.viz.gfe/tests/com/raytheon/viz/gfe/core/FakeDataManager.java index c2da335e94..4ae16f25fa 100644 --- a/cave/com.raytheon.viz.gfe/tests/com/raytheon/viz/gfe/core/FakeDataManager.java +++ b/cave/com.raytheon.viz.gfe/tests/com/raytheon/viz/gfe/core/FakeDataManager.java @@ -72,7 +72,7 @@ public class FakeDataManager extends DataManager { private AutoSaveJob autoSaveJob; public FakeDataManager() throws GFEServerException { - super(); + super(new DataManagerOffscreenFactory(), null); parmManager = super.getParmManager(); spatialDisplayManager = super.getSpatialDisplayManager(); parmOp = super.getParmOp();