use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class NextSplitPointHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
final Shell shell = window.getShell();
XLIFFEditorImplWithNatTable xliffEditor = null;
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart instanceof IEditorPart) {
if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
List<String> splitPointList = xliffEditor.getSplitXliffPoints();
if (splitPointList.size() <= 0) {
MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("NextSplitPointHandler.msg.nullSplitPoint"));
return null;
}
final XLFHandler xlfHander = xliffEditor.getXLFHandler();
// 先对 splitPointList 进行排序
Collections.sort(splitPointList, new Comparator<String>() {
public int compare(String rowId1, String rowId2) {
int rowIndex1 = xlfHander.getRowIndex(rowId1);
int rowIndex2 = xlfHander.getRowIndex(rowId2);
return rowIndex1 > rowIndex2 ? 1 : -1;
}
});
List<String> selectionRowIdList = xliffEditor.getSelectedRowIds();
if (selectionRowIdList != null && selectionRowIdList.size() > 0) {
curSelectionRowId = selectionRowIdList.get(0);
}
// 开始定位,定位之前让 nattable 恢复默认布局
xliffEditor.resetOrder();
if (curSelectionRowId == null) {
curSelectionRowId = splitPointList.get(0);
} else {
int curSelectionRowIndex = xlfHander.getRowIndex(curSelectionRowId);
for (String curRowId : splitPointList) {
int pointRowIndex = xlfHander.getRowIndex(curRowId);
if (pointRowIndex > curSelectionRowIndex) {
curSelectionRowId = curRowId;
xliffEditor.jumpToRow(curSelectionRowId);
break;
}
}
}
}
}
return null;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class SplitXliffHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
final String navegatorID = "net.heartsome.cat.common.ui.navigator.view";
final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
final Shell shell = window.getShell();
IFile selectFile = null;
XLIFFEditorImplWithNatTable xliffEditor = null;
List<Integer> splitXlfPointsIndex = new LinkedList<Integer>();
List<String> splitXlfPointsRowId = new LinkedList<String>();
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
// 如果是导航视图,那么就获取导航视图中选中的文件
if (activePart instanceof IViewPart) {
if (navegatorID.equals(activePart.getSite().getId())) {
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(navegatorID);
ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
Object object = structuredSelection.getFirstElement();
if (object instanceof IFile) {
selectFile = (IFile) object;
String fileExtension = selectFile.getFileExtension();
// 如果后缀名不是xlf,那么就退出操作
if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
return null;
}
FileEditorInput fileInput = new FileEditorInput(selectFile);
IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
IEditorPart editorPart = null;
if (editorRefer.length >= 1) {
editorPart = editorRefer[0].getEditor(true);
xliffEditor = (XLIFFEditorImplWithNatTable) editorPart;
if (window.getActivePage().getActiveEditor() != editorPart) {
window.getActivePage().activate(editorPart);
}
} else {
try {
xliffEditor = (XLIFFEditorImplWithNatTable) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
} catch (PartInitException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
return null;
}
}
}
} else if (activePart instanceof IEditorPart) {
if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
selectFile = ((FileEditorInput) xliffEditor.getEditorInput()).getFile();
}
}
// 根据每个tu节点的rowId获取其具体的位置,才好进行排序
Map<Integer, String> pointIndexRowIdMap = new HashMap<Integer, String>();
for (String rowId : xliffEditor.getSplitXliffPoints()) {
// 获取指定tu节点所处其他结点的序列号
int tuPostion = xliffEditor.getXLFHandler().getTUPositionByRowId(rowId);
if (tuPostion >= 1) {
splitXlfPointsIndex.add(tuPostion);
pointIndexRowIdMap.put(tuPostion, rowId);
}
}
if (splitXlfPointsIndex.size() <= 0) {
MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg2"));
return null;
}
// 对切割点集合进行排序
for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
int point1 = splitXlfPointsIndex.get(i);
for (int j = i + 1; j < splitXlfPointsIndex.size(); j++) {
int point2 = splitXlfPointsIndex.get(j);
if (point1 > point2) {
splitXlfPointsIndex.set(i, point2);
splitXlfPointsIndex.set(j, point1);
point1 = point2;
}
}
}
// 向存储rowId的list存放数据,这样的话,所存储的rowId就是经过排序了的。
for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
splitXlfPointsRowId.add(pointIndexRowIdMap.get(splitXlfPointsIndex.get(i)));
}
SplitOrMergeXlfModel model = new SplitOrMergeXlfModel();
model.setSplitFile(selectFile);
model.setSplitXlfPointsIndex(splitXlfPointsIndex);
model.setSplitXlfPointsRowId(splitXlfPointsRowId);
model.setXliffEditor(xliffEditor);
model.setShell(shell);
SplitXliffWizard wizard = new SplitXliffWizard(model);
final TSWizardDialog dialog = new NattableWizardDialog(shell, wizard);
dialog.open();
return null;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class LockRepeatedSegmentHandler method lockTU.
/**
* 概据内部匹配结果,锁定文本段。
* @param xlfHandler
* @param rowIdMap
*/
private void lockTU(final XLFHandler xlfHandler, Map<String, List<String>> rowIdMap) {
Iterator<Entry<String, List<String>>> it = rowIdMap.entrySet().iterator();
while (it.hasNext()) {
isLocked = false;
final Entry<String, List<String>> rowIdsEntry = it.next();
final String fileLC = rowIdsEntry.getKey();
// 查看该文件是否打开,若打开,则获editor的handler,若未打开,则直接使用当前handler
final IEditorInput input = new FileEditorInput(ResourceUtils.fileToIFile(fileLC));
final IEditorReference[] editorRefes = window.getActivePage().getEditorReferences();
Display.getDefault().syncExec(new Runnable() {
public void run() {
for (int i = 0; i < editorRefes.length; i++) {
if (XLIFF_EDITOR_ID.equals(editorRefes[i].getId())) {
// 先判断打开单个文件的情况
XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) (editorRefes[i].getEditor(true));
if (!nattable.isMultiFile()) {
if (nattable.getEditorInput().equals(input)) {
nattable.getXLFHandler().lockTransUnits(rowIdsEntry.getValue(), true);
isLocked = true;
nattable.getTable().redraw();
}
} else {
// 这是合并打开的情况
if (nattable.getMultiFileList().indexOf(new File(fileLC)) >= 0) {
nattable.getXLFHandler().lockTransUnits(rowIdsEntry.getValue(), true);
isLocked = true;
nattable.getTable().redraw();
}
;
}
}
}
// 如果未被锁定(当前文件没有打开),就调用当前XLFHandler去锁定所有文本段
if (!isLocked) {
xlfHandler.lockTransUnits(rowIdsEntry.getValue(), true);
}
}
});
}
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class FindReplaceDialog method doFind.
private boolean doFind() {
CellRegion cellRegion;
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (editor == null) {
return false;
}
if (forwardButton.getSelection()) {
if (editor.isHorizontalLayout()) {
cellRegion = find(0, 0);
} else {
// 解决在垂直布局查找 Source 时,如果 Source 没有匹配而 Target 有匹配,会找到 Target 中的匹配文本
if (sourceButton.getSelection()) {
cellRegion = find(0, 0);
} else {
cellRegion = find(1, 0);
}
}
} else {
NatTable natTable = editor.getTable();
int sourceRowPosition = natTable.getRowCount() - 1;
int row = LayerUtil.getLowerLayerRowPosition(natTable, sourceRowPosition, SelectionLayer.class);
if (!editor.isHorizontalLayout()) {
row *= VerticalNatTableConfig.ROW_SPAN;
if (!sourceButton.getSelection()) {
row++;
}
}
cellRegion = find(row, -1);
}
replaceButton.setEnabled(!sourceButton.getSelection() && cellRegion != null);
if (cellRegion == null) {
refreshMsgAndTable();
}
return cellRegion != null;
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class FindReplaceDialog method createRangePanel.
/**
* 范围面板
* @param composite
* @return ;
*/
private Composite createRangePanel(Composite composite) {
final Composite row = new Composite(composite, SWT.NONE);
row.setLayout(new GridLayout(2, true));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(row);
final Group directionGroup = new Group(row, SWT.SHADOW_ETCHED_IN);
directionGroup.setText(Messages.getString("dialog.FindReplaceDialog.directionGroup"));
directionGroup.setLayout(new GridLayout(1, true));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(directionGroup);
forwardButton = new Button(directionGroup, SWT.RADIO);
forwardButton.setText(Messages.getString("dialog.FindReplaceDialog.forwardButton"));
forwardButton.setSelection(true);
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).grab(false, false).applyTo(forwardButton);
backwardButton = new Button(directionGroup, SWT.RADIO);
backwardButton.setText(Messages.getString("dialog.FindReplaceDialog.backwardButton"));
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).grab(false, false).applyTo(backwardButton);
final Group rangeGroup = new Group(row, SWT.SHADOW_ETCHED_IN);
rangeGroup.setText(Messages.getString("dialog.FindReplaceDialog.rangeGroup"));
rangeGroup.setLayout(new GridLayout(1, true));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(rangeGroup);
/** 搜索范围:源语言 */
sourceButton = new Button(rangeGroup, SWT.RADIO);
sourceButton.setText(Messages.getString("dialog.FindReplaceDialog.sourceButton"));
sourceButton.setSelection(true);
sourceButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (editor != null) {
replaceButton.setEnabled(false);
replaceAllButton.setEnabled(false);
}
}
});
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).grab(false, false).applyTo(sourceButton);
targetButton = new Button(rangeGroup, SWT.RADIO);
targetButton.setText(Messages.getString("dialog.FindReplaceDialog.targetButton"));
targetButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (editor != null) {
boolean enabled = cmbFind.getText().length() > 0;
replaceAllButton.setEnabled(enabled);
}
}
});
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).grab(false, false).applyTo(targetButton);
return row;
}
Aggregations