use of org.eclipse.ui.IEditorInput in project translationstudio8 by heartsome.
the class XLIFFEditorImplWithNatTable method dispose.
/**
* 释放编辑器,同时释放其他相关资源。
* @see org.eclipse.ui.part.WorkbenchPart#dispose()
*/
public void dispose() {
// 当该编辑器被释放资源时,检查该编辑器是否被保存,并且是否是同时打开多个文件,若成立,则删除合并打开所产生的临时文件--robert 2012-03-30
if (!isStore && isMultiFile()) {
try {
IEditorInput input = getEditorInput();
IProject multiProject = ResourceUtil.getResource(input).getProject();
ResourceUtil.getResource(input).delete(true, null);
multiProject.refreshLocal(IResource.DEPTH_INFINITE, null);
CommonFunction.refreshHistoryWhenDelete(input);
} catch (CoreException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
if (titleImage != null && !titleImage.isDisposed()) {
titleImage.dispose();
titleImage = null;
}
if (table != null && !table.isDisposed()) {
table.dispose();
table = null;
}
if (statusLineImage != null && !statusLineImage.isDisposed()) {
statusLineImage.dispose();
statusLineImage = null;
}
handler = null;
JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
NattableUtil.getInstance(this).releaseResource();
super.dispose();
System.gc();
}
use of org.eclipse.ui.IEditorInput in project translationstudio8 by heartsome.
the class ExportAsTextHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
String elementName = event.getParameter("elementName");
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
Shell shell = activeEditor.getEditorSite().getShell();
if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor;
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。");
}
IEditorInput input = xliffEditor.getEditorInput();
URI uri = null;
if (input instanceof FileEditorInput) {
uri = ((FileEditorInput) input).getURI();
} else if (input instanceof FileStoreEditorInput) {
uri = ((FileStoreEditorInput) input).getURI();
} else {
return null;
}
File xliff = new File(uri);
FileDialog fd = new FileDialog(shell, SWT.SAVE);
String[] names = { "Plain Text Files [*.txt]", "All Files [*.*]" };
//$NON-NLS-1$ //$NON-NLS-2$
String[] extensions = { "*.txt", "*.*" };
fd.setFilterExtensions(extensions);
fd.setFilterNames(names);
//$NON-NLS-1$
fd.setFileName(xliff.getName() + ".txt");
String out = fd.open();
if (out == null) {
return null;
}
XLFHandler handler = xliffEditor.getXLFHandler();
boolean result = handler.saveAsText(xliff.getAbsolutePath(), out, elementName);
if (result) {
IWorkbenchPage page = xliffEditor.getEditorSite().getPage();
OpenEditorUtil.OpenFileWithSystemEditor(page, out);
} else {
MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。");
}
return null;
}
use of org.eclipse.ui.IEditorInput in project translationstudio8 by heartsome.
the class WordsFA method lockRepeatTU.
/**
* 执行锁定重复文本段
*/
private void lockRepeatTU(Map<String, WordsFAResult> wordsFAResultMap) {
final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
// 首先,判断当前所处理的文件是否合并打开
if (model.isMultiFile()) {
if (needLockRowIdList.size() <= 0) {
return;
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IEditorInput input = new FileEditorInput(model.getMultiTempIFile());
IEditorReference[] reference = window.getActivePage().findEditors(input, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
nattble = (XLIFFEditorImplWithNatTable) reference[0].getEditor(true);
XLFHandler thisHandler = nattble.getXLFHandler();
thisHandler.lockFaTU(needLockRowIdList);
nattble.redraw();
}
});
} else {
//针对已经打开的文件进行锁定
if (needLockRowIdList.size() <= 0) {
return;
}
final Map<String, List<String>> rowIdMap = RowIdUtil.groupRowIdByFileName(needLockRowIdList);
for (final IFile iFile : model.getAnalysisIFileList()) {
isOpened = false;
final String filePath = iFile.getLocation().toOSString();
if (rowIdMap.get(filePath) == null || rowIdMap.get(filePath).size() <= 0) {
continue;
}
Display.getDefault().syncExec(new Runnable() {
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IEditorInput input = new FileEditorInput(iFile);
IEditorReference[] reference = window.getActivePage().findEditors(input, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
if (reference.length > 0) {
isOpened = true;
nattble = (XLIFFEditorImplWithNatTable) reference[0].getEditor(true);
XLFHandler thisHandler = nattble.getXLFHandler();
thisHandler.lockFaTU(rowIdMap.get(filePath));
nattble.redraw();
}
}
});
if (!isOpened) {
for (String rowId : rowIdMap.get(filePath)) {
handler.lockedTU(rowId);
}
}
}
}
}
use of org.eclipse.ui.IEditorInput in project translationstudio8 by heartsome.
the class UpdateTMHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
String partId = HandlerUtil.getActivePartId(event);
ArrayList<IFile> lstXliff = new ArrayList<IFile>();
// boolean isShowCurrentLangBtn = true;
if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
// 导航视图处于激活状态
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
// ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
List<?> lstObj = ((IStructuredSelection) selection).toList();
for (Object obj : lstObj) {
if (obj instanceof IFile) {
IFile file = (IFile) obj;
// Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
if (file.getFileExtension() != null && CommonFunction.validXlfExtension(file.getFileExtension())) {
lstXliff.add(file);
}
} else if (obj instanceof IFolder) {
try {
ResourceUtils.getXliffs((IFolder) obj, lstXliff);
} catch (CoreException e) {
LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger1"), e);
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg1"));
}
} else if (obj instanceof IProject) {
try {
ResourceUtils.getXliffs((IProject) obj, lstXliff);
} catch (CoreException e) {
LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger2"), e);
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg2"));
}
}
}
CommonFunction.removeRepeateSelect(lstXliff);
if (lstXliff.size() == 0) {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
return null;
}
Iterator<IFile> iterator = lstXliff.iterator();
while (iterator.hasNext()) {
IFile file = iterator.next();
FileEditorInput editorInput = new FileEditorInput(file);
IEditorPart editorPart = page.findEditor(editorInput);
if (editorPart == null || (editorPart != null && !(editorPart instanceof IXliffEditor))) {
// isShowCurrentLangBtn = false;
break;
}
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
return null;
}
} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
// nattable 处于激活状态
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
IXliffEditor xliffEditor = (IXliffEditor) editor;
if (xliffEditor.isMultiFile()) {
List<String> lstFile = new XLFHandler().getMultiFiles(iFile);
if (lstFile.size() > 0) {
for (String filePath : lstFile) {
lstXliff.add(ResourceUtils.fileToIFile(filePath));
}
}
} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
lstXliff.add(iFile);
}
}
if (lstXliff.size() > 0) {
if (lstXliff.size() > 1) {
String projectPath = lstXliff.get(0).getProject().getFullPath().toOSString();
for (int i = 1; i < lstXliff.size(); i++) {
String projectPath2 = lstXliff.get(i).getProject().getFullPath().toOSString();
if (!projectPath.equals(projectPath2)) {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg4"));
return null;
}
}
}
ArrayList<IFile> lstFiles = new ArrayList<IFile>();
XLFValidator.resetFlag();
for (IFile iFile : lstXliff) {
if (!XLFValidator.validateXliffFile(iFile)) {
lstFiles.add(iFile);
}
}
XLFValidator.resetFlag();
lstXliff.removeAll(lstFiles);
if (lstXliff.size() == 0) {
return null;
}
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(lstXliff.get(0).getProject());
if (projectConfig.getDefaultTMDb() == null) {
MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg5"));
return null;
}
UpdateTMWizard wizard = new UpdateTMWizard(lstXliff);
TSWizardDialog dialog = new UpdateTMWizardDialog(shell, wizard);
// UpdateTMDialog dialog = new UpdateTMDialog(shell, isShowCurrentLangBtn, lstXliff);
dialog.open();
}
return null;
}
use of org.eclipse.ui.IEditorInput in project cubrid-manager by CUBRID.
the class QueryEditorPart method changeQueryEditorPartNameWithShard.
public void changeQueryEditorPartNameWithShard() {
IEditorInput input = getEditorInput();
if (!(input instanceof QueryUnit)) {
return;
}
// [TOOLS-2425]Support shard broker
boolean isShard = false;
QueryUnit queryUnit = (QueryUnit) input;
if (CubridDatabase.hasValidDatabaseInfo(queryUnit.getDatabase())) {
DatabaseInfo dbInfo = queryUnit.getDatabase().getDatabaseInfo();
isShard = dbInfo.isShard();
}
if (isShard) {
String text = null;
if (shardQueryType == DatabaseInfo.SHARD_QUERY_TYPE_ID) {
text = editorTabNameOriginal + "(SHARD_ID:" + shardId + ")";
} else {
text = editorTabNameOriginal + "(SHARD_VAL:" + shardVal + ")";
}
queryUnit.setToolTip(text);
setPartName(text);
}
}
Aggregations