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

📄 teachunitdata.java

📁 个人珍藏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		label6.setLayoutData(new GetGridData().getGridData(50, 0, 0, 0, 0,
				GridData.FILL_HORIZONTAL, 0));
		ta4 = new Text(group, SWT.BORDER | SWT.RIGHT);
		ta4.setLayoutData(new GetGridData().getGridData(60, 0, 0, 0, 0,
				GridData.FILL_HORIZONTAL, 0));
		final Label label7 = new Label(group, SWT.NONE);
		label7.setText("副教授A");
		label7.setAlignment(SWT.RIGHT);
		label7.setLayoutData(new GetGridData().getGridData(50, 0, 0, 0, 0,
				GridData.FILL_HORIZONTAL, 0));
		ta5 = new Text(group, SWT.BORDER | SWT.RIGHT);
		ta5.setLayoutData(new GetGridData().getGridData(60, 0, 0, 0, 0,
				GridData.FILL_HORIZONTAL, 0));
		final Label label8 = new Label(group, SWT.NONE);
		label8.setText("副教授B");
		label8.setAlignment(SWT.RIGHT);
		label8.setLayoutData(new GetGridData().getGridData(50, 0, 0, 0, 0,
				GridData.FILL_HORIZONTAL, 0));
		ta6 = new Text(group, SWT.BORDER | SWT.RIGHT);
		ta6.setLayoutData(new GetGridData().getGridData(35, 0, 0, 0, 0,
				GridData.FILL_HORIZONTAL, 0));
		final Label label9 = new Label(group, SWT.NONE);
		label9.setText("讲师");
		label9.setAlignment(SWT.RIGHT);
		label9.setLayoutData(new GetGridData().getGridData(50, 0, 0, 0, 0,
				GridData.FILL_HORIZONTAL, 0));
		ta7 = new Text(group, SWT.BORDER | SWT.RIGHT);
		ta7.setLayoutData(new GetGridData().getGridData(35, 0, 0, 0, 0,
				GridData.FILL_HORIZONTAL, 0));
		final Label label10 = new Label(group, SWT.NONE);
		label10.setText("助教");
		label10.setAlignment(SWT.RIGHT);
		label10.setLayoutData(new GetGridData().getGridData(50, 0, 0, 0, 0,
				GridData.FILL_HORIZONTAL, 0));
		ta8 = new Text(group, SWT.BORDER | SWT.RIGHT);
		ta8.setLayoutData(new GetGridData().getGridData(35, 0, 0, 0, 0,
				GridData.FILL_HORIZONTAL, 0));
		// 定制文本框的焦点切换
		CustomText(jfys, jfss);
		CustomText(jfss, ta1);
		CustomText(ta1, ta2);
		CustomText(ta2, ta3);
		CustomText(ta3, ta4);
		CustomText(ta4, ta5);
		CustomText(ta5, ta6);
		CustomText(ta6, ta7);
		CustomText(ta7, ta8);
		CustomText(ta8, jfys);
		// 文本框初始使能状态
		new SetTextEnabled(group, new SetControlEnabled().isEnabled(YearManager
				.getInstance().getCurYear()));
		foreColor.dispose();
	}

	// 定制数据输入文本框
	// 参数:text,需要定义的Text对象;nextText,下一个获得焦点的Text对象
	private void CustomText(final Text text, final Text nextText) {
		text.addModifyListener(new ModifyListener() {
			// 数据修改时保存到数据实体
			public void modifyText(ModifyEvent e) {
				YearTeachUnit ytu = (YearTeachUnit) ((IStructuredSelection) tableViewer
						.getSelection()).getFirstElement();
				int index = list.indexOf(ytu);
				// 根据TableViewer当前选择行保存用户在文本框中输入的数据
				if (index >= 0) {
					String textValue = text.getText();
					if (text == jfys)
						list.get(index).setJfys(new BigDecimal(textValue));
					else if (text == jfss)
						list.get(index).setJfss(new BigDecimal(textValue));
					else if (text == ta1)
						list.get(index).setTa1(Integer.parseInt(textValue));
					else if (text == ta2)
						list.get(index).setTa2(Integer.parseInt(textValue));
					else if (text == ta3)
						list.get(index).setTa3(Integer.parseInt(textValue));
					else if (text == ta4)
						list.get(index).setTa4(Integer.parseInt(textValue));
					else if (text == ta5)
						list.get(index).setTa5(Integer.parseInt(textValue));
					else if (text == ta6)
						list.get(index).setTa6(Integer.parseInt(textValue));
					else if (text == ta7)
						list.get(index).setTa7(Integer.parseInt(textValue));
					else if (text == ta8)
						list.get(index).setTa8(Integer.parseInt(textValue));
				}
			}
		});

		text.addKeyListener(new KeyAdapter() {
			public void keyPressed(final KeyEvent e) {
				if (e.character == SWT.CR) {
					if (nextText instanceof Text)
						nextText.forceFocus();
				}
			}
		});
	}

	// 创建导航按钮
	private void createToolbarButtons() {
		saveDataAction = new Action("保存数据", AbstractUIPlugin
				.imageDescriptorFromPlugin(IAppConstants.APPLICATION_ID,
						IImageKey.SAVE_DATA)) {
			public void run() {
				canEdit = false; // 退出数据可编辑状态
				saveData();
			}
		};
		editDataAction = new Action("修改数据", AbstractUIPlugin
				.imageDescriptorFromPlugin(IAppConstants.APPLICATION_ID,
						IImageKey.EDITT_DATA)) {
			public void run() {
				canEdit = true;
			}
		};
		IToolBarManager toolBar = getViewSite().getActionBars()
				.getToolBarManager();
		Action preYear = new YearAction("上一年", 0, AbstractUIPlugin
				.imageDescriptorFromPlugin(IAppConstants.APPLICATION_ID,
						IImageKey.PRE_YEAR)) {
			public void run() {
				super.run();
				refreshData();
			}
		};
		Action nextYear = new YearAction("上一年", 1, AbstractUIPlugin
				.imageDescriptorFromPlugin(IAppConstants.APPLICATION_ID,
						IImageKey.NEXT_YEAR)) {
			public void run() {
				super.run();
				refreshData();
			}
		};
		toolBar.add(preYear);
		toolBar.add(nextYear);
		toolBar.add(editDataAction);
		toolBar.add(saveDataAction);
		// 设置初始的使能状态
		editDataAction.setEnabled(new SetControlEnabled().isEnabled(YearManager
				.getInstance().getCurYear()));
		saveDataAction.setEnabled(new SetControlEnabled().isEnabled(YearManager
				.getInstance().getCurYear()));
	}

	// 刷新数据
	private void refreshData() {
		// 激活属性监听事件
		CuryearPropertyChange.getInstance().firePropertyChangeListener();
		// 刷新TeachUnitInfo视图的下拉列表框
		Combo combo = YearCombo.getINSTANCE().getCombo();
		combo
				.select(combo.indexOf(YearManager.getInstance().getCurYear()
						+ ""));
		combo.setFocus();
	}

	// 根据TableViewer当前选择行获得对应文本框数据并保存到实体变量yearTeachUnit
	// 以便进行数据绑定
	private void getCurrentRowData(IStructuredSelection selection) {
		if (selection.getFirstElement() instanceof YearTeachUnit) {
			yearTeachUnit = new YearTeachUnit();
			YearTeachUnit ytu = (YearTeachUnit) selection.getFirstElement();
			yearTeachUnit.setJfys(ytu.getJfys());
			yearTeachUnit.setJfss(ytu.getJfss());
			yearTeachUnit.setTa1(ytu.getTa1());
			yearTeachUnit.setTa2(ytu.getTa2());
			yearTeachUnit.setTa3(ytu.getTa3());
			yearTeachUnit.setTa4(ytu.getTa4());
			yearTeachUnit.setTa5(ytu.getTa5());
			yearTeachUnit.setTa6(ytu.getTa6());
			yearTeachUnit.setTa7(ytu.getTa7());
			yearTeachUnit.setTa8(ytu.getTa8());
		}
	}

	// 数据绑定
	private void bindData(Composite parent) {
		DataBindingContext dbc = DataBindingFactory.createContext(parent);
		dbc.bind(jfys, new Property(yearTeachUnit, "jfys"), null);
		dbc.bind(jfss, new Property(yearTeachUnit, "jfss"), null);
		dbc.bind(ta1, new Property(yearTeachUnit, "ta1"), null);
		dbc.bind(ta2, new Property(yearTeachUnit, "ta2"), null);
		dbc.bind(ta3, new Property(yearTeachUnit, "ta3"), null);
		dbc.bind(ta4, new Property(yearTeachUnit, "ta4"), null);
		dbc.bind(ta5, new Property(yearTeachUnit, "ta5"), null);
		dbc.bind(ta6, new Property(yearTeachUnit, "ta6"), null);
		dbc.bind(ta7, new Property(yearTeachUnit, "ta7"), null);
		dbc.bind(ta8, new Property(yearTeachUnit, "ta8"), null);
	}

	// 保存数据
	private void saveData() {
		// 判断有无记录需要保存
		Iterator data = ((List) tableViewer.getInput()).iterator();
		if (!data.hasNext()) {
			MessageDialog.openWarning(null, "提示", "没有需要保存的数据!");
			return;
		}

		Job job = new Job("正在保存数据。。。") {
			protected IStatus run(IProgressMonitor monitor) {
				monitor.beginTask("正在保存数据。。。", IProgressMonitor.UNKNOWN);
				Session session = HibernateSessionFactory
						.getSession("hibernate_derby.cfg.xml");
				Transaction tx = session.beginTransaction();
				Iterator data = ((List) tableViewer.getInput()).iterator();
				int count = 0;
				while (data.hasNext()) {
					YearTeachUnit ytu = (YearTeachUnit) data.next();
					monitor.worked(1);
					session.update(ytu);
					// 设置批量更新块大小
					if (++count % 2 == 0) {
						session.flush();
						session.clear();
					}
					// 测试用,导出产品时删除
					try {
						Thread.sleep(800);
					} catch (InterruptedException e) {
					}

				}
				tx.commit();
				HibernateSessionFactory.closeSession();
				monitor.done();
				return Status.OK_STATUS;
			}
		};
		job.addJobChangeListener(new JobChangeAdapter() {
			public void done(IJobChangeEvent event) {
				final boolean isSucess = event.getResult().isOK();
				Display.getDefault().asyncExec(new Runnable() {
					public void run() {
						if (isSucess)
							MessageDialog.openInformation(null, "提示",
									"数据已经成功保存!");
						else
							MessageDialog.openError(null, "提示", "出错,数据保存失败!");
					}
				});
			}
		});
		job.setUser(false);
		job.setPriority(Job.SHORT);
		job.schedule();
	}

	public void propertyChange(PropertyChangeEvent event) {
		if (event.getProperty().equals("curYear")) {
			setPartName(getConfigurationElement().getAttribute("name") + "---"
					+ YearManager.getInstance().getCurYear() + "年");
			editDataAction.setEnabled(new SetControlEnabled()
					.isEnabled(YearManager.getInstance().getCurYear()));
			saveDataAction.setEnabled(new SetControlEnabled()
					.isEnabled(YearManager.getInstance().getCurYear()));
			new SetTextEnabled(group, new SetControlEnabled()
					.isEnabled(YearManager.getInstance().getCurYear()));
			list = getData(YearManager.getInstance().getCurYear());
			tableViewer.setInput(list);
			tableViewer.setSelection(new StructuredSelection(
					((List) tableViewer.getInput()).get(0)));
		}
	}

	// 注销监听器
	public void dispose() {
		CuryearPropertyChange.getInstance().removePropertyChangeListener(
				IAppConstants.TEACH_UNIT_DATA_VIEW_ID);
	}

	public void setFocus() {

	}

}

⌨️ 快捷键说明

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