Search in sources :

Example 21 with ModelItem

use of org.csstudio.trends.databrowser3.model.ModelItem in project org.csstudio.display.builder by kasemir.

the class XMLPersistence method load.

private void load(final Model model, final Document doc) throws Exception {
    if (model.getItems().iterator().hasNext())
        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("Expected " + TAG_DATABROWSER + " but got " + root_node.getNodeName());
    // Global settings
    String title = DOMHelper.getSubelementString(root_node, TAG_TITLE);
    if (!title.isEmpty())
        model.setTitle(title);
    model.setSaveChanges(DOMHelper.getSubelementBoolean(root_node, TAG_SAVE_CHANGES, true));
    model.setGridVisible(DOMHelper.getSubelementBoolean(root_node, TAG_GRID, false));
    model.enableScrolling(DOMHelper.getSubelementBoolean(root_node, TAG_SCROLL, true));
    model.setUpdatePeriod(DOMHelper.getSubelementDouble(root_node, TAG_UPDATE_PERIOD, Preferences.getUpdatePeriod()));
    try {
        model.setScrollStep(Duration.ofSeconds(DOMHelper.getSubelementInt(root_node, TAG_SCROLL_STEP, (int) Preferences.getScrollStep().getSeconds())));
    } catch (Throwable ex) {
    // Ignore
    }
    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)
        model.setTimerange(start, end);
    final String rescale = DOMHelper.getSubelementString(root_node, TAG_ARCHIVE_RESCALE, ArchiveRescale.STAGGER.name());
    try {
        model.setArchiveRescale(ArchiveRescale.valueOf(rescale));
    } catch (Throwable ex) {
    // Ignore
    }
    model.setToolbarVisible(DOMHelper.getSubelementBoolean(root_node, TAG_SHOW_TOOLBAR, true));
    model.setLegendVisible(DOMHelper.getSubelementBoolean(root_node, TAG_SHOW_LEGEND, true));
    // Value Axes
    Element list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_AXES);
    if (list != null) {
        Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_AXIS);
        while (item != null) {
            model.addAxis(AxisConfig.fromDocument(item));
            item = DOMHelper.findNextElementNode(item, TAG_AXIS);
        }
    } else {
        // Check for legacy <xyGraphSettings> <axisSettingsList>
        list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_OLD_XYGRAPH_SETTINGS);
        if (list != null) {
            loadColorFromDocument(list, "plotAreaBackColor").ifPresent(model::setPlotBackground);
            Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), "axisSettingsList");
            if (item != null) {
                // First axis is 'X'
                model.setGridVisible(DOMHelper.getSubelementBoolean(item, "showMajorGrid", false));
                // Read 'Y' axes
                item = DOMHelper.findNextElementNode(item, "axisSettingsList");
                while (item != null) {
                    final String name = DOMHelper.getSubelementString(item, "title", null);
                    final AxisConfig axis = new AxisConfig(name);
                    loadColorFromDocument(item, "foregroundColor").ifPresent(axis::setColor);
                    axis.setGridVisible(DOMHelper.getSubelementBoolean(item, "showMajorGrid", false));
                    axis.setLogScale(DOMHelper.getSubelementBoolean(item, "logScale", false));
                    axis.setAutoScale(DOMHelper.getSubelementBoolean(item, "autoScale", false));
                    final Element range = DOMHelper.findFirstElementNode(item.getFirstChild(), "range");
                    if (range != null) {
                        double min = DOMHelper.getSubelementDouble(range, "lower", axis.getMin());
                        double max = DOMHelper.getSubelementDouble(range, "upper", axis.getMax());
                        axis.setRange(min, max);
                    }
                    model.addAxis(axis);
                    // Using legacy settings from _last_ axis for fonts
                    loadFontFromDocument(item, "scaleFont").ifPresent(model::setScaleFont);
                    loadFontFromDocument(item, "titleFont").ifPresent(model::setLabelFont);
                    item = DOMHelper.findNextElementNode(item, "axisSettingsList");
                }
            }
        }
    }
    // New settings, possibly replacing settings from legacy <xyGraphSettings> <axisSettingsList>
    loadColorFromDocument(root_node, TAG_BACKGROUND).ifPresent(model::setPlotBackground);
    loadFontFromDocument(root_node, TAG_TITLE_FONT).ifPresent(model::setTitleFont);
    loadFontFromDocument(root_node, TAG_LABEL_FONT).ifPresent(model::setLabelFont);
    loadFontFromDocument(root_node, TAG_SCALE_FONT).ifPresent(model::setScaleFont);
    loadFontFromDocument(root_node, TAG_LEGEND_FONT).ifPresent(model::setLegendFont);
    // Load Annotations
    list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_ANNOTATIONS);
    if (list != null) {
        // Load PV items
        final List<AnnotationInfo> annotations = new ArrayList<>();
        Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_ANNOTATION);
        while (item != null) {
            try {
                annotations.add(AnnotationInfo.fromDocument(item));
            } catch (Throwable ex) {
                Activator.getLogger().log(Level.INFO, "XML error in Annotation", ex);
            }
            item = DOMHelper.findNextElementNode(item, TAG_ANNOTATION);
        }
        model.setAnnotations(annotations);
    }
    // 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(model, item);
            // Adding item creates the axis for it if not already there
            model.addItem(model_item);
            // Ancient data browser 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, TAG_MIN, axis.getMin());
            final double max = DOMHelper.getSubelementDouble(item, 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) {
            model.addItem(FormulaItem.fromDocument(model, item));
            item = DOMHelper.findNextElementNode(item, TAG_FORMULA);
        }
    }
    // Update items from legacy <xyGraphSettings>
    list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_OLD_XYGRAPH_SETTINGS);
    if (list != null) {
        title = DOMHelper.getSubelementString(list, TAG_TITLE);
        if (!title.isEmpty())
            model.setTitle(title);
        final Iterator<ModelItem> model_items = model.getItems().iterator();
        Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), "traceSettingsList");
        while (item != null) {
            if (!model_items.hasNext())
                break;
            final ModelItem pv = model_items.next();
            Optional<RGB> rgb = loadColorFromDocument(item, "traceColor");
            if (rgb.isPresent()) {
                pv.setColor(SWTMediaPool.getJFX(rgb.get()));
            }
            pv.setLineWidth(DOMHelper.getSubelementInt(item, "lineWidth", pv.getLineWidth()));
            pv.setDisplayName(DOMHelper.getSubelementString(item, "name", pv.getDisplayName()));
            item = DOMHelper.findNextElementNode(item, "traceSettingsList");
        }
    }
}
Also used : AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) RGB(org.eclipse.swt.graphics.RGB) PVItem(org.csstudio.trends.databrowser3.model.PVItem) AnnotationInfo(org.csstudio.trends.databrowser3.model.AnnotationInfo)

Example 22 with ModelItem

use of org.csstudio.trends.databrowser3.model.ModelItem in project org.csstudio.display.builder by kasemir.

the class WaveformView method updateAnnotation.

private void updateAnnotation(final Instant time, final double value) {
    final List<AnnotationInfo> annotations = new ArrayList<AnnotationInfo>(model.getAnnotations());
    // Initial annotation offset
    Point2D offset = new Point2D(20, -20);
    // If already in model, note its offset and remove
    for (AnnotationInfo annotation : annotations) {
        if (annotation.getText().equals(ANNOTATION_TEXT)) {
            // Update offset to where user last placed it
            offset = annotation.getOffset();
            waveform_annotation = annotation;
            annotations.remove(waveform_annotation);
            break;
        }
    }
    int i = 0;
    int item_index = 0;
    for (ModelItem item : model.getItems()) {
        if (item == model_item) {
            item_index = i;
            break;
        }
        i++;
    }
    waveform_annotation = new AnnotationInfo(true, item_index, time, value, offset, ANNOTATION_TEXT);
    annotations.add(waveform_annotation);
    changing_annotations = true;
    model.setAnnotations(annotations);
    changing_annotations = false;
}
Also used : Point2D(javafx.geometry.Point2D) ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) AnnotationInfo(org.csstudio.trends.databrowser3.model.AnnotationInfo)

Example 23 with ModelItem

use of org.csstudio.trends.databrowser3.model.ModelItem in project org.csstudio.display.builder by kasemir.

the class SampleView method doCreatePartControl.

/**
 * {@inheritDoc}
 */
