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

📄 sampleview.java

📁 一些介绍J2ME的经典源码,对于在手机上开发应用很有帮助
💻 JAVA
字号:
package tableviewersample.views;import java.util.ArrayList;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Table;import org.eclipse.swt.widgets.TableColumn;import org.eclipse.ui.part.*;import org.eclipse.jface.viewers.*;import org.eclipse.swt.SWT;/** * This sample class demonstrates how to plug-in a new * workbench view. The view shows data obtained from the * model. The sample creates a dummy model on the fly, * but a real implementation would connect to the model * available either in this or another plug-in (e.g. the workspace). * The view is connected to the model using a content provider. * <p> * The view uses a label provider to define how model * objects should be presented in the view. Each * view can present the same model objects using * different labels and icons, if needed. Alternatively, * a single label provider can be shared between views * in order to ensure that objects of the same type are * presented in the same way everywhere. * <p> */public class SampleView extends ViewPart {	Composite composite;	TableViewer tableviewer;    ArrayList Books;    TableColumn column0,column1,column2,column3,column4;	/**	 * The constructor.	 */	public SampleView() {		Books = new ArrayList();	}	/**	 * This is a callback that will allow us	 * to create the viewer and initialize it.	 */	public void createPartControl(Composite parent) {		composite= new Composite(parent,SWT.NONE);		composite.setLayout(new GridLayout(1,false));				tableviewer = new TableViewer(composite);			Table table = tableviewer.getTable();		table.setLayoutData(new GridData(GridData.FILL_BOTH));		column0 = new TableColumn(table,SWT.LEFT,0);		column0.setText("Books Name");		column1 = new TableColumn(table,SWT.LEFT,1);		column1.setText("ISBN");		column2 = new TableColumn(table,SWT.LEFT,2);		column2.setText("Published Date");		column3 = new TableColumn(table,SWT.LEFT,3);		column3.setText("Price");		column4 = new TableColumn(table,SWT.LEFT,4);		column4.setText("Availabe Now?");				for(int i =0, n=table.getColumnCount(); i<n; i++){			table.getColumn(i).pack();		}				table.setHeaderVisible(true);		table.setLinesVisible(true);		//System.out.println(table.getBackground());		//System.out.println(table.getForeground());		tableviewer.setContentProvider(new SampleTableContentProvider());		tableviewer.setLabelProvider(  new SampleTableLabelProvider());		tableviewer.setInput(getInput());				//System.out.println(getInput());					}	private ArrayList getInput() {				Book b1 = new Book();		Book b2 = new Book();		Book b3 = new Book();				b1.setName("Red Book");		b1.setIsbn("U2w3e4r5t6y");		b1.setPublisheddate("1980-08-28");		b1.setPrice("$1000");		b1.setAvailable("Yes");				b2.setName("Blue Book");		b2.setIsbn("U1q2w3e4r");		b2.setPublisheddate("1981-05-04");		b2.setPrice("$1500");		b2.setAvailable("Yes");				b3.setName("Green Book");		b3.setIsbn("U0p9o8i7u");		b3.setPublisheddate("1980-03-04");		b3.setPrice("$2000");		b3.setAvailable("No");				Books.add(b1);		Books.add(b2);		Books.add(b3);				return Books;	}	/**	 * Passing the focus request to the viewer's control.	 */	public void setFocus() {			}}

⌨️ 快捷键说明

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