Exemplo n.º 1
0
 @Transient
 public PonderationRule getNonNullSellPonderationRule() {
   if (sellPonderationRule == null) {
     EventSignalConfig eventConfig =
         (EventSignalConfig) ConfigThreadLocal.get(EventSignalConfig.EVENT_SIGNAL_NAME);
     Integer sellEvtThresh = eventConfig.getSellEventTriggerThreshold();
     Integer buyEvtThresh = eventConfig.getBuyEventTriggerThreshold();
     PonderationRule defaultSellPonderationRule =
         eventConfig.getSellPonderationRule(sellEvtThresh, buyEvtThresh);
     LOGGER.warn(
         "No sell weighting rule for "
             + this.name
             + " the config rule will be used "
             + defaultSellPonderationRule);
     return defaultSellPonderationRule;
   }
   return sellPonderationRule;
 }
Exemplo n.º 2
0
  @Override
  public void populatePopups(Composite popusGroup) {

    cleanPopupButtonsGroup(popusGroup);

    {
      evtDefsChartingBut = new Button(popusGroup, SWT.PUSH);
      evtDefsChartingBut.setFont(MainGui.DEFAULTFONT);
      evtDefsChartingBut.setText(INDICATORSBUTTXT);
      evtDefsChartingBut.setToolTipText(
          "This is to setup the display of calculators historical data at the bottom of the chart.\nYou must select a share in the portfolio to display its analysis.");

      evtDefsChartingBut.addSelectionListener(
          new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
              handleEvent();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
              handleEvent();
            }

            private void handleEvent() {
              initEvtChartingPopup(true);
            }
          });
    }
    {
      indicSettings = new Button(popusGroup, SWT.NONE);
      indicSettings.setFont(MainGui.DEFAULTFONT);
      indicSettings.setText("Calculator settings ...");
      indicSettings.setToolTipText(
          "Only user defined calculators can be customised.\n"
              + "You must select one of your user defined calculators in '"
              + INDICATORSBUTTXT
              + "'\n"
              + "And wait for its calculation to finish before changing the display settings.\n"
              + "New calculators can be defined using the menu Events -> Customise and create calculators ...");
      indicSettings.addSelectionListener(
          new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
              handle();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
              handle();
            }

            private void handle() {
              initChartSettingsPopup(true);
            }
          });
    }
    {
      evtDefsTrendChartingBut = new Button(popusGroup, SWT.PUSH);
      evtDefsTrendChartingBut.setFont(MainGui.DEFAULTFONT);
      evtDefsTrendChartingBut.setText(TRENDBUTTXT);
      evtDefsTrendChartingBut.setToolTipText(
          "This is to setup the display of gathered calculators trends.\nYou must select a share in the portfolio to display its analysis.");

      evtDefsTrendChartingBut.addSelectionListener(
          new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
              handleEvent();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
              handleEvent();
            }

            private void handleEvent() {
              initEvtDefTrendPopup(true);
            }
          });
    }
    {
      Button barSettings = new Button(popusGroup, SWT.NONE);
      barSettings.setFont(MainGui.DEFAULTFONT);
      barSettings.setText("Trends settings ...");
      barSettings.addSelectionListener(
          new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
              handle();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
              handle();
            }

            private void handle() {

              ActionDialogAction action =
                  new ActionDialogAction() {

                    @Override
                    public void action(Control targetControl) {

                      Stock viewStateParams =
                          chartTarget.getHightlitedEventModel().getViewParamRoot();
                      if (viewStateParams != null) {
                        highLight(chartTarget.getHighligtedId(), viewStateParams, true);
                      } else {
                        if (chartTarget.getChartedEvtDefsTrends() != null
                            && !chartTarget.getChartedEvtDefsTrends().isEmpty()) {
                          String errorMessage =
                              "You must select a share in the portfolio to display its analysis.";
                          showPopupDialog(errorMessage, "Ok", null, null);
                        }
                      }
                    }
                  };

              if (barSettingsDialog == null || barSettingsDialog.getShell().isDisposed()) {
                barSettingsDialog = new BarSettingsDialog(chartTarget, barChartSettings, action);
                Rectangle parentBounds =
                    chartTarget.getDisplay().map(chartTarget, null, chartTarget.getBounds());
                barChartSettings =
                    barSettingsDialog.open(
                        new Point(parentBounds.x + parentBounds.width, parentBounds.y));
              } else {
                barSettingsDialog.getShell().setVisible(true);
                barSettingsDialog.getShell().setActive();
                barSettingsDialog.getShell().setFocus();
              }
            }
          });
    }
    {
      Button recalc = new Button(popusGroup, SWT.PUSH);
      recalc.setFont(MainGui.DEFAULTFONT);
      recalc.setText("Force&&Update Calculations");
      recalc.addSelectionListener(
          new EventRefreshController(
              chartTarget.getHightlitedEventModel(),
              (RefreshableView) chartTarget.getParent().getParent(),
              ConfigThreadLocal.get(EventSignalConfig.EVENT_SIGNAL_NAME)) {

            @Override
            public void widgetSelected(SelectionEvent evt) {
              LOGGER.guiInfo("Cleaning and Recalculating. Thanks for waiting ...");

              EventTaskQueue.getSingleton().invalidateTasksCreationDates(TaskId.Analysis);

              Set<EventInfo> allSelectedEventInfos = chartTarget.getChartedEvtDefsTrends();
              if (!chartTarget.getChartedEvtDef().equals(EventDefinition.ZERO))
                allSelectedEventInfos.add(chartTarget.getChartedEvtDef());

              if (allSelectedEventInfos != null
                  && !allSelectedEventInfos.isEmpty()
                  && chartTarget.getHightlitedEventModel().getViewParamRoot() != null) {
                chartTarget.getHightlitedEventModel().setViewParam(0, allSelectedEventInfos);
              }

              this.updateEventRefreshModelState(
                  0l, TaskId.FetchQuotations, TaskId.Clean, TaskId.Analysis);
              super.widgetSelected(evt);
            }
          });
    }

    popusGroup.layout();
  }
