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");
}
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;
}
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);
}
Aggregations