Search in sources :

Example 11 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project eclipse-cs by checkstyle.

the class EnhancedTableViewer method restoreState.

/**
 * Restores the sorting state from the dialog settings.
 */
private void restoreState() {
    IDialogSettings settings = mSettingsProvider != null ? mSettingsProvider.getTableSettings() : null;
    if (settings == null) {
        return;
    }
    try {
        mSortedColumnIndex = settings.getInt(TAG_COLUMN_INDEX);
    } catch (NumberFormatException e) {
        mSortedColumnIndex = 0;
    }
    try {
        mSortDirection = settings.getInt(TAG_SORT_DIRECTION);
    } catch (NumberFormatException e) {
        mSortDirection = DIRECTION_FORWARD;
    }
    TableLayout layout = new TableLayout();
    boolean allColumnsHaveStoredData = true;
    // store the column widths
    TableColumn[] columns = this.getTable().getColumns();
    for (int i = 0, size = columns.length; i < size; i++) {
        try {
            int width = settings.getInt(TAG_COLUMN_WIDTH + i);
            columns[i].setWidth(width);
            layout.addColumnData(new ColumnPixelData(width));
        } catch (NumberFormatException e) {
            // probably a new column
            allColumnsHaveStoredData = false;
        }
    }
    // weighted layout
    if (allColumnsHaveStoredData) {
        this.getTable().setLayout(layout);
    }
    // restore the selection
    try {
        this.getTable().select(settings.getInt(TAG_CURRENT_SELECTION));
    } catch (NumberFormatException e) {
    // NOOP
    }
    resort();
}
Also used : IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableLayout(org.eclipse.jface.viewers.TableLayout) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 12 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project tdq-studio-se by Talend.

the class EditSortMatchRuleNamesDialog method createTableViewer.

/**
 * create Table Viewer.
 *
 * @param parent
 * @return
 */
private void createTableViewer(Composite parent) {
    tableViewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    Table table_1 = tableViewer.getTable();
    GridData gd_table_1 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_table_1.heightHint = 217;
    table_1.setLayoutData(gd_table_1);
    Table table = (Table) tableViewer.getControl();
    TableLayout tableLayout = new TableLayout();
    tableLayout.addColumnData(new ColumnPixelData(350));
    table.setLayout(tableLayout);
    tableViewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            return (OrderMatchRule[]) inputElement;
        }

        @Override
        public void dispose() {
        // do nothing here, until now
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        // do nothing here, until now
        }
    });
    createMatchRuleNameColumn();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    tableViewer.setInput(orderMatchRuleList.toArray(new OrderMatchRule[orderMatchRuleList.size()]));
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // when the selection changed, update the up/down buttons status
            updateButtonsStatus();
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) GridData(org.eclipse.swt.layout.GridData) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 13 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project tdq-studio-se by Talend.

the class AbstractMatchAnalysisTableViewer method initTable.

/**
 * DOC zshen Comment method "initTable".
 *
 * @param headers the name of column
 * @param columnMap all of columns which can be used by current Table
 * @param pixelDataOfHeaders the width of the column
 */
public void initTable(List<String> headers, List<MetadataColumn> columnMap, boolean withSorter) {
    TableLayout tLayout = new TableLayout();
    innerTable.setLayout(tLayout);
    innerTable.setHeaderVisible(true);
    innerTable.setLinesVisible(true);
    GridData gd = new GridData(GridData.FILL_BOTH);
    innerTable.setLayoutData(gd);
    for (int index = 0; index < headers.size(); index++) {
        final int sortIndex = index;
        String columnTechnologyLabel = headers.get(index);
        String columnLabel = getInternationalizedLabel(columnTechnologyLabel);
        if (columnLabel != null) {
            if (columnLabel.length() == 1) {
                columnLabel = columnLabel + PluginConstant.SPACE_STRING + PluginConstant.SPACE_STRING;
            }
            tLayout.addColumnData(new ColumnPixelData(columnLabel.length() * getHeaderDisplayWeight(index)));
            final TableViewerColumn tableColumn = new TableViewerColumn(this, SWT.LEFT);
            tableColumn.getColumn().setText(columnLabel);
            addEditingSupportForColumn(tableColumn, columnTechnologyLabel);
            if (withSorter) {
                final ViewerComparator comparator = getComparator();
                tableColumn.getColumn().addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        ((GroupStatisticsRowCompartor) comparator).setColumn(sortIndex);
                        int dir = getTable().getSortDirection();
                        if (getTable().getSortColumn() == tableColumn.getColumn()) {
                            dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
                        } else {
                            dir = SWT.DOWN;
                        }
                        getTable().setSortDirection(dir);
                        getTable().setSortColumn(tableColumn.getColumn());
                        refresh();
                    }
                });
            }
        }
    }
    CellEditor[] editors = getCellEditor(headers, columnMap);
    // add menu
    addContextMenu();
    AbstractMatchCellModifier<T> cellModifier = getTableCellModifier();
    if (cellModifier != null) {
        cellModifier.setColumnMap(columnMap);
        this.setCellModifier(cellModifier);
    }
    this.setCellEditors(editors);
    this.setColumnProperties(headers.toArray(new String[headers.size()]));
    this.setContentProvider(getTableContentProvider());
    this.setLabelProvider(getTableLabelProvider());
    GridData tableGD = new GridData(GridData.FILL_BOTH);
    tableGD.heightHint = getTableHeightHint();
    innerTable.setLayoutData(tableGD);
}
Also used : ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) CellEditor(org.eclipse.jface.viewers.CellEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) SWT(org.eclipse.swt.SWT) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableLayout(org.eclipse.jface.viewers.TableLayout) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 14 with ColumnPixelData

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

the class PerformanceView method createCalculationItem.

private void createCalculationItem(CTabFolder folder, String title) {
    Composite container = new Composite(folder, SWT.NONE);
    TreeColumnLayout layout = new TreeColumnLayout();
    container.setLayout(layout);
    calculation = new TreeViewer(container, SWT.FULL_SELECTION);
    calculation.addSelectionChangedListener(event -> {
        Object selection = ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (selection != null && selection instanceof ClientPerformanceSnapshot.Position && ((ClientPerformanceSnapshot.Position) selection).getSecurity() != null)
            selectionService.setSelection(new SecuritySelection(getClient(), ((ClientPerformanceSnapshot.Position) selection).getSecurity()));
    });
    final Font boldFont = JFaceResources.getFontRegistry().getBold(container.getFont().getFontData()[0].getName());
    TreeViewerColumn column = new TreeViewerColumn(calculation, SWT.NONE);
    column.getColumn().setText(Messages.ColumnLable);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ClientPerformanceSnapshot.Category) {
                ClientPerformanceSnapshot.Category cat = (ClientPerformanceSnapshot.Category) element;
                return cat.getLabel();
            } else if (element instanceof ClientPerformanceSnapshot.Position) {
                ClientPerformanceSnapshot.Position pos = (ClientPerformanceSnapshot.Position) element;
                return pos.getLabel();
            }
            return null;
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof ClientPerformanceSnapshot.Category) {
                return Images.CATEGORY.image();
            } else if (element instanceof ClientPerformanceSnapshot.Position) {
                ClientPerformanceSnapshot.Position position = (ClientPerformanceSnapshot.Position) element;
                if (position.getSecurity() != null) {
                    ClientPerformanceSnapshot snapshot = ((PerformanceContentProvider) calculation.getContentProvider()).getSnapshot();
                    boolean hasHoldings = snapshot.getEndClientSnapshot().getPositionsByVehicle().get(position.getSecurity()) != null;
                    return hasHoldings ? Images.SECURITY.image() : Images.SECURITY_RETIRED.image();
                } else {
                    return null;
                }
            }
            return null;
        }

        @Override
        public Font getFont(Object element) {
            if (element instanceof ClientPerformanceSnapshot.Category)
                return boldFont;
            return null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(350));
    column = new TreeViewerColumn(calculation, SWT.RIGHT);
    column.getColumn().setText(Messages.ColumnValue);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ClientPerformanceSnapshot.Category) {
                ClientPerformanceSnapshot.Category cat = (ClientPerformanceSnapshot.Category) element;
                return Values.Money.format(cat.getValuation(), getClient().getBaseCurrency());
            } else if (element instanceof ClientPerformanceSnapshot.Position) {
                ClientPerformanceSnapshot.Position pos = (ClientPerformanceSnapshot.Position) element;
                return Values.Money.format(pos.getValuation(), getClient().getBaseCurrency());
            }
            return null;
        }

        @Override
        public Font getFont(Object element) {
            if (element instanceof ClientPerformanceSnapshot.Category)
                return boldFont;
            return null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(80));
    calculation.getTree().setHeaderVisible(true);
    calculation.getTree().setLinesVisible(true);
    calculation.setContentProvider(new PerformanceContentProvider());
    CTabItem item = new CTabItem(folder, SWT.NONE);
    item.setText(title);
    item.setControl(container);
    hookContextMenu(calculation.getTree(), this::fillContextMenu);
}
Also used : SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) CTabItem(org.eclipse.swt.custom.CTabItem) Font(org.eclipse.swt.graphics.Font) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider)

Example 15 with ColumnPixelData

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

the class ErrorLogPart method createComposite.

@PostConstruct
public void createComposite(Composite parent, LogEntryCache cache) {
    this.entries = cache.getEntries();
    Composite container = new Composite(parent, SWT.NONE);
    TreeColumnLayout layout = new TreeColumnLayout();
    container.setLayout(layout);
    logViewer = new TreeViewer(container, SWT.FULL_SELECTION);
    TreeViewerColumn column = new TreeViewerColumn(logViewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnDate);
    layout.setColumnData(column.getColumn(), new ColumnPixelData(140));
    column.setLabelProvider(new ColumnLabelProvider() {

        private DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

        @Override
        public String getText(Object element) {
            return dateFormat.format(((LogEntry) element).getDate());
        }
    });
    column = new TreeViewerColumn(logViewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnMessage);
    layout.setColumnData(column.getColumn(), new ColumnPixelData(500));
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((LogEntry) element).getMessage();
        }

        @Override
        public Image getImage(Object element) {
            LogEntry entry = (LogEntry) element;
            switch(entry.getSeverity()) {
                case IStatus.ERROR:
                    return Images.ERROR.image();
                case IStatus.WARNING:
                    return Images.WARNING.image();
                default:
                    return Images.INFO.image();
            }
        }
    });
    logViewer.getTree().setHeaderVisible(true);
    logViewer.getTree().setLinesVisible(true);
    logViewer.setContentProvider(new LogEntryContentProvider());
    logViewer.setInput(entries);
    logViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            LogEntry entry = (LogEntry) ((IStructuredSelection) event.getSelection()).getFirstElement();
            DisplayTextDialog dialog = new DisplayTextDialog(Display.getCurrent().getActiveShell(), entry.getText());
            dialog.open();
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) DisplayTextDialog(name.abuchen.portfolio.ui.dialogs.DisplayTextDialog) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) DateFormat(java.text.DateFormat) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) PostConstruct(javax.annotation.PostConstruct)

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