use of org.eclipse.core.resources.IContainer in project translationstudio8 by heartsome.
the class OpenMultiXliffHandler method execute.
@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
if (currentSelection.isEmpty() || !(currentSelection instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
Iterator<Object> selectIt = structuredSelection.iterator();
final ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
shell = window.getShell();
// 先验证是否跨项目
IProject selectedProject = null;
while (selectIt.hasNext()) {
Object object = selectIt.next();
if (object instanceof IFile) {
IFile iFile = (IFile) object;
if (!CommonFunction.validXlfExtension(iFile.getFileExtension())) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), MessageFormat.format(Messages.getString("handlers.OpenMultiXliffHandler.msg1"), iFile.getFullPath().toOSString()));
continue;
}
selectIFiles.add(iFile);
if (selectedProject == null) {
selectedProject = iFile.getProject();
} else {
if (selectedProject != iFile.getProject()) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg2"));
return null;
}
}
} else if (object instanceof IContainer) {
IContainer selectContainer = (IContainer) object;
if (selectedProject == null) {
selectedProject = selectContainer.getProject();
}
// 判断当前文件夹是否处于 XLIFF 文件夹下
try {
ResourceUtils.getXliffs(selectContainer, selectIFiles);
} catch (CoreException e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger1"), selectContainer.getFullPath().toOSString(), e);
}
}
}
// 过滤重复选择文件
CommonFunction.removeRepeateSelect(selectIFiles);
if (selectIFiles.size() < 2) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg3"));
return null;
}
MultiFilesOper oper = new MultiFilesOper(selectedProject, selectIFiles);
// 先验证这些文件是否已经合并打开,如果是,则退出
if (oper.validExist()) {
return null;
}
// 判断是否有重复打开的文件,并删除缓存中要合并打开的文件。
if (oper.hasOpenedIFile()) {
if (oper.getSelectIFiles().size() <= 0) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg4"));
return null;
} else {
boolean isResponse = MessageDialog.openConfirm(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle2"), Messages.getString("handlers.OpenMultiXliffHandler.msg5"));
if (isResponse) {
if (oper.getSelectIFiles().size() < 2) {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg6"));
return null;
}
} else {
return null;
}
}
}
final IFile multiIFile = oper.createMultiTempFile();
if (multiIFile != null && multiIFile.exists()) {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.getString("handler.OpenMultiXliffHandler.tip1"), 10);
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 7, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
// 进行判断所选择文件的语言对是否符合标准,先解析文件
final XLFHandler xlfHander = new XLFHandler();
final Map<String, Object> newResultMap = xlfHander.openFiles(ResourceUtils.iFilesToFiles(selectIFiles), subMonitor);
// 针对解析失败
if (newResultMap == null || QAConstant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) newResultMap.get(QAConstant.RETURNVALUE_RESULT)) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), (String) newResultMap.get(Constant.RETURNVALUE_MSG));
}
});
return;
}
// 验证是否有多个语言
boolean hasDiffrentLangPair = false;
Map<String, ArrayList<String>> langMap = xlfHander.getLanguages();
if (langMap.size() > 1) {
hasDiffrentLangPair = true;
} else {
for (Entry<String, ArrayList<String>> entry : langMap.entrySet()) {
if (entry.getValue().size() > 1) {
hasDiffrentLangPair = true;
}
}
}
if (monitor.isCanceled()) {
return;
}
monitor.worked(1);
if (hasDiffrentLangPair) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg7"));
}
});
// 先删除临时文件,再退出
try {
multiIFile.delete(true, monitor);
} catch (CoreException e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
}
return;
}
final boolean[] validateResult = new boolean[] { false };
Display.getDefault().syncExec(new Runnable() {
public void run() {
validateResult[0] = XLFValidator.validateXlifIFiles(selectIFiles);
}
});
if (!validateResult[0]) {
try {
multiIFile.delete(true, monitor);
} catch (CoreException e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
}
return;
}
final FileEditorInput input = new FileEditorInput(multiIFile);
if (monitor.isCanceled()) {
return;
}
monitor.worked(1);
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
// UNDO 这里合并打开时,要考虑传入参数xlfHandler,以防多次解析文件带来的消耗。
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, XLIFF_EDITOR_ID, true);
} catch (PartInitException e) {
e.printStackTrace();
}
}
});
if (monitor.isCanceled()) {
return;
}
monitor.worked(1);
monitor.done();
}
};
try {
new ProgressMonitorDialog(shell).run(true, true, runnable);
} catch (Exception e) {
logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger3"), e);
}
} else {
MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg8"));
return null;
}
return null;
}
use of org.eclipse.core.resources.IContainer in project translationstudio8 by heartsome.
the class FileAnalysis method getAllFolder.
/**
* 获取所有包括分析文件的文件夹(直接包括或间接包括都可)
* @param rootFolder 起始文件夹
* @param allFolderList 承装所有文件夹的集合
*/
public void getAllFolder(IContainer rootFolder, List<IContainer> allFolderList) {
if (allFolderList == null) {
allFolderList = new LinkedList<IContainer>();
}
IResource[] members;
try {
members = rootFolder.members();
for (IResource resource : members) {
if (resource instanceof IContainer) {
boolean faIFilesExsit = false;
//循环判断所有的要分析的文件,检查当前容器下是否包括要分析的文件
for (int fileIndex = 0; fileIndex < model.getAnalysisIFileList().size(); fileIndex++) {
IFile ifile = model.getAnalysisIFileList().get(fileIndex);
IContainer iFileParent = ifile.getParent();
while (iFileParent != null) {
if (iFileParent.equals((IContainer) resource)) {
faIFilesExsit = true;
break;
} else {
iFileParent = iFileParent.getParent();
}
}
//如果当前容器下存在分析的文件,将该容器加载到缓存中,并停止循环其他分析的文件
if (faIFilesExsit) {
allFolderList.add((IContainer) resource);
break;
}
}
getAllFolder((IContainer) resource, allFolderList);
}
}
} catch (CoreException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
use of org.eclipse.core.resources.IContainer in project translationstudio8 by heartsome.
the class SplitXliffWizard method performFinish.
@Override
public boolean performFinish() {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath containerIPath = root.getLocation().append(splitXliffWizardPage.getTargetXlfPathStr());
IContainer splitXlfsContainer = root.getContainerForLocation(containerIPath);
if (!splitXlfsContainer.exists()) {
// 创建该路径
File file = new File(splitXlfsContainer.getLocation().toOSString());
file.mkdirs();
}
model.setSplitXlfsContainer(splitXlfsContainer);
final IRunnableWithProgress splitProgress = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
// uicallback
canFinish = splitXliff.splitTheXliff(monitor);
}
};
try {
getContainer().run(true, true, splitProgress);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
// 创建项目后刷新资源视图
try {
model.getSplitFile().getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
e.printStackTrace();
}
return canFinish;
}
use of org.eclipse.core.resources.IContainer in project mechanoid by robotoworks.
the class ContainerBrowserField method onTextChanged.
@Override
protected void onTextChanged(ModifyEvent e) {
super.onTextChanged(e);
mSelectedPath = Path.fromPortableString(getTextField().getText());
if (mSelectedPath.segmentCount() > 0) {
IPath firstPart = mSelectedPath.uptoSegment(1);
IContainer container = (IContainer) mWorkspaceRoot.findMember(firstPart);
if (container != null && container instanceof IProject) {
mSelectedProject = (IProject) container;
} else {
mSelectedProject = null;
}
}
}
use of org.eclipse.core.resources.IContainer in project flux by eclipse.
the class DownloadProject method createFolder.
private void createFolder(IFolder folder) throws CoreException {
if (!folder.exists()) {
IContainer parent = folder.getParent();
if (parent instanceof IFolder) {
createFolder((IFolder) parent);
}
folder.create(true, true, null);
}
}
Aggregations