📄 makeassociationswizardpage.java
字号:
package net.sf.pim.contract.wizard;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
import net.sf.pim.contract.Contract;
import net.sf.util.StringUtil;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
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.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
public class MakeAssociationsWizardPage extends WizardPage {
private Map<String,CCombo> uiMap;
public MakeAssociationsWizardPage(String pageName) {
super(pageName);
setTitle("设定关联");
setDescription("设置要导入的字段对应关系");
}
public void createControl(Composite parent) {
Composite composite=new Composite(parent,SWT.NULL);
GridLayout gl=new GridLayout();
gl.numColumns=2;
composite.setLayout(gl);
GridData gd=new GridData();
gd.grabExcessHorizontalSpace=true;
gd.minimumWidth=120;
Contract contract = new Contract();
String[] fieldDescs=contract.getFieldDescs();
final String[] fieldNames=contract.getFieldNames();
uiMap=new HashMap<String, CCombo>();
final Map<String,Integer> map=((CSVWizard)this.getWizard()).getAssociations();
for(int i=0;i<fieldNames.length;i++){
Label label=new Label(composite,SWT.NULL);
label.setText(fieldDescs[i]);
final CCombo combo = new CCombo(composite,SWT.FLAT|SWT.READ_ONLY);
combo.setLayoutData(gd);
combo.setData(i);
combo.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
combo.addSelectionListener(new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
map.put(fieldNames[(Integer) combo.getData()],combo.getSelectionIndex());
}
});
uiMap.put(fieldNames[i], combo);
}
setControl(composite);
}
//取csv的第一行作为元数据,不考虑字段中含逗号
private String[] getCSVFieldNames(){
String[] ss=new String[0];
String fileName=((CSVWizard)this.getWizard()).getFileName();
if(fileName ==null || fileName.length() == 0)
return ss;
try {
BufferedReader br=new BufferedReader(new FileReader(fileName));
ss=StringUtil.toArray(br.readLine());
br.close();
} catch (Exception e) {
e.printStackTrace();
}
return ss;
}
public void onEnterPage(){
String[] csvHeaders=getCSVFieldNames();
for(CCombo combo:uiMap.values()){
combo.setItems(csvHeaders);
combo.add("", 0);
combo.setVisibleItemCount(csvHeaders.length+1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -