Search in sources :

Example 1 with PlotSample

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

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

the class PlotDemo method createGUI.

// final private PlotListener listener = new PlotListener()
// {
// @Override
// public void scrollRequested(final boolean enable_scrolling)
// {
// System.out.println("Scroll enabled: " + enable_scrolling);
// scroll = enable_scrolling;
// }
// 
// @Override
// public void timeConfigRequested()
// {
// System.out.println("Time Config requested");
// }
// 
// @Override
// public void timeAxisChanged(final long start_ms, final long end_ms)
// {
// start_time = TimestampHelper.fromMillisecs(start_ms);
// end_time = TimestampHelper.fromMillisecs(end_ms);
// System.out.println("Time axis: " + start_time + " ... " + end_time);
// }
// 
// @Override
// public void valueAxisChanged(final int index, final double lower, final double upper)
// {
// System.out.println("Value axis " + index + ": " + lower + " ... " + upper);
// }
// 
// @Override
// public void droppedName(final String name)
// {
// System.out.println("Name dropped: " + name);
// }
// 
// @Override
// public void droppedPVName(final ProcessVariable name, final ArchiveDataSource archive)
// {
// System.out.println("PV Name dropped: " + name);
// }
// 
// @Override
// public void droppedFilename(final String file_name)
// {
// System.out.println("File Name dropped: " + file_name);
// }
// 
// @Override
// public void xyGraphConfigChanged(XYGraph newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void removeAnnotationChanged(Annotation oldValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void addAnnotationChanged(Annotation newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void backgroundColorChanged(Color newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void timeAxisForegroundColorChanged(Color oldColor,
// Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisForegroundColorChanged(int index, Color oldColor,
// Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisTitleChanged(int index, String oldTitle,
// String newTitle) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisAutoScaleChanged(int index, boolean oldAutoScale,
// boolean newAutoScale) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceNameChanged(int index, String oldName, String newName) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceYAxisChanged(int index, AxisConfig oldConfig,
// AxisConfig config) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceTypeChanged(int index, TraceType old,
// TraceType newTraceType) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceColorChanged(int index, Color old, Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisLogScaleChanged(int index, boolean old,
// boolean logScale) {
// // TODO Auto-generated method stub
// 
// }
// };
private void createGUI(final Composite parent) {
    final GridLayout layout = new GridLayout(1, false);
    parent.setLayout(layout);
    ModelBasedPlot plot;
    try {
        plot = new ModelBasedPlot(true);
    } catch (Exception e1) {
        e1.printStackTrace();
        return;
    }
    final FXCanvas canvas = new FXCanvas(parent, SWT.NONE);
    canvas.setScene(new Scene(plot.getPlot()));
    canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
    // [Done] button to end demo
    final Button ok = new Button(parent, SWT.PUSH);
    ok.setText("Done");
    ok.setLayoutData(new GridData(SWT.RIGHT, 0, true, false));
    ok.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            run = false;
        }
    });
    // plot.addListener(listener);
    // Create demo samples
    final List<PlotSample> values = new ArrayList<PlotSample>();
    for (int i = 1; i < 10; ++i) values.add(new PlotSample("Test", TestHelper.makeValue(i)));
    values.add(new PlotSample("Test", TestHelper.makeError(15, "Disconnected")));
    // Single value. Line should continue until the following 'disconnect'.
    values.add(new PlotSample("Test", TestHelper.makeValue(17)));
    values.add(new PlotSample("Test", TestHelper.makeError(18, "Disconnected")));
    for (int i = 20; i < 30; ++i) values.add(new PlotSample("Test", TestHelper.makeValue(i)));
    final PlotSampleArray samples = new PlotSampleArray();
    samples.set(values);
    // Add item with demo samples
    final ModelItem item = new ModelItem("Demo") {

        @Override
        public PlotSamples getSamples() {
            return samples;
        }

        @Override
        public void write(final PrintWriter writer) {
        // NOP
        }
    };
    // TODO: Fix or remove
    // item.setColor(new RGB(0, 0, 255));
    plot.addTrace(item);
