Search in sources :

Example 1 with MergeXliffWizard

use of net.heartsome.cat.ts.handlexlf.wizard.MergeXliffWizard in project translationstudio8 by heartsome.

the class MergeXliffHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    final Shell shell = window.getShell();
    ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
        if (structuredSelection.size() < 2) {
            MessageDialog.openInformation(shell, Messages.getString("handler.MergeXliffHandler.msgTitle1"), Messages.getString("handler.MergeXliffHandler.msg1"));
            return null;
        }
        Vector<IFile> seleFiles = new Vector<IFile>();
        String notXlfFile = "";
        @SuppressWarnings("rawtypes") Iterator selectIt = structuredSelection.iterator();
        while (selectIt.hasNext()) {
            Object object = selectIt.next();
            if (object instanceof IFile) {
                IFile selectFile = (IFile) object;
                String fileExtension = selectFile.getFileExtension();
                // 如果后缀名不是xlf,那么就进行提示
                if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
                    notXlfFile += selectFile.getFullPath().toOSString() + ",";
                }
                seleFiles.add(selectFile);
            }
        }
        if (notXlfFile.length() > 0) {
            notXlfFile = notXlfFile.substring(0, notXlfFile.length() - 1);
            boolean isSure = MessageDialog.openConfirm(shell, Messages.getString("handler.MergeXliffHandler.msgTitle2"), MessageFormat.format(Messages.getString("handler.MergeXliffHandler.msg2"), new Object[] { notXlfFile }));
            if (!isSure) {
                return null;
            }
        }
        List<IFile> lstFiles = new ArrayList<IFile>();
        XLFValidator.resetFlag();
        for (IFile iFile : seleFiles) {
            if (!XLFValidator.validateXliffFile(iFile)) {
                lstFiles.add(iFile);
            }
        }
        XLFValidator.resetFlag();
        seleFiles.removeAll(lstFiles);
        if (seleFiles.size() == 0) {
            return null;
        }
        if (seleFiles.size() > 0) {
            String projectPath = seleFiles.get(0).getProject().getFullPath().toOSString();
            for (int i = 1; i < seleFiles.size(); i++) {
                if (!projectPath.equals(seleFiles.get(i).getProject().getFullPath().toOSString())) {
                    MessageDialog.openInformation(shell, Messages.getString("handler.MergeXliffHandler.msgTitle1"), Messages.getString("handler.MergeXliffHandler.msg3"));
                    return null;
                }
            }
            SplitOrMergeXlfModel model = new SplitOrMergeXlfModel();
            model.setMergeXliffFile(seleFiles);
            MergeXliffWizard wizard = new MergeXliffWizard(model);
            TSWizardDialog dialog = new NattableWizardDialog(shell, wizard);
            dialog.open();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) SplitOrMergeXlfModel(net.heartsome.cat.ts.handlexlf.split.SplitOrMergeXlfModel) NattableWizardDialog(net.heartsome.cat.ts.handlexlf.wizard.NattableWizardDialog) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Shell(org.eclipse.swt.widgets.Shell) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) Vector(java.util.Vector) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) MergeXliffWizard(net.heartsome.cat.ts.handlexlf.wizard.MergeXliffWizard)

Aggregations

ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 TSWizardDialog (net.heartsome.cat.common.ui.wizard.TSWizardDialog)1 SplitOrMergeXlfModel (net.heartsome.cat.ts.handlexlf.split.SplitOrMergeXlfModel)1 MergeXliffWizard (net.heartsome.cat.ts.handlexlf.wizard.MergeXliffWizard)1 NattableWizardDialog (net.heartsome.cat.ts.handlexlf.wizard.NattableWizardDialog)1 IFile (org.eclipse.core.resources.IFile)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Shell (org.eclipse.swt.widgets.Shell)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1