@Override
protected void doCreatePartControl(final Composite parent) {
    final GridLayout layout = new GridLayout(3, false);
    parent.setLayout(layout);
    // Item: pvs [Refresh]
    Label l = new Label(parent, 0);
    l.setText(Messages.SampleView_Item);
    l.setLayoutData(new GridData());
    items = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    items.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    items.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            // Configure table to display samples of the selected model item
            if (items.getSelectionIndex() == 0) {
                sample_table.setInput(null);
                return;
            }
            // / Skip initial "Select item" entry
            final int selected = items.getSelectionIndex() - 1;
            int index = 0;
            for (ModelItem item : model.getItems()) {
                if (index == selected) {
                    sample_table.setInput(item);
                    return;
                }
                ++index;
            }
            Activator.getLogger().log(Level.WARNING, "Invalid item index " + selected);
        }
    });
    final Button refresh = new Button(parent, SWT.PUSH);
    refresh.setText(Messages.SampleView_Refresh);
    refresh.setToolTipText(Messages.SampleView_RefreshTT);
    refresh.setLayoutData(new GridData());
    refresh.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            // Trigger GUI update
            update(false);
        }
    });
    // Sample Table
    // TableColumnLayout requires this to be in its own container
    final Composite table_parent = new Composite(parent, 0);
    table_parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
    final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10);
    table_parent.setLayout(table_layout);
    sample_table = new TableViewer(table_parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
    sample_table.setContentProvider(new SampleTableContentProvider());
    final Table table = sample_table.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    // Time column
    TableViewerColumn col = TableHelper.createColumn(table_layout, sample_table, Messages.TimeColumn, 90, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            cell.setText(TimestampHelper.format(sample.getPosition()));
        }
    });
    // Value column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.ValueColumn, 50, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            cell.setText(format.format(sample.getVType()));
        }

        @Override
        public String getToolTipText(Object element) {
            final PlotSample sample = (PlotSample) element;
            final VType value = sample.getVType();
            // Show numbers in their 'natural' format which may differ from the Display settings
            if (value instanceof VStatistics) {
                final VStatistics mmd = (VStatistics) value;
                return NLS.bind(Messages.SampleView_MinMaxValueTT, new String[] { Double.toString(mmd.getAverage()), Double.toString(mmd.getMin()), Double.toString(mmd.getMax()) });
            } else if (value instanceof VNumber) {
                final VNumber dbl = (VNumber) value;
                return Double.toString(dbl.getValue().doubleValue());
            } else
                return VTypeHelper.toString(value);
        }
    });
    // Severity column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.SeverityColumn, 90, 50);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            final VType value = sample.getVType();
            final AlarmSeverity severity = VTypeHelper.getSeverity(value);
            cell.setText(severity.toString());
            if (severity == AlarmSeverity.NONE) {
                cell.setBackground(null);
                return;
            }
            final Display display = cell.getControl().getDisplay();
            if (severity == AlarmSeverity.MAJOR)
                cell.setBackground(display.getSystemColor(SWT.COLOR_RED));
            else if (severity == AlarmSeverity.MINOR)
                cell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
            else
                cell.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
        }
    });
    // Status column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.StatusColumn, 90, 50);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            final VType value = sample.getVType();
            cell.setText(VTypeHelper.getMessage(value));
        }
    });
    // Sample Source column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.SampleView_Source, 90, 10);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            cell.setText(sample.getSource());
        }
    });
    ColumnViewerToolTipSupport.enableFor(sample_table);
    // Be ignorant of any change of the current model after this view
    // is disposed.
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (model != null)
                model.removeListener(model_listener);
        }
    });
}
Also used : MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) DisposeListener(org.eclipse.swt.events.DisposeListener) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) VType(org.diirt.vtype.VType) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) VStatistics(org.diirt.vtype.VStatistics) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Table(org.eclipse.swt.widgets.Table) AlarmSeverity(org.diirt.vtype.AlarmSeverity) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) VNumber(org.diirt.vtype.VNumber) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridData(org.eclipse.swt.layout.GridData) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener) Display(org.eclipse.swt.widgets.Display)

Example 24 with ModelItem

use of org.csstudio.trends.databrowser3.model.ModelItem in project org.csstudio.display.builder by kasemir.

