Search in sources :

Example 36 with Model

use of org.csstudio.trends.databrowser3.model.Model 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 37 with Model

use of org.csstudio.trends.databrowser3.model.Model 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 38 with Model

use of org.csstudio.trends.databrowser3.model.Model 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 39 with Model

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

Example 40 with Model

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

the class DataBrowserPropertySheetPage method createValueAxesTab.

/**
 * Create tab for traces (PVs, Formulas)
 *  @param tabs
 */
private void createValueAxesTab(final TabFolder tab_folder) {
    final TabItem axes_tab = new TabItem(tab_folder, 0);
    axes_tab.setText(Messages.ValueAxes);
    final Composite parent = new Composite(tab_folder, 0);
    parent.setLayout(new GridLayout());
    // Rescale options
    final Composite rescale = new Composite(parent, 0);
    rescale.setLayout(new RowLayout());
    rescale.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    final Label l = new Label(rescale, 0);
    l.setText(Messages.ArchiveRescale_Label);
    final ArchiveRescale[] rescale_items = ArchiveRescale.values();
    rescales = new Button[rescale_items.length];
    for (int i = 0; i < rescales.length; ++i) {
        final ArchiveRescale item = rescale_items[i];
        if (item.ordinal() != i)
            // $NON-NLS-1$
            throw new Error("ArchiveRescale items out of order");
        rescales[i] = new Button(rescale, SWT.RADIO);
        rescales[i].setText(item.toString());
        if (model.getArchiveRescale() == item)
            rescales[i].setSelection(true);
        rescales[i].addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                // Only react to the selected button
                if (model.getArchiveRescale() == item)
                    return;
                new ChangeArchiveRescaleCommand(model, operations_manager, item);
            }
        });
    }
    // TableColumnLayout requires the TableViewer to be in its own Composite!
    final Composite table_parent = new Composite(parent, 0);
    table_parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10);
    table_parent.setLayout(table_layout);
    final AxesTableHandler ath = new AxesTableHandler(table_parent, table_layout, operations_manager);
    ath.getAxesTable().setInput(model);
    axes_tab.setControl(parent);
}
Also used : MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) TabItem(org.eclipse.swt.widgets.TabItem) GridLayout(org.eclipse.swt.layout.GridLayout) ArchiveRescale(org.csstudio.trends.databrowser3.model.ArchiveRescale) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)16 Model (org.csstudio.trends.databrowser3.model.Model)15 ArrayList (java.util.ArrayList)10 PVItem (org.csstudio.trends.databrowser3.model.PVItem)10 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)9 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)7 Instant (java.time.Instant)6 InputStream (java.io.InputStream)5 FormulaInput (org.csstudio.trends.databrowser3.model.FormulaInput)5 FormulaItem (org.csstudio.trends.databrowser3.model.FormulaItem)4 Shell (org.eclipse.swt.widgets.Shell)4 AnnotationInfo (org.csstudio.trends.databrowser3.model.AnnotationInfo)3 PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)3 PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)3 MinSizeTableColumnLayout (org.csstudio.ui.util.MinSizeTableColumnLayout)3 IPath (org.eclipse.core.runtime.IPath)3 Separator (org.eclipse.jface.action.Separator)3 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 PartInitException (org.eclipse.ui.PartInitException)3