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);
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class FindReplaceDialog method doFindNext.
/**
* 查找下一个 ;
* @return
*/
private boolean doFindNext() {
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (editor == null) {
return false;
}
int[] selectedRows = editor.getSelectedRows();
int startingRowPosition;
if (selectedRows.length > 0) {
Arrays.sort(selectedRows);
if (forwardButton.getSelection()) {
// 从当前选中行中最大的行开始找。
startingRowPosition = selectedRows[selectedRows.length - 1];
} else {
// 从当前选中行中最大的行开始找。
startingRowPosition = selectedRows[0];
}
if (!editor.isHorizontalLayout()) {
startingRowPosition *= VerticalNatTableConfig.ROW_SPAN;
if (!sourceButton.getSelection()) {
startingRowPosition++;
}
}
int startOffset;
CellRegion cellRegion = ActiveCellRegion.getActiveCellRegion();
if (cellRegion == null || cellRegion.getPositionCoordinate().getRowPosition() != startingRowPosition) {
// 起始行不一致
if (forwardButton.getSelection()) {
startOffset = 0;
} else {
startOffset = -1;
}
} else {
PositionCoordinate coordinate = cellRegion.getPositionCoordinate();
// 得到上次查找的列
int columnIndex = coordinate.getLayer().getColumnIndexByPosition(coordinate.getColumnPosition());
if (columnIndex != (sourceButton.getSelection() ? editor.getSrcColumnIndex() : editor.getTgtColumnIndex())) {
// 如果所查找的列改变了,赋为初始值
if (forwardButton.getSelection()) {
startOffset = 0;
} else {
startOffset = -1;
}
} else {
if (forwardButton.getSelection()) {
startOffset = cellRegion.getRegion().getOffset() + cellRegion.getRegion().getLength();
} else {
startOffset = cellRegion.getRegion().getOffset() - 1;
if (startOffset == -1) {
// 解决在垂直布局时,选择向后查找在查找到某一行后会返回到最后一行继续查找的问题。
if (editor.isHorizontalLayout()) {
startingRowPosition--;
} else {
startingRowPosition -= 2;
}
}
}
}
}
cellRegion = find(startingRowPosition, startOffset);
replaceButton.setEnabled(!sourceButton.getSelection() && cellRegion != null);
if (cellRegion == null) {
refreshMsgAndTable();
}
return cellRegion != null;
} else {
return doFind();
}
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class FindReplaceDialog method doReplaceAll.
/**
* 替换全部 ;
*/
private void doReplaceAll() {
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (editor == null) {
return;
}
CellRegion cellRegion = null;
if (editor.isHorizontalLayout()) {
cellRegion = find(0, 0);
} else {
cellRegion = find(1, 0);
}
if (cellRegion == null) {
// 无查找结果
return;
}
boolean forward = forwardButton.getSelection();
if (!forward) {
forwardButton.setSelection(true);
}
int firstRowPosition = cellRegion.getPositionCoordinate().getRowPosition();
HashMap<String, String> segments = new HashMap<String, String>();
int count = 0;
String findStr = cmbFind.getText();
String replaceStr = cmbReplace.getText();
do {
PositionCoordinate coordinate = cellRegion.getPositionCoordinate();
int rowPosition = coordinate.rowPosition;
int columnPosition = coordinate.columnPosition;
int rowIndex = coordinate.getLayer().getRowIndexByPosition(rowPosition);
if (!editor.isHorizontalLayout()) {
rowIndex = rowIndex / VerticalNatTableConfig.ROW_SPAN;
}
// 判断锁定
TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
String translate = transUnit.getTuProps().get("translate");
if (translate != null && "no".equalsIgnoreCase(translate)) {
rowPosition++;
cellRegion = find(rowPosition, 0);
continue;
}
String cellValue = (String) coordinate.getLayer().getDataValueByPosition(columnPosition, rowPosition);
StringBuffer cellValueBf = new StringBuffer(cellValue);
int start = cellValue.toUpperCase().indexOf(findStr.toUpperCase());
while (start != -1) {
cellValueBf.replace(start, start + findStr.length(), replaceStr);
start = cellValueBf.indexOf(findStr, start);
count++;
}
segments.put(editor.getXLFHandler().getRowId(rowIndex), cellValueBf.toString());
rowPosition++;
if (!editor.isHorizontalLayout()) {
rowPosition++;
}
cellRegion = find(rowPosition, 0);
} while (cellRegion.getPositionCoordinate().getRowPosition() != firstRowPosition);
if (!forward) {
forwardButton.setSelection(false);
backwardButton.setSelection(true);
}
int columnIndex = 0;
if (sourceButton.getSelection()) {
columnIndex = editor.getSrcColumnIndex();
} else {
columnIndex = editor.getTgtColumnIndex();
}
try {
editor.updateSegments(segments, columnIndex, null, null);
} catch (ExecutionException e) {
LOGGER.error(Messages.getString("dialog.FindReplaceDialog.logger1"), e);
}
String msg = Messages.getString("dialog.FindReplaceDialog.status3");
statusLabel.setText(MessageFormat.format(msg, count));
ActiveCellRegion.setActiveCellRegion(null);
}
use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable in project translationstudio8 by heartsome.
the class NotSendToTMHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof XLIFFEditorImplWithNatTable) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
if (selectedRowIds != null && selectedRowIds.size() > 0) {
boolean isSendtoTm = true;
XLFHandler handler = xliffEditor.getXLFHandler();
for (String rowId : selectedRowIds) {
if (!handler.isSendToTM(rowId) && isSendtoTm) {
isSendtoTm = false;
break;
}
}
NattableUtil util = NattableUtil.getInstance(xliffEditor);
util.changeSendToTmState(selectedRowIds, isSendtoTm ? "yes" : "no");
}
}
return null;
}
Aggregations