Search in sources :

Example 1 with Exchange

use of name.abuchen.portfolio.model.Exchange in project portfolio by buchen.

the class AbstractQuoteProviderPage method onExchangeChanged.

private void onExchangeChanged(SelectionChangedEvent event) {
    Exchange exchange = (Exchange) ((IStructuredSelection) event.getSelection()).getFirstElement();
    setStatus(null);
    if (exchange == null) {
        clearSampleQuotes();
    } else {
        QuoteFeed feed = (QuoteFeed) ((IStructuredSelection) comboProvider.getSelection()).getFirstElement();
        showSampleQuotes(feed, exchange);
    }
}
Also used : Exchange(name.abuchen.portfolio.model.Exchange) AlphavantageQuoteFeed(name.abuchen.portfolio.online.impl.AlphavantageQuoteFeed) HTMLTableQuoteFeed(name.abuchen.portfolio.online.impl.HTMLTableQuoteFeed) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed)

Example 2 with Exchange

use of name.abuchen.portfolio.model.Exchange in project portfolio by buchen.

the class YahooFinanceQuoteFeedTest method testThatAtLeastTheGivenExchangeIsReturned.

@Test
public void testThatAtLeastTheGivenExchangeIsReturned() throws IOException {
    YahooFinanceQuoteFeed feed = new YahooFinanceQuoteFeed() {

        @Override
        protected void searchSymbols(List<Exchange> answer, String query) throws IOException {
            throw new IOException();
        }
    };
    Security s = new Security();
    s.setTickerSymbol("BAS.DE");
    ArrayList<Exception> errors = new ArrayList<Exception>();
    List<Exchange> exchanges = feed.getExchanges(s, errors);
    assertThat(exchanges.size(), is(1));
    assertThat(exchanges.get(0).getId(), is("BAS.DE"));
    assertThat(errors.size(), is(1));
}
Also used : Exchange(name.abuchen.portfolio.model.Exchange) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with Exchange

use of name.abuchen.portfolio.model.Exchange in project portfolio by buchen.

the class AbstractQuoteProviderPage method setupInitialData.

private void setupInitialData() {
    QuoteFeed feed = getQuoteFeedProvider(getFeed());
    if (feed != null)
        comboProvider.setSelection(new StructuredSelection(feed));
    else
        comboProvider.getCombo().select(0);
    createDetailDataWidgets(feed);
    if (// $NON-NLS-1$
    model.getTickerSymbol() != null && feed != null && feed.getId() != null && feed.getId().startsWith("YAHOO")) {
        Exchange exchange = new Exchange(model.getTickerSymbol(), model.getTickerSymbol());
        ArrayList<Exchange> input = new ArrayList<>();
        input.add(exchange);
        comboExchange.setInput(input);
        comboExchange.setSelection(new StructuredSelection(exchange));
    } else if (textFeedURL != null) {
        textFeedURL.setText(getFeedURL());
    }
}
Also used : Exchange(name.abuchen.portfolio.model.Exchange) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) AlphavantageQuoteFeed(name.abuchen.portfolio.online.impl.AlphavantageQuoteFeed) HTMLTableQuoteFeed(name.abuchen.portfolio.online.impl.HTMLTableQuoteFeed) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed)

Example 4 with Exchange

use of name.abuchen.portfolio.model.Exchange in project portfolio by buchen.

the class AbstractQuoteProviderPage method afterPage.

@Override
public void afterPage() {
    QuoteFeed feed = (QuoteFeed) ((IStructuredSelection) comboProvider.getSelection()).getFirstElement();
    setFeed(feed.getId());
    if (comboExchange != null && feed.getId() != null && feed.getId().startsWith(YAHOO)) {
        Exchange exchange = (Exchange) ((IStructuredSelection) comboExchange.getSelection()).getFirstElement();
        if (exchange != null) {
            model.setTickerSymbol(exchange.getId());
            tickerSymbol = exchange.getId();
            setFeedURL(null);
        }
    } else if (textFeedURL != null) {
        setFeedURL(textFeedURL.getText());
    }
}
Also used : Exchange(name.abuchen.portfolio.model.Exchange) AlphavantageQuoteFeed(name.abuchen.portfolio.online.impl.AlphavantageQuoteFeed) HTMLTableQuoteFeed(name.abuchen.portfolio.online.impl.HTMLTableQuoteFeed) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed)

Example 5 with Exchange

use of name.abuchen.portfolio.model.Exchange in project portfolio by buchen.

the class AbstractQuoteProviderPage method createDetailDataWidgets.

private void createDetailDataWidgets(QuoteFeed feed) {
    boolean dropDown = feed != null && feed.getId() != null && feed.getId().startsWith(YAHOO);
    boolean feedURL = feed != null && feed.getId() != null && feed.getId().equals(HTMLTableQuoteFeed.ID);
    boolean needsTicker = feed != null && feed.getId() != null && feed.getId().equals(AlphavantageQuoteFeed.ID);
    if (textFeedURL != null) {
        textFeedURL.dispose();
        textFeedURL = null;
    }
    if (comboExchange != null) {
        comboExchange.getControl().dispose();
        comboExchange = null;
    }
    if (textTicker != null) {
        textTicker.dispose();
        textTicker = null;
        // $NON-NLS-1$
        model.removePropertyChangeListener("tickerSymbol", tickerSymbolPropertyChangeListener);
    }
    if (dropDown) {
        labelDetailData.setText(Messages.LabelExchange);
        comboExchange = new ComboViewer(grpQuoteFeed, SWT.READ_ONLY);
        comboExchange.setContentProvider(ArrayContentProvider.getInstance());
        comboExchange.setLabelProvider(new LabelProvider() {

            @Override
            public String getText(Object element) {
                return ((Exchange) element).getName();
            }
        });
        GridDataFactory.fillDefaults().hint(300, SWT.DEFAULT).applyTo(comboExchange.getControl());
        comboExchange.addSelectionChangedListener(this::onExchangeChanged);
    } else if (feedURL) {
        labelDetailData.setText(Messages.EditWizardQuoteFeedLabelFeedURL);
        textFeedURL = new Text(grpQuoteFeed, SWT.BORDER);
        GridDataFactory.fillDefaults().hint(300, SWT.DEFAULT).applyTo(textFeedURL);
        textFeedURL.addModifyListener(e -> onFeedURLChanged());
    } else if (needsTicker) {
        labelDetailData.setText(Messages.ColumnTicker);
        textTicker = new Text(grpQuoteFeed, SWT.BORDER);
        GridDataFactory.fillDefaults().hint(100, SWT.DEFAULT).applyTo(textTicker);
        ISWTObservableValue observeText = WidgetProperties.text(SWT.Modify).observe(textTicker);
        // $NON-NLS-1$
        bindings.getBindingContext().bindValue(observeText, BeanProperties.value("tickerSymbol").observe(model));
        // $NON-NLS-1$
        model.addPropertyChangeListener("tickerSymbol", tickerSymbolPropertyChangeListener);
    } else {
        // $NON-NLS-1$
        labelDetailData.setText("");
    }
    grpQuoteFeed.layout(true);
    grpQuoteFeed.getParent().layout();
}
Also used : SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) HashMap(java.util.HashMap) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue) Exchange(name.abuchen.portfolio.model.Exchange) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) WidgetProperties(org.eclipse.jface.databinding.swt.WidgetProperties) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) Map(java.util.Map) FillLayout(org.eclipse.swt.layout.FillLayout) BindingHelper(name.abuchen.portfolio.ui.util.BindingHelper) Text(org.eclipse.swt.widgets.Text) Job(org.eclipse.core.runtime.jobs.Job) FormLayout(org.eclipse.swt.layout.FormLayout) AlphavantageQuoteFeed(name.abuchen.portfolio.online.impl.AlphavantageQuoteFeed) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) FormData(org.eclipse.swt.layout.FormData) Status(org.eclipse.core.runtime.Status) Security(name.abuchen.portfolio.model.Security) FormAttachment(org.eclipse.swt.layout.FormAttachment) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Group(org.eclipse.swt.widgets.Group) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) HTMLTableQuoteFeed(name.abuchen.portfolio.online.impl.HTMLTableQuoteFeed) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) Objects(java.util.Objects) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) SWT(org.eclipse.swt.SWT) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed) Label(org.eclipse.swt.widgets.Label) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue) Text(org.eclipse.swt.widgets.Text) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

Exchange (name.abuchen.portfolio.model.Exchange)6 QuoteFeed (name.abuchen.portfolio.online.QuoteFeed)5 AlphavantageQuoteFeed (name.abuchen.portfolio.online.impl.AlphavantageQuoteFeed)5 HTMLTableQuoteFeed (name.abuchen.portfolio.online.impl.HTMLTableQuoteFeed)5 ArrayList (java.util.ArrayList)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 List (java.util.List)2 Security (name.abuchen.portfolio.model.Security)2 PropertyChangeListener (java.beans.PropertyChangeListener)1 IOException (java.io.IOException)1 MessageFormat (java.text.MessageFormat)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Messages (name.abuchen.portfolio.ui.Messages)1 PortfolioPlugin (name.abuchen.portfolio.ui.PortfolioPlugin)1 BindingHelper (name.abuchen.portfolio.ui.util.BindingHelper)1 BeanProperties (org.eclipse.core.databinding.beans.BeanProperties)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1