Search in sources :

Example 1 with TableViewerLabelProvider

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

Aggregations

TableViewerLabelProvider (net.heartsome.cat.ts.ui.plugin.TableViewerLabelProvider)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1 Table (org.eclipse.swt.widgets.Table)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1