Search in sources :

Example 1 with BaseWidget

use of kutch.biff.marvin.widget.BaseWidget 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 2 with BaseWidget

use of kutch.biff.marvin.widget.BaseWidget in project Board-Instrumentation-Framework by intel.

the class Marvin method DumpAllWidgetsInformation.

private void DumpAllWidgetsInformation() {
    if (_Config.getConfiguration().isDebugMode()) {
        for (BaseWidget objWidget : BaseWidget.getWidgetList()) {
            if (dumpWidgetInfo) {
                StringBuilder sb = new StringBuilder();
                sb.append("Widget Information: ");
                sb.append(objWidget.toString(false));
                LOGGER.config(sb.toString());
            }
            // setup shift and ctrl click actions for debug
            objWidget.SetupTaskAction();
            if (null != objWidget.getRegionObject()) {
            // objWidget.getRegionObject().requestLayout();
            }
        }
        if (dumpWidgetInfo) {
            LOGGER.config("External Grid/Tab usage file from " + ConfigFilename + "\n" + kutch.biff.marvin.widget.widgetbuilder.WidgetBuilder.GetFileTree());
        }
    }
}
Also used : BaseWidget(kutch.biff.marvin.widget.BaseWidget)

Example 3 with BaseWidget

use of kutch.biff.marvin.widget.BaseWidget in project Board-Instrumentation-Framework by intel.

the class WidgetBuilder method ParseWidgetDefinitionFile.

private static BaseWidget ParseWidgetDefinitionFile(String Filename) {
    BaseWidget retWidget = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db;
    try {
        db = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
        return null;
    }
    File file = new File(Filename);
    if (file.exists()) {
        Document docWidget;
        try {
            docWidget = db.parse(file);
        } catch (SAXException | IOException ex) {
            LOGGER.severe(ex.toString());
            return null;
        }
        AliasMgr.getAliasMgr().PushAliasList(true);
        if (// let's see if there are any aliases in the widget file!
        !AliasMgr.ReadAliasFromRootDocument(docWidget)) {
            return null;
        }
        FrameworkNode baseNode = new FrameworkNode(docWidget.getElementsByTagName("Widget").item(0));
        if (false == baseNode.hasAttributes()) {
            LOGGER.severe("Invalid Widget definition in " + Filename);
            return null;
        }
        String strWidget = baseNode.getAttribute("Type");
        if (null == strWidget) {
            LOGGER.severe("Invalid Widget definition in " + Filename);
            return null;
        }
        if (strWidget.equalsIgnoreCase("SteelGauge")) {
            retWidget = SteelGaugeBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("SteelGaugeRadial")) {
            retWidget = SteelGaugeRadialBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("SteelGaugeRadialSteel")) {
            retWidget = SteelGaugeRadialSteelBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("Steel180Gauge")) {
            retWidget = SteelGauge180Builder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("SteelSimpleGauge")) {
            retWidget = SteelSimpleGaugeBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("SteelLCD")) {
            retWidget = SteelLCDWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("LedBargraph")) {
            retWidget = SteelLedBarGraphBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("StaticImage")) {
            retWidget = StaticImageBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("DynamicImage")) {
            retWidget = DynamicImageBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("Text")) {
            retWidget = TextBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("ProgressBar")) {
            retWidget = ProgressBarBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("ProgressIndicator")) {
            retWidget = ProgressIndicatorBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("Button")) {
            retWidget = ButtonWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("MultiSourceLineChart")) {
            retWidget = ChartWidgetBuilder.BuildMultiSourceLineChart(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("LineChart")) {
            retWidget = ChartWidgetBuilder.BuildLineChart(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("AreaChart")) {
            retWidget = ChartWidgetBuilder.BuildAreaChart(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("MultiSourceAreaChart")) {
            retWidget = ChartWidgetBuilder.BuildMultiSourceAreaChart(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("MultiSourceStackedAreaChart")) {
            retWidget = ChartWidgetBuilder.BuildMultiSourceStackedAreaChart(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("StackedAreaChart")) {
            retWidget = ChartWidgetBuilder.BuildStackedAreaChart(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("PieChart")) {
            retWidget = PieChartWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("BarChart")) {
            retWidget = ChartWidgetBuilder.BuildBarChart(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("StackedBarChart")) {
            retWidget = ChartWidgetBuilder.BuildStackedlBarChart(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("HorizontalBarChart")) {
            retWidget = ChartWidgetBuilder.BuildHorizontalBarChart(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("FlipPanel")) {
            retWidget = FlipPanelWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("Spacer")) {
            retWidget = SpacerWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("SVG")) {
            retWidget = SVG_WidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("PDF_Reader")) {
            LOGGER.severe("PDF Reader not currently supported");
            retWidget = null;
        // retWidget = PDF_ReaderWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("AudioPlayer")) {
            retWidget = AudioPlayerWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("VideoPlayer")) {
            retWidget = VideoPlayerWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("Web")) {
            retWidget = WebWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("QuickView")) {
            retWidget = QuickViewWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("QuickViewLCD")) {
            retWidget = QuickViewLCDWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("DoubleBarGauge")) {
            retWidget = DoubleBarGaugeWidgetBuilder.Build(baseNode, Filename);
        } else if (strWidget.equalsIgnoreCase("BarGauge")) {
            retWidget = BarGaugeWidgetBuilder.Build(baseNode, Filename);
        } else {
            LOGGER.severe("Unknown Widget type : " + strWidget + " in :" + Filename);
        }
        if (null != retWidget) {
            retWidget.setWidgetInformation(file.getParent(), Filename, strWidget);
        }
    } else {
        LOGGER.severe("Widget Definition file does not exist: " + Filename);
        return null;
    }
    AliasMgr.getAliasMgr().PopAliasList();
    return retWidget;
}
Also used : BaseWidget(kutch.biff.marvin.widget.BaseWidget) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) File(java.io.File) FrameworkNode(kutch.biff.marvin.utility.FrameworkNode) SAXException(org.xml.sax.SAXException)

Aggregations

BaseWidget (kutch.biff.marvin.widget.BaseWidget)3 File (java.io.File)2 FrameworkNode (kutch.biff.marvin.utility.FrameworkNode)2 IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1