use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class ConcordanceSearchHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
if (!isEnabled()) {
return null;
}
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof IXliffEditor) {
IXliffEditor xliffEditor = (IXliffEditor) editor;
String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
// IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
if (lstDatabase.size() == 0) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.ConcordanceSearchHandler.msgTitle"), Messages.getString("handler.ConcordanceSearchHandler.msg"));
return null;
}
String selectText = xliffEditor.getSelectPureText();
if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
} else if (selectText == null) {
selectText = "";
}
String srcLang = xliffEditor.getSrcColumnName();
String tgtLang = xliffEditor.getTgtColumnName();
ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file, srcLang, tgtLang, selectText.trim());
Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
dialog.open();
if (srcLangL.isBidi() || tgtLangL.isBidi()) {
dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
}
if (selectText != null && !selectText.trim().equals("")) {
dialog.initGroupIdAndSearch();
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
ICommandService commandService = (ICommandService) site.getService(ICommandService.class);
Command command = commandService.getCommand(ActionFactory.COPY.getCommandId());
IEvaluationService evalService = (IEvaluationService) site.getService(IEvaluationService.class);
IEvaluationContext currentState = evalService.getCurrentState();
ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
try {
command.executeWithChecks(executionEvent);
} catch (Exception e1) {
}
}
}
}
return null;
}
use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class DeleteAllSegmentTranslationsHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg3"));
if (res) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
try {
XLFHandler handler = xliffEditor.getXLFHandler();
int count = xliffEditor.getAllRowCount();
int[] selectedRows = new int[count];
for (int i = 0; i < count; i++) {
selectedRows[i] = i;
}
List<Integer> rows = new ArrayList<Integer>();
boolean exitFlag = false;
for (int i = 0; i < selectedRows.length; i++) {
String tgt = handler.getCaseTgtContent(handler.getRowId(selectedRows[i]));
if (null != tgt) {
if (tgt.equals("no")) {
exitFlag = true;
continue;
}
}
rows.add(selectedRows[i]);
}
if (rows.size() != 0) {
int columnIndex = xliffEditor.getTgtColumnIndex();
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
if (cellEditor != null && cellEditor.getColumnIndex() == columnIndex) {
cellEditor.getSegmentViewer().getTextWidget().forceFocus();
}
int[] updateRows = new int[rows.size()];
for (int i = 0; i < rows.size(); i++) {
int ri = rows.get(i);
updateRows[i] = ri;
}
xliffEditor.updateCells(updateRows, columnIndex, "");
if (exitFlag) {
MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg2"));
}
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
return null;
}
use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class DeleteSelectionSegmentTranslationsHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg1"));
if (res) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
try {
XLFHandler handler = xliffEditor.getXLFHandler();
int[] selectedRows = xliffEditor.getSelectedRows();
List<Integer> rows = new ArrayList<Integer>();
boolean exitFlag = false;
for (int i = 0; i < selectedRows.length; i++) {
String tgt = handler.getCaseTgtContent(handler.getRowId(selectedRows[i]));
if (null != tgt) {
if (tgt.equals("no")) {
exitFlag = true;
continue;
}
}
rows.add(selectedRows[i]);
}
if (rows.size() != 0) {
int columnIndex = xliffEditor.getTgtColumnIndex();
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
if (cellEditor != null && cellEditor.getColumnIndex() == columnIndex) {
cellEditor.getSegmentViewer().getTextWidget().forceFocus();
}
int[] updateRows = new int[rows.size()];
for (int i = 0; i < rows.size(); i++) {
int ri = rows.get(i);
updateRows[i] = ri;
}
xliffEditor.updateCells(updateRows, columnIndex, "");
if (exitFlag) {
MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg2"));
}
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
return null;
}
use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class SplitSegmentHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
if (cellEditor == null) {
return null;
}
if (!cellEditor.getCellType().equals(NatTableConstant.SOURCE)) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
return null;
}
int rowIndex = cellEditor.getRowIndex();
// 如果是垂直布局,那么 rowIndex 要除以2 --robert
if (!xliffEditor.isHorizontalLayout()) {
rowIndex = rowIndex / 2;
}
int caretOffset = cellEditor.getRealSplitOffset();
if (caretOffset < 0) {
// 文本框已经关闭时
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
return null;
}
// 不能选择多个字符进行分割
String selText = cellEditor.getSegmentViewer().getTextWidget().getSelectionText();
if (selText.length() != 0) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
return null;
}
XLFHandler handler = xliffEditor.getXLFHandler();
String rowId = handler.getRowId(rowIndex);
/* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 起 */
String tgt = handler.getCaseTgtContent(rowId);
if (null != tgt) {
if (tgt.equals("no")) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg2"));
return null;
}
}
int cellTextLength = ((UpdateDataBean) cellEditor.getCanonicalValue()).getText().length();
if (caretOffset <= 0 || caretOffset >= cellTextLength) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg3"));
return null;
}
/* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 终 */
// 关闭Editor
cellEditor.close();
IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
try {
operationHistory.execute(new SplitSegmentOperation("Split Segment", xliffEditor, handler, rowIndex, caretOffset), null, null);
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
use of org.eclipse.core.commands.ExecutionException in project translationstudio8 by heartsome.
the class UpdateDataAndAutoResizeCommandHandler method doCommand.
@Override
protected boolean doCommand(UpdateDataAndAutoResizeCommand command) {
try {
// int columnPosition = command.getColumnPosition();
// int rowPosition = command.getRowPosition();
// dataLayer.getDataProvider().setDataValue(columnPosition, rowPosition, command.getNewValue());
// dataLayer.fireLayerEvent(new CellVisualChangeEvent(dataLayer, columnPosition, rowPosition));
//
// int currentRow = command.getRowPosition() + 1; // 修改行在当前一屏显示的几行中的相对位置
// table.doCommand(new AutoResizeCurrentRowsCommand(table, new int[] { currentRow },
// table.getConfigRegistry(), new GC(table)));
IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
operationHistory.execute(new UpdateDataOperation(table, dataLayer, command), null, null);
return true;
} catch (UnsupportedOperationException e) {
LOGGER.error(MessageFormat.format(Messages.getString("handler.UpdateDataAndAutoResizeCommandHandler.logger1"), command.getNewValue()), e);
e.printStackTrace(System.err);
System.err.println("Failed to update value to: " + command.getNewValue());
} catch (ExecutionException e) {
LOGGER.error("", e);
e.printStackTrace();
}
return false;
}
Aggregations