Search in sources :

Example 11 with ModelItem

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

the class DeleteAxesAction method run.

@Override
public void run() {
    // Get selected axis items
    final Object[] sel = ((IStructuredSelection) axes_table.getSelection()).toArray();
    if (sel.length <= 0)
        return;
    final AxisConfig[] axes = new AxisConfig[sel.length];
    for (int i = 0; i < axes.length; ++i) {
        axes[i] = (AxisConfig) sel[i];
        // Check if axis is used by any model items.
        final ModelItem item = model.getFirstItemOnAxis(axes[i]);
        if (item != null) {
            MessageDialog.openWarning(axes_table.getTable().getShell(), Messages.DeleteAxis, NLS.bind(Messages.DeleteAxisWarningFmt, axes[i].getName(), item.getName()));
            return;
        }
    }
    // one axis position
    for (AxisConfig axis : axes) new DeleteAxisCommand(operations_manager, model, axis);
}
Also used : AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 12 with ModelItem

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

the class EditFormulaDialog method determineInputs.

/**
 * @return List of inputs for formula: Each model item is a possible input,
 *          mapped to a variable name that's either already used in the
 *          formula for that model item, or a simple "x1", "x2", ... when
 *          not already used
 */
@SuppressWarnings("nls")
private InputItem[] determineInputs() {
    final Model model = formula.getModel().get();
    // Create list of inputs.
    final ArrayList<InputItem> inputs = new ArrayList<InputItem>();
    // Every model item is a possible input.
    model_loop: for (ModelItem model_item : model.getItems()) {
        // Formula cannot be an input to itself
        if (model_item == formula)
            continue;
        // Create InputItem for that ModelItem
        InputItem input = null;
        // See if model item is already used in the formula
        for (FormulaInput existing_input : formula.getInputs()) {
            if (existing_input.getItem() == model_item) {
                // Yes, use the existing variable name
                input = new InputItem(model_item.getName(), existing_input.getVariableName());
                break;
            }
        }
        // If input is unused, assign variable name x1, x2, ...
        if (input == null) {
            for (InputItem existing_item : inputs) if (existing_item.getInputName().equals(model_item.getName())) {
                // The item with the same name was already added to the input list.
                continue model_loop;
            }
            // Try "x1", then "xx1", "xxx1" until an unused name is found
            String var_name = Integer.toString(inputs.size() + 1);
            boolean name_in_use;
            do {
                name_in_use = false;
                var_name = "x" + var_name;
                for (final FormulaInput existing_input : formula.getInputs()) if (existing_input.getVariableName().equals(var_name)) {
                    name_in_use = true;
                    break;
                }
            } while (name_in_use);
            input = new InputItem(model_item.getName(), var_name);
        }
        inputs.add(input);
    }
    return inputs.toArray(new InputItem[inputs.size()]);
}
Also used : InputItem(org.csstudio.apputil.ui.formula.InputItem) Model(org.csstudio.trends.databrowser3.model.Model) ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) FormulaInput(org.csstudio.trends.databrowser3.model.FormulaInput)

Example 13 with ModelItem

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

the class EditItemsCommand method undo.

@Override
public void undo() {
    for (int i = 0; i < items.size(); ++i) {
        final ModelItem item = items.get(i);
        try {
            item.setVisible(wasVisible.get(i));
            item.setName(oldName.get(i));
            item.setDisplayName(oldDisplayName.get(i));
            item.setColor(oldColor.get(i));
            item.setLineWidth(oldLineWidth.get(i));
            item.setAxis(oldAxis.get(i));
            item.setTraceType(oldTraceType.get(i));
            item.setWaveformIndex(oldWaveformIndex.get(i));
            if (item instanceof PVItem) {
                ((PVItem) item).setScanPeriod(oldScanPeriod.get(i));
                ((PVItem) item).setLiveCapacity(oldBufferSizes.get(i));
                ((PVItem) item).setRequestType(oldRequestType.get(i));
            }
        } catch (Exception ex) {
            ExceptionDetailsErrorDialog.openError(null, Messages.Error, ex);
        }
    }
}
Also used : ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 14 with ModelItem

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

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

the class EditItemsDialog method createDialogArea.

