Search in sources :

Example 1 with PVItem

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

the class DataBrowserEditor method init.

/**
 * Initialize model from editor input
 *  {@inheritDoc}
 */
@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
    setSite(site);
    if (input instanceof DataBrowserModelEditorInput) {
        // Received model with input
        model = ((DataBrowserModelEditorInput) input).getModel();
        setInput(input);
    } else {
        // Create new model
        model = new Model();
        setInput(new DataBrowserModelEditorInput(input, model));
        // Load model content from file
        try (final InputStream stream = SingleSourcePlugin.getResourceHelper().getInputStream(input)) {
            if (stream != null)
                new XMLPersistence().load(model, stream);
        } catch (Exception ex) {
            throw new PartInitException(NLS.bind(Messages.ConfigFileErrorFmt, input.getName()), ex);
        }
    }
    // Update the editor's name from "Data Browser" to title of model or file name
    // See DataBrowserModelEditorInput.getName()
    setPartName(getEditorInput().getName());
    model_listener = new ModelListenerAdapter() {

        @Override
        public void changedSaveChangesBehavior(final boolean save_changes) {
            is_dirty = save_changes;
            firePropertyChange(IEditorPart.PROP_DIRTY);
        }

        @Override
        public void changedTitle() {
            setDirty(true);
        }

        @Override
        public void changedLayout() {
            setDirty(true);
        }

        @Override
        public void changedTiming() {
            setDirty(true);
        }

        @Override
        public void changedArchiveRescale() {
            setDirty(true);
        }

        @Override
        public void changedColorsOrFonts() {
            setDirty(true);
        }

        @Override
        public void changedTimerange() {
            setDirty(true);
        }

        @Override
        public void changeTimeAxisConfig() {
            setDirty(true);
        }

        @Override
        public void changedAxis(final Optional<AxisConfig> axis) {
            setDirty(true);
        }

        @Override
        public void itemAdded(final ModelItem item) {
            setDirty(true);
        }

        @Override
        public void itemRemoved(final ModelItem item) {
            setDirty(true);
        }

        @Override
        public void changedItemVisibility(final ModelItem item) {
            setDirty(true);
        }

        @Override
        public void changedItemLook(final ModelItem item) {
            site.getShell().getDisplay().asyncExec(() -> setDirty(true));
        }

        @Override
        public void changedItemDataConfig(PVItem item) {
            setDirty(true);
        }

        @Override
        public void scrollEnabled(final boolean scroll_enabled) {
            setDirty(true);
        }

        @Override
        public void changedAnnotations() {
            setDirty(true);
        }
    };
    model.addListener(model_listener);
}
Also used : AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) InputStream(java.io.InputStream) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) PartInitException(org.eclipse.ui.PartInitException) ModelListenerAdapter(org.csstudio.trends.databrowser3.model.ModelListenerAdapter) Model(org.csstudio.trends.databrowser3.model.Model) XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence) PartInitException(org.eclipse.ui.PartInitException) PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 2 with PVItem

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

the class EditFormulaDialogDemo method dialogDemo.

public void dialogDemo() throws Exception {
    final Shell shell = new Shell();
    // Demo model with some PVs and a formula
    final Model model = new Model();
    model.addItem(new PVItem("fred", 0.0));
    model.addItem(new PVItem("freddy", 0.0));
    model.addItem(new PVItem("jane", 0.0));
    model.addItem(new PVItem("janet", 0.0));
    final FormulaItem formula = new FormulaItem("demo", "2*x2", new FormulaInput[] { new FormulaInput(model.getItem("fred"), "x2"), new FormulaInput(model.getItem("janet"), "jj") });
    model.addItem(formula);
    final EditFormulaDialog edit = new EditFormulaDialog(null, shell, formula);
    System.out.println("Before editing:");
    dump(formula);
    if (edit.open()) {
        System.out.println("After editing:");
        dump(formula);
    } else
        System.out.println("Cancelled");
}
Also used : FormulaItem(org.csstudio.trends.databrowser3.model.FormulaItem) Shell(org.eclipse.swt.widgets.Shell) Model(org.csstudio.trends.databrowser3.model.Model) FormulaInput(org.csstudio.trends.databrowser3.model.FormulaInput) PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 3 with PVItem

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

the class ControllerDemo method debug.

protected void debug() {
    for (ModelItem item : model.getItems()) {
        if (!(item instanceof PVItem)) {
            continue;
        }
        System.out.println("\n" + item.getName() + ":");
        final PlotSamples samples = item.getSamples();
        samples.getLock().lock();
        try {
            if (samples.size() <= 0)
                continue;
            Instant last = samples.get(0).getPosition();
            for (int s = 0; s < samples.size(); ++s) {
                final PlotSample sample = samples.get(s);
                System.out.println(sample);
                final Instant time = sample.getPosition();
                if (time.compareTo(last) < 0) {
                    System.out.println("Time sequence error!");
                    break;
                }
                last = time;
            }
        } finally {
            samples.getLock().unlock();
        }
    }
    new XMLPersistence().write(model, System.out);
}
Also used : Instant(java.time.Instant) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) PVItem(org.csstudio.trends.databrowser3.model.PVItem) XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence) PlotSamples(org.csstudio.trends.databrowser3.model.PlotSamples)

