Ejemplo n.º 1
0
  private void createExchange(final Shell parent) {
    final Shell shell = ViewUtility.createModalDialogShell(parent, "Create Exchange");

    Composite nameComposite = _toolkit.createComposite(shell, SWT.NONE);
    nameComposite.setBackground(shell.getBackground());
    nameComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    nameComposite.setLayout(new GridLayout(2, false));

    _toolkit.createLabel(nameComposite, "Name:").setBackground(shell.getBackground());
    final Text nameText = new Text(nameComposite, SWT.BORDER);
    nameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    Composite typeComposite = _toolkit.createComposite(shell, SWT.NONE);
    typeComposite.setBackground(shell.getBackground());
    typeComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    typeComposite.setLayout(new GridLayout(2, false));

    String[] exchangeTypes;
    if (_ApiVersion.greaterThanOrEqualTo(1, 3)) // if the server supports Qpid JMX API 1.3
    { // request the current exchange types from the broker
      try {
        exchangeTypes = _vhmb.getExchangeTypes();
      } catch (IOException e1) {
        exchangeTypes =
            DEFAULT_EXCHANGE_TYPE_VALUES.toArray(new String[DEFAULT_EXCHANGE_TYPE_VALUES.size()]);
      }
    } else // use the fallback defaults.
    {
      exchangeTypes =
          DEFAULT_EXCHANGE_TYPE_VALUES.toArray(new String[DEFAULT_EXCHANGE_TYPE_VALUES.size()]);
    }

    _toolkit.createLabel(typeComposite, "Type:").setBackground(shell.getBackground());
    final org.eclipse.swt.widgets.List typeList =
        new org.eclipse.swt.widgets.List(typeComposite, SWT.SINGLE | SWT.BORDER);
    typeList.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    typeList.setItems(exchangeTypes);

    Composite durableComposite = _toolkit.createComposite(shell, SWT.NONE);
    durableComposite.setBackground(shell.getBackground());
    GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
    gridData.minimumWidth = 220;
    durableComposite.setLayoutData(gridData);
    durableComposite.setLayout(new GridLayout(2, false));

    _toolkit.createLabel(durableComposite, "Durable:").setBackground(shell.getBackground());
    final Button durableButton = new Button(durableComposite, SWT.CHECK);
    durableButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false));

    Composite okCancelButtonsComp = _toolkit.createComposite(shell);
    okCancelButtonsComp.setBackground(shell.getBackground());
    okCancelButtonsComp.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true));
    okCancelButtonsComp.setLayout(new GridLayout(2, false));

    Button okButton = _toolkit.createButton(okCancelButtonsComp, "OK", SWT.PUSH);
    okButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
    Button cancelButton = _toolkit.createButton(okCancelButtonsComp, "Cancel", SWT.PUSH);
    cancelButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));

    okButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            String name = nameText.getText();

            if (name == null || name.length() == 0) {
              ViewUtility.popupErrorMessage("Create Exchange", "Please enter a valid name");
              return;
            }

            int selectedTypeIndex = typeList.getSelectionIndex();

            if (selectedTypeIndex == -1) {
              ViewUtility.popupErrorMessage("Create Exchange", "Please select an Exchange type");
              return;
            }

            String type = typeList.getItem(selectedTypeIndex);

            boolean durable = durableButton.getSelection();

            shell.dispose();

            try {
              _vhmb.createNewExchange(name, type, durable);

              ViewUtility.operationResultFeedback(null, "Created Exchange", null);
              try {
                // delay to allow mbean registration notification processing
                Thread.sleep(250);
              } catch (InterruptedException ie) {
                // ignore
              }
            } catch (Exception e5) {
              ViewUtility.operationFailedStatusBarMessage("Error creating Exchange");
              MBeanUtility.handleException(_mbean, e5);
            }

            refresh(_mbean);
          }
        });

    cancelButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            shell.dispose();
          }
        });

    shell.setDefaultButton(okButton);
    shell.pack();
    ViewUtility.centerChildInParentShell(parent, shell);

    shell.open();
  }
