protected EventsCalculationThread( Date startDate, Date endDate, String eventListName, Currency calculationCurrency, Set<Observer> observers, Boolean keepCache, Queue eventQueue, JmsTemplate jmsTemplate) { super(); this.startDate = startDate; this.endDate = endDate; this.eventListName = eventListName; this.calculationCurrency = calculationCurrency; this.keepCache = keepCache; this.eventQueue = eventQueue; this.jmsTemplate = jmsTemplate; this.configs = ConfigThreadLocal.getAll(); this.observers = observers; for (Observer observer : observers) { this.addObserver(observer); } }
@Override public void run() { ConfigThreadLocal.set(Config.EVENT_SIGNAL_NAME, configs.get(Config.EVENT_SIGNAL_NAME)); ConfigThreadLocal.set( Config.INDICATOR_PARAMS_NAME, configs.get(Config.INDICATOR_PARAMS_NAME)); SymbolEvents eventsForStock = EventsResources.getInstance() .crudReadEventsForStock( selectedShare, exentedStartDate, chartTarget.getSlidingEndDate(), true, chartTarget.getChartedEvtDefsTrends(), IndicatorCalculationServiceMain.UI_ANALYSIS); setChanged(); notifyObservers(eventsForStock); }
@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; }
@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(); }
private void updateBarChart( final Stock selectedShare, Date exentedStartDate, final Boolean recalculationGranted, final Boolean needsUpdate) { final Map<String, Config> configs = ConfigThreadLocal.getAll(); Observer barDataObs = new Observer() { @Override public void update(Observable o, final Object arg) { final Set<EventInfo> noDataTrends = new HashSet<EventInfo>(); if (arg == null || ((SymbolEvents) arg).getDataResultMap().isEmpty()) { // No events found if (!recalculationGranted) { // No events found despite recalc chartTarget.getMainChartWraper().resetBarChart(); } else { noDataTrends.addAll(chartTarget.getChartedEvtDefsTrends()); } } else { // That's all or partially good, we display final Map<EventInfo, TuningResDTO> tuningRess = new ConcurrentHashMap<EventInfo, TuningResDTO>(); for (final EventInfo eventDefinition : chartTarget.getChartedEvtDefsTrends()) { TuningResDTO tuningResCache = null; try { tuningResCache = chartTarget .getHightlitedEventModel() .updateTuningRes( selectedShare, eventDefinition, chartTarget.getSlidingStartDate(), chartTarget.getSlidingEndDate()); } catch (Exception e) { LOGGER.error(e, e); } if (tuningResCache != null) { tuningRess.put(eventDefinition, tuningResCache); } else { noDataTrends.add(eventDefinition); } } Runnable runnable = new Runnable() { public void run() { try { SymbolEvents ses = (SymbolEvents) arg; SortedMap<DataSetBarDescr, SortedMap<Date, Double>> barsData = ChartBarUtils.buildBarsData( selectedShare, chartTarget.getChartedEvtDefsTrends(), chartTarget.getSlidingStartDate(), chartTarget.getSlidingEndDate(), ses, tuningRess, barChartSettings); chartTarget .getMainChartWraper() .updateBarDataSet( barsData, chartTarget.getHighligtedId(), barChartSettings, chartTarget.getPlotChartDimensions()); } catch (Exception e) { LOGGER.error( "arg : " + arg + ", chartTarget.getMainChartWraper() : " + chartTarget.getMainChartWraper() + ", chartTarget.getHighligtedId() : " + chartTarget.getHighligtedId() + ", barChartSettings : " + barChartSettings + ", chartTarget.getPlotChartDimensions() : " + chartTarget.getPlotChartDimensions(), e); } } }; try { EventQueue.invokeAndWait(runnable); } catch (Exception e) { LOGGER.error(e, e); } } // Missing bars if (!needsUpdate && !noDataTrends.isEmpty()) { String chartedEvtStr = EventDefinition.getReadableEventDefSetAsString(", ", noDataTrends); String errMsg = "No events are available for : " + chartedEvtStr + " and " + selectedShare.getFriendlyName() + " within the period you have selected.\n" + "If you just cleared the calculation results, you may want to Force and Update the calculations."; String addMsg = "This may also happen if calculations failed or if there is not enough quotations for the period.\n" + // + "Check the selected Trends in " + TRENDBUTTXT + " as well as the date // boundaries against the available quotations.\n" "You may want to check the date boundaries against the available quotations.\n" + "Also note that some calculators need full OLHC and Volume in order to be calculated.\n" + "If '" + chartedEvtStr + "' is one of your calculators you may also want to check its formula."; showPopupDialog(errMsg, "Ok", addMsg, null); } } }; Observable eventsDataLoader = new EventsDataLoader(configs, selectedShare, exentedStartDate); eventsDataLoader.addObserver(barDataObs); Thread updateBarChartThread = new Thread((Runnable) eventsDataLoader); updateBarChartThread.start(); }
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(); } }