Example #1
0
    @Override
    public int compare(Viewer viewer, Object e1, Object e2) {
      ManagedBean mbean1 = (ManagedBean) e1;
      ManagedBean mbean2 = (ManagedBean) e2;

      int comparison = 0;
      switch (column) {
        case 0:
          comparison = mbean1.getName().compareTo(mbean2.getName());
          break;
        default:
          comparison = 0;
      }
      // If descending order, flip the direction
      if (direction == DESCENDING) {
        comparison = -comparison;
      }
      return comparison;
    }
Example #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();
  }