Ejemplo n.º 1
0
  /* (non-Javadoc)
   * @see org.eclipse.jface.dialogs.Dialog#okPressed()
   */
  @Override
  protected void okPressed() {
    try {
      IAccount account =
          (IAccount) ((IStructuredSelection) accountCombo.getSelection()).getFirstElement();
      IOrderType orderType =
          (IOrderType) ((IStructuredSelection) typeCombo.getSelection()).getFirstElement();
      Double limitPrice =
          orderType == IOrderType.Market ? null : priceFormat.parse(price.getText()).doubleValue();

      Order order =
          new Order(
              account,
              orderType,
              (IOrderSide) ((IStructuredSelection) sideCombo.getSelection()).getFirstElement(),
              security,
              numberFormat.parse(quantity.getText()).longValue(),
              limitPrice);

      if (!routeCombo.getSelection().isEmpty()) {
        order.setRoute(
            (IOrderRoute) ((IStructuredSelection) routeCombo.getSelection()).getFirstElement());
      }

      if (!validityCombo.getSelection().isEmpty()) {
        IOrderValidity validity =
            (IOrderValidity)
                ((IStructuredSelection) validityCombo.getSelection()).getFirstElement();
        order.setValidity(validity);
        if (expireDate.getEnabled()) {
          order.setExpire(expireDate.getSelection());
        }
      }

      if (!orderReference.getText().equals("")) {
        order.setReference(orderReference.getText());
      }

      IBroker connector =
          (IBroker) ((IStructuredSelection) brokerCombo.getSelection()).getFirstElement();
      IOrderMonitor tracker = connector.prepareOrder(order);
      tracker.submit();

      super.okPressed();
    } catch (Exception e) {
      Status status =
          new Status(
              IStatus.ERROR, UIActivator.PLUGIN_ID, 0, Messages.OrderDialog_SubmitErrorMessage, e);
      UIActivator.log(status);
      ErrorDialog.openError(getShell(), getShell().getText(), null, status);
    }
  }