Search in sources :

Example 1 with DataBrowserEditor

use of org.csstudio.trends.databrowser3.editor.DataBrowserEditor 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)

Example 2 with DataBrowserEditor

use of org.csstudio.trends.databrowser3.editor.DataBrowserEditor in project org.csstudio.display.builder by kasemir.

the class DataBrowserAwareView method updateEditor.

/**
 * The editor has changed.
 */
private void updateEditor(DataBrowserEditor new_editor) {
    final Model old_model = (editor == null) ? null : editor.getModel();
    editor = new_editor;
    final Model new_model = (editor == null) ? null : editor.getModel();
    updateModel(old_model, new_model);
}
Also used : Model(org.csstudio.trends.databrowser3.model.Model)

Example 3 with DataBrowserEditor

use of org.csstudio.trends.databrowser3.editor.DataBrowserEditor 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)

Aggregations

Model (org.csstudio.trends.databrowser3.model.Model)3 DataBrowserEditor (org.csstudio.trends.databrowser3.editor.DataBrowserEditor)2 InputStream (java.io.InputStream)1 Instant (java.time.Instant)1 ProcessVariable (org.csstudio.csdata.ProcessVariable)1 TimestampedPV (org.csstudio.csdata.TimestampedPV)1 DataBrowserModelEditorInput (org.csstudio.trends.databrowser3.editor.DataBrowserModelEditorInput)1 ChannelInfo (org.csstudio.trends.databrowser3.model.ChannelInfo)1 PVItem (org.csstudio.trends.databrowser3.model.PVItem)1 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)1 PathEditorInput (org.csstudio.utility.singlesource.PathEditorInput)1 ResourceHelper (org.csstudio.utility.singlesource.ResourceHelper)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IPath (org.eclipse.core.runtime.IPath)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IEditorInput (org.eclipse.ui.IEditorInput)1