Exemplo n.º 3
0
  private void eventsRecalculationAck(
      final Stock selectedShare,
      Date slidingStartDate,
      Date slidingEndDate,
      final HashSet<EventInfo> notUpToDateEI,
      Calendar minDate) {

    final RefreshableView parentView = (RefreshableView) chartTarget.getParent().getParent();
    final EventRefreshController ctrller =
        new EventRefreshController(
            chartTarget.getHightlitedEventModel(),
            parentView,
            ConfigThreadLocal.get(EventSignalConfig.EVENT_SIGNAL_NAME)) {

          @Override
          public void widgetSelected(SelectionEvent evt) {

            LOGGER.guiInfo("Cleaning and Recalculating. Thanks for waiting ...");
            EventTaskQueue.getSingleton().invalidateTasksCreationDates(TaskId.Analysis);
            this.updateEventRefreshModelState(
                0l, TaskId.FetchQuotations, TaskId.Clean, TaskId.Analysis);
            super.widgetSelected(evt);
          }
        };

    @SuppressWarnings("unchecked")
    boolean isValidTask =
        ctrller.isValidTask(
            TaskId.Analysis,
            selectedShare,
            new HashSet[] {notUpToDateEI},
            slidingStartDate,
            slidingEndDate);

    if (isValidTask) {

      chartTarget.getHightlitedEventModel().setViewParamRoot(selectedShare);
      chartTarget.getHightlitedEventModel().setViewParam(0, notUpToDateEI);

      String msg =
          "Analysis are not up to date for "
              + selectedShare.getName()
              + ", the selected time frame and the requested trends.";
      String click = "Click to update calculations";
      if (minDate.after(new Date(0)))
        msg =
            msg
                + "\nMinimun calculation date reached for this stock : "
                + new SimpleDateFormat("MMM dd yyyy").format(minDate);
      for (EventInfo eventInfo : notUpToDateEI) {
        if (chartTarget.getChartedEvtDefsTrends().contains(eventInfo)
            || chartTarget.getChartedEvtDef().equals(eventInfo)) {
          msg = msg + "\n'" + eventInfo.getEventReadableDef() + "' may be a candidate for update";
        }
      }
      ActionDialogAction action =
          new ActionDialogAction() {

            @Override
            public void action(Control targetControl) {
              ctrller.widgetSelected(null);
            }
          };

      showPopupDialog(msg, click, null, action);

    } else {
      //			hidePopupDialog();
    }
  }