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

📄 securitiesview.java

📁 EclipseTrader is a stock exchange analysis system, featuring shares pricing watch, intraday and hi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        GridLayout gridLayout = new GridLayout();        gridLayout.marginWidth = gridLayout.marginHeight = 0;        gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;        content.setLayout(gridLayout);                table = new Table(content, SWT.MULTI|SWT.FULL_SELECTION);        table.setHeaderVisible(true);        table.setLinesVisible(false);        if (theme != null)        {            table.setForeground(theme.getColorRegistry().get(TABLE_FOREGROUND));            table.setBackground(theme.getColorRegistry().get(TABLE_BACKGROUND));            table.setFont(theme.getFontRegistry().get(TABLE_FONT));        }        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));        table.addSelectionListener(new SelectionAdapter() {            public void widgetSelected(SelectionEvent e)            {                updateSelection();            }        });        table.addMouseListener(new MouseAdapter() {            public void mouseDown(MouseEvent e)            {                if (table.getItem(new Point(e.x, e.y)) == null)                {                    table.deselectAll();                    getSite().getSelectionProvider().setSelection(new NullSelection());                }            }        });        // TODO This is a workaround for the sort column background color        table.addListener(SWT.EraseItem, new Listener() {            public void handleEvent(Event event)            {                event.gc.setBackground(((TableItem)event.item).getBackground());                event.gc.fillRectangle(event.getBounds());            }        });        TableColumn column = new TableColumn(table, SWT.NONE);        column.setText(Messages.SecuritiesView_Code);        column.addControlListener(columnControlListener);        column.addSelectionListener(columnSelectionListener);        column = new TableColumn(table, SWT.NONE);        column.setText(Messages.SecuritiesView_Description);        column.addControlListener(columnControlListener);        column.addSelectionListener(columnSelectionListener);        column = new TableColumn(table, SWT.NONE);        column.setText(Messages.SecuritiesView_Currency);        column.addControlListener(columnControlListener);        column.addSelectionListener(columnSelectionListener);                // Drag and drop support        DragSource dragSource = new DragSource(table, DND.DROP_COPY|DND.DROP_MOVE);        dragSource.setTransfer(new Transfer[] { SecurityTransfer.getInstance() });        dragSource.addDragListener(new DragSourceListener() {            public void dragStart(DragSourceEvent event)            {                if (table.getSelectionCount() == 0)                    event.doit = false;            }            public void dragSetData(DragSourceEvent event)            {                TableItem selection[] = table.getSelection();                Security[] securities = new Security[selection.length];                for (int i = 0; i < selection.length; i++)                {                    SecurityTableItem item = (SecurityTableItem)selection[i];                    securities[i] = item.getSecurity();                }                event.data = securities;            }            public void dragFinished(DragSourceEvent event)            {            }        });                IPreferenceStore prefs = CorePlugin.getDefault().getPreferenceStore();        prefs.setDefault(PREFS_SORT_COLUMN, sortColumn);        prefs.setDefault(PREFS_SORT_DIRECTION, sortDirection);        sortColumn = prefs.getInt(PREFS_SORT_COLUMN);        sortDirection = prefs.getInt(PREFS_SORT_DIRECTION);        getSite().setSelectionProvider(new SelectionProvider());        IActionBars actionBars = getViewSite().getActionBars();        actionBars.setGlobalActionHandler("delete", deleteAction); //$NON-NLS-1$        actionBars.setGlobalActionHandler("properties", propertiesAction); //$NON-NLS-1$        MenuManager menuMgr = new MenuManager("#popupMenu", "popupMenu"); //$NON-NLS-1$ //$NON-NLS-2$        menuMgr.setRemoveAllWhenShown(true);        menuMgr.addMenuListener(new IMenuListener() {            public void menuAboutToShow(IMenuManager menuManager)            {                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());                menuManager.add(deleteAction);                menuManager.add(new Separator("bottom")); //$NON-NLS-1$                menuManager.add(new Separator());                menuManager.add(propertiesAction);            }        });        table.setMenu(menuMgr.createContextMenu(table));        getSite().registerContextMenu(menuMgr, getSite().getSelectionProvider());        parent.getDisplay().asyncExec(new Runnable() {            public void run()            {                updateView();                CorePlugin.getRepository().allSecurities().addCollectionObserver(SecuritiesView.this);            }        });    }    /* (non-Javadoc)     * @see org.eclipse.ui.part.WorkbenchPart#setFocus()     */    public void setFocus()    {        table.getParent().setFocus();    }    /* (non-Javadoc)     * @see org.eclipse.ui.part.WorkbenchPart#dispose()     */    public void dispose()    {        if (theme != null)            theme.removePropertyChangeListener(themeChangeListener);        CorePlugin.getRepository().allSecurities().removeCollectionObserver(this);        super.dispose();    }        /* (non-Javadoc)     * @see net.sourceforge.eclipsetrader.core.ICollectionObserver#itemAdded(java.lang.Object)     */    public void itemAdded(Object o)    {        final Security security = (Security)o;        table.getDisplay().asyncExec(new Runnable() {            public void run()            {                if (!table.isDisposed())                {                    TableItem items[] = table.getItems();                    for (int i = 0; i < items.length; i++)                    {                        Security arg1 = ((SecurityTableItem)items[i]).getSecurity();                        if (comparator.compare(security, arg1) < 0)                        {                            new SecurityTableItem(table, SWT.NONE, i, security);                            updateSelection();                            return;                        }                    }                    new SecurityTableItem(table, SWT.NONE, security);                    updateSelection();                }            }        });   }    /* (non-Javadoc)     * @see net.sourceforge.eclipsetrader.core.ICollectionObserver#itemRemoved(java.lang.Object)     */    public void itemRemoved(Object o)    {        final Security security = (Security)o;        table.getDisplay().asyncExec(new Runnable() {            public void run()            {                if (!table.isDisposed())                {                    TableItem items[] = table.getItems();                    for (int i = 0; i < items.length; i++)                    {                        if (security.equals(((SecurityTableItem) items[i]).getSecurity()))                            items[i].dispose();                    }                    updateSelection();                }            }        });    }    public void updateView()    {        List list = CorePlugin.getRepository().allSecurities();        Collections.sort(list, comparator);                int index = 0;        SecurityTableItem tableItem = null;        for (Iterator iter = list.iterator(); iter.hasNext(); )        {            Security security = (Security)iter.next();            if (index < table.getItemCount())            {                tableItem = (SecurityTableItem) table.getItem(index);                tableItem.setSecurity(security);            }            else                tableItem = new SecurityTableItem(table, SWT.NONE, security);            index++;        }        table.setItemCount(index);                String[] sizes = CorePlugin.getDefault().getPreferenceStore().getString(PREFS_COLUMNS_SIZE).split(";"); //$NON-NLS-1$        for (int i = 0; i < table.getColumnCount(); i++)        {            if (i < sizes.length && sizes[i].length() != 0)                table.getColumn(i).setWidth(Integer.parseInt(sizes[i]));            else            {                table.getColumn(i).pack();                if (table.getColumn(i).getWidth() == 0)                    table.getColumn(i).setWidth(100);            }        }        if ("gtk".equals(SWT.getPlatform())) //$NON-NLS-1$            table.getColumn(table.getColumnCount() - 1).pack();                if (sortColumn >= 0 && sortColumn < table.getColumnCount())        {            table.setSortColumn(table.getColumn(sortColumn));            table.setSortDirection(sortDirection == 0 ? SWT.UP : SWT.DOWN);        }        else        {            table.setSortColumn(null);            sortColumn = -1;            sortDirection = 0;        }                updateSelection();    }        public Security[] getSelection()    {        TableItem selection[] = table.getSelection();        Security[] securities = new Security[selection.length];        for (int i = 0; i < selection.length; i++)        {            SecurityTableItem item = (SecurityTableItem)selection[i];            securities[i] = item.getSecurity();        }        return securities;    }        private void updateSelection()    {        Security[] security = getSelection();        if (security.length == 1)            getSite().getSelectionProvider().setSelection(new SecuritySelection(security[0]));        else            getSite().getSelectionProvider().setSelection(new NullSelection());        deleteAction.setEnabled(security.length != 0);        propertiesAction.setEnabled(security.length == 1);        changeQuoteFeedAction.setEnabled(security.length != 0);        changeLevel2FeedAction.setEnabled(security.length != 0);        changeHistoryFeedAction.setEnabled(security.length != 0);        changeIntradayOptionsAction.setEnabled(security.length != 0);        changeTradingOptionsAction.setEnabled(security.length != 0);    }        private class SecurityTableItem extends TableItem implements DisposeListener, Observer    {        private Security security;        public SecurityTableItem(Table parent, int style, int index, Security security)        {            super(parent, style, index);            setSecurity(security);            addDisposeListener(this);        }        public SecurityTableItem(Table parent, int style, Security security)        {            super(parent, style);            setSecurity(security);            addDisposeListener(this);        }                /* (non-Javadoc)         * @see org.eclipse.swt.widgets.TableItem#checkSubclass()         */        protected void checkSubclass()        {        }        public Security getSecurity()        {            return security;        }        private void setSecurity(Security security)        {            if (this.security != null)                this.security.deleteObserver(this);            this.security = security;            update();                        this.security.addObserver(this);        }        private void update()        {            setText(0, security.getCode());            setText(1, security.getDescription());            setText(2, security.getCurrency() != null ? security.getCurrency().getCurrencyCode() : ""); //$NON-NLS-1$        }        /* (non-Javadoc)         * @see java.util.Observer#update(java.util.Observable, java.lang.Object)         */        public void update(Observable o, Object arg)        {            getDisplay().asyncExec(new Runnable() {                public void run()                {                    if (!isDisposed())                        update();                }            });        }        /* (non-Javadoc)         * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)         */        public void widgetDisposed(DisposeEvent e)        {            if (this.security != null)                this.security.deleteObserver(this);        }    }}

⌨️ 快捷键说明

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