Search in sources :

Example 6 with FrameworkNode

use of kutch.biff.marvin.utility.FrameworkNode in project Board-Instrumentation-Framework by intel.

the class WidgetBuilder method BuildRepeatList.

public static List<Widget> BuildRepeatList(FrameworkNode repeatNode) {
    ArrayList<Widget> objWidgetList = new ArrayList<>();
    int count, start;
    String strCountAlias = "";
    String strValueAlias = "";
    AliasMgr.getAliasMgr().PushAliasList(false);
    AliasMgr.getAliasMgr().AddAliasFromAttibuteList(repeatNode, new // can define an alias list in <repeat>
    String[] { "Count", "startvlaue", "currentCountAlias", "currentvalueAlias" });
    if (!repeatNode.hasAttribute("Count")) {
        LOGGER.severe("For did not have Count attribute.");
        return null;
    }
    count = repeatNode.getIntegerAttribute("Count", -1);
    if (count < 1) {
        LOGGER.warning("For Count value invalid: " + repeatNode.getAttribute("Count"));
        return objWidgetList;
    }
    start = repeatNode.getIntegerAttribute("StartValue", 0);
    if (start < 0) {
        LOGGER.severe("For Start value invalid: " + repeatNode.getAttribute("startValue"));
        return null;
    }
    if (repeatNode.hasAttribute("CurrentCountAlias")) {
        strCountAlias = repeatNode.getAttribute("CurrentCountAlias");
    }
    if (repeatNode.hasAttribute("CurrentValueAlias")) {
        strValueAlias = repeatNode.getAttribute("CurrentValueAlias");
    }
    for (int iLoop = 0; iLoop < count; iLoop++) {
        AliasMgr.getAliasMgr().PushAliasList(false);
        if (!strCountAlias.isEmpty()) {
            AliasMgr.getAliasMgr().AddAlias(strCountAlias, Integer.toString(iLoop));
        }
        if (!strValueAlias.isEmpty()) {
            AliasMgr.getAliasMgr().AddAlias(strValueAlias, Integer.toString(iLoop + start));
        }
        // Always have these aliases
        AliasMgr.getAliasMgr().AddAlias("CurrentValueAlias", Integer.toString(iLoop + start));
        AliasMgr.getAliasMgr().AddAlias("CurrentCountAlias", Integer.toString(iLoop));
        for (FrameworkNode node : repeatNode.getChildNodes()) {
            if (node.getNodeName().equalsIgnoreCase("#Text") || node.getNodeName().equalsIgnoreCase("#comment")) {
                continue;
            }
            if (node.getNodeName().equalsIgnoreCase("Widget") || node.getNodeName().equalsIgnoreCase("Grid") || node.getNodeName().equalsIgnoreCase("DynamicGrid")) {
                Widget widget = WidgetBuilder.Build(node);
                if (null != widget) {
                    objWidgetList.add(widget);
                } else {
                    LOGGER.severe("Error creating " + node.getNodeName() + " in <Repeat>");
                    return null;
                }
            } else if (node.getNodeName().equalsIgnoreCase("GridMacro") || node.getNodeName().equalsIgnoreCase("MacroGrid")) {
                ReadGridMacro(node);
            } else if (// embedded <Repeat>s - kewl!
            node.getNodeName().equalsIgnoreCase("For")) {
                objWidgetList.addAll(BuildRepeatList(node));
            } else {
                LOGGER.warning("Unknown item in <For> :" + node.getNodeName() + " ignoring");
            }
        }
        AliasMgr.getAliasMgr().PopAliasList();
    }
    AliasMgr.getAliasMgr().PopAliasList();
    return objWidgetList;
}
Also used : BaseWidget(kutch.biff.marvin.widget.BaseWidget) Widget(kutch.biff.marvin.widget.Widget) GridWidget(kutch.biff.marvin.widget.GridWidget) DynamicGridWidget(kutch.biff.marvin.widget.DynamicGridWidget) ArrayList(java.util.ArrayList) FrameworkNode(kutch.biff.marvin.utility.FrameworkNode)

Example 7 with FrameworkNode

