use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.
the class LockRepeatedSegmentHandler method lockTMSegment.
private LockTMSegment lockTMSegment(final List<IFile> iFileList, boolean isLockTM100Segment, boolean isLockTM101Segment, IProgressMonitor monitor) {
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, iFileList.size(), SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask("", 10);
subMonitor.setTaskName(Messages.getString("translation.LockRepeatedSegmentHandler.task2"));
XLFHandler xlfHandler = null;
singleNattable = null;
Display.getDefault().syncExec(new Runnable() {
public void run() {
IEditorReference[] editorRefer = window.getActivePage().findEditors(new FileEditorInput(iFileList.get(0)), XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
if (editorRefer.length > 0) {
singleNattable = ((XLIFFEditorImplWithNatTable) editorRefer[0].getEditor(true));
}
}
});
if (singleNattable != null) {
xlfHandler = singleNattable.getXLFHandler();
}
if (xlfHandler == null) {
xlfHandler = new XLFHandler();
for (final IFile iFile : iFileList) {
File file = iFile.getLocation().toFile();
try {
Map<String, Object> resultMap = xlfHandler.openFile(file);
if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
// 打开文件失败。
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, Messages.getString("translation.LockRepeatedSegmentHandler.msgTitle"), MessageFormat.format(Messages.getString("translation.LockRepeatedSegmentHandler.msg2"), iFile.getLocation().toOSString()));
}
});
list.remove(iFile);
return null;
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
if (!monitorWork(monitor, 1)) {
return null;
}
}
} else {
subMonitor.worked(1);
}
List<String> filesPath = ResourceUtils.IFilesToOsPath(iFileList);
LockTMSegment lts = new LockTMSegment(xlfHandler, tmMatcher, filesPath, curProject);
lts.setLockedContextMatch(isLockTM101Segment);
lts.setLockedFullMatch(isLockTM100Segment);
// 查记忆库并锁定,占剩下的 9/10。
SubProgressMonitor subSubMonitor = new SubProgressMonitor(subMonitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
if (!lts.executeTranslation(subSubMonitor)) {
isCancel = true;
subSubMonitor.done();
subMonitor.done();
return null;
}
subSubMonitor.done();
subMonitor.done();
if (singleNattable != null) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
singleNattable.getTable().redraw();
}
});
}
Map<String, List<String>> needLockRowIdMap = lts.getNeedLockRowIdMap();
if (needLockRowIdMap.size() > 0) {
lockTU(xlfHandler, needLockRowIdMap);
}
return lts;
}
use of org.eclipse.ui.part.FileEditorInput 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 org.eclipse.ui.part.FileEditorInput in project Malai by arnobl.
the class ActionModelWizard method performFinish.
/**
* Do the work after everything is specified.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean performFinish() {
try {
// Remember the file.
//
final IFile modelFile = getModelFile();
// Do the work within an operation.
//
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor progressMonitor) {
try {
// Create a resource set
//
ResourceSet resourceSet = new ResourceSetImpl();
// Get the URI of the model file.
//
URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
// Create a resource for this file.
//
Resource resource = resourceSet.createResource(fileURI);
// Add the initial model object to the contents.
//
EObject rootObject = createInitialModel();
if (rootObject != null) {
resource.getContents().add(rootObject);
}
// Save the contents of the resource to the file system.
//
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
resource.save(options);
} catch (Exception exception) {
ActionEditorPlugin.INSTANCE.log(exception);
} finally {
progressMonitor.done();
}
}
};
getContainer().run(false, false, operation);
// Select the new file resource in the current view.
//
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
final IWorkbenchPart activePart = page.getActivePart();
if (activePart instanceof ISetSelectionTarget) {
final ISelection targetSelection = new StructuredSelection(modelFile);
getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
((ISetSelectionTarget) activePart).selectReveal(targetSelection);
}
});
}
//
try {
page.openEditor(new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
} catch (PartInitException exception) {
MessageDialog.openError(workbenchWindow.getShell(), ActionEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
return false;
}
return true;
} catch (Exception exception) {
ActionEditorPlugin.INSTANCE.log(exception);
return false;
}
}
use of org.eclipse.ui.part.FileEditorInput in project Malai by arnobl.
the class EventModelWizard method performFinish.
/**
* Do the work after everything is specified.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean performFinish() {
try {
// Remember the file.
//
final IFile modelFile = getModelFile();
// Do the work within an operation.
//
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor progressMonitor) {
try {
// Create a resource set
//
ResourceSet resourceSet = new ResourceSetImpl();
// Get the URI of the model file.
//
URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
// Create a resource for this file.
//
Resource resource = resourceSet.createResource(fileURI);
// Add the initial model object to the contents.
//
EObject rootObject = createInitialModel();
if (rootObject != null) {
resource.getContents().add(rootObject);
}
// Save the contents of the resource to the file system.
//
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
resource.save(options);
} catch (Exception exception) {
MalaiEventEditorPlugin.INSTANCE.log(exception);
} finally {
progressMonitor.done();
}
}
};
getContainer().run(false, false, operation);
// Select the new file resource in the current view.
//
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
final IWorkbenchPart activePart = page.getActivePart();
if (activePart instanceof ISetSelectionTarget) {
final ISelection targetSelection = new StructuredSelection(modelFile);
getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
((ISetSelectionTarget) activePart).selectReveal(targetSelection);
}
});
}
//
try {
page.openEditor(new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
} catch (PartInitException exception) {
MessageDialog.openError(workbenchWindow.getShell(), MalaiEventEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
return false;
}
return true;
} catch (Exception exception) {
MalaiEventEditorPlugin.INSTANCE.log(exception);
return false;
}
}
use of org.eclipse.ui.part.FileEditorInput in project Malai by arnobl.
the class InteractionEditor method doSaveAs.
/**
* This also changes the editor's input.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void doSaveAs() {
SaveAsDialog saveAsDialog = new SaveAsDialog(getSite().getShell());
saveAsDialog.open();
IPath path = saveAsDialog.getResult();
if (path != null) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
if (file != null) {
doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString(), true), new FileEditorInput(file));
}
}
}
Aggregations