Example 4 with PVItem

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

the class OpenDataBrowserPopup method add.

/**
 * Add item
 *  @param model Model to which to add the item
 *  @param pv PV to add
 *  @param archive Archive to use or <code>null</code>
 *  @throws Exception on error
 */
private void add(final Model model, final ProcessVariable pv, final ArchiveDataSource archive) throws Exception {
    final PVItem item = new PVItem(pv.getName(), period);
    if (archive == null)
        item.useDefaultArchiveDataSources();
    else
        item.addArchiveDataSource(archive);
    // Add item to new axis
    item.setAxis(model.addAxis());
    model.addItem(item);
}
Also used : PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 5 with PVItem

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

the class OpenDataBrowserPopup method execute.

/**
 * {@inheritDoc}
 */
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // Get selection first because the ApplicationContext might change.
    ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    if (selection == null) {
        // This works for double-clicks.
        selection = HandlerUtil.getCurrentSelection(event);
    }
    // Create new editor
    final DataBrowserEditor editor = DataBrowserEditor.createInstance();
    if (editor == null)
        return null;
    // Add received items
    final Model model = editor.getModel();
    try {
        if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).getFirstElement() instanceof ChannelInfo) {
            // Received items are from search dialog
            final Object[] channels = ((IStructuredSelection) selection).toArray();
            for (Object channel : channels) {
                final ChannelInfo info = (ChannelInfo) channel;
                add(model, info.getProcessVariable(), info.getArchiveDataSource());
            }
        } else {
            // Add received PVs with default archive data sources
            final List<TimestampedPV> timestampedPVs = Arrays.asList(AdapterUtil.convert(selection, TimestampedPV.class));
            if (!timestampedPVs.isEmpty()) {
                // Add received items, tracking their start..end time
                long start_ms = Long.MAX_VALUE, end_ms = 0;
                for (TimestampedPV timestampedPV : timestampedPVs) {
                    final long time = timestampedPV.getTime();
                    if (time < start_ms)
                        start_ms = time;
                    if (time > end_ms)
                        end_ms = time;
                    final PVItem item = new PVItem(timestampedPV.getName().trim(), period);
                    item.setAxis(model.addAxis());
                    item.useDefaultArchiveDataSources();
                    model.addItem(item);
                }
                final Instant start = Instant.ofEpochMilli(start_ms).minus(Duration.ofMinutes(30));
                final Instant end = Instant.ofEpochMilli(end_ms).plus(Duration.ofMinutes(30));
                model.enableScrolling(false);
                model.setTimerange(start, end);
            } else {
                final ProcessVariable[] pvs = AdapterUtil.convert(selection, ProcessVariable.class);
                for (ProcessVariable pv : pvs) add(model, pv, null);
            }
        }
    } catch (Exception ex) {
        MessageDialog.openError(editor.getSite().getShell(), Messages.Error, NLS.bind(Messages.ErrorFmt, ex.getMessage()));
    }
    return null;
}
Also used : ProcessVariable(org.csstudio.csdata.ProcessVariable) Instant(java.time.Instant) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) TimestampedPV(org.csstudio.csdata.TimestampedPV) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) ISelection(org.eclipse.jface.viewers.ISelection) Model(org.csstudio.trends.databrowser3.model.Model) PVItem(org.csstudio.trends.databrowser3.model.PVItem) DataBrowserEditor(org.csstudio.trends.databrowser3.editor.DataBrowserEditor)

Aggregations

PVItem (org.csstudio.trends.databrowser3.model.PVItem)19 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)7 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)6 ArrayList (java.util.ArrayList)5 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)4 Model (org.csstudio.trends.databrowser3.model.Model)4 Instant (java.time.Instant)3 FormulaItem (org.csstudio.trends.databrowser3.model.FormulaItem)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 Shell (org.eclipse.swt.widgets.Shell)3 TestProperties (org.csstudio.apputil.test.TestProperties)2 TraceType (org.csstudio.javafx.rtplot.TraceType)2 FormulaInput (org.csstudio.trends.databrowser3.model.FormulaInput)2 PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)2 RequestType (org.csstudio.trends.databrowser3.model.RequestType)2 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)2 Test (org.junit.Test)2 InputStream (java.io.InputStream)1 List (java.util.List)1 Optional (java.util.Optional)1