From 4523a2702572497d1c500c0d4c82bdfab6cfb1d9 Mon Sep 17 00:00:00 2001 From: Brad Gonzales Date: Wed, 23 Oct 2013 13:48:07 -0500 Subject: [PATCH] Issue #2303 Fixed CAVE status messaging by fixing the setting of the UFStatus factory handler. Amend: Also applied old patch to fix tool tips on message bar. Change-Id: I2f83bbd07be9cb07d51c23a7e068144692f44771 Former-commit-id: 104b17b0511eebf732e1255be064dd8c67567119 [formerly 3a450cd3c07af00e411c189955a7c170181e29c1] [formerly df1e60b07885191bd0f47c1a58285a34cabe6f42] [formerly df1e60b07885191bd0f47c1a58285a34cabe6f42 [formerly 60d7a13afd898b3d60a0d5945fc1546aea7a586a]] [formerly 104b17b0511eebf732e1255be064dd8c67567119 [formerly 3a450cd3c07af00e411c189955a7c170181e29c1] [formerly df1e60b07885191bd0f47c1a58285a34cabe6f42] [formerly df1e60b07885191bd0f47c1a58285a34cabe6f42 [formerly 60d7a13afd898b3d60a0d5945fc1546aea7a586a]] [formerly e3883dba15f62aa98d2e52fa7620cad9709582d7 [formerly df1e60b07885191bd0f47c1a58285a34cabe6f42 [formerly 60d7a13afd898b3d60a0d5945fc1546aea7a586a] [formerly e3883dba15f62aa98d2e52fa7620cad9709582d7 [formerly 3abca4ca950facaaa5a29cf2aaa6fccdcf469e95]]]]] Former-commit-id: e3883dba15f62aa98d2e52fa7620cad9709582d7 Former-commit-id: df70a63e208b8b395b3e29d62bf99c7465233d8c [formerly a6b82470ebf11c6ed11b9acf83e0e09c47d1dc54] [formerly 086dfe9ebcc2da1dd63b085ea694471b68f696c5] [formerly 5e613975e595926f8eec9c465a68d10cf9748a36 [formerly 626bc6ac4ce722cbc6c9e2cd43b6ed575ca56112] [formerly 086dfe9ebcc2da1dd63b085ea694471b68f696c5 [formerly b8cd1d5446e322d21d60d8679a73818243cc2c66]]] Former-commit-id: e73c753631887df715367e2956d4d165f598d784 [formerly 1ca501591be07777618ac2ea857a9cccc4228ac9] [formerly f71babda9a79dbde5171ba8b537a9ffb345f0224 [formerly 5b5bb8975df2d9dcc1afcf0974415ecfa712553a]] Former-commit-id: 8ac93d46072fc88d26b688d9e9e01a5dec5719dd [formerly f71babda9a79dbde5171ba8b537a9ffb345f0224] Former-commit-id: 17fe979698444c106b516a3e8fb589b979f25e24 --- .../ui/dialogs/AlertVisConfigDlg.java | 33 +++- .../alertviz/ui/dialogs/MonitorToolTip.java | 63 +++---- .../uf/viz/core/status/VizStatusHandler.java | 177 ------------------ .../core/status/VizStatusHandlerFactory.java | 26 ++- .../common/status/AbstractHandlerFactory.java | 34 ++++ .../status/DefaultStatusHandlerFactory.java | 14 +- .../status/IUFStatusHandlerFactory.java | 7 + ...rStatusHandler.java => StatusHandler.java} | 59 +++--- .../raytheon/uf/common/status/UFStatus.java | 37 ++-- 9 files changed, 185 insertions(+), 265 deletions(-) delete mode 100644 cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/status/VizStatusHandler.java rename edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/{SysErrStatusHandler.java => StatusHandler.java} (84%) diff --git a/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/AlertVisConfigDlg.java b/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/AlertVisConfigDlg.java index cf13556683..e08bee1378 100644 --- a/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/AlertVisConfigDlg.java +++ b/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/AlertVisConfigDlg.java @@ -27,6 +27,8 @@ import java.util.Map; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackAdapter; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Color; @@ -97,6 +99,7 @@ import com.raytheon.uf.viz.alertviz.ui.dialogs.ConfigurationFileDlg.Function; * item update; * 07 Feb 2013 15490 Xiaochuan Past this object to LayoutControlsComp. * 26 Aug 2013 #2293 lvenable Fixed color memory leak and cleaned up some code. + * 23 Oct 2013 2303 bgonzale Old patch to fix tool tip layout. * * * @@ -392,6 +395,11 @@ public class AlertVisConfigDlg extends Dialog implements mttLayout = new MonitorToolTip(layoutGroup, true); layoutControls = new LayoutControlsComp(layoutGroup, configData, this, this); + layoutGroup.addMouseTrackListener(new MouseTrackAdapter() { + public void mouseHover(MouseEvent e) { + mttLayout.open(); + } + }); } /** @@ -409,6 +417,11 @@ public class AlertVisConfigDlg extends Dialog implements mttCommonSetting = new MonitorToolTip(commonSettingsGroup, true); + commonSettingsGroup.addMouseTrackListener(new MouseTrackAdapter() { + public void mouseHover(MouseEvent e) { + mttCommonSetting.open(); + } + }); createCommonSettingsControls(commonSettingsGroup); } @@ -616,7 +629,13 @@ public class AlertVisConfigDlg extends Dialog implements sourcesLbl.setData(MonitorToolTip.tooltipTextKey, getSourcesToolTipText()); - mttSource = new MonitorToolTip(sourcesLbl, true); + mttSource = new MonitorToolTip(sourcesLbl, false); + + sourcesLbl.addMouseTrackListener(new MouseTrackAdapter() { + public void mouseHover(MouseEvent e) { + mttSource.open(); + } + }); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.widthHint = 125; @@ -842,13 +861,13 @@ public class AlertVisConfigDlg extends Dialog implements priorityLbl.setData(MonitorToolTip.tooltipTextKey, getPrioritiesToolTipText()); - mttPriorities = new MonitorToolTip(priorityLbl, true); + mttPriorities = new MonitorToolTip(priorityLbl, false); - // priorityLbl.addMouseTrackListener(new MouseTrackAdapter() { - // public void mouseHover(MouseEvent e) { - // mttPriorities.open(); - // } - // }); + priorityLbl.addMouseTrackListener(new MouseTrackAdapter() { + public void mouseHover(MouseEvent e) { + mttPriorities.open(); + } + }); // --------------------------------------------------------- // Put the priority canvases on the display diff --git a/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/MonitorToolTip.java b/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/MonitorToolTip.java index 3ca8ee6052..c67f055ec4 100644 --- a/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/MonitorToolTip.java +++ b/cave/com.raytheon.uf.viz.alertviz.ui/src/com/raytheon/uf/viz/alertviz/ui/dialogs/MonitorToolTip.java @@ -1,11 +1,7 @@ package com.raytheon.uf.viz.alertviz.ui.dialogs; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; @@ -37,6 +33,7 @@ public class MonitorToolTip { * 17Jan2011 5150 cjeanbap Adjusted tooltip location and fix IllegalArgumentException. * 18Jan2011 5449 cjeanbap Fixed NullPointerException. * 24Jan 2011 1978 cjeanbap Removed unused variables. + * 23Oct 2011 2303 bgonzale Old patch to fix tool tip layout. * * * @@ -44,8 +41,6 @@ public class MonitorToolTip { * @version 1.0 */ - private Pattern LinePattern = Pattern.compile("^(.*)$", Pattern.MULTILINE); - private Display display; private Shell parentShell; @@ -54,7 +49,7 @@ public class MonitorToolTip { public static final String tooltipTextKey = "tooltiptext"; - private boolean useBorderWidth = true; + private boolean ignoreDisplayPos = true; public MonitorToolTip(Control control) { this.control = control; @@ -62,7 +57,7 @@ public class MonitorToolTip { public MonitorToolTip(Control control, boolean ignoreDisplayPos) { this.control = control; - this.useBorderWidth = ignoreDisplayPos; + this.ignoreDisplayPos = ignoreDisplayPos; } /** @@ -144,33 +139,7 @@ public class MonitorToolTip { } label.addListener(SWT.MouseExit, labelListener); label.addListener(SWT.MouseDown, labelListener); - Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT); - Rectangle rect = Display.getCurrent().getBounds(); - Point pt = Display.getCurrent() - .map(control, null, 0, 0); - - final int borderEstimate = (useBorderWidth ? (control - .getBorderWidth() * 2 + 1) : 9); - String labelText = label.getText(); - GC gc = new GC(control); - int fontHeight = gc.getFontMetrics().getHeight(); - gc.dispose(); - Matcher m = LinePattern.matcher(labelText); - int numberOfTextLines = 0; // m.groupCount(); - while (m.find()) { - ++numberOfTextLines; - } - numberOfTextLines = numberOfTextLines > 1 ? numberOfTextLines + 1 - : numberOfTextLines; - int yAdj = fontHeight * numberOfTextLines - + borderEstimate + (useBorderWidth ? 4 : 0); - if (pt.y + yAdj + fontHeight > rect.height) { - pt.y -= yAdj; - } else { - pt.y += control.getSize().y + borderEstimate; - } - - tip.setBounds(pt.x, pt.y, size.x, size.y); + setToolTipBounds(label, tip); tip.setVisible(true); textFont.dispose(); } @@ -184,4 +153,28 @@ public class MonitorToolTip { ctrl.addListener(SWT.MouseExit, tableListener); ctrl.addListener(SWT.Paint, tableListener); } + + private void setToolTipBounds(Label label, Shell tip) { + // size of tool tip + Point tipSize = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT); + // bounds of the current display + Rectangle displayBounds = Display.getCurrent().getBounds(); + // x screen coordinate + int xCoord = Display.getCurrent().map(control, null, 0, 0).x; + // y coordinate of widget that the tool tip is next to + Control widget = ignoreDisplayPos ? control : control.getParent(); + int widgetYCoord = Display.getCurrent().map(widget, null, 0, 0).y; + Point widgetSize = widget.computeSize(SWT.DEFAULT, + SWT.DEFAULT); + + int yCoord = widgetYCoord; + // check if the tip extends past the end of the display + if (yCoord + widgetSize.y + tipSize.y > displayBounds.height) { + yCoord = yCoord - tipSize.y - control.getParent().getBorderWidth(); + } else { + yCoord = yCoord + widgetSize.y; + } + tip.setBounds(xCoord, yCoord, tipSize.x, tipSize.y); + } + } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/status/VizStatusHandler.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/status/VizStatusHandler.java deleted file mode 100644 index fe3af344b9..0000000000 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/status/VizStatusHandler.java +++ /dev/null @@ -1,177 +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.uf.viz.core.status; - -import org.eclipse.ui.statushandlers.StatusManager; - -import com.raytheon.uf.common.status.AbstractHandlerFactory; -import com.raytheon.uf.common.status.IUFStatusHandler; -import com.raytheon.uf.common.status.UFStatus; -import com.raytheon.uf.common.status.UFStatus.Priority; - -/** - * Sends StatusMessages into the Eclipse Status Manager - * - *
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * Oct 6, 2008  1433       chammack    Initial creation
- * 
- * - * @author chammack - * @version 1.0 - */ - -public class VizStatusHandler implements IUFStatusHandler { - - private final String category; - - private String source; - - private final String pluginId; - - private final AbstractHandlerFactory factory; - - public VizStatusHandler(AbstractHandlerFactory factory, String pluginId, - String category) { - this.factory = factory; - this.category = category; - this.pluginId = pluginId; - } - - public VizStatusHandler(String pluginId, String category, String source) { - this.category = category; - this.source = source; - this.pluginId = pluginId; - this.factory = null; - } - - @Override - public boolean isPriorityEnabled(Priority p) { - return true; - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.common.status.IUFStatusHandler#handle(com.raytheon.uf - * .common.status.UFStatus) - */ - @Override - public void handle(UFStatus status) { - handle(status, this.category); - } - - @Override - public void handle(UFStatus status, String category) { - if (this.source == null) { - if (factory != null) { - this.source = factory.getSource(source, pluginId); - } - } - - VizStatusInternal vizStatus = new VizStatusInternal(status, category, - source, pluginId); - StatusManager.getManager().handle(vizStatus); - } - - @Override - public void handle(Priority p, String msg) { - handle(new UFStatus(p, msg)); - } - - @Override - public void handle(Priority priority, String category, String message) { - handle(priority, category, message, (Throwable) null); - } - - @Override - public void handle(Priority p, String msg, Throwable t) { - handle(new UFStatus(p, msg, t)); - } - - @Override - public void handle(Priority p, String category, String msg, Throwable t) { - handle(new UFStatus(p, msg, t), category); - } - - @Override - public void debug(String message) { - handle(Priority.DEBUG, message); - } - - @Override - public void debug(String category, String message) { - handle(Priority.DEBUG, category, message); - } - - @Override - public void info(String message) { - handle(Priority.INFO, message); - } - - @Override - public void info(String category, String message) { - handle(Priority.INFO, category, message); - } - - @Override - public void warn(String message) { - handle(Priority.WARN, message); - } - - @Override - public void warn(String category, String message) { - handle(Priority.WARN, category, message); - } - - @Override - public void error(String message) { - handle(Priority.ERROR, message); - } - - @Override - public void error(String category, String message) { - handle(Priority.ERROR, category, message); - } - - @Override - public void error(String message, Throwable throwable) { - handle(Priority.ERROR, message, throwable); - } - - @Override - public void error(String message, String category, Throwable throwable) { - handle(Priority.ERROR, category, message, throwable); - } - - @Override - public void fatal(String message, Throwable throwable) { - handle(Priority.FATAL, message, throwable); - } - - @Override - public void fatal(String message, String category, Throwable throwable) { - handle(Priority.FATAL, category, message, throwable); - } - -} diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/status/VizStatusHandlerFactory.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/status/VizStatusHandlerFactory.java index f8c98cc110..de0a69de93 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/status/VizStatusHandlerFactory.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/status/VizStatusHandlerFactory.java @@ -25,6 +25,8 @@ import java.util.MissingResourceException; import javax.xml.bind.JAXBException; +import org.eclipse.ui.statushandlers.StatusManager; + import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; @@ -34,6 +36,8 @@ import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.status.AbstractHandlerFactory; import com.raytheon.uf.common.status.FilterPatternContainer; import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.StatusHandler; +import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; /** @@ -45,6 +49,8 @@ import com.raytheon.uf.common.status.UFStatus.Priority; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Aug 25, 2010 rjpeter Initial creation + * Oct 23, 2013 2303 bgonzale Merged VizStatusHandler and SysErrStatusHandler into StatusHandler. + * Implemented log method from base class. * * * @@ -56,8 +62,8 @@ public class VizStatusHandlerFactory extends AbstractHandlerFactory { private static final String CATEGORY = "WORKSTATION"; - private static final VizStatusHandler instance = new VizStatusHandler( - VizStatusHandler.class.getPackage().getName(), CATEGORY, CATEGORY); + private static final StatusHandler instance = new StatusHandler( + StatusHandler.class.getPackage().getName(), CATEGORY, CATEGORY); public VizStatusHandlerFactory() { super(CATEGORY); @@ -77,13 +83,14 @@ public class VizStatusHandlerFactory extends AbstractHandlerFactory { @Override public IUFStatusHandler createInstance(String pluginId, String category, String source) { - return new VizStatusHandler(pluginId, category, source); + return new StatusHandler(pluginId, category, source); } @Override public IUFStatusHandler createInstance(AbstractHandlerFactory factory, String pluginId, String category) { - return new VizStatusHandler(factory, pluginId, category); + return new StatusHandler(pluginId, category, getSource( + null, pluginId)); } @Override @@ -103,7 +110,7 @@ public class VizStatusHandlerFactory extends AbstractHandlerFactory { if (locFile == null) { throw new MissingResourceException( "Unable to retrieve the localization file", - VizStatusHandler.class.getName(), + VizStatusHandlerFactory.class.getName(), LocalizationType.COMMON_STATIC.name() + File.separator + LocalizationLevel.BASE.name() + File.separator + "configuredHandlers.xml"); @@ -118,4 +125,13 @@ public class VizStatusHandlerFactory extends AbstractHandlerFactory { } return FilterPatternContainer.createDefault(); } + + @Override + protected void log(Priority priority, String pluginId, String category, + String source, String message, Throwable throwable) { + VizStatusInternal vizStatus = new VizStatusInternal(new UFStatus( + priority, message, throwable), category, source, pluginId); + StatusManager.getManager().handle(vizStatus); + } + } diff --git a/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/AbstractHandlerFactory.java b/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/AbstractHandlerFactory.java index 83f5e62ca8..8942f3942c 100644 --- a/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/AbstractHandlerFactory.java +++ b/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/AbstractHandlerFactory.java @@ -24,6 +24,8 @@ import java.util.Map; import java.util.Observable; import java.util.Observer; +import com.raytheon.uf.common.status.UFStatus.Priority; + /** * Abstract implementation of the Handler Factories. * @@ -215,6 +217,38 @@ public abstract class AbstractHandlerFactory implements getSourceFilters(); } + public void log(Priority priority, StatusHandler statusHandler, + String message, Throwable throwable) { + String source = statusHandler.getSource(); + String pluginId = statusHandler.getPluginId(); + if (source == null) { + source = getSource(source, pluginId); + statusHandler.setSource(source); + } + this.log(priority, pluginId, statusHandler.getCategory(), source, + message, throwable); + } + + protected void log(Priority priority, String pluginId, String category, + String source, String message, Throwable throwable) { + StringBuilder sb = new StringBuilder(); + sb.append(priority).append(' '); + sb.append(pluginId).append(": "); + if (category != null) { + sb.append(category); + if (source != null) { + sb.append(": "); + sb.append(source); + } + sb.append(" - "); + } + sb.append(message); + System.err.println(sb.toString()); + if (throwable != null) { + throwable.printStackTrace(System.err); + } + } + protected abstract IUFStatusHandler createMonitorInstance(String pluginId, String monitorSource); diff --git a/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/DefaultStatusHandlerFactory.java b/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/DefaultStatusHandlerFactory.java index ff0cdb3f0a..5fa9dee720 100644 --- a/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/DefaultStatusHandlerFactory.java +++ b/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/DefaultStatusHandlerFactory.java @@ -19,6 +19,7 @@ **/ package com.raytheon.uf.common.status; + /** * TODO Add Description * @@ -29,6 +30,7 @@ package com.raytheon.uf.common.status; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Mar 15, 2011 randerso Initial creation + * Oct 23, 2013 2303 bgonzale Merged VizStatusHandler and SysErrStatusHandler into StatusHandler. * * * @@ -36,13 +38,15 @@ package com.raytheon.uf.common.status; * @version 1.0 */ -public class DefaultStatusHandlerFactory extends AbstractHandlerFactory { - private static final IUFStatusHandler handler = new SysErrStatusHandler( +public class DefaultStatusHandlerFactory extends + AbstractHandlerFactory { + private static final IUFStatusHandler handler = new StatusHandler( DefaultStatusHandlerFactory.class.getPackage().getName(), "DEFAULT", "DEFAULT"); private static final String CATEGORY = "DEFAULT"; + public DefaultStatusHandlerFactory() { super(CATEGORY); } @@ -90,7 +94,8 @@ public class DefaultStatusHandlerFactory extends AbstractHandlerFactory { @Override protected IUFStatusHandler createInstance(String pluginId, String category, String source) { - return new SysErrStatusHandler(pluginId, category, source); + return new StatusHandler(category, source, + pluginId); } @Override @@ -101,7 +106,8 @@ public class DefaultStatusHandlerFactory extends AbstractHandlerFactory { @Override public IUFStatusHandler createInstance(AbstractHandlerFactory factory, String pluginId, String category) { - return new SysErrStatusHandler(pluginId, category, CATEGORY); + return new StatusHandler(category, CATEGORY, + pluginId); } } diff --git a/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/IUFStatusHandlerFactory.java b/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/IUFStatusHandlerFactory.java index c0b28a9c2f..7590b4d626 100644 --- a/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/IUFStatusHandlerFactory.java +++ b/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/IUFStatusHandlerFactory.java @@ -19,6 +19,9 @@ **/ package com.raytheon.uf.common.status; +import com.raytheon.uf.common.status.UFStatus.Priority; + + /** * Describes a method of creating UFStatusHandlerFactory * @@ -27,6 +30,7 @@ package com.raytheon.uf.common.status; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Aug 17, 2010 3265 rjpeter Initial creation + * Oct 23, 2013 2303 bgonzale Added method for logging. * * * @author rjpeter @@ -97,4 +101,7 @@ public interface IUFStatusHandlerFactory { public IUFStatusHandler createInstance(AbstractHandlerFactory factory, String pluginId, String category); + public void log(Priority priority, StatusHandler statusHandler, + String message, Throwable throwable); + } \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/SysErrStatusHandler.java b/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/StatusHandler.java similarity index 84% rename from edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/SysErrStatusHandler.java rename to edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/StatusHandler.java index 1b65bdd9ce..8b66b9e954 100644 --- a/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/SysErrStatusHandler.java +++ b/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/StatusHandler.java @@ -22,7 +22,8 @@ package com.raytheon.uf.common.status; import com.raytheon.uf.common.status.UFStatus.Priority; /** - * TODO Add Description + * Status handler for status messages. Outputs via the UFStatus configured + * factory. * *
  * 
@@ -31,6 +32,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Mar 15, 2011            randerso     Initial creation
+ * Oct 22, 2013 2303       bgonzale     Merged VizStatusHandler and SysErrStatusHandler.
  * 
  * 
* @@ -38,15 +40,16 @@ import com.raytheon.uf.common.status.UFStatus.Priority; * @version 1.0 */ -public class SysErrStatusHandler implements IUFStatusHandler { +public class StatusHandler implements IUFStatusHandler { private final String pluginId; private final String category; - private final String source; + private String source; - public SysErrStatusHandler(String pluginId, String category, String source) { + public StatusHandler(String pluginId, + String category, String source) { this.pluginId = pluginId; this.category = category; this.source = source; @@ -128,25 +131,7 @@ public class SysErrStatusHandler implements IUFStatusHandler { @Override public void handle(Priority priority, String category, String message, Throwable throwable) { - StringBuilder sb = new StringBuilder(); - sb.append(priority).append(' '); - sb.append(this.pluginId).append(": "); - - if (this.category != null) { - sb.append(this.category); - - if (this.source != null) { - sb.append(": "); - sb.append(this.source); - } - sb.append(" - "); - } - - sb.append(message); - System.err.println(sb.toString()); - if (throwable != null) { - throwable.printStackTrace(System.err); - } + UFStatus.log(priority, this, message, throwable); } @Override @@ -209,4 +194,32 @@ public class SysErrStatusHandler implements IUFStatusHandler { handle(Priority.FATAL, category, message, throwable); } + /** + * @return the pluginId + */ + public String getPluginId() { + return pluginId; + } + + /** + * @return the category + */ + public String getCategory() { + return category; + } + + /** + * @return the source + */ + public String getSource() { + return source; + } + + /** + * Set the source + */ + public void setSource(String source) { + this.source = source; + } + } diff --git a/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/UFStatus.java b/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/UFStatus.java index 23fa5a0caf..88e22b582d 100644 --- a/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/UFStatus.java +++ b/edexOsgi/com.raytheon.uf.common.status/src/com/raytheon/uf/common/status/UFStatus.java @@ -21,6 +21,7 @@ package com.raytheon.uf.common.status; import java.util.Iterator; import java.util.ServiceLoader; +import java.util.concurrent.atomic.AtomicReference; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -57,6 +58,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority; * ------------ ---------- ----------- -------------------------- * Oct 6, 2008 1433 chammack Initial creation * Apr 17, 2013 1786 mpduff Allow setting of Handler Factory. + * Oct 23, 2013 2303 bgonzale Fixed setting of Handler Factory. * * * @author chammack @@ -101,9 +103,9 @@ public class UFStatus { protected final String message; /** handler factory */ - private static IUFStatusHandlerFactory handlerFactory = createHandlerFactory(); + private static AtomicReference handlerFactoryRef = createHandlerFactory(); - private static final IUFStatusHandlerFactory createHandlerFactory() { + private static final AtomicReference createHandlerFactory() { ServiceLoader loader = ServiceLoader.load( IUFStatusHandlerFactory.class, IUFStatusHandlerFactory.class.getClassLoader()); @@ -128,7 +130,7 @@ public class UFStatus { + IUFStatusHandlerFactory.class.getName() + " handlers defined"); } - return factory; + return new AtomicReference(factory); } /** @@ -204,14 +206,14 @@ public class UFStatus { * @return */ public static IUFStatusHandler getHandler() { - return handlerFactory.getInstance(); + return handlerFactoryRef.get().getInstance(); } /** * @return the handlerfactory */ public static IUFStatusHandlerFactory getHandlerfactory() { - return handlerFactory; + return handlerFactoryRef.get(); } /** @@ -222,7 +224,7 @@ public class UFStatus { * @return */ public static IUFStatusHandler getHandler(Class cls) { - return handlerFactory.getInstance(cls); + return handlerFactoryRef.get().getInstance(cls); } /** @@ -234,7 +236,7 @@ public class UFStatus { * @return */ public static IUFStatusHandler getHandler(Class cls, String source) { - return handlerFactory.getInstance(cls, source); + return handlerFactoryRef.get().getInstance(cls, source); } /** @@ -246,7 +248,7 @@ public class UFStatus { * @return */ public static IUFStatusHandler getHandler(String pluginId, String source) { - return handlerFactory.getInstance(pluginId, source); + return handlerFactoryRef.get().getInstance(pluginId, source); } /** @@ -261,7 +263,7 @@ public class UFStatus { */ public static IUFStatusHandler getHandler(String pluginId, String category, String source) { - return handlerFactory.getInstance(pluginId, category, source); + return handlerFactoryRef.get().getInstance(pluginId, category, source); } /** @@ -275,7 +277,7 @@ public class UFStatus { */ public static IUFStatusHandler getHandler(Class cls, String category, String source) { - return handlerFactory.getInstance(cls, category, source); + return handlerFactoryRef.get().getInstance(cls, category, source); } /** @@ -287,7 +289,7 @@ public class UFStatus { * @return */ public static IUFStatusHandler getNamedHandler(String name) { - return handlerFactory.getInstance(name); + return handlerFactoryRef.get().getInstance(name); } /** @@ -299,7 +301,7 @@ public class UFStatus { * @return */ public static IUFStatusHandler getMonitorHandler(Class cls) { - return handlerFactory.getMonitorInstance(cls); + return handlerFactoryRef.get().getMonitorInstance(cls); } /** @@ -313,7 +315,7 @@ public class UFStatus { */ public static IUFStatusHandler getMonitorHandler(Class cls, String monitorSource) { - return handlerFactory.getMonitorInstance(cls, monitorSource); + return handlerFactoryRef.get().getMonitorInstance(cls, monitorSource); } /** @@ -323,6 +325,13 @@ public class UFStatus { * the handler factory */ public static void setHandlerFactory(IUFStatusHandlerFactory factory) { - handlerFactory = factory; + handlerFactoryRef.set(factory); } + + static void log(Priority priority, StatusHandler statusHandler, + String message, Throwable throwable) { + handlerFactoryRef.get() + .log(priority, statusHandler, message, throwable); + } + }