📄 generatehbmfiledialog.java
字号:
/* * 创建日期 2003-8-10 * * 更改所生成文件模板为 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释 */package com.tanghan.plugin.dbviews.dialog.hibernate;import java.sql.Types;import java.util.List;import java.util.ResourceBundle;import org.apache.log4j.Logger;import org.eclipse.jface.util.Assert;import org.eclipse.swt.SWT;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Combo;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Text;import com.tanghan.db.Field;import com.tanghan.db.Table;import com.tanghan.plugin.TanghanPlugin;import com.tanghan.plugin.dbviews.dialog.TanghanAbstractDialog;import com.tanghan.util.DealString;import com.tanghan.util.Log;/** * @author Jerry Tang * @version v0.1.0 * @copyright (C) 2003 Tanghan Studio * */public class GenerateHBMFileDiaLog extends TanghanAbstractDialog { final static String DATE_TYPE="date"; final static String LONG_TYPE="long"; final static String STRING_TYPE="string"; final static String TIMESTAMP_TYPE="timestamp"; private static Logger log = Log.getInstanse().getLogger(GenerateHBMFileDiaLog.class); private static ResourceBundle res = TanghanPlugin.getDefault().getResourceBundle(); private static final String HBM_FILE_EXT = ".hbm.xml"; private Table table; private Field keyFld = null; private Combo seCombo = null; private Combo kfcCombo = null; final static String[] hibernateKeyTypes = new String[] {DATE_TYPE, LONG_TYPE, STRING_TYPE, TIMESTAMP_TYPE}; /** * @param parentShell */ public GenerateHBMFileDiaLog(Shell parentShell, final Table table) { super(parentShell); Assert.isNotNull(table, "Table is null!"); this.table = table; } /* (非 Javadoc) * @see org.eclipse.jface.dialogs.IconAndMessageDialog#getImage() */ protected Image getImage() { return null; } /* (非 Javadoc) * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { super.okPressed(); } /* (非 Javadoc) * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ protected Control createDialogArea(Composite parent) { this.getShell().setText("Hibernate Config File"); this.getShell().setMaximized(false); this.getShell().setMinimized(false); // create the top level composite for the dialog area Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 5; layout.marginWidth = 5; layout.numColumns = 3; composite.setLayout(layout); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 3; composite.setLayoutData(data); Text tableNameTxt = this.addTextLine(composite, "Table Name", 200, 3); tableNameTxt.setText(table.getTableName()); tableNameTxt.setEditable(false); Text hbmFileTxt = this.addTextLine(composite, "Mapping File Name", 200, 3); hbmFileTxt.setText(changetoHBMFileName(table.getTableName())); 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; } } Text keyFieldTxt = this.addTextLine(composite, "Key Field Name", 200, 3); if (keyFld != null) { keyFieldTxt.setText(keyFld.getFieldName()); } else { keyFieldTxt.setText("id"); } createCombos(composite, 3); Text packageTxt = this.addTextLine(composite, "Package Name", 200, 3); Text baseClassTxt = this.addTextLine(composite, "Base Class Name", 200, 3); Text projectTxt = this.addTextLine(composite, "Project Name", 200, 3); return super.createDialogArea(parent); } protected void createCombos(Composite composite, int span) { (new Label(composite, SWT.RIGHT)).setText("Schema Export"); 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", "uuid.string", "vm.long", "vm.hex", "assigned", "native", "sequence", "hilo.long", "hilo.hex", "seqhilo.long" }); seCombo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int select = seCombo.getSelectionIndex(); if (select > -1) { String gName = (String) seCombo.getItem(select); //String gName = (String)kfcCombo.get; if ( gName.equals("vm.long") || gName.equals("native") || gName.equals("sequence") || gName.equals("hilo.long") || gName.equals("seqhilo.long") ) { kfcCombo.setText(LONG_TYPE); } else if ( gName.equals("uuid.hex") || gName.equals("uuid.string") || gName.equals("vm.hex") || gName.equals("hilo.hex") ) { kfcCombo.setText(STRING_TYPE); } } } }); (new Label(composite, SWT.RIGHT)).setText("Key Field Class"); 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); if (keyFld != null) { if (keyFld.getFieldType() == Types.BIGINT || keyFld.getFieldType() == Types.INTEGER || keyFld.getFieldType() == Types.NUMERIC) { seCombo.setText("hilo.long"); kfcCombo.setText(LONG_TYPE); } else { seCombo.setText("uuid.string"); kfcCombo.setText(STRING_TYPE); } } } /**把表名称转换为Hibernate配置文件的名称*/ private String changetoHBMFileName(String tableName) { String tn = DealString.trim(tableName); if (tn.length() < 2) { return ""; } String firstCh = tn.substring(0, 2).toUpperCase(); String lastChs = ""; if (tn.indexOf("_") > 1) { lastChs = tn.substring(1, tn.indexOf("_")); } //String. return firstCh + lastChs + "Bean" + HBM_FILE_EXT; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -