use of org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.
the class QAResultViewPart method openMultiFilesEditor.
/**
* 处理合并打开文件 nattable editor的相关问题
* @return ;
*/
public IXliffEditor openMultiFilesEditor() {
IXliffEditor xliffEditor = null;
FileEditorInput fileInput = new FileEditorInput(oper.getCurMultiTempFile());
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 = (IXliffEditor) editorPart;
// 若该文件未激活,激活此文件
if (window.getActivePage().getActiveEditor() != editorPart) {
window.getActivePage().activate(editorPart);
}
// 对于已经打开过的文件,进行重排序
xliffEditor.resetOrder();
} else {
// 如果文件没有打开,那么先打开文件
try {
// 如果保存合并打开所有信息的临时文件已经被删除,那么,重新生成临时文件
if (!oper.getCurMultiTempFile().getLocation().toFile().exists()) {
// 检查这两个文件是否重新进行合并打开了的。
IFile findMultiTempIfile = oper.getMultiFilesTempIFile(true);
if (findMultiTempIfile != null) {
fileInput = new FileEditorInput(findMultiTempIfile);
oper.setCurMultiTempFile(findMultiTempIfile);
} else {
//先验证这些所处理的文件是否有已经被打开的
List<IFile> openedFileList = oper.getOpenedIfile();
if (openedFileList.size() > 0) {
String openFileStr = "";
for (IFile ifile : openedFileList) {
openFileStr += "\t" + ifile.getFullPath().toOSString() + "\n";
}
MessageDialog.openInformation(getSite().getShell(), Messages.getString("views.QAResultViewPart.msgTitle"), MessageFormat.format(Messages.getString("qa.views.QAResultViewPart.addTip1"), openFileStr));
return null;
}
// 如果选中的文件没有合并打开,那么就重新打开它们
IFile multiIFile = oper.createMultiTempFile();
if (multiIFile != null && multiIFile.exists()) {
fileInput = new FileEditorInput(multiIFile);
oper.setCurMultiTempFile(multiIFile);
} else {
MessageDialog.openInformation(getSite().getShell(), Messages.getString("views.QAResultViewPart.msgTitle"), Messages.getString("views.QAResultViewPart.msg1"));
return null;
}
xliffEditor = (IXliffEditor) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
}
}
} catch (PartInitException e) {
e.printStackTrace();
logger.error(Messages.getString("qa.views.QAResultViewPart.log2"), e);
}
}
return xliffEditor;
}
use of org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.
the class MatchViewPart method selectionChanged.
/**
* 监听XLFEditor的选择事件
*/
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
if (part == null || selection == null) {
return;
}
if (!(part instanceof IEditorPart)) {
updateActionState();
return;
}
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
updateActionState();
return;
}
IXliffEditor editor = (IXliffEditor) part;
IStructuredSelection structuredSelecion = (IStructuredSelection) selection;
final Object object = structuredSelecion.getFirstElement();
if (object instanceof Integer) {
int rowIndex = -1;
int selRowIndex = (Integer) object;
if (rowIndex == selRowIndex) {
if (gridTable.getItemCount() != 0) {
updateActionState();
}
return;
} else {
rowIndex = selRowIndex;
}
XLFHandler handler = editor.getXLFHandler();
String rowId = handler.getRowId(rowIndex);
// handler.getTransUnit(rowId);
TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
if (transUnit == null) {
updateActionState();
return;
}
TransUnitInfo2TranslationBean tuInfoBean = getTuInfoBean(transUnit, handler, rowId);
FileEditorInput input = (FileEditorInput) getSite().getPage().getActiveEditor().getEditorInput();
IProject currentProject = input.getFile().getProject();
copyEnable.resetSelection();
gridTable.removeAll();
altTransCacheList.clear();
menuMgr.setEditor(editor);
menuMgr.setRowIndex(rowIndex);
executeMatch(editor, rowId, transUnit, tuInfoBean, currentProject);
}
}
use of org.eclipse.ui.IEditorPart 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 org.eclipse.ui.IEditorPart 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 org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.
the class AddTermToTBHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof IXliffEditor) {
IXliffEditor xliffEditor = (IXliffEditor) editor;
IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
// ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
// List<DatabaseModelBean> lstDatabase = projectConfig.getTermBaseDbs(true);
TbImporter.getInstance().setProject(file.getProject());
if (!TbImporter.getInstance().checkImporter()) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.AddTermToTBHandler.msgTitle"), Messages.getString("handler.AddTermToTBHandler.msg"));
return null;
}
StringBuffer srcTerm = new StringBuffer();
StringBuffer tgtTerm = new StringBuffer();
String srcAllText = xliffEditor.getRowTransUnitBean(xliffEditor.getSelectedRows()[0]).getSrcText();
xliffEditor.getSelectSrcOrTgtPureText(srcTerm, tgtTerm);
AddTermToTBDialog dialog = AddTermToTBDialog.getInstance(editor.getSite().getShell(), srcTerm.toString().trim(), tgtTerm.toString().trim(), AddTermToTBDialog.ADD_TYPE);
dialog.setProject(file.getProject());
dialog.setSrcLang(xliffEditor.getSrcColumnName());
dialog.setTgtLang(xliffEditor.getTgtColumnName());
dialog.setSrcAllText(srcAllText);
dialog.open();
}
return null;
}
Aggregations