use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class AutomaticQA method setInitData.
public void setInitData(XLFHandler handler) {
this.handler = handler;
preferenceStore = Activator.getDefault().getPreferenceStore();
model = new QAModel();
window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
filterMap = getNotIncludePara();
root = ResourcesPlugin.getWorkspace().getRoot();
xmlHandler = new QAXmlHandler();
// 存储品质检查的检查项
model.setBatchQAItemIdList(getAutoQAItems());
// 存储品质检查的检查时不包括的文本段
model.setNotInclude(filterMap);
model.setShell(window.getShell());
XLIFFEditorImplWithNatTable nattable = XLIFFEditorImplWithNatTable.getCurrent();
boolean isMultiFile = nattable.isMultiFile();
if (isMultiFile) {
model.setMuliFiles(true);
IFile multiTempIFile = ((FileEditorInput) nattable.getEditorInput()).getFile();
ArrayList<IFile> selectIFiles = (ArrayList<IFile>) ResourceUtils.filesToIFiles(nattable.getMultiFileList());
model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
} else {
model.setMuliFiles(false);
}
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class BatchQAHandler method execute.
@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
isMultiFile = false;
preferenceStore = Activator.getDefault().getPreferenceStore();
// UNDO 如果焦点在其他视图上时,获取的文件错误。
IFile multiTempIFile = null;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
final Shell shell = window.getShell();
// ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
if (HandlerUtil.getActivePart(event) instanceof IViewPart) {
ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
Iterator<Object> selectIt = structuredSelection.iterator();
while (selectIt.hasNext()) {
Object object = selectIt.next();
if (object instanceof IFile) {
IFile selectFile = (IFile) object;
String fileExtension = selectFile.getFileExtension();
// 如果后缀名不是xlf,那么就进行提示
if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
boolean isSure = MessageDialog.openConfirm(shell, Messages.getString("qa.all.dialog.warning"), MessageFormat.format(Messages.getString("qa.all.tip.notXliff"), new Object[] { selectFile.getFullPath() }));
if (!isSure) {
return null;
}
continue;
}
selectIFiles.add(selectFile);
} else if (object instanceof IProject) {
IProject selectProject = (IProject) object;
try {
ResourceUtils.getXliffs(selectProject, selectIFiles);
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.handlers.BatchQAHandler.log1"), e);
}
} else if (object instanceof IContainer) {
IContainer selectContainer = (IContainer) object;
try {
ResourceUtils.getXliffs(selectContainer, selectIFiles);
} catch (Exception e) {
logger.error(Messages.getString("qa.handlers.BatchQAHandler.log1"), e);
e.printStackTrace();
}
}
}
}
} else {
//如果左边未选择品质检查的类型,那么,获取nattable中打开的文件
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
if (activeEditor != null && !activeEditor.getSite().getId().equals(XLIFF_EDITOR_ID)) {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.tip2"));
return null;
}
XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) activeEditor;
isMultiFile = nattable.isMultiFile();
multiTempIFile = ((FileEditorInput) nattable.getEditorInput()).getFile();
if (isMultiFile) {
List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
for (String multiFileStr : multiFilesList) {
selectIFiles.add(ResourceUtils.fileToIFile(multiFileStr));
}
} else {
selectIFiles.add(multiTempIFile);
}
}
CommonFunction.removeRepeateSelect(selectIFiles);
if (selectIFiles.size() == 0) {
MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.tip1"));
return null;
}
List<IFile> lstFiles = new ArrayList<IFile>();
XLFValidator.resetFlag();
for (IFile iFile : selectIFiles) {
if (!XLFValidator.validateXliffFile(iFile)) {
lstFiles.add(iFile);
}
}
XLFValidator.resetFlag();
selectIFiles.removeAll(lstFiles);
if (selectIFiles.size() == 0) {
return null;
}
model = new QAModel();
model.setQaXlfList(selectIFiles);
quality = new QualityAssurance(model);
BatchQADialog dialog = new BatchQADialog(shell, model, isMultiFile);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
// 先调用方法,查看品质检查结果视图是否处于显示状态,如果显示了的。删除数据
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = workbenchPage.findView(QAResultViewPart.ID);
if (view != null) {
// 运行时,将结果视图中列表的数据清除
((QAResultViewPart) view).clearTableData();
}
QAResult qaResult = new QAResult();
// 存储品质检查的检查项
model.setBatchQAItemIdList(getBatchQAItems());
// 存储品质检查的检查时不包括的文本段
model.setNotInclude(getNotIncludePara());
//给品质检查结果视图发出通告,本次检查对象为合并打开文件
// qaResult.firePropertyChange(isMultiFile, new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
// 将当前所处理的文件传至 qaResult
List<String> fileList = new ArrayList<String>();
for (IFile iFIle : model.getQaXlfList()) {
fileList.add(iFIle.getLocation().toOSString());
}
qaResult.setFilePathList(fileList);
HsMultiActiveCellEditor.commit(true);
if (isMultiFile) {
model.setMuliFiles(true);
model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
qaResult.setMultiOper(model.getMultiOper());
quality.beginMultiFileQA(qaResult);
} else {
model.setMuliFiles(false);
qaResult.setMultiOper(model.getMultiOper());
quality.beginQA(qaResult);
}
}
return null;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class CustomFilterDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
gray = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY);
black = parent.getDisplay().getSystemColor(SWT.COLOR_BLACK);
tParent = (Composite) super.createDialogArea(parent);
GridLayoutFactory.swtDefaults().extendedMargins(5, 5, 10, 0).numColumns(2).equalWidth(false).applyTo(tParent);
tParent.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite cmpLeft = new Composite(tParent, SWT.BORDER);
cmpLeft.setLayout(new GridLayout(2, false));
GridDataFactory.swtDefaults().applyTo(cmpLeft);
Composite cmpList = new Composite(cmpLeft, SWT.NONE);
cmpList.setLayout(new GridLayout(1, true));
cmpList.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
new Label(cmpList, SWT.NONE).setText(Messages.getString("dialog.CustomFilterDialog.c1Lbl"));
initCustomFilterList(cmpList);
Composite cmpBtn = new Composite(cmpLeft, SWT.None);
cmpBtn.setLayout(new GridLayout());
cmpBtn.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
Button addCustom = new Button(cmpBtn, SWT.PUSH);
addCustom.setText(Messages.getString("dialog.CustomFilterDialog.addCustom"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(addCustom);
addCustom.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (isChange()) {
if (!MessageDialog.openConfirm(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg1"))) {
return;
}
}
refresh();
}
});
Button delCustom = new Button(cmpBtn, SWT.PUSH);
delCustom.setText(Messages.getString("dialog.CustomFilterDialog.delCustom"));
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).applyTo(delCustom);
delCustom.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String[] filters = customFilterList.getSelection();
if (filters != null && filters.length > 0) {
if (MessageDialog.openConfirm(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg2"))) {
for (int i = 0; i < filters.length; i++) {
customFilters.remove(filters[i]);
customFiltersAddition.remove(filters[i]);
customFiltersIndex.remove(filters[i]);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IEditorReference[] editors = page.getEditorReferences();
for (IEditorReference ef : editors) {
IEditorPart editor = ef.getEditor(false);
if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
Combo cb = ((XLIFFEditorImplWithNatTable) editor).getFilterCombo();
if (cb != null && !cb.isDisposed()) {
cb.remove(filters[i]);
}
}
}
}
}
// cmbFilter.remove(filters[i]);
customFilterList.remove(filters[i]);
XLFHandler.getFilterMap().remove(filters[i]);
}
PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION, customFilters);
PreferenceStore.saveCustomCondition(IPreferenceConstants.FILTER_CONDITION_INDEX, customFiltersIndex);
}
} else {
MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg3"));
}
}
});
Button editCustom = new Button(cmpBtn, SWT.PUSH);
editCustom.setText(Messages.getString("dialog.CustomFilterDialog.editCustom"));
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).applyTo(editCustom);
editCustom.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
edit();
}
});
Composite cmpRight = new Composite(tParent, SWT.NONE);
cmpRight.setLayout(new GridLayout(1, true));
cmpRight.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite top = new Composite(cmpRight, SWT.NONE);
top.setLayout(new GridLayout(2, false));
top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
new Label(top, SWT.NONE).setText(Messages.getString("dialog.CustomFilterDialog.topLbl"));
filterNameTxt = new Text(top, SWT.BORDER);
filterNameTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
filterNameTxt.forceFocus();
top = new Composite(cmpRight, SWT.NONE);
top.setLayout(new GridLayout(2, false));
top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
andBtn = new Button(top, SWT.RADIO);
andBtn.setText(Messages.getString("dialog.CustomFilterDialog.andBtn"));
andBtn.setSelection(true);
orBtn = new Button(top, SWT.RADIO);
orBtn.setText(Messages.getString("dialog.CustomFilterDialog.orBtn"));
scroll = new ScrolledComposite(cmpRight, SWT.V_SCROLL | SWT.BORDER);
scroll.setAlwaysShowScrollBars(true);
scroll.setLayoutData(new GridData(GridData.FILL_BOTH));
scroll.setExpandHorizontal(true);
scroll.setExpandVertical(true);
// scroll.setSize(500, 200);
dynaComp = new Composite(scroll, SWT.None);
scroll.setContent(dynaComp);
dynaComp.setLayout(new GridLayout(1, true));
new DynaComposite(dynaComp, SWT.NONE);
return parent;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class CustomFilterDialog method okPressed.
@Override
protected void okPressed() {
String filterNameStr = filterNameTxt.getText();
if (filterNameStr == null || "".equals(filterNameStr)) {
MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg6"));
return;
}
StringBuilder xpath = new StringBuilder();
String link = andBtn.getSelection() ? " and " : " or ";
ArrayList<String[]> tempValue = new ArrayList<String[]>();
for (DynaComposite comp : conditionList) {
// 得到所有自定义条件组合的xpath
String tempXpath = comp.getXpath(true);
if (RESULT_FAILED.equals(tempXpath)) {
return;
}
xpath.append(tempXpath).append(link);
tempValue.add(comp.getTempIndex());
}
if (xpath.length() > 0) {
if (isAdd()) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IEditorReference[] editors = page.getEditorReferences();
for (IEditorReference e : editors) {
IEditorPart editor = e.getEditor(false);
if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
Combo cb = ((XLIFFEditorImplWithNatTable) editor).getFilterCombo();
if (cb != null && !cb.isDisposed()) {
cb.add(filterNameTxt.getText());
}
}
}
}
}
// cmbFilter.add(filterNameTxt.getText());
} else {
XLFHandler.getFilterMap().put(filterNameTxt.getText(), xpath.substring(0, xpath.lastIndexOf(link)));
}
customFilters.put(filterNameStr, xpath.substring(0, xpath.lastIndexOf(link)));
customFiltersAddition.put(filterNameStr, link.trim());
customFiltersIndex.put(filterNameStr, tempValue);
PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION, new TreeMap<String, String>(customFilters));
PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION_ADDITION, customFiltersAddition);
PreferenceStore.saveCustomCondition(IPreferenceConstants.FILTER_CONDITION_INDEX, customFiltersIndex);
reload();
}
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class PopupMenuAction method run.
@Override
public void run(NatTable natTable, MouseEvent event) {
// ActiveCellEditor.commit(); // 执行弹出菜单前先关闭编辑模式的单元格
super.run(natTable, event);
if (selectionLayer == null) {
selectionLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
}
int rowIndex = natTable.getRowIndexByPosition(getGridRowPosition());
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (!editor.isHorizontalLayout()) {
rowIndex = rowIndex / 2;
}
// 如果该行已经选中的了,直接显示出右键菜单。
if (!isSelected(rowIndex)) {
HsMultiActiveCellEditor.commit(true);
natTable.doCommand(new SelectCellCommand(natTable, getGridColumnPosition(), getGridRowPosition(), isWithShiftMask(), isWithControlMask()));
HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
}
menu.setData(event.data);
menu.setVisible(true);
}
Aggregations