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

📄 newhbmfilesconfigwizardpage.java

📁 eclipse的hibernate插件,支持eclipse2.*版本
💻 JAVA
字号:
/* * Created on 2003-8-21 * * To change the template for this generated file go to * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments */package com.tanghan.plugin.dbviews.wizard;import java.sql.Types;import java.util.ArrayList;import java.util.List;import java.util.ResourceBundle;import org.apache.commons.lang.StringUtils;import org.apache.log4j.Logger;import org.eclipse.core.runtime.IStatus;import org.eclipse.jdt.ui.wizards.NewTypeWizardPage;import org.eclipse.jface.util.Assert;import org.eclipse.swt.SWT;import org.eclipse.swt.events.ModifyEvent;import org.eclipse.swt.events.ModifyListener;import org.eclipse.swt.events.SelectionAdapter;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.Combo;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Text;import com.tanghan.db.Field;import com.tanghan.db.Table;import com.tanghan.plugin.TanghanPlugin;import com.tanghan.util.DealString;import com.tanghan.util.Log;/** * @author jerry * * To change the template for this generated type comment go to * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments */public class NewHBMFilesConfigWizardPage extends NewTypeWizardPage {		final static String DATE_TYPE="date"; //$NON-NLS-1$	final static String LONG_TYPE="long"; //$NON-NLS-1$	final static String STRING_TYPE="string"; //$NON-NLS-1$	final static String TIMESTAMP_TYPE="timestamp"; //$NON-NLS-1$		private static Logger log = Log.getInstanse().getLogger(NewHBMFilesConfigWizardPage.class);		private static ResourceBundle res =		TanghanPlugin.getDefault().getResourceBundle();	private static final String HBM_FILE_EXT = ".hbm.xml"; //$NON-NLS-1$	private Table table;	private Field keyFld = null;	private Combo seCombo = null;		private Combo kfcCombo = null;	private  HBMConfigData configData = null;	private List pksColumns = null;		private Text hbmFileTxt ;	final static String[] hibernateKeyTypes = new String[] {DATE_TYPE, LONG_TYPE,  STRING_TYPE, TIMESTAMP_TYPE};		/**	 * @param name	 */	public NewHBMFilesConfigWizardPage( final Table table,final HBMConfigData configData) {		super(true, res.getString("Tanghan.Plugin.Hibernate.Wizard.HBM.New")); //$NON-NLS-1$		Assert.isNotNull(table, res.getString("Tanghan.Plugin.Hibernate.Wizard.Table.Null")); //$NON-NLS-1$		this.table = table;		this.configData = configData;		initColumns();	}	private void initColumns(){		pksColumns = new ArrayList();		for(int i = 0;i<configData.getTable().getFieldList().size();i++){			Field fd = (Field) (configData.getTable().getFieldList().get(i));			if(fd.isPrimaryKey()){				pksColumns.add(fd);			}		}	}	/* (non-Javadoc)	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)	 */	public void createControl(Composite parent) {		Composite composite= new Composite(parent, SWT.NONE);				int nColumns= 4;		GridLayout layout= new GridLayout();		layout.numColumns= nColumns;				composite.setLayout(layout);						createContainerControls(composite, nColumns);			createPackageControls(composite, nColumns);							createSeparator(composite, nColumns);				createTypeNameControls(composite, nColumns);				createSuperClassControls(composite, nColumns);		setSuperClass(configData.getSuperClass(),true);				//createSuperInterfacesControls(composite, nColumns);		//this.createI		//this.getS		createMySelf(composite,nColumns);				setTypeName(StringUtils.capitalise(table.getTableName()),true);		configData.setClassName(StringUtils.capitalise(table.getTableName()));				setControl(composite);					}	private void createMySelf(Composite composite,int nColumns){		Text tableNameTxt = this.addTextLine(composite, res.getString("Tanghan.Plugin.Hibernate.Wizard.Table.Name"), 200, nColumns); //$NON-NLS-1$		hbmFileTxt =			this.addTextLine(composite, res.getString("Tanghan.Plugin.Hibernate.Wizard.Mapping.File.Name"), 200, nColumns); //$NON-NLS-1$					tableNameTxt.setText(table.getTableName());		tableNameTxt.setEditable(false);		//hbmFileTxt.setText(changetoHBMFileName(table.getTableName()));		//configData.setMappingFileName(StringUtils.capitalise(table.getTableName())+HBM_FILE_EXT);		//hbmFileTxt.setText(configData.getMappingFileName());								hbmFileTxt.setEditable(false);		List fldsList = table.getFieldList();		for (int i = 0; i < fldsList.size(); i++) {			Field fld = (Field) fldsList.get(i);			if (fld.isPrimaryKey()) {				keyFld = fld;				break;			}		}		if(this.pksColumns.size()==1){			final Text keyFieldTxt =				this.addTextLine(composite, res.getString("Tanghan.Plugin.Hibernate.Wizard.Key.Field.Name"), 200, nColumns); //$NON-NLS-1$			keyFieldTxt.setEditable(false);			if (keyFld != null) {				keyFieldTxt.setText(keyFld.getFieldName());			} else {				keyFieldTxt.setText("id"); //$NON-NLS-1$			}			keyFieldTxt.addModifyListener(new ModifyListener(){				public void modifyText(ModifyEvent e){					keyFieldChanged(keyFieldTxt);				}			});			createCombos(composite, nColumns);		}	}	protected void keyFieldChanged(final Text keyFieldTxt){		configData.setKeyFieldName(keyFieldTxt.getText());		log.debug("Key Field Name: "+configData.getKeyFieldName()); //$NON-NLS-1$	}		protected void createCombos(Composite composite, int span) {		(new Label(composite, SWT.RIGHT)).setText(res.getString("Tanghan.Plugin.Hibernate.Wizard.Schema.Export")); //$NON-NLS-1$		seCombo = new Combo(composite, SWT.NORMAL | SWT.DROP_DOWN);		GridData gridData = new GridData();		if (span > 0) {			gridData.verticalAlignment = GridData.FILL;			gridData.horizontalSpan = span - 1;		}		seCombo.setLayoutData(gridData);		seCombo.setItems(			new String[] {				"uuid.hex", //$NON-NLS-1$				"uuid.string", //$NON-NLS-1$				"vm.long", //$NON-NLS-1$				"vm.hex", //$NON-NLS-1$				"assigned", //$NON-NLS-1$				"native", //$NON-NLS-1$				"sequence", //$NON-NLS-1$				"hilo.long", //$NON-NLS-1$				"hilo.hex", //$NON-NLS-1$				"seqhilo.long",				"identity" }); //$NON-NLS-1$								(new Label(composite, SWT.RIGHT)).setText(res.getString("Tanghan.Plugin.Hibernate.Wizard.Key.Field.Class")); //$NON-NLS-1$		kfcCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN);		gridData = new GridData();		if (span > 0) {			gridData.verticalAlignment = GridData.FILL;			gridData.horizontalSpan = span - 1;		}		kfcCombo.setLayoutData(gridData);		kfcCombo.setItems(hibernateKeyTypes);		//seCombo.addM		seCombo.addSelectionListener(new SelectionAdapter() {			public void widgetSelected(SelectionEvent e) {				int select = seCombo.getSelectionIndex();				if (select > -1) {					String gName = (String) seCombo.getItem(select);					configData.setSchemaExport(gName);					log.debug("Schema Export : "+configData.getSchemaExport()); //$NON-NLS-1$					//String gName = (String)kfcCombo.get;					if (						gName.equals("vm.long") || //$NON-NLS-1$						gName.equals("native") || //$NON-NLS-1$						gName.equals("sequence") || //$NON-NLS-1$						gName.equals("hilo.long") || //$NON-NLS-1$						gName.equals("identity") || //$NON-NLS-1$						gName.equals("seqhilo.long") //$NON-NLS-1$										) {						kfcCombo.setText(LONG_TYPE);						configData.setKeyFieldClass(LONG_TYPE);					}					else if (						gName.equals("uuid.hex") || //$NON-NLS-1$						gName.equals("uuid.string") || //$NON-NLS-1$						gName.equals("vm.hex") || //$NON-NLS-1$						gName.equals("hilo.hex") //$NON-NLS-1$					) {						kfcCombo.setText(STRING_TYPE);						configData.setKeyFieldClass(STRING_TYPE);					}				}					}		});		kfcCombo.addSelectionListener(new SelectionAdapter() {			public void widgetSelected(SelectionEvent e) {				int select = seCombo.getSelectionIndex();				if (select > -1) {					String gName = (String) kfcCombo.getItem(select);					configData.setKeyFieldClass(gName);					log.debug("Key Field Class : "+configData.getKeyFieldClass()); //$NON-NLS-1$				}					}		});		if (keyFld != null) {			if (keyFld.getFieldType() == Types.BIGINT				|| keyFld.getFieldType() == Types.INTEGER				|| keyFld.getFieldType() == Types.NUMERIC) {					seCombo.setText("hilo.long"); //$NON-NLS-1$					configData.setSchemaExport("hilo.long"); //$NON-NLS-1$					kfcCombo.setText(LONG_TYPE);					configData.setKeyFieldClass(LONG_TYPE);			} else {				seCombo.setText("uuid.string"); //$NON-NLS-1$				configData.setSchemaExport("uuid.string"); //$NON-NLS-1$				kfcCombo.setText(STRING_TYPE);				configData.setKeyFieldClass(STRING_TYPE);			}		}	}		/**添加输入行*/	protected Text addTextLine(Composite composite,String lableText,int textSize,int span){		Label label = new Label(composite, SWT.RIGHT);		label.setText(lableText);		Text text = new Text(composite, SWT.BORDER);		GridData gridData = new GridData();		if(span>0){			gridData.verticalAlignment = GridData.FILL;			gridData.horizontalSpan = span-1;		}		gridData.widthHint = textSize;		text.setLayoutData(gridData);		return text;	}	/**添加带Button的输入行*/	protected Text addTextFileButtonLine(final Composite composite,String lableText,int textSize,int span,String txt,SelectionListener listener){		Assert.isTrue(span>1);		Label label = new Label(composite, SWT.RIGHT);		label.setText(lableText);		final Text text = new Text(composite, SWT.BORDER);		GridData gridData = new GridData();		if(span>1){			gridData.horizontalAlignment = GridData.FILL;			gridData.horizontalSpan = span-1;		}		gridData.widthHint = textSize;		text.setLayoutData(gridData);		Button bButton = new Button(composite, SWT.CENTER|SWT.PUSH);		bButton.setText(txt);		gridData = new GridData();		gridData.horizontalAlignment = GridData.FILL;		bButton.setLayoutData(gridData);		bButton.addSelectionListener(listener);				return text;	}		/* (非 Javadoc)	 * @see org.eclipse.jdt.ui.wizards.NewContainerWizardPage#containerChanged()	 */	protected IStatus containerChanged() {		IStatus is = super.containerChanged(); 		configData.setPackageRoot(getPackageFragmentRoot());		configData.setFile(this.getWorkspaceRoot().findMember(getPackageFragmentRoot().getPath()).getLocation().toFile());		if(configData.getPackageRoot()==null){			this.setPageComplete(false);		}else{			this.setPageComplete(true);		}		log.debug(configData.getPackageRoot().getJavaProject().getProject().getLocation().toFile().toString());		return is;	}	/* (非 Javadoc)	 * @see org.eclipse.jface.wizard.IWizardPage#isPageComplete()	 */	public boolean isPageComplete() {		if(!super.isPageComplete())			return false;		if(configData.getPackageRoot()==null){			return false;		}		if(DealString.equals(configData.getClassName(),"")){ //$NON-NLS-1$			return false;		}		return true;	}	/* (非 Javadoc)	 * @see org.eclipse.jdt.ui.wizards.NewTypeWizardPage#typeNameChanged()	 */	protected IStatus typeNameChanged() {		IStatus is = super.typeNameChanged(); 		configData.setClassName(getTypeName());		configData.setMappingFileName(StringUtils.capitalise(configData.getClassName())+HBM_FILE_EXT);		hbmFileTxt.setText(configData.getMappingFileName());		if(DealString.equals(configData.getClassName(),"")){ //$NON-NLS-1$			this.setPageComplete(false);		}else{			this.setPageComplete(true);		}		return is;	}	/* (非 Javadoc)	 * @see org.eclipse.jdt.ui.wizards.NewTypeWizardPage#packageChanged()	 */	protected IStatus packageChanged() {		IStatus is = super.packageChanged(); 		configData.setPackageName(getPackageText());		log.debug("Package:"+getPackageText()); //$NON-NLS-1$		return is;	}	/* (非 Javadoc)	 * @see org.eclipse.jdt.ui.wizards.NewTypeWizardPage#superClassChanged()	 */	protected IStatus superClassChanged() {		IStatus is = super.superClassChanged(); 		configData.setSuperClass(getSuperClass());		log.debug("Super Class:"+getSuperClass()); //$NON-NLS-1$		return is;	}	/* (非 Javadoc)	 * @see org.eclipse.jdt.ui.wizards.NewTypeWizardPage#superInterfacesChanged()	 */	protected IStatus superInterfacesChanged() {		IStatus is = super.superInterfacesChanged();		configData.setSuperInterfaces(getSuperInterfaces());		return is;	}}

⌨️ 快捷键说明

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