Search in sources :

Example 96 with CoreException

use of org.eclipse.core.runtime.CoreException in project translationstudio8 by heartsome.

the class ArchiveFileExportOperation2 method run.

/**
	 * Export the resources that were previously specified for export (or if a single resource was specified then export
	 * it recursively)
	 */
public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException {
    this.monitor = progressMonitor;
    try {
        initialize();
    } catch (IOException e) {
        throw new InvocationTargetException(e, NLS.bind(DataTransferMessages.ZipExport_cannotOpen, e.getMessage()));
    }
    try {
        // ie.- a single resource for recursive export was specified
        int totalWork = IProgressMonitor.UNKNOWN;
        try {
            if (resourcesToExport == null) {
                totalWork = countChildrenOf(resource);
            } else {
                totalWork = countSelectedResources();
            }
        } catch (CoreException e) {
        // Should not happen
        }
        monitor.beginTask(DataTransferMessages.DataTransfer_exportingTitle, totalWork);
        if (resourcesToExport == null) {
            exportResource(resource);
        } else {
            // ie.- a list of specific resources to export was specified
            exportSpecifiedResources();
        }
        try {
            exporter.finished();
        } catch (IOException e) {
            throw new InvocationTargetException(e, NLS.bind(DataTransferMessages.ZipExport_cannotClose, e.getMessage()));
        }
    } finally {
        monitor.done();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 97 with CoreException

use of org.eclipse.core.runtime.CoreException 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();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 98 with CoreException

use of org.eclipse.core.runtime.CoreException in project translationstudio8 by heartsome.

the class MergeXliffWizardPage method createMergeXlfGroup.

public void createMergeXlfGroup(Composite tparent) {
    final Group xliffDataGroup = new Group(tparent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(8, 8).applyTo(xliffDataGroup);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(xliffDataGroup);
    xliffDataGroup.setText(Messages.getString("wizard.MergeXliffWizardPage.xliffDataGroup"));
    tableViewer = new TableViewer(xliffDataGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    final Table table = tableViewer.getTable();
    GridData tableData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
    tableData.heightHint = 50;
    table.setLayoutData(tableData);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    String[] columnNames = new String[] { Messages.getString("wizard.MergeXliffWizardPage.columnNames1"), Messages.getString("wizard.MergeXliffWizardPage.columnNames2") };
    int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
    for (int i = 0; i < columnNames.length; i++) {
        TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
        tableColumn.setText(columnNames[i]);
    }
    tableViewer.setLabelProvider(new TableViewerLabelProvider());
    tableViewer.setContentProvider(new ArrayContentProvider());
    tableViewer.setInput(getSplitTableInfos());
    validXlf();
    // 让列表列宽动态变化
    table.addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event event) {
            final Table table = ((Table) event.widget);
            final TableColumn[] columns = table.getColumns();
            event.widget.getDisplay().syncExec(new Runnable() {

                public void run() {
                    double[] columnWidths = new double[] { 0.15, 0.75 };
                    for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                }
            });
        }
    });
    Composite buttonComp = new Composite(xliffDataGroup, SWT.None);
    GridLayoutFactory.fillDefaults().numColumns(1).margins(8, 8).applyTo(buttonComp);
    GridDataFactory.fillDefaults().grab(false, true).hint(100, SWT.DEFAULT).applyTo(buttonComp);
    Button addbutton = new Button(buttonComp, SWT.NONE);
    addbutton.setText(Messages.getString("wizard.MergeXliffWizardPage.addbutton"));
    addbutton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    addbutton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(xliffDataGroup.getShell(), true, IResource.FILE);
            dialog.setMessage(Messages.getString("wizard.MergeXliffWizardPage.dialogMsg"));
            dialog.setTitle(Messages.getString("wizard.MergeXliffWizardPage.dialogTitle"));
            dialog.setDoubleClickSelects(true);
            try {
                dialog.setInput(EFS.getStore(root.getLocationURI()));
            } catch (CoreException e1) {
                LOGGER.error("", e1);
                e1.printStackTrace();
            }
            dialog.addFilter(new ViewerFilter() {

                @Override
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    if (element instanceof LocalFile) {
                        LocalFile folder = (LocalFile) element;
                        if (folder.getName().equalsIgnoreCase(".hsConfig") || folder.getName().equalsIgnoreCase(".metadata") || folder.getName().equalsIgnoreCase(".config") || folder.getName().equalsIgnoreCase(".nonTransElement")) {
                            return false;
                        }
                        if (projectPath.equals(folder.toString())) {
                            return true;
                        }
                        String xliffFolderPath = folder.toString();
                        String tempPath = projectPath + System.getProperty("file.separator") + ".TEMP";
                        String configPath = projectPath + System.getProperty("file.separator") + ".config";
                        String projectFilePath = projectPath + System.getProperty("file.separator") + ".project";
                        if (xliffFolderPath.startsWith(tempPath) || xliffFolderPath.startsWith(configPath) || xliffFolderPath.startsWith(projectFilePath)) {
                            return false;
                        } else if (xliffFolderPath.startsWith(projectPath)) {
                            return xliffFolderPath.substring(projectPath.length()).startsWith(System.getProperty("file.separator"));
                        }
                    }
                    return false;
                }
            });
            dialog.create();
            dialog.open();
            if (dialog.getResult() != null) {
                Object[] selectFiles = dialog.getResult();
                XLFValidator.resetFlag();
                for (int i = 0; i < selectFiles.length; i++) {
                    IFile iFile = root.getFileForLocation(Path.fromOSString(selectFiles[i].toString()));
                    if (XLFValidator.validateXliffFile(iFile)) {
                        // 如果该文件已经存在于列表中,就向添加到重复集合中
                        if (model.getMergeXliffFile().indexOf(iFile) >= 0) {
                            exsistFileList.add(iFile);
                        }
                        model.getMergeXliffFile().add(iFile);
                    }
                }
                XLFValidator.resetFlag();
                tableViewer.setInput(getSplitTableInfos());
                if (!validIsRepeate()) {
                    validXlf();
                }
            //					for (int i = 0; i < selectFiles.length; i++) {
            //						IFile file = root.getFileForLocation(Path.fromOSString(selectFiles[i].toString()));
            //						// 如果该文件已经存在于列表中,就向添加到重复集合中
            //						if (model.getMergeXliffFile().indexOf(file) >= 0) {
            //							exsistFileList.add(file);
            //						}
            //						model.getMergeXliffFile().add(file);
            //					}
            //					tableViewer.setInput(getSplitTableInfos());
            //					if (!validIsRepeate()) {
            //						validXlf();
            //					}
            }
        }
    });
    Button deleteButton = new Button(buttonComp, SWT.NONE);
    deleteButton.setText(Messages.getString("wizard.MergeXliffWizardPage.deleteButton"));
    deleteButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    deleteButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            ISelection selection = tableViewer.getSelection();
            Table table = tableViewer.getTable();
            if (selection != null && !selection.isEmpty()) {
                int[] indices = table.getSelectionIndices();
                for (int index : indices) {
                    String fileFullPath = table.getItem(index).getText(1);
                    for (int i = 0; i < model.getMergeXliffFile().size(); i++) {
                        if (model.getMergeXliffFile().get(i).getFullPath().toOSString().equals(fileFullPath)) {
                            model.getMergeXliffFile().remove(i);
                            break;
                        }
                    }
                    // 如果该文件存在于重复集合中,则从该集合中删除
                    for (int j = 0; j < exsistFileList.size(); j++) {
                        if (exsistFileList.get(j).getFullPath().toOSString().equals(fileFullPath)) {
                            exsistFileList.remove(j);
                            break;
                        }
                    }
                }
                tableViewer.setInput(getSplitTableInfos());
            }
            if (!validIsRepeate()) {
                validXlf();
            }
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) Listener(org.eclipse.swt.widgets.Listener) IFile(org.eclipse.core.resources.IFile) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) FileFolderSelectionDialog(net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableColumn(org.eclipse.swt.widgets.TableColumn) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) CoreException(org.eclipse.core.runtime.CoreException) TableViewerLabelProvider(net.heartsome.cat.ts.handlexlf.split.TableViewerLabelProvider) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 99 with CoreException

use of org.eclipse.core.runtime.CoreException 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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 100 with CoreException

use of org.eclipse.core.runtime.CoreException in project translationstudio8 by heartsome.

the class PreMachineTransUitls method executeTranslation.

public static void executeTranslation(List<IFile> list, final Shell shell) {
    HsMultiActiveCellEditor.commit(true);
    try {
        if (list.size() == 0) {
            MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg1"));
            return;
        }
        List<IFile> lstFiles = new ArrayList<IFile>();
        XLFValidator.resetFlag();
        for (IFile iFile : list) {
            if (!XLFValidator.validateXliffFile(iFile)) {
                lstFiles.add(iFile);
            }
        }
        XLFValidator.resetFlag();
        list = new ArrayList<IFile>(list);
        list.removeAll(lstFiles);
        if (list.size() == 0) {
            return;
        }
        final IProject project = list.get(0).getProject();
        final List<String> filesWithOsPath = ResourceUtils.IFilesToOsPath(list);
        final XLFHandler xlfHandler = new XLFHandler();
        Map<String, Object> resultMap = xlfHandler.openFiles(filesWithOsPath);
        if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
            // 打开文件失败。			
            MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg2"));
            return;
        }
        Map<String, List<XliffBean>> map = xlfHandler.getXliffInfo();
        final PreMachineTransParameters parameters = new PreMachineTransParameters();
        PreMachineTranslationDialog dialog = new PreMachineTranslationDialog(shell, map, parameters);
        if (dialog.open() == Window.OK) {
            if (project == null) {
                MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg3"));
                return;
            }
            if (filesWithOsPath == null || filesWithOsPath.size() == 0) {
                MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg4"));
                return;
            }
            final List<IFile> lstFile = list;
            IRunnableWithProgress runnable = new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    PreMachineTranslation pt = new PreMachineTranslation(xlfHandler, filesWithOsPath, project, parameters);
                    try {
                        final List<PreMachineTranslationCounter> result = pt.executeTranslation(monitor);
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                            //PreMachineTranslationResultDialog dialog = new PreMachineTranslationResultDialog(shell, result);
                            //dialog.open();
                            }
                        });
                        project.refreshLocal(IResource.DEPTH_INFINITE, null);
                        result.clear();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (CoreException e) {
                        logger.error("", e);
                        e.printStackTrace();
                    } finally {
                        pt.clearResources();
                    }
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                            for (IFile file : lstFile) {
                                FileEditorInput editorInput = new FileEditorInput(file);
                                IEditorPart editorPart = page.findEditor(editorInput);
                                // 选择所有语言
                                XLFHandler handler = null;
                                if (editorPart != null && editorPart instanceof IXliffEditor) {
                                    // xliff 文件已用 XLIFF 编辑器打开
                                    IXliffEditor xliffEditor = (IXliffEditor) editorPart;
                                    handler = xliffEditor.getXLFHandler();
                                    handler.resetCache();
                                    VTDGen vg = new VTDGen();
                                    String path = ResourceUtils.iFileToOSPath(file);
                                    if (vg.parseFile(path, true)) {
                                        handler.getVnMap().put(path, vg.getNav());
                                        xliffEditor.refresh();
                                    }
                                }
                            }
                        }
                    });
                }
            };
            try {
                new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
                MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.result.msg"));
            } catch (InvocationTargetException e) {
                logger.error("", e);
            } catch (InterruptedException e) {
                logger.error("", e);
            }
        }
    } finally {
        HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) PreMachineTransParameters(net.heartsome.cat.ts.machinetranslation.bean.PreMachineTransParameters) PreMachineTranslationDialog(net.heartsome.cat.ts.machinetranslation.dialog.PreMachineTranslationDialog) ArrayList(java.util.ArrayList) List(java.util.List) PreMachineTranslationCounter(net.heartsome.cat.ts.machinetranslation.bean.PreMachineTranslationCounter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) VTDGen(com.ximpleware.VTDGen) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)569 IStatus (org.eclipse.core.runtime.IStatus)127 Status (org.eclipse.core.runtime.Status)124 IFile (org.eclipse.core.resources.IFile)119 IOException (java.io.IOException)96 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)93 IProject (org.eclipse.core.resources.IProject)90 IResource (org.eclipse.core.resources.IResource)84 ArrayList (java.util.ArrayList)71 InvocationTargetException (java.lang.reflect.InvocationTargetException)63 IPath (org.eclipse.core.runtime.IPath)63 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)60 File (java.io.File)56 IFolder (org.eclipse.core.resources.IFolder)45 InputStream (java.io.InputStream)42 IWorkspace (org.eclipse.core.resources.IWorkspace)40 PersistenceException (org.talend.commons.exception.PersistenceException)39 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)37 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)36 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)34