// start_time = VTypeHelper.getTimestamp(samples.getSample(0).getValue());
// end_time = VTypeHelper.getTimestamp(samples.getSample(samples.getSize()-1).getValue());
// plot.setTimeRange(start_time, end_time);
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) Scene(javafx.scene.Scene) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) PlotSampleArray(org.csstudio.trends.databrowser3.model.PlotSampleArray) FXCanvas(javafx.embed.swt.FXCanvas) PrintWriter(java.io.PrintWriter)

Example 3 with PlotSample

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

the class WaveformView method showSelectedSample.

/**
 * Show the current sample of the current model item.
 */
private void showSelectedSample() {
    // Get selected sample (= one waveform)
    final PlotSamples samples = model_item.getSamples();
    final int idx = sample_index.getSelection();
    final PlotSample sample;
    samples.getLock().lock();
    try {
        sample_index.setMaximum(samples.size());
        sample = samples.get(idx);
    } finally {
        samples.getLock().unlock();
    }
    // Setting the value can be delayed while the plot is being updated
    final VType value = sample.getVType();
    Activator.getThreadPool().execute(() -> waveform.setValue(value));
    if (value == null)
        clearInfo();
    else {
        updateAnnotation(sample.getPosition(), sample.getValue());
        int size = value instanceof VNumberArray ? ((VNumberArray) value).getData().size() : 1;
        plot.getXAxis().setValueRange(0.0, (double) size);
        timestamp.setText(TimestampHelper.format(VTypeHelper.getTimestamp(value)));
        status.setText(NLS.bind(Messages.SeverityStatusFmt, VTypeHelper.getSeverity(value).toString(), VTypeHelper.getMessage(value)));
    }
    plot.requestUpdate();
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) VType(org.diirt.vtype.VType) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) PlotSamples(org.csstudio.trends.databrowser3.model.PlotSamples)

Example 4 with PlotSample

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

the class TraceTableHandler method createColumns.

/**
 * Create table columns: Auto-sizable, with label provider and editor
 *  @param table_layout
 *  @param operations_manager
 *  @param table_viewer
 */
