Search in sources :

Example 1 with FormulaItem

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

the class EditFormulaDialogDemo method dialogDemo.

public void dialogDemo() throws Exception {
    final Shell shell = new Shell();
    // Demo model with some PVs and a formula
    final Model model = new Model();
    model.addItem(new PVItem("fred", 0.0));
    model.addItem(new PVItem("freddy", 0.0));
    model.addItem(new PVItem("jane", 0.0));
    model.addItem(new PVItem("janet", 0.0));
    final FormulaItem formula = new FormulaItem("demo", "2*x2", new FormulaInput[] { new FormulaInput(model.getItem("fred"), "x2"), new FormulaInput(model.getItem("janet"), "jj") });
    model.addItem(formula);
    final EditFormulaDialog edit = new EditFormulaDialog(null, shell, formula);
    System.out.println("Before editing:");
    dump(formula);
    if (edit.open()) {
        System.out.println("After editing:");
        dump(formula);
    } else
        System.out.println("Cancelled");
}
Also used : FormulaItem(org.csstudio.trends.databrowser3.model.FormulaItem) Shell(org.eclipse.swt.widgets.Shell) Model(org.csstudio.trends.databrowser3.model.Model) FormulaInput(org.csstudio.trends.databrowser3.model.FormulaInput) PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 2 with FormulaItem

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

the class AddModelItemCommand method forFormula.

/**
 * Create PV via undo-able AddModelItemCommand,
 *  displaying errors in dialog
 *  @param shell Shell used for error dialogs
 *  @param operations_manager OperationsManager where command will be reg'ed
 *  @param model Model were PV is to be added
 *  @param axis Axis
 *  @return AddModelItemCommand or <code>null</code> on error
 */
public static Optional<AddModelItemCommand> forFormula(final Shell shell, final UndoableActionManager operations_manager, final Model model, final String formula_name, final AxisConfig axis) {
    // Create item
    final FormulaItem item;
    try {
        // $NON-NLS-1$
        item = new FormulaItem(formula_name, "0", new FormulaInput[0]);
        axis.setVisible(true);
        item.setAxis(axis);
    } catch (Exception ex) {
        MessageDialog.openError(shell, Messages.Error, NLS.bind(Messages.AddItemErrorFmt, formula_name, ex.getMessage()));
        return Optional.empty();
    }
    // Add to model via undo-able command
    return Optional.of(new AddModelItemCommand(shell, operations_manager, model, item));
}
Also used : FormulaItem(org.csstudio.trends.databrowser3.model.FormulaItem) FormulaInput(org.csstudio.trends.databrowser3.model.FormulaInput)

Example 3 with FormulaItem

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

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

the class DataBrowserPropertySheetPage method createTracesTabDetailPanel.

/**
 * Within SashForm of the "Traces" tab, create the Item item detail panel:
 *  PV archive data sources, Formula
 *  @param sashform
 *  @param trace_table TableViewer for the trace table
 */
private void createTracesTabDetailPanel(final SashForm sashform) {
    final Composite item_detail_top = new Composite(sashform, SWT.BORDER);
    item_detail_top.setLayout(new FormLayout());
    archive_panel = new Composite(item_detail_top, 0);
    FormData fd = new FormData();
    fd.left = new FormAttachment(0);
    fd.top = new FormAttachment(0);
    fd.right = new FormAttachment(100);
    fd.bottom = new FormAttachment(100);
    archive_panel.setLayoutData(fd);
    archive_panel.setLayout(new GridLayout());
    Label l = new Label(archive_panel, 0);
    l.setText(Messages.ArchiveDataSources);
    l.setLayoutData(new GridData());
    // TableColumnLayout requires the TableViewer to be in its own Composite!
    final Composite table_parent = new Composite(archive_panel, 0);
    table_parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10);
    table_parent.setLayout(table_layout);
    archive_table = new TableViewer(table_parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
    final Table table = archive_table.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    final ArchivesTableHandler ath = new ArchivesTableHandler();
    ath.createColumns(table_layout, operations_manager, archive_table);
    archive_table.setContentProvider(ath);
    formula_panel = new Composite(item_detail_top, 0);
    fd = new FormData();
    fd.left = new FormAttachment(0);
    fd.top = new FormAttachment(0);
    fd.right = new FormAttachment(100);
    fd.bottom = new FormAttachment(100);
    formula_panel.setLayoutData(fd);
    formula_panel.setLayout(new GridLayout(2, false));
    l = new Label(formula_panel, 0);
    l.setText(Messages.FormulaLabel);
    l.setLayoutData(new GridData());
    formula_txt = new Text(formula_panel, SWT.READ_ONLY | SWT.BORDER);
    formula_txt.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    formula_txt.setToolTipText(Messages.FormulaLabelEditTT);
    formula_txt.addMouseListener(new MouseListener() {

        @Override
        public void mouseDown(MouseEvent e) {
            final Object item = ((IStructuredSelection) trace_table.getSelection()).getFirstElement();
            if (!(item instanceof FormulaItem))
                return;
            final FormulaItem formula = (FormulaItem) item;
            final EditFormulaDialog dlg = new EditFormulaDialog(operations_manager, formula_txt.getShell(), formula);
            dlg.open();
        }

        @Override
        public void mouseUp(MouseEvent e) {
        /* NOP */
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
        /* NOP */
        }
    });
    archive_panel.setVisible(false);
    formula_panel.setVisible(false);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) FormulaItem(org.csstudio.trends.databrowser3.model.FormulaItem) Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) MouseListener(org.eclipse.swt.events.MouseListener) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 5 with FormulaItem

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

the class DataBrowserPropertySheetPage method updateTracesTabDetailPanel.

/**
 * Update the lower 'detail' section of the "Traces" tab
 *  based on the currently selected item
 */
private void updateTracesTabDetailPanel() {
    // Show PV or Formula Panel depending on selection
    final IStructuredSelection sel = (IStructuredSelection) trace_table.getSelection();
    if (sel.size() == 1) {
        final Object item = sel.getFirstElement();
        if (item instanceof PVItem) {
            formula_panel.setVisible(false);
            archive_panel.setVisible(true);
            archive_table.setInput(item);
            return;
        }
        if (item instanceof FormulaItem) {
            final FormulaItem formula = (FormulaItem) item;
            formula_txt.setText(formula.getExpression());
            archive_table.setInput(null);
            archive_panel.setVisible(false);
            formula_panel.setVisible(true);
            return;
        }
    }
    // else: Neither PV nor formula, or multiple items selected
    archive_table.setInput(null);
    archive_panel.setVisible(false);
    formula_panel.setVisible(false);
}
Also used : FormulaItem(org.csstudio.trends.databrowser3.model.FormulaItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Aggregations

FormulaItem (org.csstudio.trends.databrowser3.model.FormulaItem)6 FormulaInput (org.csstudio.trends.databrowser3.model.FormulaInput)3 PVItem (org.csstudio.trends.databrowser3.model.PVItem)3 Model (org.csstudio.trends.databrowser3.model.Model)2 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)1 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)1 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)1 AddAxisCommand (org.csstudio.trends.databrowser3.propsheet.AddAxisCommand)1 EditFormulaDialog (org.csstudio.trends.databrowser3.propsheet.EditFormulaDialog)1 MinSizeTableColumnLayout (org.csstudio.ui.util.MinSizeTableColumnLayout)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseListener (org.eclipse.swt.events.MouseListener)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1