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;
}
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();
}
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"));
}
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);
}
}
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"));
}
Aggregations