public void createColumns(final TableColumnLayout table_layout, final UndoableActionManager operations_manager, final TableViewer table_viewer) {
    color_registry = new LocalResourceManager(JFaceResources.getResources(), table_viewer.getTable());
    final Shell shell = table_viewer.getTable().getShell();
    // Visible Column ----------
    TableViewerColumn view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceVisibility, 45, 1);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setImage(item.isVisible() ? Activator.getDefault().getImage(Activator.ICON_CHECKED) : Activator.getDefault().getImage(Activator.ICON_UNCHECKED));
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.TraceVisibilityTT;
        }
    });
    new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {

        @Override
        public int compare(final ModelItem item1, final ModelItem item2) {
            final int v1 = item1.isVisible() ? 1 : 0;
            final int v2 = item2.isVisible() ? 1 : 0;
            final int cmp = v1 - v2;
            if (cmp != 0)
                return cmp;
            return item1.getName().compareTo(item2.getName());
        }
    };
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).isVisible();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final ModelItem item = (ModelItem) element;
            final boolean visible = ((Boolean) value).booleanValue();
            if (!visible && prompt_for_not_visible) {
                if (!MessageDialog.openQuestion(shell, Messages.HideTraceWarning, Messages.HideTraceWarningDetail))
                    return;
                prompt_for_not_visible = false;
            }
            new ChangeVisibilityCommand(operations_manager, item, visible);
            editing = false;
        }
    });
    // Trace PV/Formula Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.ItemName, 70, 70);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(item.getName());
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.ItemNameTT;
        }
    });
    new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {

        @Override
        public int compare(final ModelItem item1, final ModelItem item2) {
            return item1.getName().compareTo(item2.getName());
        }
    };
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).getName();
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final String new_name = value.toString().trim();
            final ModelItem item = (ModelItem) element;
            if (new_name.equals(item.getName()))
                return;
            new ChangeNameCommand(shell, operations_manager, item, new_name);
            editing = false;
        }
    });
    // Display Name Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceDisplayName, 70, 70);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(item.getDisplayName());
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.TraceDisplayNameTT;
        }
    });
    new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {

        @Override
        public int compare(final ModelItem item1, final ModelItem item2) {
            return item1.getDisplayName().compareTo(item2.getDisplayName());
        }
    };
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).getDisplayName();
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final String new_name = value.toString().trim();
            final ModelItem item = (ModelItem) element;
            if (new_name.equals(item.getDisplayName()))
                return;
            new ChangeDisplayNameCommand(operations_manager, item, new_name);
            editing = false;
        }
    });
    // Color Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.Color, 40, 10);
    view_col.setLabelProvider(new ColorCellLabelProvider<ModelItem>() {

        @Override
        protected Color getColor(ModelItem item) {
            return color_registry.createColor(SWTMediaPool.getRGB(item.getPaintColor()));
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            return new RGBCellEditor(table_viewer.getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).getRGBColor();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            new ChangeColorCommand(operations_manager, (ModelItem) element, SWTMediaPool.getJFX((RGB) value));
            editing = false;
        }
    });
    // Selected sample time stamp and value
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.CursorTimestamp, 150, 30);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            final Optional<PlotDataItem<Instant>> sample = item.getSelectedSample();
            if (sample.isPresent())
                cell.setText(TimeHelper.format(sample.get().getPosition()));
            else
                cell.setText(Messages.NotApplicable);
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.CursorTimestampTT;
        }
    });
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.CursorValue, 40, 30);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            final Optional<PlotDataItem<Instant>> sample = item.getSelectedSample();
            if (sample.isPresent()) {
                final PlotSample plot_sample = (PlotSample) sample.get();
                String text = DefaultVTypeFormat.get().format(plot_sample.getVType());
                final String units = item.getUnits();
                if (units != null)
                    // $NON-NLS-1$
                    text += " " + units;
                cell.setText(text);
            } else
                cell.setText(Messages.NotApplicable);
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.CursorValueTT;
        }
    });
    // Scan Period Column (only applies to PVItems) ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.ScanPeriod, 70, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            if (item instanceof PVItem)
                cell.setText(Double.toString(((PVItem) item).getScanPeriod()));
            else
                cell.setText(Messages.NotApplicable);
        }

        @Override
        public String getToolTipText(final Object element) {
            if (!(element instanceof PVItem))
                return null;
            return Messages.ScanPeriodTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected boolean canEdit(Object element) {
            return element instanceof PVItem;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected Object getValue(final Object element) {
            if (element instanceof PVItem)
                return Double.toString(((PVItem) element).getScanPeriod());
            else
                return Messages.NotApplicable;
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            if (!(element instanceof PVItem))
                return;
            final PVItem pv = (PVItem) element;
            try {
                final double period = Double.parseDouble(value.toString().trim());
                if (period != pv.getScanPeriod())
                    new ChangeSamplePeriodCommand(shell, operations_manager, pv, period);
                editing = false;
            } catch (NumberFormatException ex) {
                // Display will revert to original value
                return;
            }
        }
    });
    // Buffer size Column (only applies to PVItems) ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.LiveSampleBufferSize, 70, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            if (item instanceof PVItem)
                cell.setText(Integer.toString(((PVItem) item).getLiveCapacity()));
            else
                cell.setText(Messages.NotApplicable);
        }

        @Override
        public String getToolTipText(final Object element) {
            if (!(element instanceof PVItem))
                return null;
            final PVItem pv = (PVItem) element;
            return NLS.bind(Messages.LiveBufferSizeInfoFmt, pv.getLiveCapacity(), new RelativeTime(pv.getLiveCapacity()).toString());
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected boolean canEdit(Object element) {
            return element instanceof PVItem;
        }

        @Override
        protected Object getValue(final Object element) {
            if (element instanceof PVItem)
                return Integer.toString(((PVItem) element).getLiveCapacity());
            else
                return Messages.NotApplicable;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            if (!(element instanceof PVItem))
                return;
            final PVItem pv = (PVItem) element;
            try {
                final int size = Integer.parseInt(value.toString().trim());
                if (size != pv.getLiveCapacity())
                    new ChangeLiveCapacityCommand(shell, operations_manager, pv, size);
                editing = false;
            } catch (NumberFormatException ex) {
                // Display will revert to original value
                return;
            }
        }
    });
    // Axis Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.Axis, 60, 30);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(item.getAxis().getName());
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.AxisTT;
        }
    });
    new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {

        @Override
        public int compare(final ModelItem item1, final ModelItem item2) {
            final int cmp = item1.getAxis().getName().compareTo(item2.getAxis().getName());
            if (cmp != 0)
                return cmp;
            return item1.getDisplayName().compareTo(item2.getDisplayName());
        }
    };
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        // Thread-safe copy of model axes as this editor is invoked
        final List<AxisConfig> axes = new ArrayList<>();

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            final List<String> axis_names = new ArrayList<>();
            axes.clear();
            for (AxisConfig axis : model.getAxes()) {
                axes.add(axis);
                axis_names.add(axis.getName());
            }
            final ComboBoxCellEditor combo = new ComboBoxCellEditor(table_viewer.getTable(), axis_names.toArray(new String[axis_names.size()]), SWT.READ_ONLY);
            combo.setValue(getValue(element));
            return combo;
        }

        @Override
        protected Object getValue(final Object element) {
            return model.getAxisIndex(((ModelItem) element).getAxis());
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final int axis_index = ((Integer) value).intValue();
            final AxisConfig axis = axes.get(axis_index);
            final ModelItem item = (ModelItem) element;
            if (axis != item.getAxis())
                new ChangeAxisCommand(operations_manager, item, axis);
            editing = false;
        }
    });
    // Trace Type Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceType, 75, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(item.getTraceType().toString());
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.TraceTypeTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            final ComboBoxCellEditor combo = new ComboBoxCellEditor(table_viewer.getTable(), TraceType.getDisplayNames(), SWT.READ_ONLY);
            combo.setValue(getValue(element));
            return combo;
        }

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).getTraceType().ordinal();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final TraceType trace_type = TraceType.values()[(((Integer) value).intValue())];
            final ModelItem item = (ModelItem) element;
            if (trace_type != item.getTraceType())
                new ChangeTraceTypeCommand(operations_manager, item, trace_type);
            editing = false;
        }
    });
    // Line Width Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceLineWidth, 40, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(Integer.toString(item.getLineWidth()));
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.TraceLineWidthTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected Object getValue(final Object element) {
            return Integer.toString(((ModelItem) element).getLineWidth());
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            int width;
            try {
                width = Integer.parseInt(value.toString().trim());
            } catch (NumberFormatException ex) {
                width = 0;
            }
            final ModelItem item = (ModelItem) element;
            if (width != item.getLineWidth())
                new ChangeLineWidthCommand(operations_manager, item, width);
            editing = false;
        }
    });
    // Point Type Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.PointType, 75, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(item.getPointType().toString());
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.PointTypeTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            final ComboBoxCellEditor combo = new ComboBoxCellEditor(table_viewer.getTable(), PointType.getDisplayNames(), SWT.READ_ONLY);
            combo.setValue(getValue(element));
            return combo;
        }

        @Override
        protected Object getValue(final Object element) {
            return ((ModelItem) element).getPointType().ordinal();
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final PointType point_type = PointType.values()[((Integer) value).intValue()];
            final ModelItem item = (ModelItem) element;
            if (point_type != item.getPointType())
                new ChangePointTypeCommand(operations_manager, item, point_type);
            editing = false;
        }
    });
    // Point Size Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.PointSize, 40, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(Integer.toString(item.getPointSize()));
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.PointSizeTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected Object getValue(final Object element) {
            return Integer.toString(((ModelItem) element).getPointSize());
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            int size;
            try {
                size = Integer.parseInt(value.toString().trim());
            } catch (NumberFormatException ex) {
                size = 0;
            }
            final ModelItem item = (ModelItem) element;
            if (size != item.getPointSize())
                new ChangePointSizeCommand(operations_manager, item, size);
            editing = false;
        }
    });
    // Request Type Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.RequestType, 75, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            if (item instanceof PVItem)
                cell.setText(((PVItem) item).getRequestType().toString());
            else
                cell.setText(Messages.NotApplicable);
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.RequestTypeTT;
        }
    });
    // Edit as boolean: Raw == false,  Optimized == true
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected boolean canEdit(final Object element) {
            return element instanceof PVItem;
        }

        @Override
        protected CellEditor getCellEditor(final Object element) {
            editing = true;
            return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
        }

        @Override
        protected Object getValue(final Object element) {
            return ((PVItem) element).getRequestType() == RequestType.OPTIMIZED;
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            final PVItem item = (PVItem) element;
            final RequestType request_type = ((Boolean) value).booleanValue() ? RequestType.OPTIMIZED : RequestType.RAW;
            if (request_type == RequestType.RAW && prompt_for_raw_data_request) {
                if (!MessageDialog.openQuestion(shell, Messages.RequestTypeWarning, Messages.RequestTypeWarningDetail))
                    return;
                prompt_for_raw_data_request = false;
            }
            new ChangeRequestTypeCommand(operations_manager, item, request_type);
            editing = false;
        }
    });
    // Waveform Index Column ----------
    view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.WaveformIndexCol, 40, 10);
    view_col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final ModelItem item = (ModelItem) cell.getElement();
            cell.setText(Integer.toString(item.getWaveformIndex()));
        }

        @Override
        public String getToolTipText(Object element) {
            return Messages.WaveformIndexColTT;
        }
    });
    view_col.setEditingSupport(new EditSupportBase(table_viewer) {

        @Override
        protected Object getValue(final Object element) {
            return Integer.toString(((ModelItem) element).getWaveformIndex());
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            editing = true;
            return super.getCellEditor(element);
        }

        @Override
        protected void setValue(final Object element, final Object value) {
            int index;
            try {
                index = Integer.parseInt(value.toString().trim());
                if (index < 0)
                    return;
                final ModelItem item = (ModelItem) element;
                if (index != item.getWaveformIndex())
                    new ChangeWaveformIndexCommand(operations_manager, item, index);
            } catch (NumberFormatException ex) {
                return;
            } finally {
                editing = false;
            }
        }
    });
    ColumnViewerToolTipSupport.enableFor(table_viewer);
}
Also used : CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) ArrayList(java.util.ArrayList) RelativeTime(org.csstudio.apputil.time.RelativeTime) Shell(org.eclipse.swt.widgets.Shell) ArrayList(java.util.ArrayList) List(java.util.List) TableColumnSortHelper(org.csstudio.apputil.ui.swt.TableColumnSortHelper) PVItem(org.csstudio.trends.databrowser3.model.PVItem) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) TraceType(org.csstudio.javafx.rtplot.TraceType) Optional(java.util.Optional) Color(org.eclipse.swt.graphics.Color) Instant(java.time.Instant) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) ViewerCell(org.eclipse.jface.viewers.ViewerCell) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) PointType(org.csstudio.javafx.rtplot.PointType) TableViewer(org.eclipse.jface.viewers.TableViewer) RequestType(org.csstudio.trends.databrowser3.model.RequestType)

Example 5 with PlotSample

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

Aggregations

PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)5 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)4 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 PVItem (org.csstudio.trends.databrowser3.model.PVItem)2 PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)2 VType (org.diirt.vtype.VType)2 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)2 ViewerCell (org.eclipse.jface.viewers.ViewerCell)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 PrintWriter (java.io.PrintWriter)1 List (java.util.List)1 Optional (java.util.Optional)1 FXCanvas (javafx.embed.swt.FXCanvas)1