Search in sources :

Example 1 with XMLPersistence

use of org.csstudio.trends.databrowser3.persistence.XMLPersistence 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 XMLPersistence

use of org.csstudio.trends.databrowser3.persistence.XMLPersistence 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 3 with XMLPersistence

use of org.csstudio.trends.databrowser3.persistence.XMLPersistence in project org.csstudio.display.builder by kasemir.

the class DataBrowserWidget method cloneModel.

public Model cloneModel() {
    // XXX: see about copying over live samples from old to new model
    final Model model = new Model();
    model.setMacros(this.getMacrosOrProperties());
    try {
        final InputStream input = this.getFileInputStream();
        new XMLPersistence().load(model, input);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Cannot create copy of data browser", ex);
    }
    return model;
}
Also used : InputStream(java.io.InputStream) DisplayModel(org.csstudio.display.builder.model.DisplayModel) Model(org.csstudio.trends.databrowser3.model.Model) XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence)

Example 4 with XMLPersistence

use of org.csstudio.trends.databrowser3.persistence.XMLPersistence in project org.csstudio.display.builder by kasemir.

the class OpenDisplayFile method openDisplay.

/**
 * {@inheritDoc}
 */
@Override
public void openDisplay(final String path, final String data) throws Exception {
    final Model model = new Model();
    // Read file
    final ResourceHelper resources = SingleSourcePlugin.getResourceHelper();
    final IPath ipath = resources.newPath(path);
    try (final InputStream stream = resources.getInputStream(ipath)) {
        new XMLPersistence().load(model, stream);
    }
    final IEditorInput input = new DataBrowserModelEditorInput(new PathEditorInput(ipath), model);
    // Create new editor
    final DataBrowserEditor editor = DataBrowserEditor.createInstance(input);
    if (editor == null)
        throw new Exception("Cannot create Data Browser");
}
Also used : IPath(org.eclipse.core.runtime.IPath) DataBrowserModelEditorInput(org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput) InputStream(java.io.InputStream) Model(org.csstudio.trends.databrowser3.model.Model) ResourceHelper(org.csstudio.utility.singlesource.ResourceHelper) XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence) IEditorInput(org.eclipse.ui.IEditorInput) DataBrowserEditor(org.csstudio.trends.databrowser3.editor.DataBrowserEditor) PathEditorInput(org.csstudio.utility.singlesource.PathEditorInput)

Example 5 with XMLPersistence

use of org.csstudio.trends.databrowser3.persistence.XMLPersistence in project org.csstudio.display.builder by kasemir.

the class DataBrowserEditor method save.

/**
 * Save current model content, mark editor as clean.
 *
 *  @param monitor <code>IProgressMonitor</code>, may be null.
 *  @param stream The stream to use.
 *  @return Returns <code>true</code> when successful.
 */
private void save(final IProgressMonitor monitor, final OutputStream stream) throws Exception {
    monitor.beginTask(Messages.Save, IProgressMonitor.UNKNOWN);
    try {
        new XMLPersistence().write(model, stream);
        setDirty(false);
        return;
    } catch (Exception ex) {
        ExceptionDetailsErrorDialog.openError(getSite().getShell(), Messages.Error, ex);
        // Writing failed, prompt for different name or 'cancel'
        doSaveAs();
    } finally {
        monitor.done();
    }
}
Also used : XMLPersistence(org.csstudio.trends.databrowser3.persistence.XMLPersistence) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)7 InputStream (java.io.InputStream)5 Model (org.csstudio.trends.databrowser3.model.Model)5 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)2 PVItem (org.csstudio.trends.databrowser3.model.PVItem)2 IPath (org.eclipse.core.runtime.IPath)2 PartInitException (org.eclipse.ui.PartInitException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Instant (java.time.Instant)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 IMacroTableProvider (org.csstudio.apputil.macros.IMacroTableProvider)1 InfiniteLoopException (org.csstudio.apputil.macros.InfiniteLoopException)1 MacroTable (org.csstudio.apputil.macros.MacroTable)1 MacroUtil (org.csstudio.apputil.macros.MacroUtil)1 DisplayModel (org.csstudio.display.builder.model.DisplayModel)1