/** * 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 Set<String> existing_names = new HashSet<>(); for (ModelItem item : model.getItems()) existing_names.add(item.getName()); final List<AxisConfig> axes = new ArrayList<>(); final List<String> axes_names = new ArrayList<>(); for (AxisConfig axis : model.getAxes()) { axes.add(axis); axes_names.add(axis.getName()); } final AddPVDialog dlg = new AddPVDialog(shell, existing_names, axes_names, formula); dlg.setName(name); if (dlg.open() != Window.OK) return false; // Did user select axis? final AxisConfig axis; if (dlg.getAxisIndex() >= 0) axis = axes.get(dlg.getAxisIndex()); 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(), 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(), dlg.getScanPeriod(), axis, archive); return true; }