Ejemplo n.º 1
0
  protected void createMiscellaneousGroup(Composite parent) {
    Group content = new Group(parent, SWT.NONE);
    content.setText(Messages.OrderDialog_MiscLabel);
    content.setLayout(new GridLayout(2, false));
    content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    Label label = new Label(content, SWT.NONE);
    label.setText(Messages.OrderDialog_TimeInForceLabel);
    validityCombo = new ComboViewer(content, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN);
    validityCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    validityCombo.setContentProvider(new ArrayContentProvider());
    validityCombo.setLabelProvider(new LabelProvider());

    label = new Label(content, SWT.NONE);
    label.setText(Messages.OrderDialog_ExpireLabel);
    expireDate =
        new CDateTime(content, CDT.BORDER | CDT.DATE_SHORT | CDT.DROP_DOWN | CDT.TAB_FIELDS);
    expireDate.setPattern(Util.getDateFormatPattern());
    expireDate.setSelection(new Date());
    expireDate.setEnabled(false);

    label = new Label(content, SWT.NONE);
    label.setText(Messages.OrderDialog_ReferenceLabel);
    orderReference = new Text(content, SWT.BORDER);
    orderReference.setLayoutData(new GridData(convertWidthInCharsToPixels(40), SWT.DEFAULT));
  }
 @Override
 protected Object doGetValue() {
   if (!dateTime.isDisposed()) {
     return dateTime.getSelection();
   }
   return null;
 }
Ejemplo n.º 3
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);
    }
  }
 @Override
 protected void doSetValue(Object value) {
   if (value instanceof Date && !dateTime.isDisposed()) {
     Date oldValue;
     Date newValue;
     try {
       updating = true;
       oldValue = dateTime.getSelection();
       newValue = (Date) value;
       dateTime.setSelection(newValue);
       currentSelection = newValue;
       fireValueChange(Diffs.createValueDiff(oldValue, newValue));
     } finally {
       updating = false;
     }
   }
 }
Ejemplo n.º 5
0
  /** {@inheritDoc} */
  @Override
  public Map<IPreferenceGroup, Object> eventFired() {
    Map<IPreferenceGroup, Object> preferenceControlMap = new HashMap<IPreferenceGroup, Object>();
    Date toDate = toDateTime.getSelection();
    Date fromDate = fromDateTime.getSelection();

    if (null == oldToDate || oldToDate.getTime() != toDate.getTime()) {
      preferenceControlMap.put(PreferenceId.TimeLine.TO_DATE_ID, toDate);
      oldToDate = new Date(toDate.getTime());
    }
    if (null == oldFromDate || oldFromDate.getTime() != fromDate.getTime()) {
      preferenceControlMap.put(PreferenceId.TimeLine.FROM_DATE_ID, fromDate);
      oldFromDate = new Date(fromDate.getTime());
    }

    return preferenceControlMap;
  }
Ejemplo n.º 6
0
  /** @param args */
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("CDateTime");
    shell.setLayout(new GridLayout());

    final CDateTime cdt = new CDateTime(shell, CDT.BORDER | CDT.COMPACT | CDT.SIMPLE);
    cdt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

    shell.pack();
    Point size = shell.getSize();
    Rectangle screen = display.getMonitors()[0].getBounds();
    shell.setBounds((screen.width - size.x) / 2, (screen.height - size.y) / 2, size.x, size.y);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
