use of net.heartsome.cat.ts.ui.qa.model.QAResultBean in project translationstudio8 by heartsome.
the class QAResultViewPart method propertyChange.
public void propertyChange(final PropertyChangeEvent evt) {
/*
* 备注,传过来的数据是一个 ArrayList<QAResultBean>, 每组数据都是相同的 rowId
*/
if ("printData".equals(evt.getPropertyName())) {
try {
Display.getDefault().syncExec(new Runnable() {
@SuppressWarnings("unchecked")
public void run() {
Object obj = evt.getNewValue();
if (obj instanceof List) {
List<QAResultBean> objList = (List<QAResultBean>) obj;
if (objList.size() <= 0) {
return;
}
isQAEnd = false;
String rowId = objList.get(0).getRowId();
// 如果是自动检查。那么要删除之前的记录
int addIndex = -1;
if (qaResult.isAutoQA()) {
if (qaResult.isSameOperObjForAuto()) {
for (int i = 0; i < dataList.size(); i++) {
QAResultBean bean = dataList.get(i);
if (rowId.equals(bean.getRowId())) {
dataList.remove(bean);
addIndex = i;
i--;
}
}
if (addIndex == -1) {
addIndex = 0;
}
dataList.addAll(addIndex, objList);
tableModel.textRenderer.clearRowHeiMap();
table.redraw();
} else {
dataList.clear();
tableModel.textRenderer.clearRowHeiMap();
table.redraw();
filePathList = qaResult.getFilePathList();
qaResult.setSameOperObjForAuto(true);
}
} else {
dataList.addAll(objList);
table.redraw();
}
if (qaResult.isAutoQA()) {
if (addIndex > 0) {
table.setSelection(0, addIndex + 1, true);
}
}
} else if (obj instanceof String) {
// 这是针对自动品质检查,若一个文本段没有错误,那么就将这个文本段之前的提示进行清除
if (qaResult.isAutoQA()) {
if (qaResult.isSameOperObjForAuto()) {
String rowId = (String) obj;
for (int i = 0; i < dataList.size(); i++) {
QAResultBean bean = dataList.get(i);
if (rowId.equals(bean.getRowId())) {
dataList.remove(bean);
i--;
}
}
} else {
dataList.clear();
tableModel.textRenderer.clearRowHeiMap();
table.redraw();
filePathList = qaResult.getFilePathList();
qaResult.setSameOperObjForAuto(true);
}
}
table.redraw();
}
}
});
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.views.QAResultViewPart.log1"), e);
}
} else if ("isMultiFiles".equals(evt.getPropertyName())) {
try {
Display.getCurrent().syncExec(new Runnable() {
public void run() {
isMultiFile = (Boolean) ((Object[]) evt.getNewValue())[0];
if (isMultiFile) {
oper = (MultiFilesOper) ((Object[]) evt.getNewValue())[1];
} else {
oper = null;
}
}
});
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.views.QAResultViewPart.log1"), e);
}
} else if ("informQAEndFlag".equals(evt.getPropertyName())) {
// 通知品质检查已经结束
isQAEnd = true;
}
}
use of net.heartsome.cat.ts.ui.qa.model.QAResultBean in project translationstudio8 by heartsome.
the class QAResultViewPart method createPropMenu.
/**
* 创建右键参数
*/
private void createPropMenu() {
Menu propMenu = new Menu(table);
table.setMenu(propMenu);
MenuItem deletWarnItem = new MenuItem(propMenu, SWT.NONE);
deletWarnItem.setText(Messages.getString("views.QAResultViewPart.deletWarnItem"));
deletWarnItem.setImage(deleteImage);
deletWarnItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
QAResultBean bean;
for (int i = 0; i < dataList.size(); i++) {
bean = dataList.get(i);
// 0为错误,1为警告
if (1 == bean.getLevel()) {
dataList.remove(bean);
i--;
}
}
tableModel.textRenderer.clearRowHeiMap();
table.redraw();
}
});
MenuItem deleteAllItem = new MenuItem(propMenu, SWT.NONE);
deleteAllItem.setText(Messages.getString("views.QAResultViewPart.deleteAllItem"));
deleteAllItem.setImage(deleteImage);
deleteAllItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dataList.clear();
tableModel.textRenderer.clearRowHeiMap();
table.redraw();
}
});
// 导出品质检查报告
exportItem = new MenuItem(propMenu, SWT.NONE);
exportItem.setText(Messages.getString("qa.views.QAResultViewPart.exportPopMenu"));
exportItem.setImage(exportImg);
exportItem.setEnabled(false);
exportItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ExportQAResultDialog dialog = new ExportQAResultDialog(getSite().getShell());
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
final String exportFilePath = dialog.getExportFilePath();
if (exportFilePath == null || exportFilePath.isEmpty()) {
MessageDialog.openInformation(getSite().getShell(), Messages.getString("qa.all.dialog.info"), Messages.getString("qa.views.QAResultViewPart.msg.nullFilePath"));
return;
}
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("", 1);
while (!isQAEnd) {
try {
Thread.sleep(500);
} catch (Exception e2) {
logger.error("", e2);
}
if (monitor.isCanceled()) {
return;
}
}
List<QAResultBean> exportDataList = new ArrayList<QAResultBean>();
exportDataList.addAll(dataList);
ExportQAResult export = new ExportQAResult(isMultiFile, exportFilePath);
export.beginExport(dataList, filePathList, monitor);
monitor.done();
}
};
try {
new ProgressMonitorDialog(getSite().getShell()).run(true, true, runnable);
} catch (Exception e1) {
logger.error("", e1);
}
}
}
});
propMenu.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if (deleteImage != null && !deleteImage.isDisposed()) {
deleteImage.dispose();
}
}
});
}
use of net.heartsome.cat.ts.ui.qa.model.QAResultBean in project translationstudio8 by heartsome.
the class ExportQAResult method beginExport.
public void beginExport(List<QAResultBean> dataList, List<String> fileLCList, IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
// 分成十份,其中解析文件 1 份,其余 9 份
monitor.beginTask("", 10);
monitor.setTaskName(Messages.getString("qa.export.ExportQAResult.monitor.title"));
// 将 fileLCList 转换成相对路径
List<File> fileList = new ArrayList<File>();
for (String fileLC : fileLCList) {
fileList.add(new File(fileLC));
}
for (IFile iFile : ResourceUtils.filesToIFiles(fileList)) {
filePathList.add(iFile.getFullPath().toOSString());
}
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
monitor.worked(1);
// UNDO 这里按文件排序给注释了。。。。
// // 先按文件排序
// sort(dataList);
// 工作簿
XSSFWorkbook workbook = new XSSFWorkbook();
// 创建sheet页
XSSFSheet sheet = workbook.createSheet();
// 设置sheet名称
workbook.setSheetName(0, Messages.getString("qa.export.ExportQAResult.sheet.title"));
sheet.setColumnWidth(0, 255 * 6);
sheet.setColumnWidth(1, 255 * 20);
sheet.setColumnWidth(2, 255 * 30);
sheet.setColumnWidth(3, 255 * 60);
sheet.setColumnWidth(4, 255 * 60);
XSSFFont titleFont = workbook.createFont();
titleFont.setColor(IndexedColors.GREY_80_PERCENT.getIndex());
titleFont.setBold(true);
titleFont.setFontHeight(20);
XSSFFont headerFont = workbook.createFont();
headerFont.setBold(true);
headerFont.setFontHeight(14);
XSSFFont errorFont = workbook.createFont();
errorFont.setColor(IndexedColors.RED.getIndex());
XSSFCellStyle titleStyle = workbook.createCellStyle();
titleStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
titleStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
titleStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
titleStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
titleStyle.setAlignment(HorizontalAlignment.CENTER);
titleStyle.setFont(titleFont);
XSSFCellStyle headerStyle = workbook.createCellStyle();
headerStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
headerStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
headerStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
headerStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
headerStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
headerStyle.setFont(headerFont);
XSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
cellStyle.setWrapText(true);
XSSFCellStyle errorCellStyle = workbook.createCellStyle();
errorCellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
errorCellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
errorCellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
errorCellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
errorCellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
errorCellStyle.setWrapText(true);
errorCellStyle.setFont(errorFont);
// 生成标题行
XSSFRow row = sheet.createRow(0);
XSSFCell cell = row.createCell(0);
cell.setCellStyle(titleStyle);
cell.setCellValue(Messages.getString("qa.export.ExportQAResult.titleCell"));
String[] headers = new String[] { // 级别
Messages.getString("qa.export.ExportQAResult.header.errorLeavel"), // 类型
Messages.getString("qa.export.ExportQAResult.header.qaType"), // 位置
Messages.getString("qa.export.ExportQAResult.header.location"), // 源文
Messages.getString("qa.export.ExportQAResult.header.srcText"), // 译文
Messages.getString("qa.export.ExportQAResult.header.tgtText") };
// 产生表格标题行
row = sheet.createRow(1);
for (short i = 0; i < headers.length; i++) {
cell = row.createCell(i);
cell.setCellStyle(headerStyle);
cell.setCellValue(headers[i]);
}
// 开始生成数据
int index = 1;
String rowId = null;
// 先处理品质检查结果数据为空的情况
if (dataList.size() <= 0) {
if (isMultiFile) {
String multiFileStr = getMultiResouce();
index++;
row = sheet.createRow(index);
for (int i = 0; i < headers.length; i++) {
cell = row.createCell(i);
cell.setCellStyle(cellStyle);
if (i == headers.length - 1) {
cell.setCellValue(multiFileStr);
}
}
} else {
for (String filePath : this.filePathList) {
index++;
row = sheet.createRow(index);
for (int i = 0; i < headers.length; i++) {
cell = row.createCell(i);
cell.setCellStyle(cellStyle);
if (i == headers.length - 1) {
cell.setCellValue(filePath);
}
}
}
}
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));
} else {
int interval = 1;
if (dataList.size() > 9) {
interval = dataList.size() / 9;
}
int startMergeRow = -1;
int endMergeRow = -1;
for (int i = 0; i < dataList.size(); i++) {
QAResultBean bean = dataList.get(i);
index++;
System.out.println(index);
if (index % interval == 0) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
monitor.worked(1);
}
row = sheet.createRow(index);
// 处理合并 级别 与 类型 两列的行
mergeIF: if (bean.getMergeId() != null) {
if (mergedIdSet.contains(bean.getMergeId())) {
break mergeIF;
}
startMergeRow = index;
mergeFor: for (int j = i + 1; j < dataList.size(); j++) {
if (dataList.get(j).getMergeId() != null && dataList.get(j).getMergeId().equals(bean.getMergeId())) {
mergedIdSet.add(bean.getMergeId());
endMergeRow = index + (j - i);
} else {
break mergeFor;
}
}
if (startMergeRow >= 0 && endMergeRow >= 0) {
sheet.addMergedRegion(new CellRangeAddress(startMergeRow, endMergeRow, 0, 0));
sheet.addMergedRegion(new CellRangeAddress(startMergeRow, endMergeRow, 1, 1));
startMergeRow = -1;
endMergeRow = -1;
}
}
// 循环当前行的每一列
for (int h = 0; h < headers.length; h++) {
cell = row.createCell(h);
cell.setCellStyle(cellStyle);
String text = null;
switch(h) {
case 0:
if (bean.getLevel() == 0) {
text = Messages.getString("qa.export.ExportQAResult.errorLeavel.error");
cell.setCellStyle(errorCellStyle);
} else if (bean.getLevel() == 1) {
text = Messages.getString("qa.export.ExportQAResult.errorLeavel.warning");
}
cell.setCellValue(text);
break;
case 1:
text = bean.getQaTypeText();
cell.setCellValue(text);
break;
case 2:
text = bean.getFileName() + " [" + bean.getLineNumber() + "]";
cell.setCellValue(text);
break;
case 3:
text = bean.getSrcContent();
cell.setCellValue(getDisplayText(text));
break;
case 4:
text = bean.getTgtContent();
cell.setCellValue(getDisplayText(text));
break;
default:
break;
}
}
}
// // 这是合并 文件路径
// if (isMultiFile) {
// sheet.addMergedRegion(new CellRangeAddress(resourceIndex, index, 6, 6));
// }else {
// sheet.addMergedRegion(new CellRangeAddress(resourceIndex, index, 6, 6));
// }
// sheet.addMergedRegion(new CellRangeAddress(rowidIndex, index, 1, 1));
// sheet.addMergedRegion(new CellRangeAddress(rowidIndex, index, 4, 4));
// sheet.addMergedRegion(new CellRangeAddress(rowidIndex, index, 5, 5));
// 标题行合并(处理未合并完的部份)
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));
}
try {
FileOutputStream fileoutputstream = new FileOutputStream(exportFilePath);
workbook.write(fileoutputstream);
fileoutputstream.close();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("qa.all.dialog.info"), Messages.getString("qa.export.ExportQAResult.MSG.exportSuccess"));
}
});
} catch (Exception e) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("qa.all.dialog.info"), Messages.getString("qa.export.ExportQAResult.MSG.exportFail"));
}
});
LOGGER.error(Messages.getString("qa.export.ExportQAResult.LOG.exportError"), e);
}
}
use of net.heartsome.cat.ts.ui.qa.model.QAResultBean in project translationstudio8 by heartsome.
the class ParaCompletenessQA method startQA.
@Override
public String startQA(QAModel model, IProgressMonitor monitor, IFile iFile, QAXmlHandler xmlHandler, QATUDataBean tuDataBean) {
hasError = false;
String lineNumber = tuDataBean.getLineNumber();
String qaTypeText = Messages.getString("qa.all.qaItem.ParaCompletenessQA");
String srcContent = tuDataBean.getSrcContent();
String tgtContent = tuDataBean.getTgtContent();
String rowId = tuDataBean.getRowId();
// 检查未翻译的情况
if (tgtContent == null || "".equals(tgtContent)) {
// errorTip = Messages.getString("qa.ParaCompletenessQA.tip1");
hasError = true;
} else if (tgtContent.length() > 0 && "".equals(tgtContent.trim())) {
// 如果源文也是一个空格,那么通过检查,如果源文不是空格,则提示未翻译
if (!(srcContent.length() > 0 && "".equals(srcContent.trim()))) {
// errorTip = Messages.getString("qa.ParaCompletenessQA.tip2");
hasError = true;
}
} else if (tgtContent.trim().equals(srcContent.trim())) {
// 检查源文与译文一致的情况
// errorTip = Messages.getString("qa.ParaCompletenessQA.tip3");
hasError = true;
}
if (hasError) {
super.printQAResult(new QAResultBean(level, QAConstant.QA_PARACOMPLETENESS, qaTypeText, null, tuDataBean.getFileName(), lineNumber, srcContent, tgtContent, rowId));
}
String result = "";
if (hasError && level == 0) {
result = QAConstant.QA_PARACOMPLETENESS;
}
return result;
}
use of net.heartsome.cat.ts.ui.qa.model.QAResultBean in project translationstudio8 by heartsome.
the class SpaceOfParaCheckQA method startQA.
@Override
public String startQA(QAModel model, IProgressMonitor monitor, IFile iFile, QAXmlHandler xmlHandler, QATUDataBean tuDataBean) {
if (tuDataBean.getTgtContent() == null || "".equals(tuDataBean.getTgtContent())) {
return "";
}
hasError = false;
String lineNumber = tuDataBean.getLineNumber();
String qaTypeText = Messages.getString("qa.all.qaItem.SpaceOfParaCheck");
String srcContent = tuDataBean.getSrcContent();
String tgtContent = tuDataBean.getTgtContent();
String rowId = tuDataBean.getRowId();
int srcFirstSpaceNum = getSpaceNumber(srcContent, true);
int srcLastSpaceNum = getSpaceNumber(srcContent, false);
int tarFirstSpaceNum = getSpaceNumber(tgtContent, true);
int tarLastSpaceNum = getSpaceNumber(tgtContent, false);
// String errorTip = "";
if (srcFirstSpaceNum > tarFirstSpaceNum) {
// errorTip = MessageFormat.format(Messages.getString("qa.SpaceOfParaCheckQA.tip1"), new Object[] {
// srcFirstSpaceNum, tarFirstSpaceNum, (srcFirstSpaceNum - tarFirstSpaceNum) });
hasError = true;
} else if (srcFirstSpaceNum < tarFirstSpaceNum) {
// errorTip = MessageFormat.format(Messages.getString("qa.SpaceOfParaCheckQA.tip2"), new Object[] {
// srcFirstSpaceNum, tarFirstSpaceNum, (tarFirstSpaceNum - srcFirstSpaceNum) });
hasError = true;
}
//如果源文本全是空格,只提示段首空格,不提示段尾
if (srcFirstSpaceNum == srcContent.length()) {
return "";
}
//处理段末空格的检查
if (srcLastSpaceNum > tarLastSpaceNum) {
// errorTip = MessageFormat.format(Messages.getString("qa.SpaceOfParaCheckQA.tip3"), new Object[] {
// srcLastSpaceNum, tarLastSpaceNum, (srcLastSpaceNum - tarLastSpaceNum) });
hasError = true;
} else if (srcLastSpaceNum < tarLastSpaceNum) {
// errorTip = MessageFormat.format(Messages.getString("qa.SpaceOfParaCheckQA.tip4"), new Object[] {
// srcLastSpaceNum, tarLastSpaceNum, (tarLastSpaceNum - srcLastSpaceNum) });
hasError = true;
}
if (hasError) {
super.printQAResult(new QAResultBean(level, QAConstant.QA_SPACEOFPARACHECK, qaTypeText, null, tuDataBean.getFileName(), lineNumber, srcContent, tgtContent, rowId));
}
String result = "";
if (hasError && level == 0) {
result = QAConstant.QA_SPACEOFPARACHECK;
}
return result;
}
Aggregations