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

📄 coreplugin.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;import java.io.File;import java.io.FileInputStream;import java.net.URL;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.Iterator;import java.util.List;import java.util.Properties;import net.sourceforge.eclipsetrader.core.db.Account;import net.sourceforge.eclipsetrader.core.db.DefaultAccount;import net.sourceforge.eclipsetrader.core.db.PersistentPreferenceStore;import net.sourceforge.eclipsetrader.core.internal.LogListener;import net.sourceforge.eclipsetrader.core.internal.Messages;import net.sourceforge.eclipsetrader.core.internal.XMLRepository;import org.apache.log4j.BasicConfigurator;import org.apache.log4j.PropertyConfigurator;import org.eclipse.core.runtime.IConfigurationElement;import org.eclipse.core.runtime.IExtensionPoint;import org.eclipse.core.runtime.IExtensionRegistry;import org.eclipse.core.runtime.IProgressMonitor;import org.eclipse.core.runtime.IStatus;import org.eclipse.core.runtime.Platform;import org.eclipse.core.runtime.Status;import org.eclipse.core.runtime.jobs.Job;import org.eclipse.jface.preference.IPreferenceStore;import org.eclipse.jface.preference.PreferenceStore;import org.eclipse.jface.resource.ImageDescriptor;import org.eclipse.jface.util.IPropertyChangeListener;import org.eclipse.jface.util.PropertyChangeEvent;import org.eclipse.ui.IPerspectiveDescriptor;import org.eclipse.ui.IPerspectiveListener;import org.eclipse.ui.IViewReference;import org.eclipse.ui.IWorkbenchPage;import org.eclipse.ui.PlatformUI;import org.eclipse.ui.plugin.AbstractUIPlugin;import org.osgi.framework.BundleContext;public class CorePlugin extends AbstractUIPlugin{    public static final String PLUGIN_ID = "net.sourceforge.eclipsetrader.core"; //$NON-NLS-1$    public static final String FEED_EXTENSION_POINT = PLUGIN_ID + ".feeds"; //$NON-NLS-1$    public static final String TRADING_PROVIDERS_EXTENSION_POINT = PLUGIN_ID + ".tradingProviders"; //$NON-NLS-1$    public static final String PATTERN_EXTENSION_POINT = PLUGIN_ID + ".patterns"; //$NON-NLS-1$    public static final String ACCOUNT_PROVIDERS_EXTENSION_POINT = PLUGIN_ID + ".accountProviders"; //$NON-NLS-1$    public static final String LABEL_PROVIDERS_EXTENSION_POINT = PLUGIN_ID + ".viewLabelProviders"; //$NON-NLS-1$    public static final String LOGGER_PREFERENCES_EXTENSION_POINT = PLUGIN_ID + ".loggingPreferences"; //$NON-NLS-1$    public static final String FEED_RUNNING = "FEED_RUNNING"; //$NON-NLS-1$    public static final String PREFS_ENABLE_HTTP_PROXY = "ENABLE_HTTP_PROXY"; //$NON-NLS-1$    public static final String PREFS_PROXY_HOST_ADDRESS = "PROXY_HOST_ADDRESS"; //$NON-NLS-1$    public static final String PREFS_PROXY_PORT_ADDRESS = "PROXY_PORT_ADDRESS"; //$NON-NLS-1$    public static final String PREFS_ENABLE_PROXY_AUTHENTICATION = "ENABLE_PROXY_AUTHENTICATION"; //$NON-NLS-1$    public static final String PREFS_PROXY_USER = "PROXY_USER"; //$NON-NLS-1$    public static final String PREFS_PROXY_PASSWORD = "PROXY_PASSWORD"; //$NON-NLS-1$    public static final String PREFS_HISTORICAL_PRICE_RANGE = "HISTORICAL_PRICE_RANGE"; //$NON-NLS-1$    public static final String PREFS_NEWS_DATE_RANGE = "NEWS_DATE_RANGE"; //$NON-NLS-1$    public static final String PREFS_UPDATE_HISTORY = "UPDATE_HISTORY"; //$NON-NLS-1$    public static final String PREFS_UPDATE_HISTORY_ONCE = "UPDATE_HISTORY_ONCE"; //$NON-NLS-1$    public static final String PREFS_UPDATE_HISTORY_LAST = "UPDATE_HISTORY_LAST"; //$NON-NLS-1$    public static final String PREFS_UPDATE_NEWS = "UPDATE_NEWS"; //$NON-NLS-1$    public static final String PREFS_UPDATE_CURRENCIES = "UPDATE_CURRENCIES"; //$NON-NLS-1$    public static final String PREFS_DELETE_CANCELED_ORDERS = "DELETE_CANCELED_ORDERS"; //$NON-NLS-1$    public static final String PREFS_DELETE_CANCELED_ORDERS_DAYS = "DELETE_CANCELED_ORDERS_DAYS"; //$NON-NLS-1$    public static final String PREFS_DELETE_FILLED_ORDERS = "DELETE_FILLED_ORDERS"; //$NON-NLS-1$    public static final String PREFS_DELETE_FILLED_ORDERS_DAYS = "DELETE_FILLED_ORDERS_DAYS"; //$NON-NLS-1$    private static CorePlugin plugin;    private static Repository repository;    private static SimpleDateFormat dateTimeFormat = new SimpleDateFormat(Messages.CorePlugin_DateTimeFormat);    private static SimpleDateFormat dateTimeParse = new SimpleDateFormat(Messages.CorePlugin_DateTimeParse);    private static SimpleDateFormat dateFormat = new SimpleDateFormat(Messages.CorePlugin_DateFormat);    private static SimpleDateFormat dateParse = new SimpleDateFormat(Messages.CorePlugin_DateParse);    private static SimpleDateFormat timeFormat = new SimpleDateFormat(Messages.CorePlugin_TimeFormat);    private static SimpleDateFormat timeParse = new SimpleDateFormat(Messages.CorePlugin_TimeParse);    private IPropertyChangeListener feedPropertyListener = new IPropertyChangeListener() {        public void propertyChange(PropertyChangeEvent event)        {            if (event.getProperty().equals(CorePlugin.FEED_RUNNING))            {                if (CorePlugin.getDefault().getPreferenceStore().getBoolean(CorePlugin.FEED_RUNNING) && CorePlugin.getDefault().getPreferenceStore().getBoolean(CorePlugin.PREFS_UPDATE_CURRENCIES))                {                    Job job = new Job(Messages.CorePlugin_UpdateCurrencies) {                        protected IStatus run(IProgressMonitor monitor)                        {                            return CurrencyConverter.getInstance().updateExchanges(monitor);                        }                    };                    job.setUser(false);                    job.schedule();                }            }        }    };    private IPerspectiveListener perspectiveListener = new IPerspectiveListener() {        public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective)        {            IViewReference[] refs = page.getViewReferences();            for (int i = 0; i < refs.length; i++)                refs[i].getView(true);        }        public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId)        {        }    };    public CorePlugin()    {        plugin = this;    }    /* (non-Javadoc)     * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)     */    public void start(BundleContext context) throws Exception    {        super.start(context);        System.setProperty("workspace_loc", Platform.getLocation().toPortableString());        configureLogging();                LogListener logListener = new LogListener();        Platform.addLogListener(logListener);        getLog().addLogListener(logListener);                IPreferenceStore preferenceStore = getPreferenceStore();        preferenceStore.setDefault(FEED_RUNNING, false);        if (preferenceStore.getDefaultInt(PREFS_HISTORICAL_PRICE_RANGE) == 0)            preferenceStore.setDefault(PREFS_HISTORICAL_PRICE_RANGE, 5);        if (preferenceStore.getDefaultInt(PREFS_NEWS_DATE_RANGE) == 0)            preferenceStore.setDefault(PREFS_NEWS_DATE_RANGE, 3);        preferenceStore.setDefault(PREFS_DELETE_CANCELED_ORDERS, false);        preferenceStore.setDefault(PREFS_DELETE_CANCELED_ORDERS_DAYS, 2);        preferenceStore.setDefault(PREFS_DELETE_FILLED_ORDERS, false);        preferenceStore.setDefault(PREFS_DELETE_FILLED_ORDERS_DAYS, 5);        preferenceStore.setValue(FEED_RUNNING, false);        CorePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(feedPropertyListener);                PlatformUI.getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(perspectiveListener);    }    /**     * Log4j configurator     */    public void configureLogging()    {        try        {            PreferenceStore preferences = new PreferenceStore();            // Set the default values from extension registry            IExtensionRegistry registry = Platform.getExtensionRegistry();            IExtensionPoint extensionPoint = registry.getExtensionPoint(CorePlugin.LOGGER_PREFERENCES_EXTENSION_POINT);            IConfigurationElement[] members = extensionPoint.getConfigurationElements();            for (int i = 0; i < members.length; i++)            {                IConfigurationElement element = members[i];                 if (element.getName().equals("logger"))                {                    if (element.getAttribute("defaultValue") != null)                    {                        String[] item = element.getAttribute("name").split(";");                        for (int x = 0; x < item.length; x++)                            preferences.setDefault("log4j.logger." + item[x], element.getAttribute("defaultValue"));                    }                }            }                        // Set the default values from the bundle's properties file            try {                URL url = CorePlugin.getDefault().getBundle().getResource("log4j.properties"); //$NON-NLS-1$                Properties properties = new Properties();                properties.load(url.openStream());                for (Iterator iter = properties.keySet().iterator(); iter.hasNext(); )                {                    String key = (String)iter.next();                    preferences.setDefault(key, (String)properties.get(key));                }                // Read the values from the user's configuration                File file = CorePlugin.getDefault().getStateLocation().append("log4j.properties").toFile();                if (file.exists())                    preferences.load(new FileInputStream(file));            } catch(Exception e) {                CorePlugin.logException(e);            }            // Configure log4j            Properties properties = new Properties();            String[] names = preferences.preferenceNames();            for (int i = 0; i < names.length; i++)                properties.put(names[i], preferences.getString(names[i]));            PropertyConfigurator.configure(properties);        }        catch (Exception e)        {            BasicConfigurator.configure();            logException(e);        }    }    /* (non-Javadoc)     * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)     */    public void stop(BundleContext context) throws Exception    {        FeedMonitor.stop();        Level2FeedMonitor.stop();        if (repository != null)            repository.dispose();        getPreferenceStore().setValue(FEED_RUNNING, false);        CorePlugin.getDefault().getPreferenceStore().removePropertyChangeListener(feedPropertyListener);                CurrencyConverter.getInstance().dispose();                super.stop(context);        plugin = null;    }    public static CorePlugin getDefault()    {        return plugin;    }    public static Repository getRepository()    {        if (repository == null)        {            try            {                Class clazz = Class.forName("net.sourceforge.eclipsetrader.core.RepositoryImpl");                repository = (Repository)clazz.newInstance();            }            catch (Exception e)            {                repository = new XMLRepository();            }        }        return repository;    }    /**     * Returns an image descriptor for the image file at the given     * plug-in relative path.     *     * @param path the path     * @return the image descriptor     */    public static ImageDescriptor getImageDescriptor(String path)    {

⌨️ 快捷键说明

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