Beispiel #1
0
  /**
   * Update combo box of this view.
   *
   * @param model_changed set true if the model was changed.
   */
  private void update(final boolean model_changed) {
    if (model == null) { // Clear/disable GUI
      items.setItems(new String[] {Messages.SampleView_NoPlot});
      items.select(0);
      items.setEnabled(false);
      sample_table.setInput(null);
      return;
    }

    // Show PV names.
    // Also build array for following index-based check of selected item
    final List<ModelItem> model_items = new ArrayList<>();
    final List<String> names_list = new ArrayList<>();
    names_list.add(Messages.SampleView_SelectItem);
    for (ModelItem item : model.getItems()) {
      model_items.add(item);
      names_list.add(item.getName());
    }
    final String[] names = names_list.toArray(new String[names_list.size()]);
    if (!model_changed && items.getSelectionIndex() > 0) {
      // Is the previously selected item still valid?
      if (sample_table.getInput() instanceof ModelItem) {
        final ModelItem selected_item = (ModelItem) sample_table.getInput();
        if (model_items.indexOf(selected_item) != -1) { // Show same PV name again in combo box
          items.setItems(names);
          items.select(model_items.indexOf(selected_item) + 1);
          items.setEnabled(true);
          // Update sample table size. Not locking for size()
          sample_table.setItemCount(selected_item.getSamples().size());
          sample_table.refresh();
          return;
        }
      }
    }
    // Previously selected item no longer valid.
    // Show new items, clear rest
    items.setItems(names);
    items.select(0);
    items.setEnabled(true);
    sample_table.setInput(null);
  }
Beispiel #2
0
  /**
   * 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;
  }