好不容易做好的,不要了,删了可惜,在这备份一下吧

package xmleditor.editors;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.forms.IDetailsPage;
import org.eclipse.ui.forms.IFormPart;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;

import com.highsoft.common.jpa.meta.EntityFieldMetaData;
import com.highsoft.common.jpa.meta.EntityMetaData;

public class DetailPage implements IDetailsPage {

	private IManagedForm mform;
	private Section section;
	private Text name;
	private Text description;
	private Text class_;
	private Text table;
	private Text idGenType;
	private Text idClass;
	private Button add;
	private Button del;
	private Button sav;
	private Table field;
//	private TableViewer tableViewer;
//	private 表格
	public Composite client;
	private EntityMetaData entityMetaData;
	private static final String RTEXT_DATA =Message.DetailNoitce;
//	public static final String[] COLUMN_NAME={"idFlag","column","length",
//					"precision","nullable","filterInclude","sortInclude"};
				 
	@Override
	public void createContents(Composite parent) {
		//设置父类面板的布局
		TableWrapLayout layout= new TableWrapLayout();
		layout.topMargin=5;
		layout.leftMargin=5;
		layout.rightMargin=2;
		layout.bottomMargin=2;
		parent.setLayout(layout);
		//获得表单工具对象
		FormToolkit toolkit= mform.getToolkit();
		//创建detail的内容区
		section=toolkit.createSection(parent,Section.DESCRIPTION|Section.TITLE_BAR);
		section.marginWidth=10;
		section.setText(Message.DetailSectionName);
		section.setDescription(Message.DetailSectionDescription);
		TableWrapData td= new TableWrapData(TableWrapData.FILL,TableWrapData.TOP);
		td.grabHorizontal=true;
		section.setLayoutData(td);
		
		//创建内容区所设置的面板
		client=toolkit.createComposite(section);
		section.setClient(client);
		GridLayout gridlayout= new GridLayout();
		gridlayout.marginWidth=0;
		gridlayout.marginHeight=0;
		gridlayout.numColumns=2;
		gridlayout.marginLeft=0;
		gridlayout.marginRight=0;
		gridlayout.horizontalSpacing=10;
		client.setLayout(gridlayout);
		//创建detail部分的控件
		
		GridData gridData= new GridData();
		gridData.horizontalAlignment=GridData.FILL;//设置水平充满单元格
		gridData.grabExcessHorizontalSpace=true; //水平抢占空间方式
		toolkit.createLabel(client, "name:");
		name=toolkit.createText(client, " ");
		name.setLayoutData(gridData);
		toolkit.createLabel(client, "description:");		
		description=toolkit.createText(client, " ");
		description.setLayoutData(gridData);
		toolkit.createLabel(client, "class:");		
		class_=toolkit.createText(client, " ");
		class_.setLayoutData(gridData);
		toolkit.createLabel(client, "table:");		
		table=toolkit.createText(client, " ");
		table.setLayoutData(gridData);
		toolkit.createLabel(client, "idGenType:");		
		idGenType=toolkit.createText(client, " ");
		idGenType.setLayoutData(gridData);
		toolkit.createLabel(client, "idClass:");		
		idClass=toolkit.createText(client, " ");
		idClass.setLayoutData(gridData);
//		field=toolkit.createTable(client, SWT.FULL_SELECTION);
//		field.setLinesVisible(true);
//		field.setHeaderVisible(true);
//		TableItem[] items=field.getItems();
//		
//		for(int i=0;i<items.length;i++){
//			final TableEditor editor= new TableEditor(field);
//			final Text text= new Text(field,SWT.NONE);
//			text.setText(items[i].getText(0));
//			editor.grabHorizontal=true;
//			editor.setEditor(text, items[i], 0);
//			text.addModifyListener(new ModifyListener() {
//				
//				@Override
//				public void modifyText(ModifyEvent e) {
//					// 
//					editor.getItem().setText(1, text.getText());
//					
//				}
//			});
//		}
		
//
//		GridData gdd = new GridData(GridData.FILL_BOTH);
//		gdd.heightHint = 200;
//		gdd.widthHint = 210;
//		gdd.horizontalSpan=2;
//		field.setLayoutData(gdd);
//		tableViewer=new TableViewer(field);
//		//創建表頭
//				for(int i=0;i<COLUMN_NAME.length;i++){
//					TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.LEFT); 
//					 column.getColumn().setText(COLUMN_NAME[i]);  
//			            column.getColumn().setWidth(100);  
//			          //  column.setEditingSupport(new TableViewerEditingSupport(tableViewer, i));  
//			            //new org.eclipse.swt.widgets.TableColumn(tableViewer.getTable(), SWT.LEFT).setText(COLUMN_NAME[i]);
//					
//					tableViewer.getTable().getColumn(i).pack();
//				}
//				tableViewer.setContentProvider(new DetailContentProvider());
//				tableViewer.setLabelProvider(new DeatilLabelProvider());
//				
//				tableViewer.setColumnProperties(COLUMN_NAME);
//				CellEditor[] editors= new CellEditor[7];
//				editors[0]=new TextCellEditor(tableViewer.getTable());
//				//editors[0] = new ComboBoxCellEditor(tableViewer.getTable(), new String[] {"true","false"}, SWT.READ_ONLY); 
//				editors[1]=new TextCellEditor(tableViewer.getTable());
//				editors[2]=new TextCellEditor(tableViewer.getTable());
//				editors[3]=new TextCellEditor(tableViewer.getTable());
//				editors[4]=new TextCellEditor(tableViewer.getTable());
//				editors[5]=new TextCellEditor(tableViewer.getTable());
//				editors[6]=new TextCellEditor(tableViewer.getTable());
//				tableViewer.setCellEditors(editors);
//				tableViewer.setCellModifier(new ICellModifier() {
//					
//					@Override
//					public void modify(Object element, String property, Object value) {
//						if(element instanceof Item)
//							element=((Item)element).getData();
//						EntityFieldMetaData entityFieldMetaData=(EntityFieldMetaData)element;
//						if(property.equals(COLUMN_NAME[0]))
//						entityFieldMetaData.setIdFlag(Boolean.parseBoolean((String)value));
//						else if(property.equals(COLUMN_NAME[1]))
//							entityFieldMetaData.setColumn((String)value);
//						else if(property.equals(COLUMN_NAME[2]))
//							entityFieldMetaData.setLength(Integer.parseInt((String)value));
//						else if(property.equals(COLUMN_NAME[3]))
//							entityFieldMetaData.setPrecision(Integer.parseInt((String)value));
//						else if(property.equals(COLUMN_NAME[4]))
//							entityFieldMetaData.setNullable(Boolean.parseBoolean((String)value));
//						else if(property.equals(COLUMN_NAME[5]))
//							entityFieldMetaData.setFilterInclude(Boolean.parseBoolean((String)value));
//						else if(property.equals(COLUMN_NAME[6]))
//							entityFieldMetaData.setSortInclude(Boolean.parseBoolean((String)value));
//						tableViewer.refresh();
//						
//					}
//					
//					@Override
//					public Object getValue(Object element, String property) {
//						EntityFieldMetaData entityFieldMetaData=(EntityFieldMetaData)element;
//						if(property.equals(COLUMN_NAME[0]))
//							return String.valueOf(entityFieldMetaData.isIdFlag());
//						else if(property.equals(COLUMN_NAME[1]))
//							return entityFieldMetaData.getColumn();
//						else if(property.equals(COLUMN_NAME[2]))
//							return String.valueOf(entityFieldMetaData.getLength());
//						else if(property.equals(COLUMN_NAME[3]))
//							return String.valueOf(entityFieldMetaData.getPrecision());
//						else if(property.equals(COLUMN_NAME[4]))
//							return String.valueOf(entityFieldMetaData.isNullable());
//						else if(property.equals(COLUMN_NAME[5]))
//							return String.valueOf(entityFieldMetaData.isFilterInclude());
//						else if(property.equals(COLUMN_NAME[6]))
//							return String.valueOf(entityFieldMetaData.isSortInclude());
//						return null;
//					}
//					
//					@Override
//					public boolean canModify(Object element, String property) {
//						
//						// TODO Auto-generated method stub
//						return true;
//					}
//				});
//				
				
				
				
				
				
		Composite cmp= toolkit.createComposite(parent);
		GridLayout gddd= new GridLayout();
		gddd.marginWidth=50;
		//gddd.numColumns=3;
		gddd.horizontalSpacing=10;
		cmp.setLayout(gddd);
		
//		add=toolkit.createButton(cmp, "Add...", SWT.PUSH);		
//		del=toolkit.createButton(cmp, "DEL...", SWT.PUSH);		
//		sav=toolkit.createButton(cmp, "Save", SWT.PUSH);	
//SelectionListener listener= new SelectionListener() {
//			
//			@Override
//			public void widgetSelected(SelectionEvent e) {
//				Widget w=e.widget;
//				if(w==add){ //第一个按钮触发事件
//					TableItem item= new TableItem(field, SWT.NONE);
//					item.setText(new String[]{"true","COLUMN_0","20","2","false","true","true"});
//					
//				}else if(w==del){//第二个按钮触发事件
//					int selectedRow=field.getSelectionIndex();
//					if(selectedRow>-1)
//						field.remove(selectedRow);
//					
//				}else if(w==sav){//第三个按钮触发事件
//					TableItem[] items=field.getItems();
//					
//					//保存文件代码。。。。。。
//				}
//				
//			}
//			
//			@Override
//			public void widgetDefaultSelected(SelectionEvent arg0) {
//				// TODO Auto-generated method stub
//				
//			}
//		};
//		add.addSelectionListener(listener);
//		del.addSelectionListener(listener);
//		sav.addSelectionListener(listener);
		

	}
	
	@Override
	public void commit(boolean arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void initialize(IManagedForm form) {
		// TODO Auto-generated method stub
		this.mform=form;
	}

	@Override
	public boolean isDirty() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isStale() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void refresh() {
		// TODO Auto-generated method stub
		update();
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean setFormInput(Object arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	//当master区域选中事件发生时
	public void selectionChanged(IFormPart part, ISelection seletion) {

		//首先获得选中的对象
		IStructuredSelection currentSelection=(IStructuredSelection)seletion;
		if(currentSelection.size()==1){
			entityMetaData=(EntityMetaData)currentSelection.getFirstElement();
		}
		if(entityMetaData!=null)
			update();
		
			
	}

	private void update() {
		name.setText(entityMetaData.getEntityName());
		description.setText(entityMetaData.getDescription());
		class_.setText(entityMetaData.getEntityClass());
		table.setText(entityMetaData.getTable());
		idGenType.setText(entityMetaData.getIdGenType());
		idClass.setText(entityMetaData.getIdClass());
	//	tableViewer.setInput(entityMetaData.getFieldList());
	}



} 

 [code="java"][/code]

 

 

好不容易做好的,不要了,删了可惜,在这备份一下吧

你可能感兴趣的:(备份)