Example #1
0
  public void setPVFormula(String pvFormula) {
    log.log(Level.FINE, "setPVFormula ({0})", pvFormula); // $NON-NLS-1$

    // If we are already scanning that pv, do nothing
    if (this.pvFormula != null && this.pvFormula.equals(pvFormula)) {
      return;
    }

    this.pvFormula = pvFormula;

    // The PV is different, so disconnect and reset the visuals
    if (pv != null) {
      pv.close();
      pv = null;
    }

    valuePanel.changeValue(null, false);
    changeValuePanel.reset();
    metadataPanel.changeValue(null);
    detailsPanel.changeValue(null, null);
    viewerPanel.changeValue(null);
    setLastError(null);
    copyValueAction.setEnabled(false);
    // If name is blank, update status to waiting and quit
    if ((pvFormula == null) || pvFormula.trim().isEmpty()) {
      setStatus(Messages.Probe_statusWaitingForPV);
      pvFormula = null;
    }

    // Update displayed name, unless it's already current
    if (!(Objects.equals(pvFomulaInputBar.getPVFormula(), pvFormula))) {
      pvFomulaInputBar.setPVFormula(pvFormula);
    }

    if (pvFormula != null) {
      setStatus(Messages.Probe_statusSearching);
      DesiredRateReadWriteExpression<?, Object> expression = formula(pvFormula);
      pv =
          PVManager.readAndWrite(expression)
              .timeout(ofMillis(5000), Messages.Probe_retryAfterTimeout)
              .readListener(
                  new PVReaderListener<Object>() {
                    @Override
                    public void pvChanged(PVReaderEvent<Object> event) {
                      Object value = event.getPvReader().getValue();
                      setLastError(event.getPvReader().lastException());
                      viewerPanel.changeValue(value);
                      if (event.getPvReader().isConnected()) {
                        setStatus(Messages.Probe_statusConnected);
                      } else {
                        setStatus(Messages.Probe_statusSearching);
                      }
                      valuePanel.changeValue(value, event.getPvReader().isConnected());
                      metadataPanel.changeValue(value);
                      copyValueAction.setEnabled(export.canExport(value));
                    }
                  })
              .readListener(changeValuePanel.getReaderListener())
              .writeListener(changeValuePanel.getWriterListener())
              .notifyOn(swtThread(this))
              .asynchWriteAndMaxReadRate(ofHertz(25));
      changeValuePanel.setPvWriter(pv);
      // Show the PV name as the title
      setPartName(pvFormula);
      detailsPanel.changeValue(expression, pvFormula);
    }
  }
Example #2
0
  public void createPartControl(Composite parent) {
    GridLayout gl_parent = new GridLayout(1, false);
    gl_parent.verticalSpacing = 0;
    gl_parent.marginWidth = 0;
    gl_parent.marginHeight = 0;
    parent.setLayout(gl_parent);

    pvFomulaInputBar =
        new PVFormulaInputBar(
            parent, SWT.None, Activator.getDefault().getDialogSettings(), MEMENTO_PVFORMULA_LIST);
    pvFomulaInputBar.addPropertyChangeListener(
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent event) {
            if ("pvFormula".equals(event.getPropertyName())) { // $NON-NLS-1$
              setPVFormula((String) event.getNewValue());
            }
          }
        });

    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    pvFomulaInputBar.setLayoutData(gd);

    errorBar = new ErrorBar(parent, SWT.NONE);
    errorBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    errorBar.setMarginRight(5);
    errorBar.setMarginLeft(5);
    errorBar.setMarginBottom(5);

    ScrolledComposite mainScroll = new ScrolledComposite(parent, SWT.V_SCROLL);
    mainScroll.setExpandHorizontal(true);
    mainScroll.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    mainPanel =
        new Composite(mainScroll, SWT.NONE) {
          @Override
          public void layout() {
            // TODO Auto-generated method stub
            super.layout();
            mainPanel.setSize(mainPanel.computeSize(SWT.DEFAULT, SWT.DEFAULT));
          }
        };
    GridLayout gl_mainPanel = new GridLayout();
    mainPanel.setLayout(gl_mainPanel);
    mainScroll.setContent(mainPanel);

    viewerPanel = new ViewerPanel(mainPanel, SWT.BORDER);
    viewerPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
    viewerPanel.setEnabled(false);

    valuePanel = new ValuePanel(mainPanel, SWT.BORDER);
    valuePanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    changeValuePanel = new ChangeValuePanel(mainPanel, SWT.BORDER);
    changeValuePanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    metadataPanel = new MetadataPanel(mainPanel, SWT.BORDER);
    metadataPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    detailsPanel = new DetailsPanel(mainPanel, SWT.BORDER);
    detailsPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    // Status bar
    statusBarPanel = new Composite(parent, SWT.NONE);
    GridLayout gl_statusBarPanel = new GridLayout(1, false);
    gl_statusBarPanel.verticalSpacing = 0;
    gl_statusBarPanel.marginWidth = 0;
    gl_statusBarPanel.marginHeight = 0;
    statusBarPanel.setLayout(gl_statusBarPanel);
    statusBarPanel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label label = new Label(statusBarPanel, SWT.SEPARATOR | SWT.HORIZONTAL);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    label.setSize(64, 2);

    statusBar = new Composite(statusBarPanel, SWT.NONE);
    statusBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    statusBar.setLayout(new GridLayout(2, false));

    statusLabel = new Label(statusBar, 0);
    statusLabel.setSize(43, 20);
    statusLabel.setText(Messages.Probe_statusLabelText);

    statusField = new Label(statusBar, SWT.BORDER);
    statusField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    statusField.setSize(326, 22);
    statusField.setText(Messages.Probe_statusWaitingForPV);

    createActions();
    initializeToolBar();

    // Determine initial state
    String initialPVFormula = null;
    boolean showViewer = false;
    boolean showValue = true;
    boolean showChangeValue = true;
    boolean showMetadata = false;
    boolean showDetails = false;

    if (memento != null) {
      initialPVFormula = memento.getString(MEMENTO_PVFORMULA);
      showViewer = nullDefault(memento.getBoolean(MEMENTO_SHOW_VIEWER), showViewer);
      showValue = nullDefault(memento.getBoolean(MEMENTO_SHOW_VALUE), showValue);
      showChangeValue = nullDefault(memento.getBoolean(MEMENTO_SHOW_CHANGE_VALUE), showChangeValue);
      showMetadata = nullDefault(memento.getBoolean(MEMENTO_SHOW_METADATA), showMetadata);
      showDetails = nullDefault(memento.getBoolean(MEMENTO_SHOW_DETAILS), showDetails);
    }
    setPVFormula(initialPVFormula);
    initSection(viewerPanel, showViewer);
    initSection(valuePanel, showValue);
    initSection(changeValuePanel, showChangeValue);
    initSection(metadataPanel, showMetadata);
    initSection(detailsPanel, showDetails);

    parent.layout();
    mainPanel.layout();
  }