📄 orderformview.java
字号:
/* * Copyright (c) 2004-2007 Marco Maccaferri and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Marco Maccaferri - initial API and implementation */package net.sourceforge.eclipsetrader.trading.views;import java.text.NumberFormat;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Arrays;import java.util.Calendar;import java.util.Collections;import java.util.Comparator;import java.util.Date;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import net.sourceforge.eclipsetrader.core.CorePlugin;import net.sourceforge.eclipsetrader.core.ITradingProvider;import net.sourceforge.eclipsetrader.core.db.Account;import net.sourceforge.eclipsetrader.core.db.Order;import net.sourceforge.eclipsetrader.core.db.OrderRoute;import net.sourceforge.eclipsetrader.core.db.OrderSide;import net.sourceforge.eclipsetrader.core.db.OrderStatus;import net.sourceforge.eclipsetrader.core.db.OrderType;import net.sourceforge.eclipsetrader.core.db.OrderValidity;import net.sourceforge.eclipsetrader.core.db.Security;import net.sourceforge.eclipsetrader.core.db.feed.TradeSource;import net.sourceforge.eclipsetrader.core.transfers.SecurityTransfer;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.eclipse.core.runtime.IConfigurationElement;import org.eclipse.core.runtime.IExtensionPoint;import org.eclipse.core.runtime.IExtensionRegistry;import org.eclipse.core.runtime.Platform;import org.eclipse.swt.SWT;import org.eclipse.swt.dnd.DND;import org.eclipse.swt.dnd.DropTarget;import org.eclipse.swt.dnd.DropTargetEvent;import org.eclipse.swt.dnd.DropTargetListener;import org.eclipse.swt.dnd.Transfer;import org.eclipse.swt.dnd.TransferData;import org.eclipse.swt.events.FocusAdapter;import org.eclipse.swt.events.FocusEvent;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Combo;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Spinner;import org.eclipse.swt.widgets.Text;import org.eclipse.ui.part.ViewPart;public class OrderFormView extends ViewPart{ Combo security; Combo provider; Combo exchange; Combo side; Combo type; Spinner quantity; Spinner price; Button send; Combo account; Combo validity; Text expire; Label total; static Map sideLabels = new HashMap(); static Map typeLabels = new HashMap(); static Map validityLabels = new HashMap(); static Map statusLabels = new HashMap(); private NumberFormat pf = NumberFormat.getInstance(); private NumberFormat nf = NumberFormat.getInstance(); SimpleDateFormat dateFormat = CorePlugin.getDateFormat(); SimpleDateFormat dateParse = CorePlugin.getDateParse(); private Log logger = LogFactory.getLog(getClass()); DropTargetListener dropTargetListener = new DropTargetListener() { public void dragEnter(DropTargetEvent event) { event.detail = DND.DROP_COPY; event.currentDataType = null; TransferData[] data = event.dataTypes; if (event.currentDataType == null) { for (int i = 0; i < data.length; i++) { if (SecurityTransfer.getInstance().isSupportedType(data[i])) { event.currentDataType = data[i]; break; } } } } public void dragOver(DropTargetEvent event) { event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL; } public void dragOperationChanged(DropTargetEvent event) { } public void dragLeave(DropTargetEvent event) { } public void dropAccept(DropTargetEvent event) { } public void drop(DropTargetEvent event) { if (SecurityTransfer.getInstance().isSupportedType(event.currentDataType)) { Security[] securities = (Security[]) event.data; setSecurity(securities[0]); quantity.setFocus(); } } }; public OrderFormView() { pf.setGroupingUsed(true); pf.setMinimumIntegerDigits(1); pf.setMinimumFractionDigits(4); pf.setMaximumFractionDigits(4); nf.setGroupingUsed(true); nf.setMinimumIntegerDigits(1); nf.setMinimumFractionDigits(2); nf.setMaximumFractionDigits(2); } /* (non-Javadoc) * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ public void createPartControl(Composite parent) { Composite content = new Composite(parent, SWT.NONE); content.setLayout(new GridLayout(11, false)); Label label = new Label(content, SWT.NONE); label.setText("Account"); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); account = new Combo(content, SWT.READ_ONLY); account.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 10, 1)); account.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { accountSelection(); } }); label = new Label(content, SWT.NONE); label.setText("Security"); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); Composite row = new Composite(content, SWT.NONE); GridLayout gridLayout = new GridLayout(5, false); gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; row.setLayout(gridLayout); row.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 10, 1)); security = new Combo(row, SWT.READ_ONLY); security.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); security.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { securitySelection(); } }); label = new Label(row, SWT.NONE); label.setText("Provider"); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); provider = new Combo(row, SWT.READ_ONLY); provider.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); provider.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { providerSelection(); validitySelection(); } }); label = new Label(row, SWT.NONE); label.setText("Exchange"); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); exchange = new Combo(row, SWT.READ_ONLY); exchange.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); label = new Label(content, SWT.NONE); label.setText("Side"); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); side = new Combo(content, SWT.READ_ONLY); side.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); side.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { sideSelection(); } }); label = new Label(content, SWT.NONE); label.setText("Type"); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); type = new Combo(content, SWT.READ_ONLY); type.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); type.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { typeSelection(); } }); label = new Label(content, SWT.NONE); label.setText("Quantity"); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); quantity = new Spinner(content, SWT.BORDER); quantity.setMinimum(1); quantity.setMaximum(999999999); quantity.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); quantity.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { updateTotal(); } }); label = new Label(content, SWT.NONE); label.setText("Price"); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); price = new Spinner(content, SWT.BORDER); price.setMinimum(0); price.setMaximum(999999999); price.setDigits(4); price.setIncrement(5); price.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); price.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { updateTotal(); } }); label = new Label(content, SWT.NONE); label.setText("Validity"); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); validity = new Combo(content, SWT.READ_ONLY); validity.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1)); validity.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { validitySelection(); } }); label = new Label(content, SWT.NONE); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 6, 1)); label = new Label(content, SWT.NONE); label.setText("Total"); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); total = new Label(content, SWT.NONE); total.setText("0,00"); total.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); send = new Button(content, SWT.PUSH); send.setText("Send Order"); send.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false, 2, 1)); send.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { sendOrder(); } }); DropTarget target = new DropTarget(content, DND.DROP_COPY); target.setTransfer(new Transfer[] { SecurityTransfer.getInstance() }); target.addDropListener(dropTargetListener); List list = new ArrayList(CorePlugin.getRepository().allSecurities()); Collections.sort(list, new Comparator() { public int compare(Object arg0, Object arg1) { return ((Security)arg0).getDescription().compareTo(((Security)arg1).getDescription()); } });
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -