⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orderformview.java

📁 EclipseTrader is a stock exchange analysis system, featuring shares pricing watch, intraday and hi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        for (Iterator iter = list.iterator(); iter.hasNext(); )        {            Security item = (Security)iter.next();            security.add(item.getDescription());        }        security.setData(list);                IExtensionRegistry registry = Platform.getExtensionRegistry();        IExtensionPoint extensionPoint = registry.getExtensionPoint(CorePlugin.TRADING_PROVIDERS_EXTENSION_POINT);        if (extensionPoint != null)        {            list = Arrays.asList(extensionPoint.getConfigurationElements());            Collections.sort(list, new Comparator() {                public int compare(Object arg0, Object arg1)                {                    return ((IConfigurationElement)arg0).getAttribute("name").compareTo(((IConfigurationElement)arg1).getAttribute("name"));                }            });            for (Iterator iter = list.iterator(); iter.hasNext(); )            {                IConfigurationElement item = (IConfigurationElement)iter.next();                provider.add(item.getAttribute("name"));            }            provider.setData(list);        }        else            provider.setData(new ArrayList());        side.select(0);                list = CorePlugin.getRepository().allAccounts();        Collections.sort(list, new Comparator() {            public int compare(Object arg0, Object arg1)            {                return ((Account)arg0).getDescription().compareTo(((Account)arg1).getDescription());            }        });        for (Iterator iter = list.iterator(); iter.hasNext(); )        {            Account s = (Account)iter.next();            account.add(s.getDescription());        }        account.setData(list);                exchange.setEnabled(exchange.getItemCount() != 0);        updateButtonEnablement();    }    /* (non-Javadoc)     * @see org.eclipse.ui.IWorkbenchPart#dispose()     */    public void dispose()    {        super.dispose();    }    /* (non-Javadoc)     * @see org.eclipse.ui.IWorkbenchPart#setFocus()     */    public void setFocus()    {    }        void setSecurity(Security newSecurity)    {        security.setText(newSecurity.getDescription());        securitySelection();                TradeSource source = newSecurity.getTradeSource();        if (source != null)        {            List list = ((List)provider.getData());            for (Iterator iter = list.iterator(); iter.hasNext(); )            {                IConfigurationElement item = (IConfigurationElement)iter.next();                if (source.getTradingProviderId().equals(item.getAttribute("id")))                    provider.setText(item.getAttribute("name"));            }            providerSelection();                        list = ((List)account.getData());            for (Iterator iter = list.iterator(); iter.hasNext(); )            {                Account item = (Account)iter.next();                if (source.getAccountId() != null && source.getAccountId().equals(item.getId()))                    account.setText(item.getDescription());            }            accountSelection();                        String[] items = exchange.getItems();            for (int i = 0; i < items.length; i++)            {                String id = (String)exchange.getData(String.valueOf(i));                if (source.getExchange().equals(id))                {                    exchange.select(i);                    break;                }            }            quantity.setSelection(source.getQuantity());            updateTotal();        }    }    void sendOrder()    {        try {            IConfigurationElement item = (IConfigurationElement)((List)provider.getData()).get(provider.getSelectionIndex());            ITradingProvider plugin = (ITradingProvider)item.createExecutableExtension("class"); //$NON-NLS-1$            Order order = new Order();            order.setSecurity((Security)((List)security.getData()).get(security.getSelectionIndex()));            if (account.getSelectionIndex() != -1)                order.setAccount((Account)((List)account.getData()).get(account.getSelectionIndex()));            order.setSide((OrderSide)side.getData(side.getText()));            order.setType((OrderType)type.getData(type.getText()));            order.setQuantity(quantity.getSelection());            if (!OrderType.MARKET.equals(order.getType()))                order.setPrice(price.getSelection() / Math.pow(10, price.getDigits()));            if (exchange.isEnabled())                order.setExchange((OrderRoute)exchange.getData(exchange.getText()));            order.setValidity((OrderValidity)validity.getData(validity.getText()));            if (expire != null)                order.setExpire(dateFormat.parse(expire.getText()));                        plugin.sendNew(order);                } catch(Exception e) {            logger.error(e, e);        }    }        void providerSelection()    {        List list = (List)provider.getData();        int index = provider.getSelectionIndex();        if (index >= 0 && index < list.size())        {            IConfigurationElement item = (IConfigurationElement)list.get(index);                        ITradingProvider source = CorePlugin.createTradeSourcePlugin(item.getAttribute("id"));            populateValues(side, source.getSides(), sideLabels);            populateValues(type, source.getTypes(), typeLabels);            populateValues(validity, source.getValidity(), validityLabels);                        exchange.removeAll();            for (Iterator iter = source.getRoutes().iterator(); iter.hasNext(); )            {                OrderRoute route = (OrderRoute)iter.next();                exchange.add(route.toString());                exchange.setData(route.toString(), route);            }            exchange.setEnabled(exchange.getItemCount() != 0);            if (exchange.getItemCount() != 0)                exchange.select(0);            exchange.getParent().getParent().layout();        }                updateTotal();        updateButtonEnablement();    }        void securitySelection()    {        List list = (List)security.getData();        int index = security.getSelectionIndex();        if (index >= 0 && index < list.size())        {            Security item = (Security)list.get(index);            if (item.getQuote() != null)                price.setSelection((int)(item.getQuote().getLast() * Math.pow(10, price.getDigits())));            else                price.setSelection(0);        }        else            price.setSelection(0);        updateTotal();        updateButtonEnablement();    }        void sideSelection()    {        updateTotal();    }        void typeSelection()    {        OrderType value = (OrderType)type.getData(type.getText());        price.setEnabled(OrderType.LIMIT.equals(value));        updateTotal();    }        void updateButtonEnablement()    {        boolean enabled = true;                if (security.getSelectionIndex() == -1)            enabled = false;        if (provider.getSelectionIndex() == -1)            enabled = false;        if (exchange.isEnabled() && exchange.getSelectionIndex() == -1)            enabled = false;                send.setEnabled(enabled);    }        void accountSelection()    {        updateTotal();    }        void updateTotal()    {        double value = quantity.getSelection() * (price.getSelection() / Math.pow(10, price.getDigits()));        total.setText(nf.format(value));        total.getParent().layout();    }        void validitySelection()    {        OrderValidity v = (OrderValidity)validity.getData(validity.getText());        if (v.equals(OrderValidity.GOOD_TILL_DATE))        {            if (expire == null)            {                expire = new Text(validity.getParent(), SWT.BORDER);                expire.setLayoutData(new GridData(80, SWT.DEFAULT));                expire.addFocusListener(new FocusAdapter() {                    public void focusLost(FocusEvent e)                    {                        try {                            Date d = dateParse.parse(expire.getText());                            expire.setText(dateFormat.format(d));                        } catch(Exception e1) {                        }                    }                });                Calendar c = Calendar.getInstance();                c.add(Calendar.DATE, 30);                expire.setText(dateFormat.format(c.getTime()));                expire.moveBelow(validity);                ((GridData)validity.getLayoutData()).horizontalSpan = 1;                                validity.getParent().layout();            }        }        else if (expire != null)        {            expire.dispose();            expire = null;            ((GridData)validity.getLayoutData()).horizontalSpan = 2;            validity.getParent().layout();        }    }        void populateValues(Combo combo, List list, Map labels)    {        int index = combo.getSelectionIndex();                combo.removeAll();        for (Iterator iter = list.iterator(); iter.hasNext(); )        {            Object value = iter.next();            String text = (String)labels.get(value);            if (text != null)            {                combo.add(text);                combo.setData(text, value);            }        }                if (index != -1 && index < combo.getItemCount())            combo.select(index);        else            combo.select(0);    }    static {        sideLabels.put(OrderSide.BUY, "Buy");        sideLabels.put(OrderSide.SELL, "Sell");        sideLabels.put(OrderSide.SELLSHORT, "Sell Short");        sideLabels.put(OrderSide.BUYCOVER, "Buy Cover");        typeLabels.put(OrderType.LIMIT, "Limit");        typeLabels.put(OrderType.MARKET, "Market");        typeLabels.put(OrderType.STOP, "Stop");        typeLabels.put(OrderType.STOPLIMIT, "Stop Limit");        validityLabels.put(OrderValidity.DAY, "Day");        validityLabels.put(OrderValidity.IMMEDIATE_OR_CANCEL, "Imm. or Cancel");        validityLabels.put(OrderValidity.AT_OPENING, "At Opening");        validityLabels.put(OrderValidity.AT_CLOSING, "At Closing");        validityLabels.put(OrderValidity.GOOD_TILL_CANCEL, "Good Till Cancel");        validityLabels.put(OrderValidity.GOOD_TILL_DATE, "Good Till Date");        statusLabels.put(OrderStatus.NEW, "New");        statusLabels.put(OrderStatus.PARTIAL, "Partial");        statusLabels.put(OrderStatus.FILLED, "Filled");        statusLabels.put(OrderStatus.CANCELED, "Canceled");        statusLabels.put(OrderStatus.REJECTED, "Rejected");        statusLabels.put(OrderStatus.PENDING_CANCEL, "Pending Cancel");        statusLabels.put(OrderStatus.PENDING_NEW, "Pending New");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -