Search in sources :

Example 11 with ColumnLayoutData

use of org.eclipse.jface.viewers.ColumnLayoutData in project erlide_eclipse by erlang.

the class TableLayoutComposite method layoutTable.

protected void layoutTable(final Table table, final int width, final Rectangle area, final boolean increase) {
    if (width <= 1) {
        return;
    }
    final TableColumn[] tableColumns = table.getColumns();
    final int size = Math.min(columns.size(), tableColumns.length);
    final int[] widths = new int[size];
    int fixedWidth = 0;
    int numberOfWeightColumns = 0;
    int totalWeight = 0;
    // First calc space occupied by fixed columns
    for (int i = 0; i < size; i++) {
        final ColumnLayoutData col = columns.get(i);
        if (col instanceof ColumnPixelData) {
            final int pixels = ((ColumnPixelData) col).width;
            widths[i] = pixels;
            fixedWidth += pixels;
        } else if (col instanceof ColumnWeightData) {
            final ColumnWeightData cw = (ColumnWeightData) col;
            numberOfWeightColumns++;
            // first time, use the weight specified by the column data,
            // otherwise use
            // the actual width as the weight
            // int weight = firstTime ? cw.weight :
            // tableColumns[i].getWidth();
            final int weight = cw.weight;
            totalWeight += weight;
        } else {
            // $NON-NLS-1$
            Assert.isTrue(false, "Unknown column layout data");
        }
    }
    // Do we have columns that have a weight
    if (numberOfWeightColumns > 0) {
        // Now distribute the rest to the columns with weight.
        final int rest = width - fixedWidth;
        int totalDistributed = 0;
        for (int i = 0; i < size; ++i) {
            final ColumnLayoutData col = columns.get(i);
            if (col instanceof ColumnWeightData) {
                final ColumnWeightData cw = (ColumnWeightData) col;
                // calculate weight as above
                // int weight = firstTime ? cw.weight :
                // tableColumns[i].getWidth();
                final int weight = cw.weight;
                int pixels = totalWeight == 0 ? 0 : weight * rest / totalWeight;
                if (pixels < cw.minimumWidth) {
                    pixels = cw.minimumWidth;
                }
                totalDistributed += pixels;
                widths[i] = pixels;
            }
        }
        // Distribute any remaining pixels to columns with weight.
        int diff = rest - totalDistributed;
        for (int i = 0; diff > 0; ++i) {
            if (i == size) {
                i = 0;
            }
            final ColumnLayoutData col = columns.get(i);
            if (col instanceof ColumnWeightData) {
                ++widths[i];
                --diff;
            }
        }
    }
    if (increase) {
        table.setSize(area.width, area.height);
    }
    for (int i = 0; i < size; i++) {
        tableColumns[i].setWidth(widths[i]);
    }
    if (!increase) {
        table.setSize(area.width, area.height);
    }
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ColumnLayoutData(org.eclipse.jface.viewers.ColumnLayoutData) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point)

Example 12 with ColumnLayoutData

use of org.eclipse.jface.viewers.ColumnLayoutData in project liferay-ide by liferay.

the class FreemarkerMultiPageEditor method createContextPage.

void createContextPage() {
    contextValues = new Properties();
    Composite composite = new Composite(getContainer(), SWT.NULL);
    composite.setLayout(new FillLayout());
    contextValuesTable = new Table(composite, SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION);
    contextValuesTable.setVisible(true);
    contextValuesTable.setLinesVisible(false);
    contextValuesTable.setHeaderVisible(true);
    contextValuesTable.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            editContextValueButton.setEnabled(true);
            deleteContextValueButton.setEnabled(true);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    contextValuesTable.addKeyListener(new ContextValueDeleteKeyListener());
    contextValuesTable.addMouseListener(new EditContextValueButtonListener());
    // create the columns
    TableColumn keyColumn = new TableColumn(contextValuesTable, SWT.LEFT);
    TableColumn valueColumn = new TableColumn(contextValuesTable, SWT.LEFT);
    keyColumn.setText(Messages.FreemarkerMultiPageEditor_COLUMN_NAME);
    valueColumn.setText(Messages.FreemarkerMultiPageEditor_COLUMN_TYPE);
    ColumnLayoutData keyColumnLayout = new ColumnWeightData(30, false);
    ColumnLayoutData valueColumnLayout = new ColumnWeightData(70, false);
    // set columns in Table layout
    TableLayout tableLayout = new TableLayout();
    tableLayout.addColumnData(keyColumnLayout);
    tableLayout.addColumnData(valueColumnLayout);
    contextValuesTable.setLayout(tableLayout);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.heightHint = 50;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    contextValuesTable.setLayoutData(data);
    Composite buttonComposite = new Composite(composite, SWT.NONE);
    data = new GridData();
    data.horizontalAlignment = GridData.BEGINNING;
    data.verticalAlignment = GridData.BEGINNING;
    buttonComposite.setLayoutData(data);
    GridLayout gl = new GridLayout(1, true);
    buttonComposite.setLayout(gl);
    buttonComposite.setVisible(true);
    addContextValueButton = new Button(buttonComposite, SWT.NATIVE);
    addContextValueButton.setText(Messages.FreemarkerMultiPageEditor_BUTTON_NEW);
    addContextValueButton.setVisible(true);
    addContextValueButton.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
    addContextValueButton.addSelectionListener(new AddContextValueButtonListener());
    data = new GridData();
    data.widthHint = 45;
    data.grabExcessHorizontalSpace = true;
    addContextValueButton.setLayoutData(data);
    editContextValueButton = new Button(buttonComposite, SWT.NATIVE);
    editContextValueButton.setText(Messages.FreemarkerMultiPageEditor_BUTTON_EDIT);
    editContextValueButton.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
    editContextValueButton.addSelectionListener(new EditContextValueButtonListener());
    data = new GridData();
    data.widthHint = 45;
    data.grabExcessHorizontalSpace = true;
    editContextValueButton.setLayoutData(data);
    deleteContextValueButton = new Button(buttonComposite, SWT.NATIVE);
    deleteContextValueButton.setText(Messages.FreemarkerMultiPageEditor_BUTTON_DELETE);
    deleteContextValueButton.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
    deleteContextValueButton.addSelectionListener(new ContextValueDeleteKeyListener());
    data = new GridData();
    data.widthHint = 45;
    data.grabExcessHorizontalSpace = true;
    deleteContextValueButton.setLayoutData(data);
    reloadContextValues();
    int index = addPage(composite);
    setPageText(index, Messages.FreemarkerMultiPageEditor_PAGE_TEXT_CONTEXT);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) FillLayout(org.eclipse.swt.layout.FillLayout) Properties(java.util.Properties) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColumnLayoutData(org.eclipse.jface.viewers.ColumnLayoutData) GridData(org.eclipse.swt.layout.GridData) TableLayout(org.eclipse.jface.viewers.TableLayout) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 13 with ColumnLayoutData

use of org.eclipse.jface.viewers.ColumnLayoutData in project jbosstools-hibernate by jbosstools.

the class AutoResizeTableLayout method autoSizeColumns.

private void autoSizeColumns() {
    int width = table.getClientArea().width;
    if (width <= 1) {
        return;
    }
    TableColumn[] tableColumns = table.getColumns();
    int size = Math.min(columns.size(), tableColumns.length);
    int[] widths = new int[size];
    int fixedWidth = 0;
    int numberOfWeightColumns = 0;
    int totalWeight = 0;
    // First calc space occupied by fixed columns.
    for (int i = 0; i < size; i++) {
        ColumnLayoutData col = columns.get(i);
        if (col instanceof ColumnPixelData) {
            int pixels = ((ColumnPixelData) col).width;
            widths[i] = pixels;
            fixedWidth += pixels;
        } else if (col instanceof ColumnWeightData) {
            ColumnWeightData cw = (ColumnWeightData) col;
            numberOfWeightColumns++;
            int weight = cw.weight;
            totalWeight += weight;
        } else {
            throw new IllegalStateException(HibernateConsoleMessages.AutoResizeTableLayout_unknown_column_layout_data);
        }
    }
    // Do we have columns that have a weight?
    if (numberOfWeightColumns > 0) {
        // Now, distribute the rest
        // to the columns with weight.
        int rest = width - fixedWidth;
        int totalDistributed = 0;
        for (int i = 0; i < size; i++) {
            ColumnLayoutData col = columns.get(i);
            if (col instanceof ColumnWeightData) {
                ColumnWeightData cw = (ColumnWeightData) col;
                int weight = cw.weight;
                int pixels = totalWeight == 0 ? 0 : weight * rest / totalWeight;
                totalDistributed += pixels;
                widths[i] = pixels;
            }
        }
        // Distribute any remaining pixels
        // to columns with weight.
        int diff = rest - totalDistributed;
        for (int i = 0; diff > 0; i++) {
            if (i == size) {
                i = 0;
            }
            ColumnLayoutData col = columns.get(i);
            if (col instanceof ColumnWeightData) {
                ++widths[i];
                --diff;
            }
        }
    }
    for (int i = 0; i < size; i++) {
        if (tableColumns[i].getWidth() != widths[i]) {
            tableColumns[i].setWidth(widths[i]);
        }
    }
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ColumnLayoutData(org.eclipse.jface.viewers.ColumnLayoutData) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableColumn(org.eclipse.swt.widgets.TableColumn)

Aggregations

ColumnLayoutData (org.eclipse.jface.viewers.ColumnLayoutData)13 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)10 TableColumn (org.eclipse.swt.widgets.TableColumn)8 Point (org.eclipse.swt.graphics.Point)6 Table (org.eclipse.swt.widgets.Table)6 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)5 TableLayout (org.eclipse.jface.viewers.TableLayout)5 KeyEvent (org.eclipse.swt.events.KeyEvent)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 Pair (org.eclipse.xtext.xbase.lib.Pair)3 Properties (java.util.Properties)2 KeyAdapter (org.eclipse.swt.events.KeyAdapter)2 Button (org.eclipse.swt.widgets.Button)2 IProject (org.eclipse.core.resources.IProject)1 PixelConverter (org.eclipse.jface.layout.PixelConverter)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1