예제 #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);
    }
  }
예제 #2
0
  private void createActions() {
    // Create the actions
    {
      // Drop down menu to select what to show
      // First selection for All and then each datasource in alphabetical
      // order
      final Menu sectionsMenu = new Menu(pvFomulaInputBar.getParent());
      MenuItem viewerMenuItem =
          ShowHideForGridLayout.createShowHideMenuItem(sectionsMenu, viewerPanel);
      viewerMenuItem.setText(Messages.Probe_sectionViewer);
      sectionToMenu.put(viewerPanel, viewerMenuItem);
      MenuItem valueMenuItem =
          ShowHideForGridLayout.createShowHideMenuItem(sectionsMenu, valuePanel);
      valueMenuItem.setText(Messages.Probe_sectionValue);
      sectionToMenu.put(valuePanel, valueMenuItem);
      MenuItem changeValueMenuItem =
          ShowHideForGridLayout.createShowHideMenuItem(sectionsMenu, changeValuePanel);
      changeValueMenuItem.setText(Messages.Probe_sectionChangeValue);
      sectionToMenu.put(changeValuePanel, changeValueMenuItem);
      MenuItem metadataMenuItem =
          ShowHideForGridLayout.createShowHideMenuItem(sectionsMenu, metadataPanel);
      metadataMenuItem.setText(Messages.Probe_sectionMetadata);
      sectionToMenu.put(metadataPanel, metadataMenuItem);
      MenuItem detailsMenuItem =
          ShowHideForGridLayout.createShowHideMenuItem(sectionsMenu, detailsPanel);
      detailsMenuItem.setText(Messages.Probe_sectionDetails);
      sectionToMenu.put(detailsPanel, detailsMenuItem);

      showHideAction =
          new Action(Messages.Probe_showHideButtonText, SWT.DROP_DOWN) {
            @Override
            public void runWithEvent(Event event) {
              // Point point = event.
              ToolItem toolItem = (ToolItem) event.widget;
              Point point =
                  toolItem
                      .getParent()
                      .toDisplay(
                          new Point(
                              toolItem.getBounds().x,
                              toolItem.getBounds().y + toolItem.getBounds().height));
              sectionsMenu.setLocation(point.x, point.y); // waiting
              sectionsMenu.setVisible(true);
            }
          };
      showHideAction.setImageDescriptor(
          ResourceManager.getPluginImageDescriptor(
              "org.eclipse.ui", //$NON-NLS-1$
              "/icons/full/obj16/submenu.gif")); //$NON-NLS-1$

      // showHideAction.setImageDescriptor(ResourceManager.getPluginImageDescriptor("org.csstudio.utility.pvmanager.ui.toolbox",
      // "icons/source.png"));
      showHideAction.setToolTipText(Messages.Probe_showHideButtonToolTipText);
      showHideAction.setMenuCreator(
          new IMenuCreator() {

            @Override
            public Menu getMenu(Menu parent) {
              return sectionsMenu;
            }

            @Override
            public Menu getMenu(Control parent) {
              // TODO Auto-generated method stub
              return sectionsMenu;
            }

            @Override
            public void dispose() {
              sectionsMenu.dispose();
            }
          });
    }

    copyValueAction =
        new Action(Messages.Probe_copyValueToClipboardButtonText, SWT.NONE) {

          public void runWithEvent(Event event) {
            try {
              StringWriter writer = new StringWriter();
              export.export(pv.getValue(), writer);
              String text = writer.toString();
              final Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
              clipboard.setContents(
                  new String[] {text}, new Transfer[] {TextTransfer.getInstance()});
            } catch (Exception ex) {
              ExceptionDetailsErrorDialog.openError(
                  PVManagerProbe.this.mainPanel.getShell(),
                  Messages.Probe_errorCopyValueToClipboard,
                  ex);
            }
          };
        };
    copyValueAction.setImageDescriptor(
        ResourceManager.getPluginImageDescriptor(
            "org.eclipse.ui", "/icons/full/etool16/paste_edit.gif")); // $NON-NLS-1$ //$NON-NLS-2$
    copyValueAction.setToolTipText(Messages.Probe_copyValueToClipboardButtonToolTipText);
    copyValueAction.setEnabled(false);
  }
예제 #3
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();
  }