Search in sources :

Example 1 with ColProperties

use of net.heartsome.cat.ts.ui.plugin.ColProperties in project translationstudio8 by heartsome.

the class ColumnTypeDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    tparent.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).hint(750, 400).grab(true, true).applyTo(tparent);
    ScrolledComposite cmpScrolled = new ScrolledComposite(tparent, SWT.V_SCROLL);
    cmpScrolled.setAlwaysShowScrollBars(false);
    cmpScrolled.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
    cmpScrolled.setExpandHorizontal(true);
    cmpScrolled.setShowFocusedControl(true);
    Composite cmpContent = new Composite(cmpScrolled, SWT.None);
    cmpScrolled.setContent(cmpContent);
    cmpContent.setLayout(new GridLayout(5, false));
    arrCmbLangs = new Combo[size];
    arrCmbPropsName = new Combo[size];
    arrCmbPropsType = new Combo[size];
    arrCmbPropsLevel = new Combo[size];
    new Label(cmpContent, SWT.None).setText(Messages.getString("dialog.ColumnTypeDialog.column1"));
    new Label(cmpContent, SWT.None).setText(Messages.getString("dialog.ColumnTypeDialog.column2"));
    new Label(cmpContent, SWT.None).setText(Messages.getString("dialog.ColumnTypeDialog.column3"));
    new Label(cmpContent, SWT.None).setText(Messages.getString("dialog.ColumnTypeDialog.column4"));
    new Label(cmpContent, SWT.None).setText(Messages.getString("dialog.ColumnTypeDialog.column5"));
    for (int i = 0; i < size; i++) {
        ColProperties type = colTypes.get(i);
        new Label(cmpContent, SWT.None).setText(type.getColName() + " : ");
        arrCmbPropsLevel[i] = new Combo(cmpContent, SWT.READ_ONLY);
        arrCmbPropsLevel[i].setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
        arrCmbPropsName[i] = new Combo(cmpContent, SWT.READ_ONLY);
        GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
        data.widthHint = 120;
        arrCmbPropsName[i].setLayoutData(data);
        arrCmbPropsType[i] = new Combo(cmpContent, SWT.READ_ONLY);
        data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
        data.widthHint = 150;
        arrCmbPropsType[i].setLayoutData(data);
        arrCmbLangs[i] = new Combo(cmpContent, SWT.READ_ONLY);
        arrCmbLangs[i].setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
        arrCmbPropsLevel[i].setItems(levelValues);
        arrCmbPropsLevel[i].select(0);
        String propLevel = type.getLevel();
        if (!propLevel.equals("")) {
            //$NON-NLS-1$
            arrCmbPropsLevel[i].setText(propLevel);
            if (propLevel.equals(ColProperties.conceptLevel)) {
                arrCmbLangs[i].setEnabled(false);
                arrCmbPropsName[i].setItems(conceptPropValues);
                arrCmbPropsName[i].select(0);
                arrCmbPropsType[i].setItems(conceptPropTypeValues);
                arrCmbPropsType[i].select(0);
            }
            if (propLevel.equals(ColProperties.langLevel)) {
                arrCmbLangs[i].setEnabled(true);
                arrCmbPropsName[i].setItems(TranslationPropValues);
                arrCmbPropsName[i].select(0);
                arrCmbPropsType[i].setItems(termDescripPropTypeValues);
                arrCmbPropsType[i].select(0);
            }
        }
        // fixed a bug 2339 by John.
        String propName = type.getPropName();
        if (!propName.equals("")) {
            //$NON-NLS-1$
            arrCmbPropsName[i].setText(propName);
        }
        // Update content for Prop Type combo
        String propType = type.getPropType();
        if (!propType.equals("")) {
            //$NON-NLS-1$
            arrCmbPropsType[i].setText(propType);
        }
        if (!propLevel.equals("")) {
            //$NON-NLS-1$
            if (propLevel.equals(ColProperties.conceptLevel)) {
                arrCmbPropsType[i].setEnabled(propName.equals(ColProperties.descripName));
                arrCmbPropsType[i].setItems(conceptPropTypeValues);
                arrCmbPropsType[i].select(0);
            }
            if (propLevel.equals(ColProperties.langLevel)) {
                arrCmbPropsType[i].setEnabled(!propName.equals(ColProperties.termName));
                if (propName.equals(ColProperties.descripName)) {
                    arrCmbPropsType[i].setItems(termDescripPropTypeValues);
                } else {
                    arrCmbPropsType[i].setItems(termTermNotePropTypeValues);
                }
                arrCmbPropsType[i].select(0);
            }
        }
        // Update content for Language Combo
        arrCmbLangs[i].setItems(LocaleService.getLanguages());
        arrCmbLangs[i].select(0);
        String lang = type.getLanguage();
        if (!lang.equals("")) {
            //$NON-NLS-1$
            arrCmbLangs[i].setText(LocaleService.getLanguage(lang));
        }
        final int idx = i;
        arrCmbPropsName[idx].addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                String level = arrCmbPropsLevel[idx].getText();
                String name = arrCmbPropsName[idx].getText();
                if (name.equals(ColProperties.termName)) {
                    arrCmbPropsType[idx].setEnabled(false);
                    arrCmbPropsType[idx].setItems(conceptPropTypeValues);
                    arrCmbPropsType[idx].select(0);
                    return;
                }
                if (name.equals(ColProperties.termNoteName)) {
                    arrCmbPropsType[idx].setEnabled(true);
                    arrCmbPropsType[idx].setItems(termTermNotePropTypeValues);
                    arrCmbPropsType[idx].select(0);
                    return;
                }
                if (name.equals(ColProperties.noteName)) {
                    arrCmbLangs[idx].setEnabled(false);
                    arrCmbPropsType[idx].setEnabled(false);
                    return;
                }
                if (name.equals(ColProperties.descripName)) {
                    arrCmbPropsType[idx].setEnabled(true);
                    if (level.equals(ColProperties.conceptLevel)) {
                        arrCmbPropsType[idx].setItems(conceptPropTypeValues);
                    } else {
                        arrCmbPropsType[idx].setItems(termDescripPropTypeValues);
                    }
                    arrCmbPropsType[idx].select(0);
                    return;
                }
                arrCmbPropsType[idx].setEnabled(false);
            }
        });
        arrCmbPropsLevel[idx].addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                String level = arrCmbPropsLevel[idx].getText();
                String name = arrCmbPropsName[idx].getText();
                if (level.equals(ColProperties.conceptLevel)) {
                    arrCmbLangs[idx].setEnabled(false);
                    arrCmbPropsName[idx].setItems(conceptPropValues);
                    arrCmbPropsName[idx].select(0);
                    arrCmbPropsType[idx].setEnabled(true);
                    arrCmbPropsType[idx].setItems(conceptPropTypeValues);
                    arrCmbPropsType[idx].select(0);
                }
                if (level.equals(ColProperties.langLevel)) {
                    arrCmbLangs[idx].setEnabled(true);
                    arrCmbPropsName[idx].setItems(TranslationPropValues);
                    arrCmbPropsName[idx].select(0);
                    arrCmbPropsType[idx].setEnabled(false);
                    if (name.equals(ColProperties.descripName)) {
                        arrCmbPropsType[idx].setItems(termDescripPropTypeValues);
                    } else {
                        arrCmbPropsType[idx].setItems(termTermNotePropTypeValues);
                    }
                    arrCmbPropsType[idx].select(0);
                }
            }
        });
    }
    cmpContent.setSize(cmpContent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    return tparent;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Combo(org.eclipse.swt.widgets.Combo) ColProperties(net.heartsome.cat.ts.ui.plugin.ColProperties)

Example 2 with ColProperties

use of net.heartsome.cat.ts.ui.plugin.ColProperties in project translationstudio8 by heartsome.

the class TBXMakerDialog method openFile.

/**
	 * 打开 CSV 文件 ;
	 */
private void openFile() {
    String[] templates = TBXTemplateUtil.getTemplateFiles(PluginUtil.getCataloguePath(), PluginUtil.getTemplatePath());
    CSVSettingDialog dialog = new CSVSettingDialog(getShell(), true, imagePath, templates);
    if (dialog.open() == IDialogConstants.OK_ID) {
        csvPath = dialog.getCsvPath();
        colSeparator = dialog.getColSeparator();
        textDelimiter = dialog.getTextDelimiter();
        encoding = dialog.getEncoding();
        lang = dialog.getLang();
        xcsTemplate = dialog.getXcsTemplate();
        try {
            template = new TBXTemplateUtil(xcsTemplate, PluginUtil.getTemplatePath(), "");
            cols = maxColumns();
            if (cols < 2) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialog.TBXMakerDialog.msgTitle"), Messages.getString("dialog.TBXMakerDialog.msg1"));
                return;
            }
            rows = 0;
            int width = (table.getClientArea().width - table.getBorderWidth() * 2 - table.getVerticalBar().getSize().x) / cols;
            if (width < 100) {
                width = 100;
            }
            table.removeAll();
            int count = table.getColumnCount();
            for (int i = 0; i < count; i++) {
                table.getColumn(0).dispose();
            }
            for (int i = 0; i < cols; i++) {
                TableColumn col = new TableColumn(table, SWT.NONE);
                //$NON-NLS-1$
                col.setData(new ColProperties("" + (i + 1)));
                table.getColumn(i).setWidth(width);
                //$NON-NLS-1$
                table.getColumn(i).setText("" + (i + 1));
            }
            fillTable();
            table.layout(true);
            lblRowCount.setText(MessageFormat.format(Messages.getString("dialog.TBXMakerDialog.lblRowCount"), rows));
            lblColCount.setText(MessageFormat.format(Messages.getString("dialog.TBXMakerDialog.lblColCount"), cols));
        } catch (IOException e) {
            LOGGER.error(Messages.getString("dialog.TBXMakerDialog.logger1"), e);
        } catch (Exception e) {
            LOGGER.error(Messages.getString("dialog.TBXMakerDialog.logger1"), e);
        }
    }
}
Also used : TBXTemplateUtil(net.heartsome.cat.ts.ui.plugin.util.TBXTemplateUtil) IOException(java.io.IOException) TableColumn(org.eclipse.swt.widgets.TableColumn) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ColProperties(net.heartsome.cat.ts.ui.plugin.ColProperties)

Example 3 with ColProperties

use of net.heartsome.cat.ts.ui.plugin.ColProperties in project translationstudio8 by heartsome.

the class TBXMakerDialog method setColumnType.

/**
	 * 设置列属性 ;
	 */
private void setColumnType() {
    if (cols < 2) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TBXMakerDialog.msgTitle"), Messages.getString("dialog.TBXMakerDialog.msg2"));
        return;
    }
    Vector<ColProperties> colTypes = new Vector<ColProperties>(cols);
    for (int i = 0; i < cols; i++) {
        colTypes.add((ColProperties) table.getColumn(i).getData());
    }
    ColumnTypeDialog selector = new ColumnTypeDialog(getShell(), colTypes, template, imagePath);
    if (selector.open() == IDialogConstants.OK_ID) {
        for (int i = 0; i < cols; i++) {
            TableColumn col = table.getColumn(i);
            ColProperties type = colTypes.get(i);
            if (!type.getColName().equals("") && !type.getLanguage().equals("")) {
                //$NON-NLS-1$ //$NON-NLS-2$
                col.setText(type.getColName());
            }
        }
    }
}
Also used : Vector(java.util.Vector) TableColumn(org.eclipse.swt.widgets.TableColumn) ColProperties(net.heartsome.cat.ts.ui.plugin.ColProperties)