@Override
protected Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new GridLayout(3, false));
    Label label = new Label(composite, SWT.NONE);
    label.setText(Messages.ApplyChanges);
    label.setLayoutData(new GridData(SWT.LEFT, 0, true, false, 3, 1));
    // Show property
    chkApplyShow = new Button(composite, SWT.CHECK);
    chkApplyShow.setLayoutData(new GridData());
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.TraceVisibility);
    label.setLayoutData(new GridData());
    chkShow = new Button(composite, SWT.CHECK);
    chkShow.setToolTipText(Messages.TraceVisibilityTT);
    if (!items.isEmpty())
        chkShow.setSelection(items.get(0).isVisible());
    chkShow.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            chkApplyShow.setSelection(true);
        }
    });
    chkShow.setLayoutData(new GridData());
    // Item property
    chkApplyItem = new Button(composite, SWT.CHECK);
    chkApplyItem.setLayoutData(new GridData());
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.ItemName);
    label.setLayoutData(new GridData());
    textItem = new Text(composite, SWT.SINGLE | SWT.BORDER);
    textItem.setToolTipText(Messages.ItemNameTT);
    if (!items.isEmpty())
        textItem.setText(items.get(0).getName());
    textItem.addModifyListener((ModifyEvent e) -> chkApplyItem.setSelection(true));
    textItem.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    // Display name property
    chkApplyDisplayName = new Button(composite, SWT.CHECK);
    chkApplyDisplayName.setLayoutData(new GridData());
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.TraceDisplayName);
    label.setLayoutData(new GridData());
    textDisplayName = new Text(composite, SWT.SINGLE | SWT.BORDER);
    textDisplayName.setToolTipText(Messages.TraceDisplayNameTT);
    if (!items.isEmpty())
        textDisplayName.setText(items.get(0).getDisplayName());
    textDisplayName.addModifyListener((ModifyEvent e) -> chkApplyDisplayName.setSelection(true));
    textDisplayName.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    // Color property
    chkApplyColor = new Button(composite, SWT.CHECK);
    chkApplyColor.setLayoutData(new GridData());
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.Color);
    label.setLayoutData(new GridData());
    blobColor = new ColorBlob(composite, new RGB(0, 0, 0));
    blobColor.setToolTipText(Messages.ColorTT);
    // TODO: this should probably use Javafx color instead of SWT...
    if (!items.isEmpty())
        blobColor.setColor(SWTMediaPool.getRGB(items.get(0).getPaintColor()));
    blobColor.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            ColorDialog dialog = new ColorDialog(getShell());
            RGB color = dialog.open();
            if (color != null) {
                blobColor.setColor(color);
                chkApplyColor.setSelection(true);
            }
        }
    });
    GridData gd = new GridData(SWT.LEFT, 0, true, false);
    gd.widthHint = 40;
    gd.heightHint = 15;
    blobColor.setLayoutData(gd);
    // Scan period property
    chkApplyScan = new Button(composite, SWT.CHECK);
    chkApplyScan.setLayoutData(new GridData());
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.ScanPeriod);
    label.setLayoutData(new GridData());
    textScan = new Text(composite, SWT.SINGLE | SWT.BORDER);
    textScan.setToolTipText(Messages.ScanPeriodTT);
    boolean enableScan = false;
    for (ModelItem item : items) {
        if (item instanceof PVItem) {
            textScan.setText(Double.toString(((PVItem) item).getScanPeriod()));
            enableScan = true;
            break;
        }
    }
    chkApplyScan.setEnabled(enableScan);
    textScan.setEnabled(enableScan);
    textScan.addVerifyListener(new NumericalVerifyListener(textScan, true));
    textScan.addModifyListener((ModifyEvent e) -> chkApplyScan.setSelection(true));
    textScan.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    // Buffer size property
    chkApplyBufferSize = new Button(composite, SWT.CHECK);
    chkApplyBufferSize.setLayoutData(new GridData());
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.LiveSampleBufferSize);
    label.setLayoutData(new GridData());
    textBufferSize = new Text(composite, SWT.SINGLE | SWT.BORDER);
    boolean enableBufferSize = false;
    for (ModelItem item : items) {
        if (item instanceof PVItem) {
            textBufferSize.setText(Integer.toString(((PVItem) item).getLiveCapacity()));
            enableBufferSize = true;
            break;
        }
    }
    chkApplyBufferSize.setEnabled(enableBufferSize);
    textBufferSize.setEnabled(enableBufferSize);
    textBufferSize.addVerifyListener(new NumericalVerifyListener(textBufferSize, false));
    textBufferSize.addModifyListener((ModifyEvent e) -> chkApplyBufferSize.setSelection(true));
    textBufferSize.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    // Width property
    chkApplyWidth = new Button(composite, SWT.CHECK);
    chkApplyWidth.setLayoutData(new GridData());
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.TraceLineWidth);
    label.setLayoutData(new GridData());
    textWidth = new Text(composite, SWT.SINGLE | SWT.BORDER);
    textWidth.setToolTipText(Messages.TraceLineWidthTT);
    if (!items.isEmpty())
        textWidth.setText(Integer.toString(items.get(0).getLineWidth()));
    textWidth.addVerifyListener(new NumericalVerifyListener(textWidth, false));
    textWidth.addModifyListener((ModifyEvent e) -> chkApplyWidth.setSelection(true));
    textWidth.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    // Axis property
    chkApplyAxis = new Button(composite, SWT.CHECK);
    chkApplyAxis.setLayoutData(new GridData());
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.Axis);
    label.setLayoutData(new GridData());
    cmbAxis = new Combo(composite, SWT.READ_ONLY);
    cmbAxis.setToolTipText(Messages.AxisTT);
    int i = 0;
    for (AxisConfig axis : axes) {
        cmbAxis.add(axis.getName());
        if (items.size() >= 0 && items.get(0).getAxisIndex() == i)
            cmbAxis.select(i);
        ++i;
    }
    cmbAxis.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            chkApplyAxis.setSelection(true);
        }
    });
    cmbAxis.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    // Trace type property
    chkApplyTraceType = new Button(composite, SWT.CHECK);
    chkApplyTraceType.setLayoutData(new GridData());
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.TraceType);
    label.setLayoutData(new GridData());
    cmbTraceType = new Combo(composite, SWT.READ_ONLY);
    cmbTraceType.setToolTipText(Messages.TraceTypeTT);
    for (i = 0; i < TraceType.values().length; i++) {
        TraceType type = TraceType.values()[i];
        cmbTraceType.add(type.toString());
        if (items.size() >= 1 && type == items.get(0).getTraceType())
            cmbTraceType.select(i);
    }
    cmbTraceType.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            chkApplyTraceType.setSelection(true);
        }
    });
    cmbTraceType.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    // Request property
    chkApplyRequest = new Button(composite, SWT.CHECK);
    chkApplyRequest.setLayoutData(new GridData());
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.RequestType);
    label.setLayoutData(new GridData());
    cmbRequest = new Combo(composite, SWT.READ_ONLY);
    cmbRequest.setToolTipText(Messages.RequestTypeTT);
    RequestType defaultType = RequestType.OPTIMIZED;
    boolean enableRequest = false;
    for (ModelItem item : items) {
        if (item instanceof PVItem) {
            defaultType = ((PVItem) item).getRequestType();
            enableRequest = true;
            break;
        }
    }
    chkApplyRequest.setEnabled(enableRequest);
    cmbRequest.setEnabled(enableRequest);
    if (enableRequest) {
        for (i = 0; i < RequestType.values().length; i++) {
            RequestType type = RequestType.values()[i];
            cmbRequest.add(type.toString());
            if (type == defaultType)
                cmbRequest.select(i);
        }
    }
    cmbRequest.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            chkApplyRequest.setSelection(true);
        }
    });
    cmbRequest.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    // Index property
    chkApplyIndex = new Button(composite, SWT.CHECK);
    chkApplyIndex.setLayoutData(new GridData());
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.WaveformIndex);
    label.setLayoutData(new GridData());
    textIndex = new Text(composite, SWT.SINGLE | SWT.BORDER);
    textIndex.setToolTipText(Messages.WaveformIndexColTT);
    if (!items.isEmpty())
        textIndex.setText(Integer.toString(items.get(0).getWaveformIndex()));
    textIndex.addVerifyListener(new NumericalVerifyListener(textIndex, false));
    textIndex.addModifyListener((ModifyEvent e) -> chkApplyIndex.setSelection(true));
    textIndex.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    return composite;
}
Also used : TraceType(org.csstudio.javafx.rtplot.TraceType) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) RGB(org.eclipse.swt.graphics.RGB) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ColorDialog(org.eclipse.swt.widgets.ColorDialog) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PVItem(org.csstudio.trends.databrowser3.model.PVItem) RequestType(org.csstudio.trends.databrowser3.model.RequestType)

Aggregations

ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)23 ArrayList (java.util.ArrayList)12 PVItem (org.csstudio.trends.databrowser3.model.PVItem)10 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)7 VType (org.diirt.vtype.VType)6 Instant (java.time.Instant)5 ValueIterator (org.csstudio.archive.reader.ValueIterator)5 Model (org.csstudio.trends.databrowser3.model.Model)4 PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)4 AnnotationInfo (org.csstudio.trends.databrowser3.model.AnnotationInfo)3 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)3 FormulaInput (org.csstudio.trends.databrowser3.model.FormulaInput)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 PrintWriter (java.io.PrintWriter)2 InputItem (org.csstudio.apputil.ui.formula.InputItem)2 TraceType (org.csstudio.javafx.rtplot.TraceType)2 PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)2 RequestType (org.csstudio.trends.databrowser3.model.RequestType)2 XMLPersistence (org.csstudio.trends.databrowser3.persistence.XMLPersistence)2