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

📄 structuredviewer.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************* * 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.ArrayList;import java.util.Arrays;import java.util.Iterator;import java.util.List;import org.eclipse.core.runtime.ListenerList;import org.eclipse.jface.util.Assert;import org.eclipse.jface.util.IOpenEventListener;import org.eclipse.jface.util.OpenStrategy;import org.eclipse.jface.util.SafeRunnable;import org.eclipse.swt.custom.TableTreeItem;import org.eclipse.swt.dnd.DragSource;import org.eclipse.swt.dnd.DragSourceListener;import org.eclipse.swt.dnd.DropTarget;import org.eclipse.swt.dnd.DropTargetListener;import org.eclipse.swt.dnd.Transfer;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.events.SelectionListener;import org.eclipse.swt.graphics.Color;import org.eclipse.swt.graphics.Font;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.Item;import org.eclipse.swt.widgets.TableItem;import org.eclipse.swt.widgets.TreeItem;import org.eclipse.swt.widgets.Widget;/** * Abstract base implementation for structure-oriented viewers (trees, lists, * tables). Supports custom sorting, filtering, and rendering. * <p> * Any number of viewer filters can be added to this viewer (using * <code>addFilter</code>). When the viewer receives an update, it asks each * of its filters if it is out of date, and refilters elements as required. * </p> *  * @see ViewerFilter * @see ViewerSorter * @see ViewerComparator */public abstract class StructuredViewer extends ContentViewer implements IPostSelectionProvider {	/**	 * A map from the viewer's model elements to SWT widgets. (key type:	 * <code>Object</code>, value type: <code>Widget</code>, or <code>Widget[]</code>).	 * <code>null</code> means that the element map is disabled.	 */	private CustomHashtable elementMap;	/**	 * The comparer to use for comparing elements, or <code>null</code> to use	 * the default <code>equals</code> and <code>hashCode</code> methods on	 * the element itself.	 */	private IElementComparer comparer;	/**	 * This viewer's comparator used for sorting. <code>null</code> means there is no comparator.	 */	private ViewerComparator sorter;	/**	 * This viewer's filters (element type: <code>ViewerFilter</code>).	 * <code>null</code> means there are no filters.	 */	private List filters;	/**	 * Indicates whether a selection change is in progress on this viewer.	 * 	 * @see #setSelection(ISelection, boolean)	 */	private boolean inChange;	/**	 * Used while a selection change is in progress on this viewer to indicates	 * whether the selection should be restored.	 * 	 * @see #setSelection(ISelection, boolean)	 */	private boolean restoreSelection;	/**	 * List of double-click state listeners (element type:	 * <code>IDoubleClickListener</code>).	 * 	 * @see #fireDoubleClick	 */	private ListenerList doubleClickListeners = new ListenerList();	/**	 * List of open listeners (element type:	 * <code>ISelectionActivateListener</code>).	 * 	 * @see #fireOpen	 */	private ListenerList openListeners = new ListenerList();	/**	 * List of post selection listeners (element type:	 * <code>ISelectionActivateListener</code>).	 * 	 * @see #firePostSelectionChanged	 */	private ListenerList postSelectionChangedListeners = new ListenerList();	/**	 * The colorAndFontCollector is an object used by viewers that	 * support the IColorProvider, the IFontProvider and/or the 	 * IViewerLabelProvider for color and font updates.	 * Initialize it to have no color or font providing	 * initially.	 * @since 3.1	 */	private ColorAndFontCollector colorAndFontCollector = new ColorAndFontCollector();		/**	 * Empty array of widgets.	 */	private static Widget[] NO_WIDGETS = new Widget[0];	/**	 * The ColorAndFontCollector is a helper class for viewers	 * that have color and font support ad optionally decorators.	 * @see IColorDecorator	 * @see IFontDecorator	 * @see IColorProvider	 * @see IFontProvider	 * @see IDecoration	 */	protected class ColorAndFontCollectorWithProviders extends ColorAndFontCollector{		IColorProvider colorProvider;		IFontProvider fontProvider;				/**		 * Create a new instance of the receiver using the supplied		 * label provider. If it is an IColorProvider or IFontProvider		 * set these values up.		 * @param provider IBaseLabelProvider		 * @see IColorProvider		 * @see IFontProvider		 */		public ColorAndFontCollectorWithProviders(IBaseLabelProvider provider) {			super();			if (provider instanceof IColorProvider) {				colorProvider = (IColorProvider) provider;			}			if (provider instanceof IFontProvider) {				fontProvider = (IFontProvider) provider;			}		}					/* (non-Javadoc)		 * @see org.eclipse.jface.viewers.StructuredViewer.ColorAndFontManager#setFontsAndColors(java.lang.Object)		 */		public void setFontsAndColors(Object element){						if(fontProvider != null){				if(font == null) {					font = fontProvider.getFont(element);				}				}						if(colorProvider == null) {				return;			}						//Set the colors if they are not set yet			if(background == null) {				background = colorProvider.getBackground(element);			}						if(foreground == null) {				foreground = colorProvider.getForeground(element);			}					}				/**		 * Apply the fonts and colors to the control if		 * required.		 * @param control		 */		public void applyFontsAndColors(TableItem control) {						if(colorProvider == null){				if(usedDecorators){					//If there is no provider only apply set values					if(background != null) {						control.setBackground(background);					}									if(foreground != null) {						control.setForeground(foreground);					}				}			}			else{				//Always set the value if there is a provider				control.setBackground(background);				control.setForeground(foreground);			}						if(fontProvider == null){				if(usedDecorators && font != null) {					control.setFont(font);				}			} else {				control.setFont(font);			}						clear();		}					/* (non-Javadoc)		 * @see org.eclipse.jface.viewers.StructuredViewer.ColorAndFontManager#applyFontsAndColors(org.eclipse.swt.widgets.TreeItem)		 */		public void applyFontsAndColors(TreeItem control) {						if(colorProvider == null){				if(usedDecorators){					//If there is no provider only apply set values					if(background != null) {						control.setBackground(background);					}									if(foreground != null) {						control.setForeground(foreground);					}				}			}			else{				//Always set the value if there is a provider				control.setBackground(background);				control.setForeground(foreground);			}						if(fontProvider == null){				if(usedDecorators && font != null) {					control.setFont(font);				}			} else {				control.setFont(font);			}						clear();		}					/* (non-Javadoc)		 * @see org.eclipse.jface.viewers.StructuredViewer.ColorAndFontManager#applyFontsAndColors(org.eclipse.swt.custom.TableTreeItem)		 */		public void applyFontsAndColors(TableTreeItem control) {						if(colorProvider == null){				if(usedDecorators){					//If there is no provider only apply set values					if(background != null) {						control.setBackground(background);					}									if(foreground != null) {						control.setForeground(foreground);					}				}			}			else{				//Always set the value if there is a provider				control.setBackground(background);				control.setForeground(foreground);			}						if(fontProvider == null){				if(usedDecorators && font != null) {					control.setFont(font);				}			} else {				control.setFont(font);			}						clear();		}					}		/**	 * The ColorAndFontManager collects fonts and colors without a	 * a color or font provider.	 *	 */	protected class ColorAndFontCollector {		Color foreground = null;		Color background = null;		Font font = null;		boolean usedDecorators = false;		/**		 * Create a new instance of the receiver with		 * no colour and font provider.			 */		public ColorAndFontCollector(){			super();		}				/**		 * Clear all of the results.		 */		public void clear() {			foreground = null;			background = null;			font = null;			usedDecorators = false;		}				/**		 * Set the initial fonts and colors for the element from the		 * content providers.		 * @param element Object		 */		public void setFontsAndColors(Object element){			//Do nothing if there are no providers		}		/**		 * Set that decorators were applied.		 */		public void setUsedDecorators() {			this.usedDecorators = true;		}		/**		 * Apply the fonts and colors to the control if		 * required.		 * @param control		 */		public void applyFontsAndColors(TableItem control) {						if(usedDecorators){				//If there is no provider only apply set values				if(background != null) {					control.setBackground(background);				}							if(foreground != null) {					control.setForeground(foreground);				}						if(font != null) {					control.setFont(font);				}			}			clear();		}				/**		 * Apply the fonts and colors to the control if		 * required.		 * @param control		 */		public void applyFontsAndColors(TreeItem control) {			if(usedDecorators){				//If there is no provider only apply set values				if(background != null) {					control.setBackground(background);				}							if(foreground != null) {					control.setForeground(foreground);				}						if(font != null) {					control.setFont(font);				}			}			clear();		}				/**		 * Apply the fonts and colors to the control if		 * required.		 * @param control		 */		public void applyFontsAndColors(TableTreeItem control) {			if(usedDecorators){				//If there is no provider only apply set values				if(background != null) {					control.setBackground(background);				}							if(foreground != null) {					control.setForeground(foreground);				}						if(font != null) {					control.setFont(font);				}			}			clear();		}				/**		 * Set the background color.

⌨️ 快捷键说明

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