Search in sources :

Example 1 with EditFormulaDialog

use of org.csstudio.trends.databrowser3.propsheet.EditFormulaDialog 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 EditFormulaDialog

use of org.csstudio.trends.databrowser3.propsheet.EditFormulaDialog 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 3 with EditFormulaDialog

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

Aggregations

FormulaItem (org.csstudio.trends.databrowser3.model.FormulaItem)3 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)1 FormulaInput (org.csstudio.trends.databrowser3.model.FormulaInput)1 Model (org.csstudio.trends.databrowser3.model.Model)1 PVItem (org.csstudio.trends.databrowser3.model.PVItem)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 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 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Shell (org.eclipse.swt.widgets.Shell)1