📄 teachunitdata.java
字号:
/*
*编写者:陈冈
*高校经费测算系统--教学单位基本情况视图
*编写时间:2006-11-16
*/
package cn.edu.jfcs.ui;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.internal.databinding.provisional.DataBindingContext;
import org.eclipse.jface.internal.databinding.provisional.description.Property;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
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.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.hibernate.CacheMode;
import org.hibernate.Query;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.Transaction;
import cn.edu.jfcs.actions.YearAction;
import cn.edu.jfcs.model.YearTeachUnit;
import cn.edu.jfcs.sys.CuryearPropertyChange;
import cn.edu.jfcs.sys.DataBindingFactory;
import cn.edu.jfcs.sys.GetGridData;
import cn.edu.jfcs.sys.HibernateSessionFactory;
import cn.edu.jfcs.sys.IAppConstants;
import cn.edu.jfcs.sys.IImageKey;
import cn.edu.jfcs.sys.SetControlEnabled;
import cn.edu.jfcs.sys.SetTableColColorListener;
import cn.edu.jfcs.sys.SetTextEnabled;
import cn.edu.jfcs.sys.YearCombo;
import cn.edu.jfcs.sys.YearManager;
public class TeachUnitData extends ViewPart implements IPropertyChangeListener {
private TableViewer tableViewer;
private Text jfys;// 应收金额
private Text jfss;// 实收金额
private Text ta1;// 教授A人数
private Text ta2;// 教授B人数
private Text ta3;// 教授C人数
private Text ta4;// 教授D人数
private Text ta5;// 副教授A人数
private Text ta6;// 副教授B人数
private Text ta7;// 讲师人数
private Text ta8; // 助教人数
private YearTeachUnit yearTeachUnit;
// 是否进入编辑状态
public static boolean canEdit = false;
// 表格的列名,同时也作为编辑器的属性名
public static final String UNITNAME = "unitname";// 教学单位名称
public static final String SSB = "ssb"; // 生师比
public static final String JXYWPER = "jxywper"; // 教学业务费比率
public static final String JXGLPER = "jxglper";// 教学管理费比率
public static final String JXYJPER = "jxyjper";// 教学研究费比率
public static final String SZPYPER = "szpyper";// 师资培养费比率
// 作为tableViewer的ColumnProperties属性,列的别名
public static final String[] PROPERTIES = { UNITNAME, SSB, JXYWPER,
JXGLPER, JXYJPER, SZPYPER };
private Action saveDataAction, editDataAction;
private Group group;
private List<YearTeachUnit> list = new ArrayList<YearTeachUnit>();
public TeachUnitData() {
}
public void createPartControl(Composite parent) {
createContents(parent);
createToolbarButtons();
getCurrentRowData((IStructuredSelection) tableViewer.getSelection());
bindData(parent);
// 注册属性监听器,以便监听curYear数值发生改变时刷新视图
CuryearPropertyChange.getInstance().addPropertyChangeListener(
IAppConstants.TEACH_UNIT_DATA_VIEW_ID, this);
}
private void createContents(Composite parent) {
setPartName(getConfigurationElement().getAttribute("name") + "---"
+ YearManager.getInstance().getCurYear() + "年");
Composite contanier = new Composite(parent, SWT.NONE);
final GridLayout gl = new GridLayout(1, false);
contanier.setLayout(gl);
createTableViewer(contanier);
createTextGroup(contanier);
}
// 创建TableViewer内容
private void createTableViewer(Composite parent) {
tableViewer = new TableViewer(parent, SWT.BORDER | SWT.H_SCROLL
| SWT.FULL_SELECTION);
tableViewer.setUseHashlookup(true);
final Table table = tableViewer.getTable();
table.setToolTipText("注意:数据输入完毕请敲回车键,否则该数据不予保存!");
table.setLayoutData(new GridData(GridData.FILL_BOTH));
// 添加列名称
final TableColumn unitnameColumn = new TableColumn(table, SWT.CENTER);
unitnameColumn.setText("教学单位");
unitnameColumn.setWidth(146);
final TableColumn zykperColumn = new TableColumn(table, SWT.CENTER);
zykperColumn.setText("生师比");
zykperColumn.setWidth(52);
final TableColumn jxywperColumn = new TableColumn(table, SWT.CENTER);
jxywperColumn.setText("教学业务费率");
jxywperColumn.setWidth(90);
final TableColumn jxglperColumn = new TableColumn(table, SWT.CENTER);
jxglperColumn.setText("教学管理费率");
jxglperColumn.setWidth(90);
final TableColumn jxyjperColumn = new TableColumn(table, SWT.CENTER);
jxyjperColumn.setText("教学研究费率");
jxyjperColumn.setWidth(90);
final TableColumn szpyperColumn = new TableColumn(table, SWT.CENTER);
szpyperColumn.setText("师资培养费率");
szpyperColumn.setWidth(90);
table.setHeaderVisible(true);
table.setLinesVisible(true);
// 设置内容器和标签容器
tableViewer.setContentProvider(new TeachUnitDataContentProvider());
tableViewer.setLabelProvider(new TeachUnitDataLabelProvider());
list = getData(YearManager.getInstance().getCurYear());
tableViewer.setInput(list);
// 设置表格行移动时的背景颜色
table.addListener(SWT.EraseItem, new SetTableColColorListener(table));
// 表格记录行变化时刷新group基本数据中的内容
tableViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event
.getSelection();
getCurrentRowData(selection);
// 数据绑定
bindData(getViewSite().getShell());
}
});
// 创建编辑器,第1列为空,不允许修改
final CellEditor[] editors = new CellEditor[6];
editors[1] = new TextCellEditor(table);
editors[2] = new TextCellEditor(table);
editors[3] = new TextCellEditor(table);
editors[4] = new TextCellEditor(table);
editors[5] = new TextCellEditor(table);
tableViewer.setColumnProperties(PROPERTIES);
tableViewer.setCellModifier(new TeachUnitDataCellModifier(tableViewer));
tableViewer.setCellEditors(editors);
// 滚动到顶端
table.select(0);
table.setFocus();
}
// 获得TableViewer的输入数据
private static List<YearTeachUnit> getData(int year) {
List<YearTeachUnit> list = new ArrayList<YearTeachUnit>();
Session session = HibernateSessionFactory
.getSession("hibernate_derby.cfg.xml");
Query query = session
.getNamedQuery("cn.edu.jfcs.ui.TeachUnitData.getTeachUnitData");
query.setInteger(0, year);
ScrollableResults result = query.setCacheMode(CacheMode.IGNORE).scroll(
ScrollMode.FORWARD_ONLY);
while (result.next()) {
YearTeachUnit ytu = (YearTeachUnit) result.get(0);
list.add(ytu);
}
HibernateSessionFactory.closeSession();
return list;
}
// 创建基本数据文本框
private void createTextGroup(Composite parent) {
Color foreColor = new Color(Display.getCurrent(), 0x00, 0x40, 0x80);
group = new Group(parent, SWT.NONE);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
group.setLayoutData(gd);
group.setText("基本数据");
group.setForeground(foreColor);
final GridLayout gridLayout_1 = new GridLayout(10, false);
group.setLayout(gridLayout_1);
// 第1行
final Label label1 = new Label(group, SWT.NONE);
label1.setText("应收金额");
label1.setAlignment(SWT.RIGHT);
label1.setLayoutData(new GetGridData().getGridData(50, 0, 0, 0, 0,
GridData.FILL_HORIZONTAL, 0));
jfys = new Text(group, SWT.BORDER | SWT.RIGHT);
jfys.setLayoutData(new GetGridData().getGridData(60, 0, 0, 0, 0,
GridData.FILL_HORIZONTAL, 0));
final Label label2 = new Label(group, SWT.NONE);
label2.setText("实收金额");
label2.setAlignment(SWT.RIGHT);
label2.setLayoutData(new GetGridData().getGridData(50, 0, 0, 0, 0,
GridData.FILL_HORIZONTAL, 0));
jfss = new Text(group, SWT.BORDER | SWT.RIGHT);
jfss.setLayoutData(new GetGridData().getGridData(60, 0, 0, 0, 0,
GridData.FILL_HORIZONTAL, 0));
final Label label3 = new Label(group, SWT.NONE);
label3.setText("教授A");
label3.setAlignment(SWT.RIGHT);
label3.setLayoutData(new GetGridData().getGridData(50, 0, 0, 0, 0,
GridData.FILL_HORIZONTAL, 0));
ta1 = new Text(group, SWT.BORDER | SWT.RIGHT);
ta1.setLayoutData(new GetGridData().getGridData(35, 0, 0, 0, 0,
GridData.FILL_HORIZONTAL, 0));
final Label label4 = new Label(group, SWT.NONE);
label4.setText("教授B");
label4.setAlignment(SWT.RIGHT);
label4.setLayoutData(new GetGridData().getGridData(50, 0, 0, 0, 0,
GridData.FILL_HORIZONTAL, 0));
ta2 = new Text(group, SWT.BORDER | SWT.RIGHT);
ta2.setLayoutData(new GetGridData().getGridData(35, 0, 0, 0, 0,
GridData.FILL_HORIZONTAL, 0));
final Label label5 = new Label(group, SWT.NONE);
label5.setText("教授C");
label5.setAlignment(SWT.RIGHT);
label5.setLayoutData(new GetGridData().getGridData(50, 0, 0, 0, 0,
GridData.FILL_HORIZONTAL, 0));
ta3 = new Text(group, SWT.BORDER | SWT.RIGHT);
ta3.setLayoutData(new GetGridData().getGridData(35, 0, 0, 0, 0,
GridData.FILL_HORIZONTAL, 0));
// 第2行
final Label label6 = new Label(group, SWT.NONE);
label6.setText("教授D");
label6.setAlignment(SWT.RIGHT);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -