Search in sources :

Example 6 with ConversionConfigBean

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

the class ReverseConversionWizardPage method initData.

/**
	 * 初始化本页面需要的数据 ;
	 */
private void initData() {
    ReverseConversionWizard wizard = (ReverseConversionWizard) getWizard();
    converterViewModels = wizard.getConverterViewModels();
    conversionConfigBeans = new ArrayList<ConversionConfigBean>();
    for (ConverterViewModel converterViewModel : converterViewModels) {
        IConversionItem conversionItem = converterViewModel.getConversionItem();
        String xliff = ResourceUtils.toWorkspacePath(conversionItem.getLocation());
        ConversionConfigBean bean = converterViewModel.getConfigBean();
        bean.setSource(xliff);
        conversionConfigBeans.add(bean);
    }
}
Also used : ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem)

Example 7 with ConversionConfigBean

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

the class ConversionWizardPage method createSegmentationGroup.

/**
	 * 创建分段规则选择组
	 * @param contents
	 *            ;
	 */
private void createSegmentationGroup(Composite contents) {
    Group segmentation = new Group(contents, SWT.NONE);
    //$NON-NLS-1$
    segmentation.setText(Messages.getString("wizard.ConversionWizardPage.segmentation"));
    segmentation.setLayout(new GridLayout(3, false));
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = 500;
    segmentation.setLayoutData(data);
    Label segLabel = new Label(segmentation, SWT.NONE);
    //$NON-NLS-1$
    segLabel.setText(Messages.getString("wizard.ConversionWizardPage.segLabel"));
    srxFile = new Text(segmentation, SWT.BORDER | SWT.READ_ONLY);
    srxFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    srxFile.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            for (ConversionConfigBean conversionConfigBean : conversionConfigBeans) {
                conversionConfigBean.setInitSegmenter(srxFile.getText());
            }
            validate();
        }
    });
    final Button segBrowse = new Button(segmentation, SWT.PUSH);
    //$NON-NLS-1$
    segBrowse.setText(Messages.getString("wizard.ConversionWizardPage.segBrowse"));
    segBrowse.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            IConversionItemDialog conversionItemDialog = FileDialogFactoryFacade.createFileDialog(getShell(), SWT.NONE);
            int result = conversionItemDialog.open();
            if (result == IDialogConstants.OK_ID) {
                IConversionItem conversionItem = conversionItemDialog.getConversionItem();
                srxFile.setText(conversionItem.getLocation().toOSString());
            }
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IConversionItemDialog(net.heartsome.cat.convert.ui.dialog.IConversionItemDialog) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem)

Example 8 with ConversionConfigBean

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

the class ConversionWizardPage method createFilesGroup.

/**
	 * 创建文件列表区域
	 * @param contents
	 *            ;
	 */
private Composite createFilesGroup(Composite contents) {
    Composite filesComposite = new Composite(contents, SWT.NONE);
    GridLayout gd = new GridLayout(2, false);
    gd.marginWidth = 0;
    filesComposite.setLayout(gd);
    filesComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    filesTable = new Table(filesComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    GridData tableData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
    tableData.heightHint = 100;
    filesTable.setLayoutData(tableData);
    filesTable.setLinesVisible(true);
    filesTable.setHeaderVisible(true);
    filesTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doSelectedEvent();
        }
    });
    tableViewer = new TableViewer(filesTable);
    lineNumColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    lineNumColumn.setText(Messages.getString("wizard.ConversionWizardPage.lineNumColumn"));
    sourceColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    sourceColumn.setText(Messages.getString("wizard.ConversionWizardPage.sourceColumn"));
    formatColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    formatColumn.setText(Messages.getString("wizard.ConversionWizardPage.formatColumn"));
    srcEncColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    srcEncColumn.setText(Messages.getString("wizard.ConversionWizardPage.srcEncColumn"));
    IValueProperty[] valueProperties = BeanProperties.values(ConversionConfigBean.class, new String[] { "index", "source", "fileType", "srcEncoding" });
    ViewerSupport.bind(tableViewer, new WritableList(conversionConfigBeans, ConversionConfigBean.class), valueProperties);
    filesComposite.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent arg0) {
            int width = filesTable.getClientArea().width;
            lineNumColumn.setWidth(width * 1 / 10);
            sourceColumn.setWidth(width * 5 / 10);
            formatColumn.setWidth(width * 3 / 10);
            srcEncColumn.setWidth(width * 1 / 10);
        }
    });
    Composite opComp = new Composite(filesComposite, SWT.NONE);
    GridLayout opCompGl = new GridLayout();
    opCompGl.marginWidth = 0;
    opCompGl.marginLeft = 0;
    opCompGl.marginTop = 0;
    opCompGl.marginHeight = 0;
    opComp.setLayout(opCompGl);
    GridData gd_opComp = new GridData();
    gd_opComp.verticalAlignment = SWT.TOP;
    opComp.setLayoutData(gd_opComp);
    Button addBt = new Button(opComp, SWT.NONE);
    addBt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    addBt.setText(Messages.getString("wizard.ConversionWizardPage.addbutton"));
    addBt.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(getShell(), true, IResource.FILE) {

                // 打开对话框时展开树形目录
                public void create() {
                    super.create();
                    super.getTreeViewer().expandAll();
                }
            };
            dialog.setMessage(Messages.getString("wizard.ConversionWizardPage.selectfiledialog.message"));
            dialog.setTitle(Messages.getString("wizard.ConversionWizardPage.selectfiledialog.title"));
            dialog.setDoubleClickSelects(true);
            try {
                dialog.setInput(EFS.getStore(ResourcesPlugin.getWorkspace().getRoot().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")) {
                            return false;
                        }
                        String projectPath = currentProject.getLocation().toOSString();
                        if (projectPath.equals(folder.toString())) {
                            return true;
                        }
                        String xliffFolderPath = folder.toString();
                        String path1 = projectPath + File.separator + Constant.FOLDER_SRC;
                        if (xliffFolderPath.startsWith(path1)) {
                            for (ConversionConfigBean bean : conversionConfigBeans) {
                                if (xliffFolderPath.indexOf(bean.getSource()) != -1) {
                                    return false;
                                }
                            }
                            return true;
                        }
                    }
                    return false;
                }
            });
            dialog.create();
            dialog.open();
            if (dialog.getResult() != null) {
                Object[] selectFiles = dialog.getResult();
                for (Object selectedFile : selectFiles) {
                    LocalFile folder = (LocalFile) selectedFile;
                    ConverterViewModel model = new ConverterViewModel(Activator.getContext(), Converter.DIRECTION_POSITIVE);
                    Object adapter = Platform.getAdapterManager().getAdapter(ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(Path.fromOSString(folder.toString())), IConversionItem.class);
                    IConversionItem sourceItem = null;
                    if (adapter instanceof IConversionItem) {
                        sourceItem = (IConversionItem) adapter;
                    }
                    // 记住所选择的文件
                    model.setConversionItem(sourceItem);
                    ConversionConfigBean bean = model.getConfigBean();
                    // 初始化源文件路径
                    bean.setSource(ResourceUtils.toWorkspacePath(folder.toString()));
                    // 初始化源语言
                    bean.setSrcLang(srcLang);
                    bean.setTgtLangList(targetlanguage);
                    if (targetlanguage != null && targetlanguage.size() > 0) {
                        List<Language> lang = new ArrayList<Language>();
                        lang.add(targetlanguage.get(0));
                        bean.setHasSelTgtLangList(lang);
                    }
                    bean.setReplaceTarget(isReplaceTarget);
                    bean.setInitSegmenter(srxFile.getText());
                    conversionConfigBeans.add(bean);
                    converterViewModels.add(model);
                }
                loadFiles();
                validate();
                tableViewer.refresh();
            }
        }
    });
    Button removeBt = new Button(opComp, SWT.NONE);
    removeBt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    removeBt.setText(Messages.getString("wizard.ConversionWizardPage.removebutton"));
    removeBt.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (conversionConfigBeans.size() == 0) {
                return;
            }
            ISelection sel = tableViewer.getSelection();
            if (sel.isEmpty()) {
                MessageDialog.openError(getShell(), Messages.getString("wizard.ConversionWizardPage.removebutton.msg1.title"), Messages.getString("wizard.ConversionWizardPage.removebutton.msg1"));
                return;
            }
            if (sel instanceof IStructuredSelection) {
                IStructuredSelection ssel = (IStructuredSelection) sel;
                Object[] objs = ssel.toArray();
                int index = conversionConfigBeans.indexOf(ssel.getFirstElement());
                index -= ssel.size();
                index = index < 0 ? 0 : index;
                for (Object obj : objs) {
                    int i = conversionConfigBeans.indexOf(obj);
                    conversionConfigBeans.remove(i);
                    converterViewModels.remove(i);
                }
                loadFiles();
                tableViewer.refresh();
                if (!conversionConfigBeans.isEmpty()) {
                    tableViewer.getTable().select(index);
                    doSelectedEvent();
                }
                validate();
            }
        }
    });
    return filesComposite;
}
Also used : ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Language(net.heartsome.cat.common.locale.Language) ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) WritableList(org.eclipse.core.databinding.observable.list.WritableList) List(java.util.List) ArrayList(java.util.ArrayList) IValueProperty(org.eclipse.core.databinding.property.value.IValueProperty) FileFolderSelectionDialog(net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Table(org.eclipse.swt.widgets.Table) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) CoreException(org.eclipse.core.runtime.CoreException) WritableList(org.eclipse.core.databinding.observable.list.WritableList) GridData(org.eclipse.swt.layout.GridData) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) TableViewer(org.eclipse.jface.viewers.TableViewer) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem)

