Search in sources :

Example 41 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.

the class ReviewExtractedItemsPage method addColumns.

private void addColumns(TableViewer viewer, TableColumnLayout layout) {
    TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnStatus);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public Image getImage(ExtractedEntry element) {
            Images image = null;
            switch(element.getMaxCode()) {
                case WARNING:
                    image = Images.WARNING;
                    break;
                case ERROR:
                    image = Images.ERROR;
                    break;
                case OK:
                default:
            }
            return image != null ? image.image() : null;
        }

        @Override
        public String getText(ExtractedEntry entry) {
            // $NON-NLS-1$
            return "";
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(22, true));
    column = new TableViewerColumn(viewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnDate);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public String getText(ExtractedEntry entry) {
            LocalDateTime date = entry.getItem().getDate();
            return date != null ? Values.DateTime.format(date) : null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(80, true));
    column = new TableViewerColumn(viewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnTransactionType);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public String getText(ExtractedEntry entry) {
            return entry.getItem().getTypeInformation();
        }

        @Override
        public Image getImage(ExtractedEntry entry) {
            Annotated subject = entry.getItem().getSubject();
            if (subject instanceof AccountTransaction)
                return Images.ACCOUNT.image();
            else if (subject instanceof PortfolioTransaction)
                return Images.PORTFOLIO.image();
            else if (subject instanceof Security)
                return Images.SECURITY.image();
            else if (subject instanceof BuySellEntry)
                return Images.PORTFOLIO.image();
            else if (subject instanceof AccountTransferEntry)
                return Images.ACCOUNT.image();
            else if (subject instanceof PortfolioTransferEntry)
                return Images.PORTFOLIO.image();
            else
                return null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(100, true));
    column = new TableViewerColumn(viewer, SWT.RIGHT);
    column.getColumn().setText(Messages.ColumnAmount);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public String getText(ExtractedEntry entry) {
            Money amount = entry.getItem().getAmount();
            return amount != null ? Values.Money.format(amount) : null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(80, true));
    column = new TableViewerColumn(viewer, SWT.RIGHT);
    column.getColumn().setText(Messages.ColumnShares);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public String getText(ExtractedEntry entry) {
            return Values.Share.formatNonZero(entry.getItem().getShares());
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(80, true));
    column = new TableViewerColumn(viewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnSecurity);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public String getText(ExtractedEntry entry) {
            Security security = entry.getItem().getSecurity();
            return security != null ? security.getName() : null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(250, true));
}
Also used : LocalDateTime(java.time.LocalDateTime) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Images(name.abuchen.portfolio.ui.Images) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) StyledString(org.eclipse.jface.viewers.StyledString) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Image(org.eclipse.swt.graphics.Image) Security(name.abuchen.portfolio.model.Security) Annotated(name.abuchen.portfolio.model.Annotated) Money(name.abuchen.portfolio.money.Money) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry)

Example 42 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.

the class CSVImportDefinitionPage method doProcessFile.

private void doProcessFile() {
    try {
        importer.processFile();
        tableViewer.getTable().setRedraw(false);
        for (TableColumn column : tableViewer.getTable().getColumns()) column.dispose();
        TableColumnLayout layout = (TableColumnLayout) tableViewer.getTable().getParent().getLayout();
        for (Column column : importer.getColumns()) {
            TableColumn tableColumn = new TableColumn(tableViewer.getTable(), SWT.None);
            layout.setColumnData(tableColumn, new ColumnPixelData(80, true));
            setColumnLabel(tableColumn, column);
        }
        List<Object> input = new ArrayList<>();
        input.add(importer);
        input.addAll(importer.getRawValues());
        tableViewer.setInput(input);
        tableViewer.refresh();
        tableViewer.getTable().pack();
        for (TableColumn column : tableViewer.getTable().getColumns()) column.pack();
        doUpdateErrorMessages();
    } catch (IOException e) {
        PortfolioPlugin.log(e);
        ErrorDialog.openError(getShell(), Messages.LabelError, e.getMessage(), new Status(Status.ERROR, PortfolioPlugin.PLUGIN_ID, e.getMessage(), e));
    } finally {
        tableViewer.getTable().setRedraw(true);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Column(name.abuchen.portfolio.datatransfer.csv.CSVImporter.Column) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 43 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData 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)

Example 44 with ColumnPixelData

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

the class DebuggerTraceView method createColumns.

private void createColumns() {
    final Tree tree = viewer.getTree();
    final TableLayout layout = new TableLayout();
    TreeViewerColumn column;
    final String[] names = { // $NON-NLS-1$ //$NON-NLS-2$
    "Kind", // $NON-NLS-1$ //$NON-NLS-2$
    "Function", // $NON-NLS-1$
    org.erlide.debug.ui.views.ActionMessages.getString("DebuggerTraceView.5") };
    for (final String name : names) {
        column = new TreeViewerColumn(viewer, SWT.NONE);
        final TreeColumn treeColumn = column.getColumn();
        treeColumn.setResizable(true);
        treeColumn.setMoveable(true);
        treeColumn.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetDefaultSelected(final SelectionEvent e) {
            }

            @Override
            public void widgetSelected(final SelectionEvent e) {
            }
        });
        // column.getColumn().setData(MARKER_FIELD, markerField);
        // Show the help in the first column
        column.setLabelProvider(new ColumnLabelProvider());
        treeColumn.setText(name);
        treeColumn.setToolTipText(name);
    }
    // column = new TreeViewerColumn(viewer, SWT.NONE);
    // treeColumn = column.getColumn();
    // treeColumn.setResizable(true);
    // treeColumn.setMoveable(true);
    // column.setLabelProvider(new ColumnLabelProvider());
    // column.getColumn().setImage(markerField.getColumnHeaderImage());
    // final EditingSupport support = markerField
    // .getEditingSupport(viewer);
    // if (support != null) {
    // column.setEditingSupport(support);
    // }
    // if (builder.getPrimarySortField().equals(markerField)) {
    // updateDirectionIndicator(column.getColumn(), markerField);
    // }
    int columnWidth = -1;
    for (int i = 0; i < names.length; ++i) {
        if (i == 0) {
            // Compute and store a font metric
            final GC gc = new GC(tree);
            gc.setFont(tree.getFont());
            final FontMetrics fontMetrics = gc.getFontMetrics();
            gc.dispose();
            columnWidth = (int) Math.max(100, fontMetrics.getAverageCharacterWidth() * 20);
        }
        // if (columnWidths != null) {
        // final Integer value = columnWidths.getInteger(getFieldId(column
        // .getColumn()));
        // 
        // // Make sure we get a useful value
        // if (value != null && value.intValue() > 0) {
        // columnWidth = value.intValue();
        // }
        // }
        // // Take trim into account if we are using the default value, but
        // not
        // // if it is restored.
        // if (columnWidth < 0) {
        // layout.addColumnData(new ColumnPixelData(markerField
        // .getDefaultColumnWidth(tree), true, true));
        // } else {
        layout.addColumnData(new ColumnPixelData(columnWidth, true));
    // }
    }
    // }
    // Remove extra columns
    // if (currentColumns.length > fields.length) {
    // for (int i = fields.length; i < currentColumns.length; i++) {
    // currentColumns[i].dispose();
    // 
    // }
    // }
    viewer.getTree().setLayout(layout);
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    tree.layout(true);
}
Also used : ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) TreeColumn(org.eclipse.swt.widgets.TreeColumn) FontMetrics(org.eclipse.swt.graphics.FontMetrics) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) GC(org.eclipse.swt.graphics.GC) TableLayout(org.eclipse.jface.viewers.TableLayout) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 45 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData 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)

Aggregations

ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)45 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)20 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)17 TableLayout (org.eclipse.jface.viewers.TableLayout)16 Composite (org.eclipse.swt.widgets.Composite)15 TableViewer (org.eclipse.jface.viewers.TableViewer)14 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)13 Image (org.eclipse.swt.graphics.Image)13 GridData (org.eclipse.swt.layout.GridData)13 TableColumn (org.eclipse.swt.widgets.TableColumn)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)8 Point (org.eclipse.swt.graphics.Point)8 Table (org.eclipse.swt.widgets.Table)8 ArrayList (java.util.ArrayList)6 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)6 Viewer (org.eclipse.jface.viewers.Viewer)6 GridLayout (org.eclipse.swt.layout.GridLayout)6