the class ControllerBase method getArchivedData.

/**
 * Initiate archive data retrieval for a specific model item
 *  @param item Model item. NOP for non-PVItem
 *  @param start Start time
 *  @param end End time
 */
private void getArchivedData(final ModelItem item, final Instant start, final Instant end) {
    // Only useful for PVItems with archive data source
    if (!(item instanceof PVItem))
        return;
    final PVItem pv_item = (PVItem) item;
    if (pv_item.getArchiveDataSources().length <= 0)
        return;
    // Determine ongoing jobs for this item
    final List<ArchiveFetchJob> ongoing = new ArrayList<>();
    final ArchiveFetchJob new_job = makeArchiveFetchJob(pv_item, start, end);
    synchronized (archive_fetch_jobs) {
        for (Iterator<ArchiveFetchJob> iter = archive_fetch_jobs.iterator(); iter.hasNext(); ) /**/
        {
            final ArchiveFetchJob job = iter.next();
            if (job.getPVItem() == pv_item) {
                ongoing.add(job);
                iter.remove();
            }
        }
        // Track new job
        archive_fetch_jobs.add(new_job);
    }
    // job.schedule();
    Activator.getThreadPool().execute(() -> {
        // In background, stop ongoing jobs
        for (ArchiveFetchJob running : ongoing) {
            try {
                running.cancel();
                running.join(10000, null);
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Cannot cancel " + running, ex);
            }
        }
        // .. then start new one
        new_job.schedule();
    });
}
Also used : ArchiveFetchJob(org.csstudio.trends.databrowser3.archive.ArchiveFetchJob) ArrayList(java.util.ArrayList) PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 25 with ModelItem

use of org.csstudio.trends.databrowser3.model.ModelItem in project org.csstudio.display.builder by kasemir.

the class DataBrowserPropertySheetPage method createTracesTabItemPanel.

/**
 * Within SashForm of the "Traces" tab, create the Model Item table
 *  @param sashform
 */
private void createTracesTabItemPanel(final SashForm sashform) {
    // TableColumnLayout requires the TableViewer to be in its own Composite!
    final Composite model_item_top = new Composite(sashform, SWT.BORDER);
    final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10);
    model_item_top.setLayout(table_layout);
    // Would like to _not_ use FULL_SELECTION so that only the currently selected
    // cell gets highlighted, allowing the 'color' to still be visible
    // -> On Linux, you only get FULL_SELECTION behavior.
    // -> On Windows, editing is really odd, need to select a column before anything
    // can be edited, plus color still invisible
    // ---> Using FULL_SELECTION
    trace_table = new TableViewer(model_item_top, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    final Table table = trace_table.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    final TraceTableHandler tth = new TraceTableHandler();
    tth.createColumns(table_layout, operations_manager, trace_table);
    trace_table.setContentProvider(tth);
    trace_table.setInput(model);
    new ControlSystemDragSource(trace_table.getControl()) {

        @Override
        public Object getSelection() {
            final IStructuredSelection selection = (IStructuredSelection) trace_table.getSelection();
            final Object[] objs = selection.toArray();
            final ModelItem[] items = Arrays.copyOf(objs, objs.length, ModelItem[].class);
            return items;
        }
    };
}
Also used : ControlSystemDragSource(org.csstudio.ui.util.dnd.ControlSystemDragSource) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)23 ArrayList (java.util.ArrayList)12 PVItem (org.csstudio.trends.databrowser3.model.PVItem)10 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)7 VType (org.diirt.vtype.VType)6 Instant (java.time.Instant)5 ValueIterator (org.csstudio.archive.reader.ValueIterator)5 Model (org.csstudio.trends.databrowser3.model.Model)4 PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)4 AnnotationInfo (org.csstudio.trends.databrowser3.model.AnnotationInfo)3 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)3 FormulaInput (org.csstudio.trends.databrowser3.model.FormulaInput)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 PrintWriter (java.io.PrintWriter)2 InputItem (org.csstudio.apputil.ui.formula.InputItem)2 TraceType (org.csstudio.javafx.rtplot.TraceType)2 PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)2 RequestType (org.csstudio.trends.databrowser3.model.RequestType)2 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)2