Beispiel #1
0
  public void createPeriodActions() {
    try {
      JAXBContext jaxbContext = JAXBContext.newInstance(PeriodList.class);
      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
      StringReader stream =
          new StringReader(
              UIActivator.getDefault()
                  .getPreferenceStore()
                  .getString(UIActivator.PREFS_CHART_PERIODS));

      PeriodList list = (PeriodList) unmarshaller.unmarshal(stream);
      Collections.sort(
          list,
          new Comparator<Period>() {

            @Override
            public int compare(Period o1, Period o2) {
              if (o1.getPeriod().higherThan(o2.getPeriod())) {
                return -1;
              }
              if (o2.getPeriod().higherThan(o1.getPeriod())) {
                return 1;
              }
              return 0;
            }
          });

      periodActions = new ContributionItem[list.size()];
      for (int i = 0; i < periodActions.length; i++) {
        periodActions[i] = new ContributionItem(list.get(i));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #2
0
  /* (non-Javadoc)
   * @see org.eclipse.ui.part.WorkbenchPart#dispose()
   */
  @Override
  public void dispose() {
    view.removeViewChangeListener(viewChangeListener);

    if (subsetHistory != null) {
      PropertyChangeSupport propertyChangeSupport =
          (PropertyChangeSupport) subsetHistory.getAdapter(PropertyChangeSupport.class);
      if (propertyChangeSupport != null) {
        propertyChangeSupport.removePropertyChangeListener(propertyChangeListener);
      }
    }

    if (UIActivator.getDefault() != null) {
      IPreferenceStore preferences = UIActivator.getDefault().getPreferenceStore();
      preferences.removePropertyChangeListener(preferenceChangeListener);
    }

    super.dispose();
  }
  /* (non-Javadoc)
   * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
   */
  @Override
  public void init(IViewSite site, IMemento memento) throws PartInitException {
    super.init(site, memento);

    BundleContext bundleContext = UIActivator.getDefault().getBundle().getBundleContext();

    ServiceReference<ITradingSystemService> serviceReference =
        bundleContext.getServiceReference(ITradingSystemService.class);
    tradingSystemService = bundleContext.getService(serviceReference);

    activator = CoreActivator.getDefault();

    IDialogSettings rootDialogSettings = UIActivator.getDefault().getDialogSettings();
    dialogSettings = rootDialogSettings.getSection(VIEW_ID);
    if (dialogSettings == null) {
      dialogSettings = rootDialogSettings.addNewSection(VIEW_ID);
      dialogSettings.put(
          COLUMNS,
          new String[] {
            "org.eclipsetrader.ui.providers.LastTrade", //$NON-NLS-1$
            "org.eclipsetrader.ui.providers.BidPrice", //$NON-NLS-1$
            "org.eclipsetrader.ui.providers.AskPrice", //$NON-NLS-1$
            "org.eclipsetrader.ui.providers.Position", //$NON-NLS-1$
            "org.eclipsetrader.ui.providers.LastTradeDateTime", //$NON-NLS-1$
            "org.eclipsetrader.ui.providers.gain", //$NON-NLS-1$
          });
      IDialogSettings section = dialogSettings.addNewSection(COLUMN_NAMES);
      section.put("org.eclipsetrader.ui.providers.LastTrade", "Last"); // $NON-NLS-1$
      section.put("org.eclipsetrader.ui.providers.BidPrice", "Bid"); // $NON-NLS-1$
      section.put("org.eclipsetrader.ui.providers.AskPrice", "Ask"); // $NON-NLS-1$
      section.put("org.eclipsetrader.ui.providers.Position", "Position"); // $NON-NLS-1$
      section.put("org.eclipsetrader.ui.providers.LastTradeDateTime", "Date / Time"); // $NON-NLS-1$
      section.put("org.eclipsetrader.ui.providers.gain", "Gain"); // $NON-NLS-1$
      dialogSettings.addNewSection(COLUMN_WIDTHS);
    }

    settingsAction = new SettingsAction(site.getShell(), this);

    IActionBars actionBars = site.getActionBars();
    actionBars.setGlobalActionHandler(settingsAction.getId(), settingsAction);
    actionBars.updateActionBars();
  }
Beispiel #4
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);
    }
  }
 public NavigatorLabelProvider() {
   if (UIActivator.getDefault() != null) {
     folderIcon = UIActivator.getDefault().getImageRegistry().get(UIConstants.FOLDER_OBJECT);
     blankIcon = UIActivator.getDefault().getImageRegistry().get(UIConstants.BLANK_OBJECT);
     marketIcon = UIActivator.getDefault().getImageRegistry().get(UIConstants.MARKET_FOLDER);
     securityIcon = UIActivator.getDefault().getImageRegistry().get(UIConstants.REPOSITORY_OBJECT);
     watchListIcon =
         UIActivator.getDefault().getImageRegistry().get(UIConstants.REPOSITORY_OBJECT);
   }
 }
  /* (non-Javadoc)
   * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
   */
  @Override
  protected Control createContents(Composite parent) {
    Composite content = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.marginWidth = gridLayout.marginHeight = 0;
    content.setLayout(gridLayout);
    initializeDialogUnits(content);

    providers = new SecuritySelectionControl(content);
    providers.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    providers.setInput(UIActivator.getDefault().getRepositoryService().getSecurities());

    performDefaults();

    return content;
  }
