/** * Find a formula that uses a model item as an input. * * @param item Item that's potentially used in a formula * @return First Formula found that uses this item, or <code>null</code> if none found */ public FormulaItem getFormulaWithInput(final ModelItem item) { // Update any formulas for (ModelItem i : items) { if (!(i instanceof FormulaItem)) continue; final FormulaItem formula = (FormulaItem) i; if (formula.usesInput(item)) return formula; } return null; }
/** * Load model * * @param doc DOM document * @throws Exception on error * @throws RuntimeException if model was already in use */ private void loadFromDocument(final Document doc) throws Exception { if (is_running || items.size() > 0) throw new RuntimeException("Model was already in use"); // Check if it's a <databrowser/>. doc.getDocumentElement().normalize(); final Element root_node = doc.getDocumentElement(); if (!root_node.getNodeName().equals(TAG_DATABROWSER)) throw new Exception("Wrong document type"); synchronized (this) { scroll_enabled = DOMHelper.getSubelementBoolean(root_node, TAG_SCROLL, scroll_enabled); } update_period = DOMHelper.getSubelementDouble(root_node, TAG_UPDATE_PERIOD, update_period); final String start = DOMHelper.getSubelementString(root_node, TAG_START); final String end = DOMHelper.getSubelementString(root_node, TAG_END); if (start.length() > 0 && end.length() > 0) { final StartEndTimeParser times = new StartEndTimeParser(start, end); setTimerange( TimestampHelper.fromCalendar(times.getStart()), TimestampHelper.fromCalendar(times.getEnd())); } RGB color = loadColorFromDocument(root_node, TAG_BACKGROUND); if (color != null) background = color; try { archive_rescale = ArchiveRescale.valueOf(DOMHelper.getSubelementString(root_node, TAG_ARCHIVE_RESCALE)); } catch (Throwable ex) { archive_rescale = ArchiveRescale.STAGGER; } // Load Time Axis final Element timeAxisNode = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_TIME_AXIS); if (timeAxisNode != null) { // Load PV items Element axisNode = DOMHelper.findFirstElementNode(timeAxisNode.getFirstChild(), TAG_AXIS); timeAxis = AxisConfig.fromDocument(axisNode); } // Load value Axes Element list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_AXES); if (list != null) { // Load PV items Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_AXIS); while (item != null) { addAxis(AxisConfig.fromDocument(item)); item = DOMHelper.findNextElementNode(item, TAG_AXIS); } } // Load Annotations list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_ANNOTATIONS); if (list != null) { // Load PV items Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_ANNOTATION); final List<AnnotationInfo> infos = new ArrayList<AnnotationInfo>(); try { while (item != null) { final AnnotationInfo annotation = AnnotationInfo.fromDocument(item); infos.add(annotation); item = DOMHelper.findNextElementNode(item, TAG_ANNOTATION); } } catch (Throwable ex) { Activator.getLogger().log(Level.INFO, "XML error in Annotation", ex); } // Add to document annotations = infos.toArray(new AnnotationInfo[infos.size()]); } // ADD by Laurent PHILIPPE // Load Title and graph settings try { graphSettings = XYGraphSettingsXMLUtil.fromDocument(root_node.getFirstChild()); } catch (Throwable ex) { Activator.getLogger().log(Level.INFO, "XML error in Title or graph settings", ex); } // Backwards compatibility with previous data browser which // used global buffer size for all PVs final int buffer_size = DOMHelper.getSubelementInt(root_node, Model.TAG_LIVE_SAMPLE_BUFFER_SIZE, -1); // Load PVs/Formulas list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_PVLIST); if (list != null) { // Load PV items Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_PV); while (item != null) { final PVItem model_item = PVItem.fromDocument(this, item); if (buffer_size > 0) model_item.setLiveCapacity(buffer_size); // Adding item creates the axis for it if not already there addItem(model_item); // Backwards compatibility with previous data browser which // stored axis configuration with each item: Update axis from that. final AxisConfig axis = model_item.getAxis(); String s = DOMHelper.getSubelementString(item, TAG_AUTO_SCALE); if (s.equalsIgnoreCase("true")) axis.setAutoScale(true); s = DOMHelper.getSubelementString(item, TAG_LOG_SCALE); if (s.equalsIgnoreCase("true")) axis.setLogScale(true); final double min = DOMHelper.getSubelementDouble(item, Model.TAG_MIN, axis.getMin()); final double max = DOMHelper.getSubelementDouble(item, Model.TAG_MAX, axis.getMax()); axis.setRange(min, max); item = DOMHelper.findNextElementNode(item, TAG_PV); } // Load Formulas item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_FORMULA); while (item != null) { addItem(FormulaItem.fromDocument(this, item)); item = DOMHelper.findNextElementNode(item, TAG_FORMULA); } } }