Example 9 with ConversionConfigBean

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

the class ConversionWizardPage method loadFiles.

/**
	 * 加载文件数据。
	 */
private void loadFiles() {
    for (int i = 0; i < conversionConfigBeans.size(); i++) {
        ConversionConfigBean bean = conversionConfigBeans.get(i);
        bean.setIndex((i + 1) + "");
        String source = bean.getSource();
        String sourceLocalPath = ConverterUtil.toLocalPath(source);
        // 自动识别文件类型
        String format = FileFormatUtils.detectFormat(sourceLocalPath);
        if (format == null) {
            //$NON-NLS-1$
            format = "";
        }
        // 自动分析源文件编码
        String srcEncValue = EncodingResolver.getEncoding(sourceLocalPath, format);
        if (srcEncValue == null) {
            //$NON-NLS-1$
            srcEncValue = "";
        }
        bean.setEmbedSkl(FileFormatUtils.canEmbedSkl(format));
        // XLIFF 文件路径
        //$NON-NLS-1$
        String xliff = "";
        // 骨架文件路径
        //$NON-NLS-1$
        String skeleton = "";
        //XLiff 文件夹
        String xliffDir = "";
        try {
            ConversionResource resource = new ConversionResource(Converter.DIRECTION_POSITIVE, sourceLocalPath);
            xliff = resource.getXliffPath();
            skeleton = resource.getSkeletonPath();
            xliffDir = resource.getXliffDir();
        } catch (CoreException e) {
            LOGGER.error("", e);
        }
        if (!"".equals(format)) {
            //$NON-NLS-1$
            String name = getSelectedFormat(format);
            if (name != null && !"".equals(name)) {
                //$NON-NLS-1$
                // 添加类型
                converterViewModels.get(i).setSelectedType(name);
            }
        }
        bean.setFileType(format);
        bean.setSrcEncoding(srcEncValue);
        bean.setXliffDir(xliffDir);
        bean.setTarget(xliff);
        bean.setSkeleton(ConverterUtil.toLocalPath(skeleton));
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) ConversionResource(net.heartsome.cat.convert.ui.utils.ConversionResource)

Example 10 with ConversionConfigBean

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

the class ConversionWizardPage method createPropertiesGroup.

private void createPropertiesGroup(Composite contents) {
    Group langComposite = new Group(contents, SWT.NONE);
    //$NON-NLS-1$
    langComposite.setText(Messages.getString("wizard.ConversionWizardPage.langComposite"));
    langComposite.setLayout(new GridLayout(2, false));
    langComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label formatLabel = new Label(langComposite, SWT.NONE);
    //$NON-NLS-1$
    formatLabel.setText(Messages.getString("wizard.ConversionWizardPage.formatLabel"));
    formatCombo = new Combo(langComposite, SWT.READ_ONLY | SWT.DROP_DOWN);
    formatCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    formatCombo.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("unchecked")
        public void widgetSelected(SelectionEvent arg0) {
            ISelection selection = tableViewer.getSelection();
            if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                Iterator<ConversionConfigBean> iter = structuredSelection.iterator();
                while (iter.hasNext()) {
                    ConversionConfigBean bean = iter.next();
                    bean.setFileType(formatCombo.getText());
                }
                // 得到选中的文件类型
                String format = getSelectedFormat(formatCombo.getText());
                int[] indices = filesTable.getSelectionIndices();
                for (int index : indices) {
                    converterViewModels.get(index).setSelectedType(format);
                    String sourcePath = converterViewModels.get(index).getConversionItem().getLocation().toOSString();
                    String sourceLocalPath = ConverterUtil.toLocalPath(sourcePath);
                    String srcEncValue = EncodingResolver.getEncoding(sourceLocalPath, formatCombo.getText());
                    if (srcEncValue != null) {
                        conversionConfigBeans.get(index).setSrcEncoding(srcEncValue);
                    }
                }
                validate();
            }
        }
    });
    Label srcEncLabel = new Label(langComposite, SWT.NONE);
    //$NON-NLS-1$
    srcEncLabel.setText(Messages.getString("wizard.ConversionWizardPage.srcEncLabel"));
    srcEncCombo = new Combo(langComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    srcEncCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    srcEncCombo.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("unchecked")
        public void widgetSelected(SelectionEvent arg0) {
            ISelection selection = tableViewer.getSelection();
            if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                Iterator<ConversionConfigBean> iter = structuredSelection.iterator();
                while (iter.hasNext()) {
                    ConversionConfigBean bean = iter.next();
                    bean.setSrcEncoding(srcEncCombo.getText());
                }
                validate();
            }
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator)

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