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

📄 securitiesview.java

📁 EclipseTrader is a stock exchange analysis system, featuring shares pricing watch, intraday and hi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2004-2006 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.core.ui.views;import java.util.Collections;import java.util.Comparator;import java.util.Iterator;import java.util.List;import java.util.Observable;import java.util.Observer;import net.sourceforge.eclipsetrader.core.CorePlugin;import net.sourceforge.eclipsetrader.core.ICollectionObserver;import net.sourceforge.eclipsetrader.core.db.Security;import net.sourceforge.eclipsetrader.core.db.feed.FeedSource;import net.sourceforge.eclipsetrader.core.db.feed.TradeSource;import net.sourceforge.eclipsetrader.core.transfers.SecurityTransfer;import net.sourceforge.eclipsetrader.core.ui.NullSelection;import net.sourceforge.eclipsetrader.core.ui.SecuritySelection;import net.sourceforge.eclipsetrader.core.ui.SelectionProvider;import net.sourceforge.eclipsetrader.core.ui.actions.PropertiesAction;import net.sourceforge.eclipsetrader.core.ui.dialogs.FeedSelectionDialog;import net.sourceforge.eclipsetrader.core.ui.dialogs.IntradayChartsDialog;import net.sourceforge.eclipsetrader.core.ui.dialogs.TradingOptionsDialog;import net.sourceforge.eclipsetrader.core.ui.internal.DeleteAction;import net.sourceforge.eclipsetrader.core.ui.internal.Messages;import net.sourceforge.eclipsetrader.core.ui.preferences.SecurityPropertiesDialog;import org.eclipse.jface.action.Action;import org.eclipse.jface.action.IMenuListener;import org.eclipse.jface.action.IMenuManager;import org.eclipse.jface.action.MenuManager;import org.eclipse.jface.action.Separator;import org.eclipse.jface.dialogs.Dialog;import org.eclipse.jface.preference.IPreferenceStore;import org.eclipse.jface.util.IPropertyChangeListener;import org.eclipse.jface.util.PropertyChangeEvent;import org.eclipse.swt.SWT;import org.eclipse.swt.dnd.DND;import org.eclipse.swt.dnd.DragSource;import org.eclipse.swt.dnd.DragSourceEvent;import org.eclipse.swt.dnd.DragSourceListener;import org.eclipse.swt.dnd.Transfer;import org.eclipse.swt.events.ControlAdapter;import org.eclipse.swt.events.ControlEvent;import org.eclipse.swt.events.ControlListener;import org.eclipse.swt.events.DisposeEvent;import org.eclipse.swt.events.DisposeListener;import org.eclipse.swt.events.MouseAdapter;import org.eclipse.swt.events.MouseEvent;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.events.SelectionListener;import org.eclipse.swt.graphics.Point;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Event;import org.eclipse.swt.widgets.Listener;import org.eclipse.swt.widgets.Table;import org.eclipse.swt.widgets.TableColumn;import org.eclipse.swt.widgets.TableItem;import org.eclipse.ui.IActionBars;import org.eclipse.ui.IViewSite;import org.eclipse.ui.IWorkbenchActionConstants;import org.eclipse.ui.PartInitException;import org.eclipse.ui.PlatformUI;import org.eclipse.ui.part.ViewPart;import org.eclipse.ui.themes.ITheme;import org.eclipse.ui.themes.IThemeManager;/** */public class SecuritiesView extends ViewPart implements ICollectionObserver{    public static final String VIEW_ID = "net.sourceforge.eclipsetrader.views.securities"; //$NON-NLS-1$    public static final String PREFS_SORT_COLUMN = "SECURITIES_SORT_COLUMN"; //$NON-NLS-1$    public static final String PREFS_SORT_DIRECTION = "SECURITIES_SORT_DIRECTION"; //$NON-NLS-1$    public static final String PREFS_COLUMNS_SIZE = "SECURITIES_COLUMNS_SIZE"; //$NON-NLS-1$    public static final String TABLE_BACKGROUND = "TABLE_BACKGROUND"; //$NON-NLS-1$    public static final String TABLE_FOREGROUND = "TABLE_FOREGROUND"; //$NON-NLS-1$    public static final String TABLE_FONT = "TABLE_FONT"; //$NON-NLS-1$    Table table;    int sortColumn = 0;    int sortDirection = 1;    ITheme theme;    Action deleteAction = new DeleteAction(this);    Action propertiesAction;    Action changeQuoteFeedAction;    Action changeLevel2FeedAction;    Action changeHistoryFeedAction;    Action changeIntradayOptionsAction;    Action changeTradingOptionsAction;    Comparator comparator = new Comparator() {        public int compare(Object arg0, Object arg1)        {            switch(sortColumn)            {                case 0:                    if (sortDirection == 0)                        return ((Security)arg0).getCode().compareTo(((Security)arg1).getCode());                    else                        return ((Security)arg1).getCode().compareTo(((Security)arg0).getCode());                case 1:                    if (sortDirection == 0)                        return ((Security)arg0).getDescription().compareTo(((Security)arg1).getDescription());                    else                        return ((Security)arg1).getDescription().compareTo(((Security)arg0).getDescription());                case 2:                {                    String s0 = ""; //$NON-NLS-1$                    String s1 = ""; //$NON-NLS-1$                    if (((Security)arg0).getCurrency() != null)                        s0 = ((Security)arg0).getCurrency().getCurrencyCode();                    if (((Security)arg1).getCurrency() != null)                        s1 = ((Security)arg1).getCurrency().getCurrencyCode();                    if (sortDirection == 0)                        return s0.compareTo(s1);                    else                        return s1.compareTo(s0);                }            }            return 0;        }    };    IPropertyChangeListener themeChangeListener = new IPropertyChangeListener() {        public void propertyChange(PropertyChangeEvent event)        {            if (event.getProperty().equals(TABLE_BACKGROUND))                table.setBackground(theme.getColorRegistry().get(TABLE_BACKGROUND));            else if (event.getProperty().equals(TABLE_FOREGROUND))                table.setForeground(theme.getColorRegistry().get(TABLE_FOREGROUND));            else if (event.getProperty().equals(TABLE_FONT))                table.setFont(theme.getFontRegistry().get(TABLE_FONT));        }    };    ControlListener columnControlListener = new ControlAdapter() {        public void controlResized(ControlEvent e)        {            StringBuffer sizes = new StringBuffer();            for (int i = 0; i < table.getColumnCount(); i++)                sizes.append(String.valueOf(table.getColumn(i).getWidth()) + ";"); //$NON-NLS-1$            CorePlugin.getDefault().getPreferenceStore().setValue(PREFS_COLUMNS_SIZE, sizes.toString());        }    };    SelectionListener columnSelectionListener = new SelectionAdapter() {        public void widgetSelected(SelectionEvent e)        {            int index = table.indexOf((TableColumn)e.widget);            if (sortColumn == index)                sortDirection = sortDirection == 0 ? 1 : 0;            else            {                sortColumn = index;                sortDirection = 0;            }            IPreferenceStore prefs = CorePlugin.getDefault().getPreferenceStore();            prefs.setValue(PREFS_SORT_COLUMN, sortColumn);            prefs.setValue(PREFS_SORT_DIRECTION, sortDirection);                        updateView();        }    };    /* (non-Javadoc)     * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)     */    public void init(IViewSite site) throws PartInitException    {        propertiesAction = new PropertiesAction() {            public void run()            {                Security[] security = getSelection();                if (security.length == 1)                {                    SecurityPropertiesDialog dlg = new SecurityPropertiesDialog(security[0], getSite().getShell());                    dlg.open();                }            }        };                changeQuoteFeedAction = new Action() {            public void run()            {                Security[] selection = getSelection();                FeedSelectionDialog dlg = new FeedSelectionDialog(table.getShell(), "quote");                if (dlg.open() == Dialog.OK)                {                    FeedSource source = dlg.getFeedSource();                    for (int i = 0; i < selection.length; i++)                    {                        if (source != null)                        {                            FeedSource newSource = new FeedSource();                            newSource.setId(source.getId());                            newSource.setExchange(source.getExchange());                            newSource.setSymbol(selection[i].getQuoteFeed() != null ? selection[i].getQuoteFeed().getSymbol() : "");                            selection[i].setQuoteFeed(newSource);                        }                        else                            selection[i].setQuoteFeed(null);                        CorePlugin.getRepository().save(selection[i]);                    }                }            }        };        changeQuoteFeedAction.setText("Quote Feed");        changeLevel2FeedAction = new Action() {            public void run()            {                Security[] selection = getSelection();                FeedSelectionDialog dlg = new FeedSelectionDialog(table.getShell(), "level2");                if (dlg.open() == Dialog.OK)                {                    FeedSource source = dlg.getFeedSource();                    for (int i = 0; i < selection.length; i++)                    {                        if (source != null)                        {                            FeedSource newSource = new FeedSource();                            newSource.setId(source.getId());                            newSource.setExchange(source.getExchange());                            newSource.setSymbol(selection[i].getLevel2Feed() != null ? selection[i].getLevel2Feed().getSymbol() : "");                            selection[i].setLevel2Feed(newSource);                        }                        else                            selection[i].setLevel2Feed(null);                        CorePlugin.getRepository().save(selection[i]);                    }                }            }        };        changeLevel2FeedAction.setText("Level2 Feed");        changeHistoryFeedAction = new Action() {            public void run()            {                Security[] selection = getSelection();                FeedSelectionDialog dlg = new FeedSelectionDialog(table.getShell(), "history");                if (dlg.open() == Dialog.OK)                {                    FeedSource source = dlg.getFeedSource();                    for (int i = 0; i < selection.length; i++)                    {                        if (source != null)                        {                            FeedSource newSource = new FeedSource();                            newSource.setId(source.getId());                            newSource.setExchange(source.getExchange());                            newSource.setSymbol(selection[i].getHistoryFeed() != null ? selection[i].getHistoryFeed().getSymbol() : "");                            selection[i].setHistoryFeed(newSource);                        }                        else                            selection[i].setHistoryFeed(null);                        CorePlugin.getRepository().save(selection[i]);                    }                }            }        };        changeHistoryFeedAction.setText("History Feed");        changeIntradayOptionsAction = new Action() {            public void run()            {                IntradayChartsDialog dlg = new IntradayChartsDialog(table.getShell()) {                    protected void okPressed()                    {                        Security[] selection = getSelection();                        for (int i = 0; i < selection.length; i++)                        {                            intradayDataOptions.saveSettings(selection[i]);                            CorePlugin.getRepository().save(selection[i]);                        }                        super.okPressed();                    }                };                dlg.open();            }        };        changeIntradayOptionsAction.setText("Intraday Charts");        changeTradingOptionsAction = new Action() {            public void run()            {                TradingOptionsDialog dlg = new TradingOptionsDialog(table.getShell()) {                    protected void okPressed()                    {                        Security[] selection = getSelection();                        for (int i = 0; i < selection.length; i++)                        {                            TradeSource source = options.getSource();                            TradeSource oldSource = selection[i].getTradeSource();                            if (oldSource != null)                                source.setSymbol(oldSource.getSymbol());                            selection[i].setTradeSource(source);                                                        CorePlugin.getRepository().save(selection[i]);                        }                        super.okPressed();                    }                };                dlg.open();            }        };        changeTradingOptionsAction.setText("Trading Options");        IMenuManager menuManager = site.getActionBars().getMenuManager();        menuManager.add(new Separator("top")); //$NON-NLS-1$        menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));        menuManager.add(new Separator());        MenuManager changeMenu = new MenuManager("Change", "change");        changeMenu.add(changeQuoteFeedAction);        changeMenu.add(changeLevel2FeedAction);        changeMenu.add(changeHistoryFeedAction);        changeMenu.add(new Separator());        changeMenu.add(changeTradingOptionsAction);        changeMenu.add(new Separator());        changeMenu.add(changeIntradayOptionsAction);        menuManager.add(changeMenu);        menuManager.add(new Separator("bottom")); //$NON-NLS-1$                IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();        if (themeManager != null)        {            theme = themeManager.getCurrentTheme();            if (theme != null)                theme.addPropertyChangeListener(themeChangeListener);        }                super.init(site);    }    /* (non-Javadoc)     * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)     */    public void createPartControl(Composite parent)    {        Composite content = new Composite(parent, SWT.NONE);

⌨️ 快捷键说明

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