📄 memberdatadialog.java
字号:
package cn.com.likai.mms.db;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class MemberDataDialog extends Dialog{
private List selectList;
private StackLayout stackLayout = new StackLayout();
private Composite rightComp;
private Composite baseDataComp;
private Composite magnumOpusComp;
private Composite projectsComp;
private Composite encouragementComp;
private Composite commentComp;
private Member member;//界面的数据类
private Text nameText;//姓名的输入框
private Combo sexCombo;//性别的输入框
private Text provinceText;//籍贯的输入框
private Text birthdayText;//出生年月的输入框
private Text peopleText;//民族的输入框
private Text partyText;//党派的输入框
private Text professionalTitleText;//职称的输入框
private Text committeeText;//委员会的输入框
private Text degreeText;//学位的输入框
private Text educationText;//学历输入框
private Text dutyText;//职务输入框
private Text adressText;//地址输入框
private Text zipText;//邮编输入框
private Text workPlaceText;//工作单位输入框
private Text workPhoneText;//办公电话输入框
private Text homePhoneText;//住宅电话输入框
private Text emailText;//电子邮箱输入框
private Text mobilePhoneText;//手机输入框
private Text learnSpecialtyText;//所学专业输入框
private Text workSpecialtyText;//从事专业输入框
private Text workTimeText;//从事时间输入框
private Text schoolText;//毕业学校输入框
private Text workStartText;//参加工作时间
private Combo isZkyAcademicianCombo;//是否中科院院士
private Combo isGcyAcademicianCombo;//是否工程院院士
private Combo isAllowanceCombo;//是否享受政府特殊津贴
private Combo isContributeCombo;//是否突出贡献专家
private Text certificateText;//专业资格证书输入框
private Text academyDutyText;//学会职务
private Text magnumOpusText;//熟悉专业及其代表作
private Text projectsText;//近五年从事的主要研究项目
private Text encouragementText;//主要获奖情况
private Text beCompetentForText;//能胜任哪些方面工作
private Text workAttitudeText;//所在单位意见
private Text gljAttitudeText;//通信管理局意见
//构造函数
public MemberDataDialog(Shell parentShell){
super(parentShell);
}
public Member getInput(){
return this.member;
}
public void setInput(Member member){
this.member = member;
}
//改变对话框的式样
//改写父类Dialog的getShellStyle方法可以改变窗口的默认式样
protected int getShellStyle(){
//用super.getShellStyle()得到原有式样,再附加上两个新式样
return super.getShellStyle()|SWT.RESIZE|SWT.MAX;
}
//改变对话框的大小
protected Point getInitialSize(){
return new Point(850,470);
}
//改写父类创建按钮的方法使其失效.
protected Button createButton(Composite parent,int id,String label,boolean defaultButton){
return null;
}
//定义好"导出EXCEL"按钮的ID值
public static final int APPLY_ID = 101;
//改写父类的initializeBounds方法,并调用父类的createButton方法建立按钮
protected void initializeBounds(){
Composite comp = (Composite) getButtonBar();
super.createButton(comp,APPLY_ID,"导出EXCEL", true);
super.createButton(comp, IDialogConstants.OK_ID, "确定", false);
super.createButton(comp, IDialogConstants.CANCEL_ID, "取消", false);
super.initializeBounds();
}
//在这个方法里面构建Dialog中的界面内容
protected Control createDialogArea(Composite parent){
Composite topComp = new Composite(parent,SWT.NONE);
topComp.setLayoutData(new GridData(GridData.FILL_BOTH));
//---------------分割窗口--------------------------
SashForm sashForm = new SashForm(topComp,SWT.NONE);
sashForm.setBounds(10, 10, 820, 370);
//分割窗左边的列表
selectList = new List(sashForm,SWT.BORDER);
selectList.setItems(new String[]{"基本信息","熟悉专业及代表作","近五年从事的主要研究项目","主要获奖情况","评定"});
//加选择监听器
selectList.addSelectionListener(new MySelectionListener());
//右边的堆栈式容器
rightComp = new Composite(sashForm,SWT.NONE);
rightComp.setLayout(stackLayout);
//生成面板的代码,自定义方法
baseDataComp = createBaseDataComp(rightComp);
magnumOpusComp = createMagnumOpusComp(rightComp);
projectsComp = createProjectsComp(rightComp);
encouragementComp = createEncouragementComp(rightComp);
commentComp = createCommentComp(rightComp);
//在堆栈布局上先显示"基本信息"面板
stackLayout.topControl = baseDataComp;
//分割窗口的左右空间比例
sashForm.setWeights(new int[]{2,6});
//取出数据类给界面做初始化
if(member != null){
nameText.setText(member.getName()==null?"":member.getName());
sexCombo.select(member.getSex()?0:1);
if(member.getBirthday() == null)
birthdayText.setText("");
else
birthdayText.setText(dateToString(member.getBirthday()));
provinceText.setText(member.getProvince()==null?"":member.getProvince());
peopleText.setText(member.getPeople()==null?"":member.getPeople());
partyText.setText(member.getParty()==null?"":member.getParty());
professionalTitleText.setText(member.getProfessionalTitle()==null?"":member.getProfessionalTitle());
degreeText.setText(member.getDegree()==null?"":member.getDegree());
educationText.setText(member.getEducation()==null?"":member.getEducation());
dutyText.setText(member.getDuty()==null?"":member.getDuty());
adressText.setText(member.getAdress()==null?"":member.getAdress());
zipText.setText(member.getZip()==null?"":member.getZip());
workPlaceText.setText(member.getWorkPlace()==null?"":member.getWorkPlace());
workPhoneText.setText(member.getWorkPhone()==null?"":member.getWorkPhone());
homePhoneText.setText(member.getHomePhone()==null?"":member.getHomePhone());
emailText.setText(member.getEmail()==null?"":member.getEmail());
mobilePhoneText.setText(member.getMobilePhone()==null?"":member.getMobilePhone());
learnSpecialtyText.setText(member.getLearnSpecialty()==null?"":member.getLearnSpecialty());
workSpecialtyText.setText(member.getWorkSpecialty()==null?"":member.getWorkSpecialty());
schoolText.setText(member.getSchool()==null?"":member.getSchool());
if(member.getWorkStart() == null)
workStartText.setText("");
else
workStartText.setText(dateToString(member.getWorkStart()));
isZkyAcademicianCombo.select(member.getIsZkyAcademician()?0:1);
isGcyAcademicianCombo.select(member.getIsGcyAcademician()?0:1);
isAllowanceCombo.select(member.getIsAllowance()?0:1);
isContributeCombo.select(member.getIsContribute()?0:1);
certificateText.setText(member.getCertificate()==null?"":member.getCertificate());
academyDutyText.setText(member.getAcademyDuty()==null?"":member.getAcademyDuty());
committeeText.setText(member.getCommittee()==null?"":member.getCommittee());
magnumOpusText.setText(member.getMagnumOpus()==null?"":member.getMagnumOpus());
projectsText.setText(member.getProjects()==null?"":member.getProjects());
encouragementText.setText(member.getEncouragement()==null?"":member.getEncouragement());
beCompetentForText.setText(member.getBeCompetentFor()==null?"":member.getBeCompetentFor());
workAttitudeText.setText(member.getWorkAttitude()==null?"":member.getWorkAttitude());
gljAttitudeText.setText(member.getGljAttitude()==null?"":member.getGljAttitude());
workTimeText.setText(member.getWorkTime()==null?"":member.getWorkTime());
}
return topComp;
}
/**
* 自定义的生成GridData对象
* 参数:style:对齐充满方式
* horizontalSpan:所占列数
*/
private GridData createGridData(int style,int horizontalSpan){
GridData gridData = new GridData(style);
gridData.horizontalSpan = horizontalSpan;
return gridData;
}
/**
* 自定义的生成GridData对象
* 参数:width对象的宽度
*/
private GridData createGridData(int width){
GridData gridData = new GridData();
gridData.widthHint = width;
return gridData;
}
/**
* 自定义生成不可见的占位标签
* 参数:parent在哪个容器中生成
* num生成标签的个数
*/
private void createOccupation(Composite parent,int num){
for(int i=1;i<=num;i++){
new Label(parent,SWT.NONE).setVisible(false);
}
}
/**
* 选择监听器,采用事件的命名内部类的写法
*/
private class MySelectionListener extends SelectionAdapter{
public void widgetSelected(SelectionEvent e){
//得到列表被选项的序号,然后再判断显示哪个面板
switch(selectList.getSelectionIndex()){
case 0:
stackLayout.topControl = baseDataComp;
break;
case 1:
stackLayout.topControl = magnumOpusComp;
break;
case 2:
stackLayout.topControl = projectsComp;
break;
case 3:
stackLayout.topControl = encouragementComp;
break;
case 4:
stackLayout.topControl = commentComp;
break;
default: break;
}
rightComp.layout();
}
}
/**
* "基本信息"面板的生成方法
*/
private Composite createBaseDataComp(Composite rightComp){
Composite topComp = new Composite(rightComp,SWT.NONE);
topComp.setLayout(new RowLayout());
Group baseDataGroup = new Group(topComp,SWT.NONE);
baseDataGroup.setLayout(new GridLayout(8,false));
baseDataGroup.setText("基本信息");
baseDataGroup.setLayoutData(new RowData(600,225));
//姓名
new Label(baseDataGroup,SWT.NONE).setText("姓 名");
nameText = new Text(baseDataGroup,SWT.BORDER);
//性别
new Label(baseDataGroup,SWT.NONE).setText("性别");
sexCombo = new Combo(baseDataGroup,SWT.BORDER);
sexCombo.add("男 ");
sexCombo.add("女 ");
sexCombo.select(0);
//籍贯
new Label(baseDataGroup,SWT.NONE).setText("籍 贯");
provinceText = new Text(baseDataGroup,SWT.BORDER);
provinceText.setLayoutData(createGridData(150));
//出生年月
new Label(baseDataGroup,SWT.NONE).setText("出生年月");
birthdayText = new Text(baseDataGroup,SWT.BORDER);
birthdayText.setText("0000-00-00");
//民族
new Label(baseDataGroup,SWT.NONE).setText("民 族");
peopleText = new Text(baseDataGroup,SWT.BORDER);
//党派
new Label(baseDataGroup,SWT.NONE).setText("党派");
partyText = new Text(baseDataGroup,SWT.BORDER);
//职称
new Label(baseDataGroup,SWT.NONE).setText("职 称");
professionalTitleText = new Text(baseDataGroup,SWT.BORDER);
professionalTitleText.setLayoutData(createGridData(100));
//委员会
new Label(baseDataGroup,SWT.NONE).setText("委员会");
committeeText = new Text(baseDataGroup,SWT.BORDER);
//学位
new Label(baseDataGroup,SWT.NONE).setText("学 位");
degreeText = new Text(baseDataGroup,SWT.BORDER);
//学历
new Label(baseDataGroup,SWT.NONE).setText("学历");
educationText = new Text(baseDataGroup,SWT.BORDER);
//职务
new Label(baseDataGroup,SWT.NONE).setText("职 务");
dutyText = new Text(baseDataGroup,SWT.BORDER);
dutyText.setLayoutData(createGridData(150));
//设置两个占位的标签
createOccupation(baseDataGroup,2);
//通信地址
new Label(baseDataGroup,SWT.NONE).setText("通信地址");
adressText = new Text(baseDataGroup,SWT.BORDER);
adressText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,5));
//邮编
new Label(baseDataGroup,SWT.NONE).setText("邮编");
zipText = new Text(baseDataGroup,SWT.BORDER);
//工作单位
new Label(baseDataGroup,SWT.NONE).setText("工作单位");
workPlaceText = new Text(baseDataGroup,SWT.BORDER);
workPlaceText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,5));
//两个占位标签
createOccupation(baseDataGroup,2);
//办公电话
new Label(baseDataGroup,SWT.NONE).setText("办公电话");
workPhoneText = new Text(baseDataGroup,SWT.BORDER);
workPhoneText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
//住宅电话
new Label(baseDataGroup,SWT.NONE).setText("住宅电话");
homePhoneText = new Text(baseDataGroup,SWT.BORDER);
homePhoneText.setLayoutData(createGridData(150));
//两个占位标签
createOccupation(baseDataGroup,2);
//电子邮件
new Label(baseDataGroup,SWT.NONE).setText("电子邮件");
emailText = new Text(baseDataGroup,SWT.BORDER);
emailText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
//手机
new Label(baseDataGroup,SWT.NONE).setText("手 机");
mobilePhoneText = new Text(baseDataGroup,SWT.BORDER);
mobilePhoneText.setLayoutData(createGridData(150));
//两个占位标签
createOccupation(baseDataGroup,2);
//所学专业
new Label(baseDataGroup,SWT.NONE).setText("所学专业");
learnSpecialtyText = new Text(baseDataGroup,SWT.BORDER);
learnSpecialtyText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
//现从事专业
new Label(baseDataGroup,SWT.NONE).setText("从事专业");
workSpecialtyText = new Text(baseDataGroup,SWT.BORDER);
workSpecialtyText.setLayoutData(createGridData(150));
//从事专业时间
new Label(baseDataGroup,SWT.NONE).setText("从事时间");
workTimeText = new Text(baseDataGroup,SWT.BORDER);
//毕业学校
new Label(baseDataGroup,SWT.NONE).setText("毕业院校");
schoolText = new Text(baseDataGroup,SWT.BORDER);
schoolText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -