Search in sources :

Example 1 with ConversionConfigBean

use of net.heartsome.cat.convert.ui.model.ConversionConfigBean in project translationstudio8 by heartsome.

the class PreviewTranslationHandler method getConverterViewModel.

/**
	 * 得到 ConverterViewModel 对象
	 * @param file
	 *            需要预览翻译的文件
	 * @return
	 * @throws ExecutionException
	 *             ;
	 */
private ConverterViewModel getConverterViewModel(IFile file) throws ExecutionException {
    Object adapter = Platform.getAdapterManager().getAdapter(file, IConversionItem.class);
    if (adapter instanceof IConversionItem) {
        IConversionItem item = (IConversionItem) adapter;
        ConverterViewModel converterViewModel = new ConverterViewModel(Activator.getContext(), // 逆向转换
        Converter.DIRECTION_REVERSE);
        converterViewModel.setConversionItem(item);
        try {
            ConversionResource resource = new ConversionResource(Converter.DIRECTION_REVERSE, item);
            String xliffpath = resource.getXliffPath();
            String targetPath = resource.getPreviewPath();
            ConversionConfigBean configBean = converterViewModel.getConfigBean();
            configBean.setSource(xliffpath);
            configBean.setTarget(targetPath);
            configBean.setTargetEncoding("UTF-8");
            // 设为预览翻译模式
            configBean.setPreviewMode(true);
            final IStatus status = converterViewModel.validateXliffFile(ConverterUtil.toLocalPath(xliffpath), new XLFHandler(), // 注:验证的过程中,会为文件类型和骨架文件的路径赋值。
            null);
            if (status != null && status.isOK()) {
                return converterViewModel;
            } else {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        MessageDialog.openInformation(shell, Messages.getString("handler.PreviewTranslationHandler.msgTitle"), status.getMessage());
                    }
                });
                throw new ExecutionException(status.getMessage(), status.getException());
            }
        } catch (CoreException e) {
            throw new ExecutionException(e.getMessage(), e);
        }
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) ConversionResource(net.heartsome.cat.convert.ui.utils.ConversionResource) ExecutionException(org.eclipse.core.commands.ExecutionException) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 2 with ConversionConfigBean

use of net.heartsome.cat.convert.ui.model.ConversionConfigBean in project translationstudio8 by heartsome.

the class ConversionWizardPage method createConversionOptionsGroup.

/**
	 * 转换选项组
	 * @param contents
	 *            ;
	 */
private void createConversionOptionsGroup(Composite contents) {
    Group options = new Group(contents, SWT.NONE);
    //$NON-NLS-1$
    options.setText(Messages.getString("wizard.ConversionWizardPage.options"));
    options.setLayout(new GridLayout(1, false));
    options.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    /* 如果已经存在,是否要替换 */
    final Button btnReplaceTarget = new Button(options, SWT.CHECK);
    //$NON-NLS-1$
    btnReplaceTarget.setText(Messages.getString("wizard.ConversionWizardPage.btnReplaceTarget"));
    btnReplaceTarget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    btnReplaceTarget.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            isReplaceTarget = btnReplaceTarget.getSelection();
            for (ConversionConfigBean conversionConfigBean : conversionConfigBeans) {
                conversionConfigBean.setReplaceTarget(btnReplaceTarget.getSelection());
            }
            validate();
        }
    });
    final Button btnOpenPreTrans = new Button(options, SWT.CHECK);
    btnOpenPreTrans.setText(Messages.getString("wizard.ConversionWizardPage.btnOpenPreTrans"));
    btnOpenPreTrans.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    btnOpenPreTrans.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            isOpenPreTrans = btnOpenPreTrans.getSelection();
        }
    });
    Composite composite = new Composite(options, SWT.NONE);
    GridLayout gd = new GridLayout(1, false);
    gd.marginWidth = 0;
    gd.marginHeight = 0;
    composite.setLayout(gd);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    Label tgtLangLbl = new Label(composite, SWT.NONE);
    tgtLangLbl.setText(Messages.getString("wizard.ConversionWizardPage.tgtLangLbl"));
    tgtLangViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    Table tgtLangTable = tgtLangViewer.getTable();
    GridData gdTgtLangTable = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gdTgtLangTable.heightHint = 80;
    tgtLangTable.setLayoutData(gdTgtLangTable);
    tgtLangViewer.setLabelProvider(new LanguageLabelProvider());
    tgtLangViewer.setContentProvider(new ArrayContentProvider());
    tgtLangViewer.setInput(conversionConfigBeans.get(0).getTgtLangList());
    tgtLangViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            @SuppressWarnings("unchecked") List<Language> selectedList = sel.toList();
            for (ConversionConfigBean conversionConfigBean : conversionConfigBeans) {
                conversionConfigBean.setHasSelTgtLangList(selectedList);
            }
            validate();
        }
    });
    tgtLangViewer.getTable().select(0);
    IDialogSettings dialogSettings = Activator.getDefault().getDialogSettings();
    btnReplaceTarget.setSelection(dialogSettings.getBoolean(REPLACE_TARGET));
    btnOpenPreTrans.setSelection(dialogSettings.getBoolean(OPEN_PRE_TRANS));
    this.isOpenPreTrans = btnOpenPreTrans.getSelection();
    isReplaceTarget = btnReplaceTarget.getSelection();
    for (ConversionConfigBean conversionConfigBean : conversionConfigBeans) {
        conversionConfigBean.setReplaceTarget(isReplaceTarget);
    }
    validate();
}
Also used : Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) LanguageLabelProvider(net.heartsome.cat.ts.ui.composite.LanguageLabelProvider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) WritableList(org.eclipse.core.databinding.observable.list.WritableList) List(java.util.List) ArrayList(java.util.ArrayList) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 3 with ConversionConfigBean

use of net.heartsome.cat.convert.ui.model.ConversionConfigBean in project translationstudio8 by heartsome.

the class ConversionWizardPage method bindValue.

/**
	 * 对 UI 和 View Model 进行绑定 ;
	 */
private void bindValue() {
    DataBindingContext dbc = new DataBindingContext();
    WizardPageSupport.create(this, dbc);
    ConversionConfigBean configBean = conversionConfigBeans.get(0);
    // bind the format
    //$NON-NLS-1$
    dbc.bindList(SWTObservables.observeItems(formatCombo), BeansObservables.observeList(configBean, "fileFormats"));
    // final IObservableValue format = BeansObservables.observeValue(selectedModel, "selectedType");
    // dbc.bindValue(SWTObservables.observeSelection(formatCombo), format);
    // bind the source encoding
    //$NON-NLS-1$
    dbc.bindList(SWTObservables.observeItems(srcEncCombo), BeansObservables.observeList(configBean, "pageEncoding"));
}
Also used : ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) DataBindingContext(org.eclipse.core.databinding.DataBindingContext)

Example 4 with ConversionConfigBean

use of net.heartsome.cat.convert.ui.model.ConversionConfigBean in project translationstudio8 by heartsome.

the class ConversionWizardPage method validate.

private void validate() {
    if (conversionConfigBeans.size() == 0) {
        setPageComplete(false);
        return;
    }
    ConversionConfigBean cb = conversionConfigBeans.get(0);
    if (cb.getHasSelTgtLangList() == null || cb.getHasSelTgtLangList().size() == 0) {
        setPageComplete(false);
        setErrorMessage(Messages.getString("wizard.ConversionWizardPage.msg1"));
        return;
    }
    IStatus result = Status.OK_STATUS;
    int line = 1;
    for (ConverterViewModel converterViewModel : converterViewModels) {
        result = converterViewModel.validate();
        if (!result.isOK()) {
            break;
        }
        line++;
    }
    if (!result.isOK()) {
        filesTable.setSelection(line - 1);
        filesTable.notifyListeners(SWT.Selection, null);
        setPageComplete(false);
        setErrorMessage(MessageFormat.format(Messages.getString("wizard.ConversionWizardPage.msg2"), line) + result.getMessage());
    } else {
        setErrorMessage(null);
        setPageComplete(true);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel)

Example 5 with ConversionConfigBean

use of net.heartsome.cat.convert.ui.model.ConversionConfigBean in project translationstudio8 by heartsome.

the class ReverseConversionWizardPage method bindValue.

/**
	 * 对 UI 和 View Model 进行绑定 ;
	 */
private void bindValue() {
    DataBindingContext dbc = new DataBindingContext();
    WizardPageSupport.create(this, dbc);
    ConversionConfigBean configBean = conversionConfigBeans.get(0);
    // bind the target encoding
    //$NON-NLS-1$
    dbc.bindList(SWTObservables.observeItems(tgtEncCombo), BeansObservables.observeList(configBean, "pageEncoding"));
}
Also used : ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) DataBindingContext(org.eclipse.core.databinding.DataBindingContext)

Aggregations

ConversionConfigBean (net.heartsome.cat.convert.ui.model.ConversionConfigBean)13 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 GridData (org.eclipse.swt.layout.GridData)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Group (org.eclipse.swt.widgets.Group)5 ConverterViewModel (net.heartsome.cat.convert.ui.model.ConverterViewModel)4 IConversionItem (net.heartsome.cat.convert.ui.model.IConversionItem)4 CoreException (org.eclipse.core.runtime.CoreException)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Button (org.eclipse.swt.widgets.Button)4 Label (org.eclipse.swt.widgets.Label)4 ArrayList (java.util.ArrayList)3 ConversionResource (net.heartsome.cat.convert.ui.utils.ConversionResource)3 ISelection (org.eclipse.jface.viewers.ISelection)3 Iterator (java.util.Iterator)2 List (java.util.List)2 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)2 WritableList (org.eclipse.core.databinding.observable.list.WritableList)2 IStatus (org.eclipse.core.runtime.IStatus)2