protected void togglePausedConsumer(IAction pauseConsumer) {

    // The button can get out of sync if two clients are used.
    final boolean currentState = queueConnection.isQueuePaused(getSubmissionQueueName());
    try {
      pauseConsumer.setChecked(!currentState); // We are toggling it.

      IPublisher<PauseBean> pauser = service.createPublisher(getUri(), IEventService.CMD_TOPIC);
      pauser.setStatusSetName(IEventService.CMD_SET); // The set that other clients may check
      pauser.setStatusSetAddRequired(true);

      PauseBean pbean = new PauseBean();
      pbean.setQueueName(getSubmissionQueueName()); // The queue we are pausing
      pbean.setPause(pauseConsumer.isChecked());
      pauser.broadcast(pbean);

    } catch (Exception e) {
      ErrorDialog.openError(
          getViewSite().getShell(),
          "Cannot pause queue " + getSubmissionQueueName(),
          "Cannot pause queue "
              + getSubmissionQueueName()
              + "\n\nPlease contact your support representative.",
          new Status(IStatus.ERROR, "org.eclipse.scanning.event.ui", e.getMessage()));
    }
    pauseConsumer.setChecked(queueConnection.isQueuePaused(getSubmissionQueueName()));
  }
  private void createActions() throws Exception {

    final IContributionManager toolMan = getViewSite().getActionBars().getToolBarManager();
    final IContributionManager dropDown = getViewSite().getActionBars().getMenuManager();
    final MenuManager menuMan = new MenuManager();

    final Action openResults =
        new Action(
            "Open results for selected run", Activator.getImageDescriptor("icons/results.png")) {
          public void run() {
            openResults(getSelection());
          }
        };

    toolMan.add(openResults);
    toolMan.add(new Separator());
    menuMan.add(openResults);
    menuMan.add(new Separator());
    dropDown.add(openResults);
    dropDown.add(new Separator());

    this.up =
        new Action("Less urgent (-1)", Activator.getImageDescriptor("icons/arrow-090.png")) {
          public void run() {
            final StatusBean bean = getSelection();
            try {
              queueConnection.reorder(bean, -1);
            } catch (EventException e) {
              ErrorDialog.openError(
                  getViewSite().getShell(),
                  "Cannot move " + bean.getName(),
                  "'" + bean.getName() + "' cannot be moved in the submission queue.",
                  new Status(IStatus.ERROR, "org.eclipse.scanning.event.ui", e.getMessage()));
            }
            refresh();
          }
        };
    up.setEnabled(false);
    toolMan.add(up);
    menuMan.add(up);
    dropDown.add(up);

    this.down =
        new Action("More urgent (+1)", Activator.getImageDescriptor("icons/arrow-270.png")) {
          public void run() {
            final StatusBean bean = getSelection();
            try {
              queueConnection.reorder(getSelection(), +1);
            } catch (EventException e) {
              ErrorDialog.openError(
                  getViewSite().getShell(),
                  "Cannot move " + bean.getName(),
                  e.getMessage(),
                  new Status(IStatus.ERROR, "org.eclipse.scanning.event.ui", e.getMessage()));
            }
            refresh();
          }
        };
    down.setEnabled(false);
    toolMan.add(down);
    menuMan.add(down);
    dropDown.add(down);

    this.pause =
        new Action("Pause job.\nPauses a running job.", IAction.AS_CHECK_BOX) {
          public void run() {
            pauseJob();
          }
        };
    pause.setImageDescriptor(Activator.getImageDescriptor("icons/control-pause.png"));
    pause.setEnabled(false);
    pause.setChecked(false);
    toolMan.add(pause);
    menuMan.add(pause);
    dropDown.add(pause);

    this.pauseConsumer =
        new Action(
            "Pause " + getPartName() + " Queue. Does not pause running job.",
            IAction.AS_CHECK_BOX) {
          public void run() {
            togglePausedConsumer(this);
          }
        };
    pauseConsumer.setImageDescriptor(Activator.getImageDescriptor("icons/control-pause-red.png"));
    pauseConsumer.setChecked(queueConnection.isQueuePaused(getSubmissionQueueName()));
    toolMan.add(pauseConsumer);
    menuMan.add(pauseConsumer);
    dropDown.add(pauseConsumer);

    this.pauseMonitor = service.createSubscriber(getUri(), EventConstants.CMD_TOPIC);
    pauseMonitor.addListener(
        new IBeanListener<PauseBean>() {
          @Override
          public void beanChangePerformed(BeanEvent<PauseBean> evt) {
            pauseConsumer.setChecked(queueConnection.isQueuePaused(getSubmissionQueueName()));
          }
        });

    this.remove =
        new Action(
            "Stop job or remove if finished",
            Activator.getImageDescriptor("icons/control-stop-square.png")) {
          public void run() {
            stopJob();
          }
        };
    remove.setEnabled(false);
    toolMan.add(remove);
    menuMan.add(remove);
    dropDown.add(remove);

    this.rerun =
        new Action("Rerun...", Activator.getImageDescriptor("icons/rerun.png")) {
          public void run() {
            rerunSelection();
          }
        };
    rerun.setEnabled(false);
    toolMan.add(rerun);
    menuMan.add(rerun);
    dropDown.add(rerun);

    IAction open =
        new Action("Open...", Activator.getImageDescriptor("icons/application-dock-090.png")) {
          public void run() {
            openSelection();
          }
        };
    toolMan.add(open);
    menuMan.add(open);
    dropDown.add(open);

    this.edit =
        new Action("Edit...", Activator.getImageDescriptor("icons/modify.png")) {
          public void run() {
            editSelection();
          }
        };
    edit.setEnabled(false);
    toolMan.add(edit);
    menuMan.add(edit);
    dropDown.add(edit);

    toolMan.add(new Separator());
    menuMan.add(new Separator());

    final Action showAll =
        new Action("Show other users results", IAction.AS_CHECK_BOX) {
          public void run() {
            showEntireQueue = isChecked();
            viewer.refresh();
          }
        };
    showAll.setImageDescriptor(Activator.getImageDescriptor("icons/spectacle-lorgnette.png"));

    toolMan.add(showAll);
    menuMan.add(showAll);
    dropDown.add(showAll);

    toolMan.add(new Separator());
    menuMan.add(new Separator());
    dropDown.add(new Separator());

    final Action refresh =
        new Action("Refresh", Activator.getImageDescriptor("icons/arrow-circle-double-135.png")) {
          public void run() {
            reconnect();
          }
        };

    toolMan.add(refresh);
    menuMan.add(refresh);
    dropDown.add(refresh);

    final Action configure =
        new Action("Configure...", Activator.getImageDescriptor("icons/document--pencil.png")) {
          public void run() {
            PropertiesDialog dialog = new PropertiesDialog(getSite().getShell(), idProperties);

            int ok = dialog.open();
            if (ok == PropertiesDialog.OK) {
              idProperties.clear();
              idProperties.putAll(dialog.getProps());
              reconnect();
            }
          }
        };

    toolMan.add(configure);
    menuMan.add(configure);
    dropDown.add(configure);

    final Action clearQueue =
        new Action("Clear Queue") {
          public void run() {
            try {
              purgeQueues();
            } catch (EventException e) {
              e.printStackTrace();
              logger.error("Canot purge queues", e);
            }
          }
        };
    menuMan.add(new Separator());
    dropDown.add(new Separator());
    menuMan.add(clearQueue);
    dropDown.add(clearQueue);

    viewer.getControl().setMenu(menuMan.createContextMenu(viewer.getControl()));
  }