Search in sources :

Example 16 with TableColumn

use of org.eclipse.swt.widgets.TableColumn 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 17 with TableColumn

use of org.eclipse.swt.widgets.TableColumn in project translationstudio8 by heartsome.

the class JavaPropertiesViewerDialog method createTableViewer.

private void createTableViewer(Composite tparent) {
    tableViewer = new TableViewer(tparent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    table = tableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(table);
    String[] columnNames = new String[] { Messages.getString("dialog.JavaPropertiesViewerDialog.columnNames1"), Messages.getString("dialog.JavaPropertiesViewerDialog.columnNames2") };
    int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
    for (int i = 0; i < columnNames.length; i++) {
        TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
        tableColumn.setText(columnNames[i]);
        tableColumn.setWidth(50);
    }
    tableViewer.setLabelProvider(new TableViewerLabelProvider());
    tableViewer.setContentProvider(new ArrayContentProvider());
    // 让列表列宽动态变化
    table.addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event event) {
            final Table table = ((Table) event.widget);
            final TableColumn[] columns = table.getColumns();
            event.widget.getDisplay().syncExec(new Runnable() {

                public void run() {
                    double[] columnWidths = new double[] { 0.48, 0.48 };
                    for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                }
            });
        }
    });
}
Also used : Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) Table(org.eclipse.swt.widgets.Table) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerLabelProvider(net.heartsome.cat.ts.ui.plugin.TableViewerLabelProvider) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 18 with TableColumn

use of org.eclipse.swt.widgets.TableColumn in project translationstudio8 by heartsome.

the class CSV2TMXConverterDialog method removeColumn.

/**
	 * 删除列 ;
	 */
private void removeColumn() {
    if (cols < 2) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.CSV2TMXConverterDialog.msgTitle"), Messages.getString("dialog.CSV2TMXConverterDialog.msg2"));
        return;
    }
    Vector<String> columns = new Vector<String>();
    int count = table.getColumnCount();
    for (int i = 0; i < count; i++) {
        columns.add(table.getColumn(i).getText());
    }
    ColumnRemoveDialog removeDialog = new ColumnRemoveDialog(getShell(), columns, imagePath);
    if (removeDialog.open() == IDialogConstants.OK_ID) {
        Vector<String> columnVector = removeDialog.getColumnVector();
        if (columnVector.size() == columns.size()) {
            return;
        }
        for (int i = 0; i < count; i++) {
            TableColumn col = table.getColumn(i);
            boolean found = false;
            for (int j = 0; j < columnVector.size(); j++) {
                if (col.getText().equals(columnVector.get(j))) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                table.getColumn(i).dispose();
                count--;
                i--;
            }
        }
        cols = table.getColumnCount();
        lblColCount.setText(MessageFormat.format(Messages.getString("dialog.CSV2TMXConverterDialog.lblColCount"), //$NON-NLS-1$
        cols));
        int width = (table.getClientArea().width - table.getBorderWidth() * 2 - table.getVerticalBar().getSize().x) / cols;
        if (width < 100) {
            width = 100;
        }
        for (int i = 0; i < cols; i++) {
            TableColumn column = table.getColumn(i);
            column.setWidth(width);
        }
    }
}
Also used : Vector(java.util.Vector) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 19 with TableColumn

use of org.eclipse.swt.widgets.TableColumn 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 20 with TableColumn

use of org.eclipse.swt.widgets.TableColumn in project translationstudio8 by heartsome.

the class BatchQADialog method createFileDataGroup.

/**
	 * @param parent
	 */
public void createFileDataGroup(Composite parent) {
    Composite parentCmp = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().extendedMargins(9, 9, 0, 0).numColumns(1).applyTo(parentCmp);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(parentCmp);
    tableViewer = new TableViewer(parentCmp, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    final Table table = tableViewer.getTable();
    GridData tableData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
    tableData.heightHint = 50;
    table.setLayoutData(tableData);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    String[] columnNames = new String[] { Messages.getString("qa.all.dialog.index"), Messages.getString("qa.dialogs.BatchQADialog.name2") };
    int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
    for (int i = 0; i < columnNames.length; i++) {
        TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
        tableColumn.setText(columnNames[i]);
        tableColumn.setWidth(50);
    }
    tableViewer.setLabelProvider(new TableViewerLabelProvider());
    tableViewer.setContentProvider(new ArrayContentProvider());
    tableViewer.setInput(getQATableInfo());
    // 让列表列宽动态变化
    table.addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event event) {
            final Table table = ((Table) event.widget);
            final TableColumn[] columns = table.getColumns();
            event.widget.getDisplay().syncExec(new Runnable() {

                public void run() {
                    double[] columnWidths = new double[] { 0.1, 0.8 };
                    for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                }
            });
        }
    });
    //如果是合并打开的文件,那么创建一个 LABLE 进行提示
    if (isMultiFile) {
        Label remarkLbl = new Label(parentCmp, SWT.WRAP);
        remarkLbl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        remarkLbl.setText(Messages.getString("qa.dialogs.BatchQADialog.tip1"));
    }
}
Also used : Table(org.eclipse.swt.widgets.Table) Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) TableColumn(org.eclipse.swt.widgets.TableColumn) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

TableColumn (org.eclipse.swt.widgets.TableColumn)305 Table (org.eclipse.swt.widgets.Table)151 GridData (org.eclipse.swt.layout.GridData)105 TableViewer (org.eclipse.jface.viewers.TableViewer)94 Composite (org.eclipse.swt.widgets.Composite)92 SelectionEvent (org.eclipse.swt.events.SelectionEvent)87 GridLayout (org.eclipse.swt.layout.GridLayout)76 TableItem (org.eclipse.swt.widgets.TableItem)76 Point (org.eclipse.swt.graphics.Point)57 Label (org.eclipse.swt.widgets.Label)55 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)52 Button (org.eclipse.swt.widgets.Button)48 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)41 FillLayout (org.eclipse.swt.layout.FillLayout)37 Listener (org.eclipse.swt.widgets.Listener)37 Event (org.eclipse.swt.widgets.Event)35 Shell (org.eclipse.swt.widgets.Shell)35 Test (org.junit.Test)33 SelectionListener (org.eclipse.swt.events.SelectionListener)32 Text (org.eclipse.swt.widgets.Text)30