Ejemplo n.º 2
0
  private void deleteQueuesOrExchanges(Shell parent, final VhostOperations op) {
    Table table;
    String windowTitle;
    String dialogueMessage;
    final String feedBackMessage;
    final String failureFeedBackMessage;

    if (op.equals(VhostOperations.DELETE_QUEUE)) {
      table = _queueTable;
      windowTitle = "Delete Queue(s)";
      dialogueMessage = "Delete Queue(s): ";
      feedBackMessage = "Queue(s) deleted";
      failureFeedBackMessage = "Error deleting Queue(s)";
    } else {
      table = _exchangeTable;
      windowTitle = "Delete Exchange(s)";
      dialogueMessage = "Delete Exchange(s): ";
      feedBackMessage = "Exchange(s) deleted";
      failureFeedBackMessage = "Error deleting Exchange(s)";
    }

    int selectionIndex = table.getSelectionIndex();
    if (selectionIndex == -1) {
      return;
    }

    int[] selectedIndices = table.getSelectionIndices();

    final ArrayList<ManagedBean> selectedMBeans = new ArrayList<ManagedBean>();

    for (int index = 0; index < selectedIndices.length; index++) {
      ManagedBean selectedMBean = (ManagedBean) table.getItem(selectedIndices[index]).getData();
      selectedMBeans.add(selectedMBean);
    }

    final Shell shell = ViewUtility.createModalDialogShell(parent, windowTitle);

    _toolkit.createLabel(shell, dialogueMessage).setBackground(shell.getBackground());

    final Text headerText = new Text(shell, SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
    headerText.setEditable(false);
    GridData data = new GridData(SWT.FILL, SWT.FILL, false, false);
    data.minimumHeight = 150;
    data.heightHint = 150;
    data.minimumWidth = 400;
    data.widthHint = 400;
    headerText.setLayoutData(data);

    String lineSeperator = System.getProperty("line.separator");
    for (ManagedBean mbean : selectedMBeans) {
      headerText.append(mbean.getName() + lineSeperator);
    }
    headerText.setSelection(0);

    Composite okCancelButtonsComp = _toolkit.createComposite(shell);
    okCancelButtonsComp.setBackground(shell.getBackground());
    okCancelButtonsComp.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true));
    okCancelButtonsComp.setLayout(new GridLayout(2, false));

    Button okButton = _toolkit.createButton(okCancelButtonsComp, "OK", SWT.PUSH);
    okButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
    Button cancelButton = _toolkit.createButton(okCancelButtonsComp, "Cancel", SWT.PUSH);
    cancelButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));

    okButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            shell.dispose();

            try {
              // perform the deletes
              for (ManagedBean mbean : selectedMBeans) {
                switch (op) {
                  case DELETE_QUEUE:
                    _vhmb.deleteQueue(mbean.getName());
                    _serverRegistry.removeManagedObject(mbean);
                    break;
                  case DELETE_EXCHANGE:
                    _vhmb.unregisterExchange(mbean.getName());
                    break;
                }
                // remove the mbean from the server registry now instead of
                // waiting for an mbean Unregistration Notification to do it
                _serverRegistry.removeManagedObject(mbean);
              }

              ViewUtility.operationResultFeedback(null, feedBackMessage, null);
            } catch (Exception e1) {
              ViewUtility.operationFailedStatusBarMessage(failureFeedBackMessage);
              MBeanUtility.handleException(_mbean, e1);
            }

            refresh(_mbean);
            ;
          }
        });

    cancelButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            shell.dispose();
          }
        });

    shell.setDefaultButton(okButton);
    shell.pack();
    ViewUtility.centerChildInParentShell(parent, shell);

    shell.open();
  }
Ejemplo n.º 3
0
  private void createQueue(final Shell parent) {
    final Shell shell = ViewUtility.createModalDialogShell(parent, "Create Queue");

    Composite nameComposite = _toolkit.createComposite(shell, SWT.NONE);
    nameComposite.setBackground(shell.getBackground());
    nameComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    nameComposite.setLayout(new GridLayout(2, false));

    _toolkit.createLabel(nameComposite, "Name:").setBackground(shell.getBackground());
    final Text nameText = new Text(nameComposite, SWT.BORDER);
    nameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    Composite ownerComposite = _toolkit.createComposite(shell, SWT.NONE);
    ownerComposite.setBackground(shell.getBackground());
    ownerComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    ownerComposite.setLayout(new GridLayout(2, false));

    _toolkit.createLabel(ownerComposite, "Owner (optional):").setBackground(shell.getBackground());
    final Text ownerText = new Text(ownerComposite, SWT.BORDER);
    ownerText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    Composite durableComposite = _toolkit.createComposite(shell, SWT.NONE);
    durableComposite.setBackground(shell.getBackground());
    GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
    gridData.minimumWidth = 220;
    durableComposite.setLayoutData(gridData);
    durableComposite.setLayout(new GridLayout(2, false));

    _toolkit.createLabel(durableComposite, "Durable:").setBackground(shell.getBackground());
    final Button durableButton = new Button(durableComposite, SWT.CHECK);
    durableButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false));

    Composite okCancelButtonsComp = _toolkit.createComposite(shell);
    okCancelButtonsComp.setBackground(shell.getBackground());
    okCancelButtonsComp.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true));
    okCancelButtonsComp.setLayout(new GridLayout(2, false));

    Button okButton = _toolkit.createButton(okCancelButtonsComp, "OK", SWT.PUSH);
    okButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
    Button cancelButton = _toolkit.createButton(okCancelButtonsComp, "Cancel", SWT.PUSH);
    cancelButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));

    okButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            String name = nameText.getText();

            if (name == null || name.length() == 0) {
              ViewUtility.popupErrorMessage("Create Queue", "Please enter a valid name");
              return;
            }

            String owner = ownerText.getText();

            if (owner != null && owner.length() == 0) {
              owner = null;
            }

            boolean durable = durableButton.getSelection();

            shell.dispose();

            try {
              _vhmb.createNewQueue(name, owner, durable);

              ViewUtility.operationResultFeedback(null, "Created Queue", null);
              try {
                // delay to allow mbean registration notification processing
                Thread.sleep(250);
              } catch (InterruptedException ie) {
                // ignore
              }
            } catch (Exception e5) {
              ViewUtility.operationFailedStatusBarMessage("Error creating Queue");
              MBeanUtility.handleException(_mbean, e5);
            }

            refresh(_mbean);
          }
        });

    cancelButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            shell.dispose();
          }
        });

    shell.setDefaultButton(okButton);
    shell.pack();
    ViewUtility.centerChildInParentShell(parent, shell);

    shell.open();
  }