Search in sources :

Example 1 with ReverseConversionWizard

use of net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard in project translationstudio8 by heartsome.

the class OpenReverseConversionDialogHandler method execute.

public Object execute(ExecutionEvent event, List<IFile> list) {
    if (list == null || list.size() == 0) {
        MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(event).getShell(), Messages.getString("handler.OpenReverseConversionDialogHandler.msgTitle1"), Messages.getString("handler.OpenReverseConversionDialogHandler.msg1"));
        return null;
    }
    // 首先验证是否是合并打开的文件 --robert	2012-10-17
    System.out.println(list.get(0).getFullPath().toOSString());
    if (isEditor) {
        // 针对合并打开
        if (list.get(0).getFullPath().toOSString().endsWith(".xlp")) {
            List<String> multiFiles = new XLFHandler().getMultiFiles(list.get(0));
            if (multiFiles.size() > 0) {
                list = new ArrayList<IFile>();
            }
            for (String filePath : multiFiles) {
                list.add(ResourceUtils.fileToIFile(filePath));
            }
        }
    }
    List<IFile> lstFiles = new ArrayList<IFile>();
    XLFValidator.resetFlag();
    for (IFile iFile : list) {
        if (!XLFValidator.validateXliffFile(iFile)) {
            lstFiles.add(iFile);
        }
    }
    CommonFunction.removeRepeateSelect(list);
    XLFValidator.resetFlag();
    if (!(list instanceof ArrayList)) {
        list = new ArrayList<IFile>(list);
    }
    list.removeAll(lstFiles);
    if (list.size() == 0) {
        return null;
    }
    ArrayList<ConverterViewModel> converterViewModels = new ArrayList<ConverterViewModel>();
    for (int i = 0; i < list.size(); i++) {
        Object adapter = Platform.getAdapterManager().getAdapter(list.get(i), IConversionItem.class);
        IConversionItem sourceItem = null;
        if (adapter instanceof IConversionItem) {
            sourceItem = (IConversionItem) adapter;
        }
        ConverterViewModel converterViewModel = new ConverterViewModel(Activator.getContext(), Converter.DIRECTION_REVERSE);
        // 记住所选择的文件
        converterViewModel.setConversionItem(sourceItem);
        converterViewModels.add(converterViewModel);
    }
    IProject project = list.get(0).getProject();
    ReverseConversionWizard wizard = new ReverseConversionWizard(converterViewModels, project);
    TSWizardDialog dialog = new TSWizardDialog(shell, wizard) {

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            super.createButtonsForButtonBar(parent);
            getButton(IDialogConstants.FINISH_ID).setText(Messages.getString("handler.OpenConversionDialogHandler.finishLbl"));
        }
    };
    int result = dialog.open();
    if (result == IDialogConstants.OK_ID) {
        final List<ConverterViewModel> models = wizard.getConverterViewModels();
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.setTaskName(Messages.getString("handler.OpenReverseConversionDialogHandler.task1"));
                monitor.beginTask(Messages.getString("handler.OpenReverseConversionDialogHandler.task2"), models.size());
                for (ConverterViewModel converterViewModel : models) {
                    try {
                        IProgressMonitor subMonitor = Progress.getSubMonitor(monitor, 1);
                        subMonitor.setTaskName(Messages.getString("handler.OpenReverseConversionDialogHandler.task3") + converterViewModel.getConversionItem().getLocation().toOSString());
                        converterViewModel.convertWithoutJob(subMonitor);
                    } catch (ConverterException e) {
                        //							Bug #2485:转换文件失败时,提示框显示有问题
                        throw new InvocationTargetException(e, e.getMessage());
                    }
                }
                monitor.done();
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(true, true, runnable);
        } catch (InvocationTargetException e) {
            MessageDialog.openInformation(shell, Messages.getString("handler.OpenReverseConversionDialogHandler.msgTitle2"), e.getMessage());
            LOGGER.error("", e);
        } catch (InterruptedException e) {
            MessageDialog.openInformation(shell, Messages.getString("handler.OpenReverseConversionDialogHandler.msgTitle2"), e.getMessage());
            LOGGER.error("", e);
        }
    }
    return null;
}
Also used : ConverterException(net.heartsome.cat.converter.ConverterException) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ReverseConversionWizard(net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 2 with ReverseConversionWizard

use of net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard in project translationstudio8 by heartsome.

the class ConversionHandler method execute.

/**
	 * the command has been executed, so extract extract the needed information from the application context.
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    String commandId = event.getCommand().getId();
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    if (currentSelection.isEmpty()) {
        return null;
    }
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
        Object object = structuredSelection.getFirstElement();
        // 通过 adapter manager 获得 conversion item
        Object adapter = Platform.getAdapterManager().getAdapter(object, IConversionItem.class);
        if (adapter instanceof IConversionItem) {
            // open the config conversion dialog
            ConverterViewModel converterViewModel = null;
            IConversionItem sourceItem = (IConversionItem) adapter;
            if (commandId.equals("net.heartsome.cat.convert.ui.commands.convertCommand")) {
                converterViewModel = new ConverterViewModel(Activator.getContext(), Converter.DIRECTION_POSITIVE);
                // 记住所选择的文件
                converterViewModel.setConversionItem(sourceItem);
                IWizard wizard = new ConversionWizard(Arrays.asList(converterViewModel), null);
                TSWizardDialog dialog = new ConversionWizardDialog(window.getShell(), wizard);
                int result = dialog.open();
                if (result == IDialogConstants.OK_ID) {
                    converterViewModel.convert();
                }
            } else {
                converterViewModel = new ConverterViewModel(Activator.getContext(), Converter.DIRECTION_REVERSE);
                converterViewModel.setConversionItem(sourceItem);
                IWizard wizard = new ReverseConversionWizard(Arrays.asList(converterViewModel), null);
                TSWizardDialog dialog = new ConversionWizardDialog(window.getShell(), wizard);
                int result = dialog.open();
                if (result == IDialogConstants.OK_ID) {
                    converterViewModel.convert();
                }
            }
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ReverseConversionWizard(net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard) ConversionWizard(net.heartsome.cat.convert.ui.wizard.ConversionWizard) IWizard(org.eclipse.jface.wizard.IWizard) ConversionWizardDialog(net.heartsome.cat.convert.ui.wizard.ConversionWizardDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ReverseConversionWizard(net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard) ISelection(org.eclipse.jface.viewers.ISelection) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog)

Aggregations

TSWizardDialog (net.heartsome.cat.common.ui.wizard.TSWizardDialog)2 ConverterViewModel (net.heartsome.cat.convert.ui.model.ConverterViewModel)2 IConversionItem (net.heartsome.cat.convert.ui.model.IConversionItem)2 ReverseConversionWizard (net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 ConversionWizard (net.heartsome.cat.convert.ui.wizard.ConversionWizard)1 ConversionWizardDialog (net.heartsome.cat.convert.ui.wizard.ConversionWizardDialog)1 ConverterException (net.heartsome.cat.converter.ConverterException)1 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IWizard (org.eclipse.jface.wizard.IWizard)1 Composite (org.eclipse.swt.widgets.Composite)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1