use of kutch.biff.marvin.utility.FrameworkNode in project Board-Instrumentation-Framework by intel.

the class WidgetBuilder method BuildWidget.

private static Widget BuildWidget(FrameworkNode widgetNode) {
    BaseWidget retWidget = null;
    String rowSpan = "1";
    String colSpan = "1";
    if (false == widgetNode.hasAttribute("File")) {
        LOGGER.severe("Widget with no file definition");
        return null;
    }
    if (false == widgetNode.hasAttribute("row")) {
        LOGGER.severe("Widget with no row");
        return null;
    }
    if (false == widgetNode.hasAttribute("column")) {
        LOGGER.severe("Widget with no column");
        return null;
    }
    if (widgetNode.hasAttribute("rowSpan")) {
        rowSpan = widgetNode.getAttribute("rowSpan");
    }
    if (widgetNode.hasAttribute("colSpan")) {
        colSpan = widgetNode.getAttribute("colSpan");
    }
    if (widgetNode.hasAttribute("columnSpan")) {
        colSpan = widgetNode.getAttribute("columnspan");
    }
    String fileName = widgetNode.getAttribute("File");
    fileName = BaseWidget.convertToFileOSSpecific(fileName);
    String fileNameWPath;
    File fCheck = new File(fileName);
    if (null == fCheck) {
        return null;
    }
    if (fCheck.exists()) {
        // fully qualified path provided (likely custom widget)
        fileNameWPath = fileName;
    } else {
        // find widget in widget dir
        fileNameWPath = BaseWidget.DefaultWidgetDirectory + File.separatorChar + fileName;
    }
    String strRow = widgetNode.getAttribute("row");
    String strColumn = widgetNode.getAttribute("column");
    retWidget = ParseWidgetDefinitionFile(fileNameWPath);
    if (null == retWidget) {
        return null;
    }
    Utility.ValidateAttributes(new String[] { "File", "row", "column", "rowSpan", "colSpan", "columnSpan", "Align", "Height", "Width", "Task", "Enabled" }, retWidget.GetCustomAttributes(), widgetNode);
    retWidget.HandleWidgetSpecificAttributes(widgetNode);
    if (true == widgetNode.hasAttribute("Enabled")) {
        String str = widgetNode.getAttribute("Enabled");
        boolean Enabled = true;
        if (str.equalsIgnoreCase("True")) {
            Enabled = true;
        } else if (str.equalsIgnoreCase("False")) {
            Enabled = false;
        } else {
            LOGGER.severe("Invalid option for Enabled attribute for widget, only True or False is valid, not: " + str);
            return null;
        }
        if (retWidget.SupportsEnableDisable()) {
            retWidget.setInitiallyEnabled(Enabled);
        } else {
            LOGGER.warning("Widget set Enabled attribute, but it is not supported by the widget.  Ignoring");
        }
    }
    if (widgetNode.hasAttribute("Task")) {
        retWidget.setTaskID(widgetNode.getAttribute("Task"));
    }
    if (true == widgetNode.hasAttribute("Height")) {
        if (!retWidget.parseHeight(widgetNode)) {
            return null;
        }
    }
    if (true == widgetNode.hasAttribute("Width")) {
        String str = widgetNode.getAttribute("Width");
        if (false == retWidget.parseWidth(widgetNode)) {
            return null;
        }
    }
    // Continue reading widget definition from Application.xml
    try {
        retWidget.setRow(Integer.parseInt(strRow));
        AliasMgr.getAliasMgr().UpdateCurrentRow(Integer.parseInt(strRow));
    } catch (NumberFormatException ex) {
        LOGGER.severe("Invalid Widget row: " + strRow + " declaration");
        return null;
    }
    try {
        retWidget.setColumn(Integer.parseInt(strColumn));
        AliasMgr.getAliasMgr().UpdateCurrentColumn(Integer.parseInt(strColumn));
    } catch (NumberFormatException ex) {
        LOGGER.severe("Invalid Widget column: " + strColumn + " declaration");
        return null;
    }
    try {
        retWidget.setRowSpan(Integer.parseInt(rowSpan));
    } catch (NumberFormatException ex) {
        LOGGER.severe("Invalid Widget rowSpan: " + rowSpan + " declaration");
        return null;
    }
    try {
        retWidget.setColumnSpan(Integer.parseInt(colSpan));
    } catch (NumberFormatException ex) {
        LOGGER.severe("Invalid Widget colSpan: " + colSpan + " declaration");
        return null;
    }
    if (true == widgetNode.hasAttribute("Align")) {
        String str = widgetNode.getAttribute("Align");
        retWidget.setAlignment(str);
    }
    // ArrayList<MyNode> Children = widgetNode.getChildNodes();
    for (FrameworkNode node : widgetNode.getChildNodes(true)) {
        if (node.getNodeName().equalsIgnoreCase("#Text") || node.getNodeName().equalsIgnoreCase("#comment")) {
            continue;
        }
        if (node.getNodeName().equalsIgnoreCase("Title")) {
            retWidget.setTitle(node.getTextContent());
        } else if (node.getNodeName().equalsIgnoreCase("StyleOverride")) {
            HandleStyleOverride(retWidget, node);
        } else if (node.getNodeName().equalsIgnoreCase("UnitsOverride")) {
            retWidget.setUnitsOverride(node.getTextContent());
        } else if (node.getNodeName().equalsIgnoreCase("InitialValue")) {
            retWidget.SetInitialValue(node.getTextContent());
        } else if (node.getNodeName().equalsIgnoreCase("ValueRange")) {
            if (false == retWidget.HandleValueRange(node)) {
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("ToolTip")) {
            if (false == retWidget.HandleToolTipConfig(node)) {
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("SelectedStyle")) {
            if (false == retWidget.HandleSelectionConfig(node)) {
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("ClickThroughTransparent")) {
            retWidget.SetClickThroughTransparentRegion(node.getBooleanValue());
        } else if (node.getNodeName().equalsIgnoreCase("MinionSrc")) {
            if (node.hasAttributes()) {
                Utility.ValidateAttributes(new String[] { "Namespace", "ID" }, node);
                if (node.hasAttribute("ID")) {
                    retWidget.setMinionID(node.getAttribute("ID"));
                } else {
                    LOGGER.severe("Malformed Widget MinionSrc Definition - ID not found");
                    return null;
                }
                if (node.hasAttribute("ID") && node.hasAttribute("Namespace")) {
                    retWidget.setNamespace(node.getAttribute("Namespace"));
                } else {
                    LOGGER.severe("Malformed Widget MinionSrc Definition - Namespace not found");
                    return null;
                }
            }
        } else if (node.getNodeName().equalsIgnoreCase("Peekaboo")) {
            if (!HandlePeekaboo(retWidget, node)) {
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("Size")) {
            if (false == HandleSizeSection(node, retWidget)) {
                return null;
            }
        } else if (false == retWidget.HandleWidgetSpecificSettings(node)) {
            LOGGER.severe("Unknown/Invalid tag in Widget Definition portion of Application.xml : " + node.getNodeName());
            return null;
        }
    }
    return retWidget;
}
Also used : BaseWidget(kutch.biff.marvin.widget.BaseWidget) File(java.io.File) FrameworkNode(kutch.biff.marvin.utility.FrameworkNode)

Example 8 with FrameworkNode

use of kutch.biff.marvin.utility.FrameworkNode in project Board-Instrumentation-Framework by intel.

the class WidgetBuilder method HandleStyleOverride.

public static boolean HandleStyleOverride(BaseWidget widget, FrameworkNode styleNode) {
    Utility.ValidateAttributes(new String[] { "File", "ID", "ScaleToShape" }, styleNode);
    if (styleNode.hasAttribute("File")) {
        widget.setBaseCSSFilename(styleNode.getAttribute("File"));
    }
    if (styleNode.hasAttribute("ID")) {
        widget.setStyleID(styleNode.getAttribute("ID"));
    }
    widget.HandleCustomStyleOverride(styleNode);
    for (FrameworkNode node : styleNode.getChildNodes()) {
        if (node.getNodeName().equalsIgnoreCase("#Text") || node.getNodeName().equalsIgnoreCase("#comment")) {
            continue;
        }
        if (node.getNodeName().equalsIgnoreCase("Item")) {
            widget.AddAdditionalStyleOverride(node.getTextContent());
        } else {
            LOGGER.severe("Unknown Tag under <StyleOverride>: " + node.getNodeName());
            return false;
        }
    }
    return true;
}
Also used : FrameworkNode(kutch.biff.marvin.utility.FrameworkNode)

Example 9 with FrameworkNode

use of kutch.biff.marvin.utility.FrameworkNode in project Board-Instrumentation-Framework by intel.

the class SteelGaugeRadialBuilder method Build.

@SuppressWarnings({ "BroadCatchBlock", "TooBroadCatch" })
public static SteelGaugeRadialWidget Build(FrameworkNode masterNode, String widgetDefFilename) {
    SteelGaugeRadialWidget objWidget = new SteelGaugeRadialWidget();
    for (FrameworkNode node : masterNode.getChildNodes()) {
        if (BaseWidget.HandleCommonDefinitionFileConfig(objWidget, node)) {
            continue;
        } else if (node.getNodeName().equalsIgnoreCase("MinValue")) {
            String str = node.getTextContent();
            try {
                objWidget.setMinValue(Double.parseDouble(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid MinValue in Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("MaxValue")) {
            String str = node.getTextContent();
            try {
                objWidget.setMaxValue(Double.parseDouble(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid MaxValue in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("Decimals")) {
            String str = node.getTextContent();
            try {
                objWidget.setDecimalPlaces(Integer.parseInt(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid Decimals in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("DialStartAngle")) {
            String str = node.getTextContent();
            try {
                objWidget.setDialStartAngle(Integer.parseInt(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid DialStartAngle in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("DialRangeAngle")) {
            String str = node.getTextContent();
            try {
                objWidget.setRangeAngle(Integer.parseInt(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid DialRangeAngle in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("MajorTicksSpace")) {
            String str = node.getTextContent();
            try {
                objWidget.setMajorTick(Integer.parseInt(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid MajorTicksSpace in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("MinorTicksSpace")) {
            String str = node.getTextContent();
            try {
                objWidget.setMinorTick(Integer.parseInt(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid MinorTicksSpace in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("TickLableOrientation")) {
            String str = node.getTextContent();
            if (0 == str.compareToIgnoreCase("Horizontal")) {
                objWidget.setOrientation(Radial.TickLabelOrientation.HORIZONTAL);
            } else if (0 == str.compareToIgnoreCase("Orthogonal")) {
                objWidget.setOrientation(Radial.TickLabelOrientation.ORTHOGONAL);
            } else if (0 == str.compareToIgnoreCase("Tangent")) {
                objWidget.setOrientation(Radial.TickLabelOrientation.TANGENT);
            } else {
                LOGGER.severe("Invalid TickLableOrientation in SteelGauge Widget Definition File. Should be Horizontal, Orthogonal or Tangent");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("EnhancedRateText")) {
            String str = node.getTextContent();
            if (0 == str.compareToIgnoreCase("True")) {
                objWidget.setEnhancedRateText(true);
            } else if (0 == str.compareToIgnoreCase("False")) {
                objWidget.setEnhancedRateText(false);
            } else {
                LOGGER.severe("Invalid EnhancedRateText in SteelGauge Widget Definition File.  Should be true or false");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("UnitText")) {
            String str = node.getTextContent();
            objWidget.setUnitText(str);
        } else {
            LOGGER.severe("Invalid SteelGauge Widget Definition File.  Unknown Tag: " + node.getNodeName());
            return null;
        }
    }
    return objWidget;
}
Also used : FrameworkNode(kutch.biff.marvin.utility.FrameworkNode) SteelGaugeRadialWidget(kutch.biff.marvin.widget.SteelGaugeRadialWidget)

Example 10 with FrameworkNode

use of kutch.biff.marvin.utility.FrameworkNode in project Board-Instrumentation-Framework by intel.

the class SteelGaugeRadialSteelBuilder method Build.

@SuppressWarnings({ "BroadCatchBlock", "TooBroadCatch" })
public static SteelGaugeRadialSteelWidget Build(FrameworkNode masterNode, String widgetDefFilename) {
    SteelGaugeRadialSteelWidget objWidget = new SteelGaugeRadialSteelWidget();
    for (FrameworkNode node : masterNode.getChildNodes()) {
        if (BaseWidget.HandleCommonDefinitionFileConfig(objWidget, node)) {
            continue;
        } else if (node.getNodeName().equalsIgnoreCase("MinValue")) {
            String str = node.getTextContent();
            try {
                objWidget.setMinValue(Double.parseDouble(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid MinValue in Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("MaxValue")) {
            String str = node.getTextContent();
            try {
                objWidget.setMaxValue(Double.parseDouble(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid MaxValue in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("Decimals")) {
            String str = node.getTextContent();
            try {
                objWidget.setDecimalPlaces(Integer.parseInt(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid Decimals in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("DialStartAngle")) {
            String str = node.getTextContent();
            try {
                objWidget.setDialStartAngle(Integer.parseInt(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid DialStartAngle in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("DialRangeAngle")) {
            String str = node.getTextContent();
            try {
                objWidget.setRangeAngle(Integer.parseInt(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid DialRangeAngle in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("MajorTicksSpace")) {
            String str = node.getTextContent();
            try {
                objWidget.setMajorTick(Integer.parseInt(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid MajorTicksSpace in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("MinorTicksSpace")) {
            String str = node.getTextContent();
            try {
                objWidget.setMinorTick(Integer.parseInt(str));
            } catch (Exception ex) {
                LOGGER.severe("Invalid MinorTicksSpace in SteelGauge Widget Definition File");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("TickLableOrientation")) {
            String str = node.getTextContent();
            if (0 == str.compareToIgnoreCase("Horizontal")) {
                objWidget.setOrientation(TickLabelOrientation.HORIZONTAL);
            } else if (0 == str.compareToIgnoreCase("Orthogonal")) {
                objWidget.setOrientation(TickLabelOrientation.ORTHOGONAL);
            } else if (0 == str.compareToIgnoreCase("Tangent")) {
                objWidget.setOrientation(TickLabelOrientation.TANGENT);
            } else {
                LOGGER.severe("Invalid TickLableOrientation in SteelGauge Widget Definition File. Should be Horizontal, Orthogonal or Tangent");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("EnhancedRateText")) {
            String str = node.getTextContent();
            if (0 == str.compareToIgnoreCase("True")) {
                objWidget.setEnhancedRateText(true);
            } else if (0 == str.compareToIgnoreCase("False")) {
                objWidget.setEnhancedRateText(false);
            } else {
                LOGGER.severe("Invalid EnhancedRateText in SteelGauge Widget Definition File.  Should be true or false");
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("UnitText")) {
            String str = node.getTextContent();
            objWidget.setUnitText(str);
        } else {
            LOGGER.severe("Invalid SteelGauge Widget Definition File.  Unknown Tag: " + node.getNodeName());
            return null;
        }
    }
    return objWidget;
}
Also used : FrameworkNode(kutch.biff.marvin.utility.FrameworkNode) SteelGaugeRadialSteelWidget(kutch.biff.marvin.widget.SteelGaugeRadialSteelWidget)

Aggregations

FrameworkNode (kutch.biff.marvin.utility.FrameworkNode)52 NodeList (org.w3c.dom.NodeList)7 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 SAXException (org.xml.sax.SAXException)5 BaseWidget (kutch.biff.marvin.widget.BaseWidget)4 Document (org.w3c.dom.Document)4 TaskManager (kutch.biff.marvin.task.TaskManager)3 DynamicGridWidget (kutch.biff.marvin.widget.DynamicGridWidget)3 GridWidget (kutch.biff.marvin.widget.GridWidget)3 Node (org.w3c.dom.Node)3 File (java.io.File)2 Menu (javafx.scene.control.Menu)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 SeriesDataSet (kutch.biff.marvin.utility.SeriesDataSet)2 Widget (kutch.biff.marvin.widget.Widget)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 List (java.util.List)1