Ejemplo n.º 7
0
 /**
  * {@inheritDoc}
  *
  * <p>If live is set on we disable this preference.
  */
 @Override
 public void eventFired(PreferenceEvent preferenceEvent) {
   if (PreferenceId.LIVEMODE.equals(preferenceEvent.getPreferenceId())) {
     Boolean liveOn =
         (Boolean) preferenceEvent.getPreferenceMap().get(PreferenceId.LiveMode.BUTTON_LIVE_ID);
     if (null != liveOn && liveOn.booleanValue()) {
       setEnabled(false);
     } else {
       setEnabled(true);
     }
   } else if (PreferenceId.TIMELINE.equals(preferenceEvent.getPreferenceId())) {
     if (preferenceEvent.getPreferenceMap().containsKey(PreferenceId.TimeLine.FROM_DATE_ID)) {
       fromDateTime.setSelection(
           (Date) preferenceEvent.getPreferenceMap().get(PreferenceId.TimeLine.FROM_DATE_ID));
     }
     if (preferenceEvent.getPreferenceMap().containsKey(PreferenceId.TimeLine.TO_DATE_ID)) {
       toDateTime.setSelection(
           (Date) preferenceEvent.getPreferenceMap().get(PreferenceId.TimeLine.TO_DATE_ID));
     }
   }
 }
 @Override
 public synchronized void dispose() {
   dateTime.removeSelectionListener(selectionListener);
   dateTime.removeFocusListener(focusListener);
   super.dispose();
 }
 /**
  * Observe the selection property of the provided CDateTime control.
  *
  * @param dateTime the control to observe
  */
 public CDateTimeObservableValue(CDateTime dateTime) {
   this.dateTime = dateTime;
   currentSelection = dateTime.getSelection();
   this.dateTime.addSelectionListener(selectionListener);
   this.dateTime.addFocusListener(focusListener);
 }
Ejemplo n.º 10
0
  /** {@inheritDoc} */
  @Override
  public Composite createControls(Composite parent, FormToolkit toolkit) {
    Section section = toolkit.createSection(parent, Section.TITLE_BAR);
    section.setText("Time Range");
    section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    mainComposite = toolkit.createComposite(section);
    mainComposite.setLayout(new GridLayout(1, false));
    section.setClient(mainComposite);

    Composite linksComposite = toolkit.createComposite(mainComposite);
    linksComposite.setLayout(new GridLayout(14, false));
    linksComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    toolkit.createLabel(linksComposite, "Last: ");
    createTimeHyperlink(linksComposite, toolkit, "15 minutes", 15 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "1 hour", 60 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "6 hours", 6 * 60 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "12 hours", 12 * 60 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "1 day", 24 * 60 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "7 days", 7 * 24 * 60 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "30 days", 30 * 24 * 60 * 60 * 1000L);

    Composite timeComposite = toolkit.createComposite(mainComposite);
    timeComposite.setLayout(new GridLayout(4, false));
    timeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    Date toDate = new Date();
    Date fromDate = new Date(toDate.getTime() - PreferenceId.TimeLine.TIMELINE_DEFAULT);

    toolkit.createLabel(timeComposite, "From: ");
    fromDateTime = new CDateTime(timeComposite, CDT.BORDER | CDT.DROP_DOWN);
    fromDateTime.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    fromDateTime.setFormat(CDT.DATE_SHORT | CDT.TIME_SHORT);
    fromDateTime.setSelection(fromDate);

    toolkit.createLabel(timeComposite, "To: ");
    toDateTime = new CDateTime(timeComposite, CDT.BORDER | CDT.DROP_DOWN);
    toDateTime.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    toDateTime.setFormat(CDT.DATE_SHORT | CDT.TIME_SHORT);
    toDateTime.setSelection(toDate);

    SelectionListener selectionListener =
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            getPreferencePanel().update();
          }
        };
    fromDateTime.addSelectionListener(selectionListener);
    toDateTime.addSelectionListener(selectionListener);

    getPreferencePanel().registerCallback(this);

    return mainComposite;
  }
Ejemplo n.º 11
0
 /**
  * Sets control enabled or not.
  *
  * @param enabled If control is enabled or not.
  */
 private void setEnabled(boolean enabled) {
   fromDateTime.setEnabled(enabled);
   toDateTime.setEnabled(enabled);
 }
Ejemplo n.º 12
0
  /** @param args */
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("CDateTime");
    shell.setLayout(new GridLayout(3, true));

    final CDateTime date = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
    date.setNullText("<day>");
    date.setPattern("dd");
    date.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

    final CDateTime month = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
    month.setNullText("<month>");
    month.setPattern("MMMM");
    month.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

    final CDateTime year = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
    year.setNullText("<year>");
    year.setPattern("yyyy");
    year.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

    shell.pack();
    Point size = shell.getSize();
    Rectangle screen = display.getMonitors()[0].getBounds();
    shell.setBounds((screen.width - size.x) / 2, (screen.height - size.y) / 2, size.x, size.y);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }