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

📄 tabletreeviewer.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2006 IBM Corporation 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: *     IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.jface.viewers;import java.util.List;import org.eclipse.jface.util.Assert;import org.eclipse.swt.SWT;import org.eclipse.swt.custom.TableTree;import org.eclipse.swt.custom.TableTreeEditor;import org.eclipse.swt.custom.TableTreeItem;import org.eclipse.swt.events.MouseAdapter;import org.eclipse.swt.events.MouseEvent;import org.eclipse.swt.events.TreeListener;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.graphics.Point;import org.eclipse.swt.graphics.Rectangle;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.Item;import org.eclipse.swt.widgets.Widget;/** * A concrete viewer based on a SWT <code>TableTree</code> control. * <p> * This class is not intended to be subclassed outside the viewer framework.  * It is designed to be instantiated with a pre-existing SWT table tree control and configured * with a domain-specific content provider, label provider, element filter (optional), * and element sorter (optional). * </p> * <p> * Content providers for table tree viewers must implement the <code>ITreeContentProvider</code> * interface. * </p> * <p> * Label providers for table tree viewers must implement either the <code>ITableLabelProvider</code> * or the <code>ILabelProvider</code> interface (see <code>TableTreeViewer.setLabelProvider</code>  * for more details). * </p> */public class TableTreeViewer extends AbstractTreeViewer {    /**     * Internal table viewer implementation.     */    private TableEditorImpl tableViewerImpl;    /**     * This viewer's table tree control.     */    private TableTree tableTree;    /**     * This viewer's table tree editor.     */    private TableTreeEditor tableTreeEditor;    /**     * Private implementation class.     */    class TableTreeViewerImpl extends TableEditorImpl {        public TableTreeViewerImpl(TableTreeViewer viewer) {            super(viewer);        }        Rectangle getBounds(Item item, int columnNumber) {            return ((TableTreeItem) item).getBounds(columnNumber);        }        int getColumnCount() {            //getColumnCount() should be a API in TableTree.            return getTableTree().getTable().getColumnCount();        }        Item[] getSelection() {            return getTableTree().getSelection();        }        void setEditor(Control w, Item item, int columnNumber) {            tableTreeEditor.setEditor(w, (TableTreeItem) item, columnNumber);        }        void setSelection(StructuredSelection selection, boolean b) {            TableTreeViewer.this.setSelection(selection, b);        }        void showSelection() {            getTableTree().showSelection();        }        void setLayoutData(CellEditor.LayoutData layoutData) {            tableTreeEditor.horizontalAlignment = layoutData.horizontalAlignment;            tableTreeEditor.grabHorizontal = layoutData.grabHorizontal;            tableTreeEditor.minimumWidth = layoutData.minimumWidth;        }        void handleDoubleClickEvent() {            Viewer viewer = getViewer();            fireDoubleClick(new DoubleClickEvent(viewer, viewer.getSelection()));            fireOpen(new OpenEvent(viewer, viewer.getSelection()));        }    }    /**     * Creates a table tree viewer on the given table tree control.     * The viewer has no input, no content provider, a default label provider,      * no sorter, and no filters.     *     * @param tree the table tree control     */    public TableTreeViewer(TableTree tree) {        super();        tableTree = tree;        hookControl(tree);        tableTreeEditor = new TableTreeEditor(tableTree);        tableViewerImpl = new TableTreeViewerImpl(this);    }    /**     * Creates a table tree viewer on a newly-created table tree control under the given parent.     * The table tree control is created using the SWT style bits <code>MULTI, H_SCROLL, V_SCROLL, and BORDER</code>.     * The viewer has no input, no content provider, a default label provider,      * no sorter, and no filters.     *     * @param parent the parent control     */    public TableTreeViewer(Composite parent) {        this(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);    }    /**     * Creates a table tree viewer on a newly-created table tree control under the given parent.     * The table tree control is created using the given SWT style bits.     * The viewer has no input, no content provider, a default label provider,      * no sorter, and no filters.     *     * @param parent the parent control     * @param style the SWT style bits     */    public TableTreeViewer(Composite parent, int style) {        this(new TableTree(parent, style));    }    /* (non-Javadoc)     * Method declared on AbstractTreeViewer.     */    protected void addTreeListener(Control c, TreeListener listener) {        ((TableTree) c).addTreeListener(listener);    }    /**     * Cancels a currently active cell editor. All changes already done in the cell     * editor are lost.     */    public void cancelEditing() {        tableViewerImpl.cancelEditing();    }    /* (non-Javadoc)     * Method declared on AbstractTreeViewer.     */    protected void doUpdateItem(Item item, Object element) {        // update icon and label        // Similar code in TableTreeViewer.doUpdateItem()        IBaseLabelProvider prov = getLabelProvider();        ITableLabelProvider tprov = null;                        if (prov instanceof ITableLabelProvider) {			tprov = (ITableLabelProvider) prov;		}                int columnCount = tableTree.getTable().getColumnCount();        TableTreeItem ti = (TableTreeItem) item;        // Also enter loop if no columns added.  See 1G9WWGZ: JFUIF:WINNT - TableViewer with 0 columns does not work        for (int column = 0; column < columnCount || column == 0; column++) {            String text = "";//$NON-NLS-1$            Image image = null;            if (tprov != null) {                text = tprov.getColumnText(element, column);                image = tprov.getColumnImage(element, column);            } else {                if (column == 0) {					ViewerLabel updateLabel = new ViewerLabel(item							.getText(), item.getImage());					buildLabel(updateLabel,element);										//As it is possible for user code to run the event 		            //loop check here.					if (item.isDisposed()) {		                unmapElement(element, item);		                return;		            }   										text = updateLabel.getText();					image = updateLabel.getImage();				}            }                        //Avoid setting text to null            if(text == null) {				text = ""; //$NON-NLS-1$			}                        ti.setText(column, text);            // Apparently a problem to setImage to null if already null            if (ti.getImage(column) != image) {				ti.setImage(column, image);			}                        getColorAndFontCollector().setFontsAndColors(element);            getColorAndFontCollector().applyFontsAndColors(ti);        }       }    /**     * Starts editing the given element.     *     * @param element the element     * @param column the column number     */    public void editElement(Object element, int column) {        tableViewerImpl.editElement(element, column);    }    /**     * Returns the cell editors of this viewer.     *     * @return the list of cell editors     */    public CellEditor[] getCellEditors() {        return tableViewerImpl.getCellEditors();    }    /**     * Returns the cell modifier of this viewer.     *     * @return the cell modifier     */    public ICellModifier getCellModifier() {        return tableViewerImpl.getCellModifier();    }    /* (non-Javadoc)     * Method declared on AbstractTreeViewer.     */    protected Item[] getChildren(Widget o) {        if (o instanceof TableTreeItem) {			return ((TableTreeItem) o).getItems();		}        if (o instanceof TableTree) {			return ((TableTree) o).getItems();		}

⌨️ 快捷键说明

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