Search in sources :

Example 6 with Source

use of org.csstudio.trends.databrowser3.export.Source 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 7 with Source

use of org.csstudio.trends.databrowser3.export.Source in project org.csstudio.display.builder by kasemir.

the class AddPVAction method runWithSuggestedName.

/**
 * Run the 'add PV' dialog with optional defaults
 *  @param name Suggested PV name, for example from drag-n-drop
 *  @param archive Archive data source for the new PV
 *  @return <code>true</code> if PV name was added, <code>false</code> if canceled by user
 */
public boolean runWithSuggestedName(final String name, final ArchiveDataSource archive) {
    // Prompt for PV name
    final AddPVDialog dlg = new AddPVDialog(shell, 1, model, formula);
    dlg.setName(0, name);
    if (dlg.open() != Window.OK)
        return false;
    // Did user select axis?
    final AxisConfig axis;
    if (dlg.getAxisIndex(0) >= 0)
        axis = model.getAxis(dlg.getAxisIndex(0));
    else
        // Use first empty axis, or create a new one
        axis = model.getEmptyAxis().orElseGet(() -> new AddAxisCommand(operations_manager, model).getAxis());
    // Create item
    if (formula) {
        final Optional<AddModelItemCommand> command = AddModelItemCommand.forFormula(shell, operations_manager, model, dlg.getName(0), axis);
        if (!command.isPresent())
            return false;
        // Open configuration dialog
        final FormulaItem formula = (FormulaItem) command.get().getItem();
        final EditFormulaDialog edit = new EditFormulaDialog(operations_manager, shell, formula);
        edit.open();
    } else
        AddModelItemCommand.forPV(shell, operations_manager, model, dlg.getName(0), dlg.getScanPeriod(0), axis, archive);
    return true;
}
Also used : AddAxisCommand(org.csstudio.trends.databrowser3.propsheet.AddAxisCommand) FormulaItem(org.csstudio.trends.databrowser3.model.FormulaItem) AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) EditFormulaDialog(org.csstudio.trends.databrowser3.propsheet.EditFormulaDialog)

Example 8 with Source

use of org.csstudio.trends.databrowser3.export.Source 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 9 with Source

use of org.csstudio.trends.databrowser3.export.Source in project org.csstudio.display.builder by kasemir.

the class ExportTest method createPVItem.

/**
 * @return PV with some archive data source
 */
private PVItem createPVItem(final String name) throws Exception {
    final PVItem item = new PVItem(name, 1.0);
    item.addArchiveDataSource(new ArchiveDataSource(URL, KEY, "test"));
    return item;
}
Also used : ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Aggregations

ArrayList (java.util.ArrayList)4 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)4 PVItem (org.csstudio.trends.databrowser3.model.PVItem)4 File (java.io.File)1 Instant (java.time.Instant)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 StartEndTimeParser (org.csstudio.apputil.time.StartEndTimeParser)1 ArchiveReader (org.csstudio.archive.reader.ArchiveReader)1 LinearValueIterator (org.csstudio.archive.reader.LinearValueIterator)1 MergingValueIterator (org.csstudio.archive.reader.MergingValueIterator)1 ValueIterator (org.csstudio.archive.reader.ValueIterator)1 Style (org.csstudio.archive.vtype.Style)1 ProcessVariable (org.csstudio.csdata.ProcessVariable)1 ArchiveFetchJob (org.csstudio.trends.databrowser3.archive.ArchiveFetchJob)1 MatlabFileExportJob (org.csstudio.trends.databrowser3.export.MatlabFileExportJob)1 MatlabScriptExportJob (org.csstudio.trends.databrowser3.export.MatlabScriptExportJob)1 PlainExportJob (org.csstudio.trends.databrowser3.export.PlainExportJob)1 Source (org.csstudio.trends.databrowser3.export.Source)1 SpreadsheetExportJob (org.csstudio.trends.databrowser3.export.SpreadsheetExportJob)1