Beispiel #7
0
  protected void doUpdate() {
    TimeSpan[] aggregation =
        new TimeSpan[] {
          TimeSpan.days(1), TimeSpan.minutes(1),
        };

    IDialogSettings dialogSettings =
        UIActivator.getDefault().getDialogSettings().getSection(ImportDataPage.class.getName());
    if (dialogSettings != null) {
      String[] s = dialogSettings.getArray("AGGREGATION");
      if (s != null && s.length != 0) {
        aggregation = new TimeSpan[s.length];
        for (int i = 0; i < aggregation.length; i++) {
          aggregation[i] = TimeSpan.fromString(s[i]);
        }
      }
    }

    DataImportJob job =
        new DataImportJob(security, DataImportJob.INCREMENTAL, null, null, aggregation);
    job.setUser(true);
    job.schedule();
  }
 protected IRepositoryService getRepositoryService() {
   return UIActivator.getDefault().getRepositoryService();
 }
Beispiel #9
0
  protected void createActions() {
    ISharedImages sharedImages =
        getViewSite().getWorkbenchWindow().getWorkbench().getSharedImages();

    zoomInAction =
        new Action(Messages.ChartViewPart_ZoomInAction) {

          @Override
          public void run() {
            int factor = viewer.getZoomFactor();
            viewer.setZoomFactor(factor + 1);
            zoomOutAction.setEnabled(true);
            zoomResetAction.setEnabled(true);
          }
        };
    zoomInAction.setId("zoomIn"); // $NON-NLS-1$
    zoomInAction.setActionDefinitionId("org.eclipsetrader.ui.charts.zoomIn"); // $NON-NLS-1$

    zoomOutAction =
        new Action(Messages.ChartViewPart_ZoomOutAction) {

          @Override
          public void run() {
            int factor = viewer.getZoomFactor();
            if (factor > 0) {
              viewer.setZoomFactor(factor - 1);
            }
            zoomOutAction.setEnabled(factor != 1);
            zoomResetAction.setEnabled(factor != 1);
          }
        };
    zoomOutAction.setId("zoomOut"); // $NON-NLS-1$
    zoomOutAction.setActionDefinitionId("org.eclipsetrader.ui.charts.zoomOut"); // $NON-NLS-1$

    zoomResetAction =
        new Action(Messages.ChartViewPart_NormalSizeAction) {

          @Override
          public void run() {
            viewer.setZoomFactor(0);
            zoomOutAction.setEnabled(false);
            zoomResetAction.setEnabled(false);
          }
        };
    zoomResetAction.setId("zoomReset"); // $NON-NLS-1$
    zoomResetAction.setActionDefinitionId("org.eclipsetrader.ui.charts.zoomReset"); // $NON-NLS-1$

    zoomOutAction.setEnabled(false);
    zoomResetAction.setEnabled(false);

    periodAllAction =
        new Action(Messages.ChartViewPart_AllPeriodAction, IAction.AS_RADIO_BUTTON) {

          @Override
          public void run() {
            setPeriod(null, TimeSpan.days(1));
          }
        };

    cutAction =
        new Action(Messages.ChartViewPart_CutAction) {

          @Override
          public void run() {}
        };
    cutAction.setId("cut"); // $NON-NLS-1$
    cutAction.setActionDefinitionId("org.eclipse.ui.edit.cut"); // $NON-NLS-1$
    cutAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
    cutAction.setDisabledImageDescriptor(
        sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED));
    cutAction.setEnabled(false);

    copyAction =
        new Action(Messages.ChartViewPart_CopyAction) {

          @Override
          public void run() {}
        };
    copyAction.setId("copy"); // $NON-NLS-1$
    copyAction.setActionDefinitionId("org.eclipse.ui.edit.copy"); // $NON-NLS-1$
    copyAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
    copyAction.setDisabledImageDescriptor(
        sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
    copyAction.setEnabled(false);

    pasteAction =
        new Action(Messages.ChartViewPart_PasteAction) {

          @Override
          public void run() {}
        };
    pasteAction.setId("copy"); // $NON-NLS-1$
    pasteAction.setActionDefinitionId("org.eclipse.ui.edit.paste"); // $NON-NLS-1$
    pasteAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
    pasteAction.setDisabledImageDescriptor(
        sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
    pasteAction.setEnabled(false);

    deleteAction =
        new Action(Messages.ChartViewPart_DeleteAction) {

          @Override
          public void run() {
            IStructuredSelection selection =
                (IStructuredSelection) getViewSite().getSelectionProvider().getSelection();
            if (!selection.isEmpty()) {
              if (MessageDialog.openConfirm(
                  getViewSite().getShell(),
                  getPartName(),
                  Messages.ChartViewPart_DeleteConfirmMessage)) {
                ChartViewItem viewItem = (ChartViewItem) selection.getFirstElement();
                ChartRowViewItem rowViewItem = (ChartRowViewItem) viewItem.getParent();
                if (rowViewItem.getItemCount() == 1) {
                  rowViewItem.getParentView().removeRow(rowViewItem);
                } else {
                  rowViewItem.removeChildItem(viewItem);
                }
              }
            }
          }
        };
    deleteAction.setId("delete"); // $NON-NLS-1$
    deleteAction.setActionDefinitionId("org.eclipse.ui.edit.delete"); // $NON-NLS-1$
    deleteAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
    deleteAction.setDisabledImageDescriptor(
        sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
    deleteAction.setEnabled(false);

    updateAction =
        new Action(Messages.ChartViewPart_UpdateAction) {

          @Override
          public void run() {
            doUpdate();
          }
        };
    updateAction.setId("update"); // $NON-NLS-1$
    updateAction.setImageDescriptor(
        UIActivator.getImageDescriptor("icons/etool16/refresh.gif")); // $NON-NLS-1$
    updateAction.setEnabled(true);

    propertiesAction =
        new PropertyDialogAction(
            new SameShellProvider(getViewSite().getShell()), getSite().getSelectionProvider()) {

          @Override
          public void run() {
            PreferenceDialog dialog = createDialog();
            if (dialog != null) {
              if (dialog.open() == Window.OK) {
                IStructuredSelection selection =
                    (IStructuredSelection) getSite().getSelectionProvider().getSelection();

                ChartViewItem viewItem = (ChartViewItem) selection.getFirstElement();
                ((ChartRowViewItem) viewItem.getParent()).refresh();

                refreshChart();
                setDirty();
              }
            }
          }
        };
    propertiesAction.setId(ActionFactory.PROPERTIES.getId());
    propertiesAction.setActionDefinitionId("org.eclipse.ui.file.properties"); // $NON-NLS-1$
    propertiesAction.setEnabled(false);

    currentPriceLineAction =
        new Action(Messages.ChartViewPart_ShowCurrentPriceAction, IAction.AS_CHECK_BOX) {

          @Override
          public void run() {
            currentPriceLineFactory.setEnable(isChecked());
            dialogSettings.put(K_SHOW_CURRENT_PRICE, isChecked());
          }
        };

    currentBookAction =
        new Action(Messages.ChartViewPart_ShowBookAction, IAction.AS_CHECK_BOX) {

          @Override
          public void run() {
            currentBookFactory.setEnable(isChecked());
            dialogSettings.put(K_SHOW_CURRENT_BOOK, isChecked());
          }
        };
  }
Beispiel #10
0
  /* (non-Javadoc)
   * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
   */
  @Override
  public void init(IViewSite site, IMemento memento) throws PartInitException {
    super.init(site, memento);

    this.memento = memento;
    this.preferenceStore = UIActivator.getDefault().getPreferenceStore();

    try {
      dialogSettings =
          UIActivator.getDefault()
              .getDialogSettings()
              .getSection(K_VIEWS)
              .getSection(site.getSecondaryId());
      uri = new URI(dialogSettings.get(K_URI));

      IRepositoryService repositoryService = UIActivator.getDefault().getRepositoryService();
      security = repositoryService.getSecurityFromURI(uri);

      String privateTemplate = dialogSettings.get(K_PRIVATE_TEMPLATE);
      if (privateTemplate != null) {
        template = unmarshal(privateTemplate);
      }

      if (template == null) {
        IPath templatePath = new Path("data"); // $NON-NLS-1$
        if (dialogSettings.get(K_TEMPLATE) != null) {
          templatePath = templatePath.append(dialogSettings.get(K_TEMPLATE));
        } else {
          templatePath = templatePath.append("basic-template.xml");
        }
        InputStream stream =
            FileLocator.openStream(UIActivator.getDefault().getBundle(), templatePath, false);
        template = unmarshal(stream);
      }
    } catch (Exception e) {
      Status status =
          new Status(
              IStatus.ERROR,
              UIActivator.PLUGIN_ID,
              Messages.ChartViewPart_LoadingErrorMessage + site.getSecondaryId(),
              e);
      UIActivator.getDefault().getLog().log(status);
    }

    site.setSelectionProvider(new SelectionProvider());

    createActions();
    createPeriodActions();

    IActionBars actionBars = site.getActionBars();

    IMenuManager menuManager = actionBars.getMenuManager();
    menuManager.add(new Separator("periods.top")); // $NON-NLS-1$
    menuManager.add(new Separator("periods")); // $NON-NLS-1$
    menuManager.add(new Separator("periods.bottom")); // $NON-NLS-1$
    menuManager.add(currentPriceLineAction);
    menuManager.add(currentBookAction);

    menuManager.appendToGroup("periods.top", periodAllAction); // $NON-NLS-1$
    if (periodActions != null) {
      for (int i = 0; i < periodActions.length; i++) {
        menuManager.appendToGroup("periods", periodActions[i]);
      }
    }

    IToolBarManager toolBarManager = actionBars.getToolBarManager();
    toolBarManager.add(new Separator("additions")); // $NON-NLS-1$
    toolBarManager.add(updateAction);

    TimeSpan periodTimeSpan = TimeSpan.fromString(dialogSettings.get(K_PERIOD));
    TimeSpan resolutionTimeSpan = TimeSpan.fromString(dialogSettings.get(K_RESOLUTION));
    setPeriodActionSelection(periodTimeSpan, resolutionTimeSpan);

    actionBars.setGlobalActionHandler(cutAction.getId(), cutAction);
    actionBars.setGlobalActionHandler(copyAction.getId(), copyAction);
    actionBars.setGlobalActionHandler(pasteAction.getId(), pasteAction);
    actionBars.setGlobalActionHandler(deleteAction.getId(), deleteAction);

    actionBars.setGlobalActionHandler(ActionFactory.PRINT.getId(), printAction);

    ToolAction toolAction =
        new ToolAction(
            Messages.ChartViewPart_LineAction, this, "org.eclipsetrader.ui.charts.tools.line");
    actionBars.setGlobalActionHandler(toolAction.getId(), toolAction);
    toolAction =
        new ToolAction(
            Messages.ChartViewPart_FiboLineAction,
            this,
            "org.eclipsetrader.ui.charts.tools.fiboline");
    actionBars.setGlobalActionHandler(toolAction.getId(), toolAction);
    toolAction =
        new ToolAction(
            Messages.ChartViewPart_FanLineAction,
            this,
            "org.eclipsetrader.ui.charts.tools.fanline");
    actionBars.setGlobalActionHandler(toolAction.getId(), toolAction);
    toolAction =
        new ToolAction(
            Messages.ChartViewPart_FiboArcAction,
            this,
            "org.eclipsetrader.ui.charts.tools.fiboarc");
    actionBars.setGlobalActionHandler(toolAction.getId(), toolAction);

    actionBars.setGlobalActionHandler(zoomInAction.getActionDefinitionId(), zoomInAction);
    actionBars.setGlobalActionHandler(zoomOutAction.getActionDefinitionId(), zoomOutAction);
    actionBars.setGlobalActionHandler(zoomResetAction.getActionDefinitionId(), zoomResetAction);
    actionBars.setGlobalActionHandler(propertiesAction.getId(), propertiesAction);
    actionBars.updateActionBars();
  }