Search in sources :

Example 1 with TBXTemplateUtil

use of net.heartsome.cat.ts.ui.plugin.util.TBXTemplateUtil 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)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ColProperties (net.heartsome.cat.ts.ui.plugin.ColProperties)1 TBXTemplateUtil (net.heartsome.cat.ts.ui.plugin.util.TBXTemplateUtil)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1