Example 4 with ColProperties

use of net.heartsome.cat.ts.ui.plugin.ColProperties in project translationstudio8 by heartsome.

the class TBXMakerDialog method getUserLangs.

private String[] getUserLangs() {
    Hashtable<String, String> langTable = new Hashtable<String, String>();
    for (int c = 0; c < cols; c++) {
        ColProperties properties = (ColProperties) table.getColumn(c).getData();
        if (properties.level.equals(ColProperties.langLevel)) {
            //$NON-NLS-1$
            langTable.put(properties.getLanguage(), "");
        }
    }
    String[] result = new String[langTable.size()];
    Enumeration<String> keys = langTable.keys();
    int index = 0;
    while (keys.hasMoreElements()) {
        result[index] = keys.nextElement();
        index++;
    }
    return result;
}
Also used : Hashtable(java.util.Hashtable) ColProperties(net.heartsome.cat.ts.ui.plugin.ColProperties)

Example 5 with ColProperties

use of net.heartsome.cat.ts.ui.plugin.ColProperties in project translationstudio8 by heartsome.

the class TBXMakerDialog method writeLangLevel.

private void writeLangLevel(String lang, TableItem item) throws IOException {
    // Write Term data
    for (int c = 0; c < cols; c++) {
        ColProperties properties = (ColProperties) table.getColumn(c).getData();
        if (properties.getLevel().equals(ColProperties.langLevel) && properties.getPropName().equals(ColProperties.termName) && properties.getLanguage().equals(lang)) {
            String term = item.getText(c);
            //$NON-NLS-1$ //$NON-NLS-2$
            writeString("<term>" + TextUtil.cleanString(term).trim() + "</term>\n");
        }
    }
    writeLangLevelProps(lang, item);
}
Also used : ColProperties(net.heartsome.cat.ts.ui.plugin.ColProperties)

Aggregations

ColProperties (net.heartsome.cat.ts.ui.plugin.ColProperties)6 TableColumn (org.eclipse.swt.widgets.TableColumn)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Hashtable (java.util.Hashtable)1 Vector (java.util.Vector)1 TBXTemplateUtil (net.heartsome.cat.ts.ui.plugin.util.TBXTemplateUtil)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1