Search in sources :

Example 61 with TableViewerColumn

use of org.eclipse.jface.viewers.TableViewerColumn in project linuxtools by eclipse.

the class ImageRunSelectionPage method createTableViewerColum.

private TableViewerColumn createTableViewerColum(final TableViewer tableViewer, final String title, final int width) {
    final TableViewerColumn viewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    final TableColumn column = viewerColumn.getColumn();
    if (title != null) {
        column.setText(title);
    }
    column.setWidth(width);
    return viewerColumn;
}
Also used : TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 62 with TableViewerColumn

use of org.eclipse.jface.viewers.TableViewerColumn in project linuxtools by eclipse.

the class DockerContainersView method createTableViewer.

private void createTableViewer(final Composite container) {
    this.search = new Text(container, SWT.SEARCH | SWT.ICON_SEARCH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(search);
    search.addModifyListener(onSearch());
    Composite tableArea = new Composite(container, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).applyTo(tableArea);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableArea);
    final TableColumnLayout tableLayout = new TableColumnLayout();
    tableArea.setLayout(tableLayout);
    this.viewer = new TableViewer(tableArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    this.viewer.setContentProvider(new DockerContainersContentProvider());
    final Table table = this.viewer.getTable();
    GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).applyTo(table);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(table);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    // 'Name' column
    // $NON-NLS-1$
    final TableViewerColumn nameColumn = createColumn(DVMessages.getString("NAME"));
    setLayout(nameColumn, tableLayout, 150);
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                return ((IDockerContainer) element).name();
            }
            return super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof IDockerContainer) {
                final IDockerContainer container = (IDockerContainer) element;
                final EnumDockerStatus containerStatus = EnumDockerStatus.fromStatusMessage(container.status());
                if (containerStatus == EnumDockerStatus.RUNNING) {
                    return STARTED_IMAGE;
                } else if (containerStatus == EnumDockerStatus.PAUSED) {
                    return PAUSED_IMAGE;
                } else {
                    return STOPPED_IMAGE;
                }
            }
            return super.getImage(element);
        }
    });
    // 'Image' column
    // $NON-NLS-1$
    final TableViewerColumn imageColumn = createColumn(DVMessages.getString("IMAGE"));
    setLayout(imageColumn, tableLayout, 150);
    imageColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                return ((IDockerContainer) element).image();
            }
            return super.getText(element);
        }
    });
    // 'Creation Date' column
    // $NON-NLS-1$
    final TableViewerColumn creationDateColumn = createColumn(DVMessages.getString("CREATED"));
    setLayout(creationDateColumn, tableLayout, 150);
    creationDateColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                return LabelProviderUtils.toCreatedDate(((IDockerContainer) element).created());
            }
            return super.getText(element);
        }
    });
    // 'Command' column
    final TableViewerColumn commandColumn = createColumn(// $NON-NLS-1$
    DVMessages.getString("COMMAND"));
    setLayout(commandColumn, tableLayout, 150);
    commandColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                return ((IDockerContainer) element).command();
            }
            return super.getText(element);
        }
    });
    // 'Ports' column
    // $NON-NLS-1$
    final TableViewerColumn portsColumn = createColumn(DVMessages.getString("PORTS"));
    setLayout(portsColumn, tableLayout, 150);
    portsColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                final StringBuilder ports = new StringBuilder();
                for (Iterator<IDockerPortMapping> iterator = ((IDockerContainer) element).ports().iterator(); iterator.hasNext(); ) {
                    final IDockerPortMapping portMapping = iterator.next();
                    ports.append(LabelProviderUtils.containerPortMappingToString(portMapping));
                    if (iterator.hasNext()) {
                        ports.append(", ");
                    }
                }
                return ports.toString();
            }
            return super.getText(element);
        }
    });
    // 'Status' column
    // $NON-NLS-1$
    final TableViewerColumn statusColumn = createColumn(DVMessages.getString("STATUS"));
    setLayout(statusColumn, tableLayout, 150);
    statusColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                return ((IDockerContainer) element).status();
            }
            return super.getText(element);
        }
    });
    // comparator
    final DockerContainersComparator comparator = new DockerContainersComparator(this.viewer);
    comparator.setColumn(creationDateColumn.getColumn());
    // Set column a second time so we reverse the order and default to most
    // currently created containers first
    comparator.setColumn(creationDateColumn.getColumn());
    this.viewer.setComparator(comparator);
    // apply search filter
    this.viewer.setFilters(getContainersFilter());
    setConnection(CommandUtils.getCurrentConnection(null));
    this.viewer.addSelectionChangedListener(onContainerSelection());
    // get the current selection in the tableviewer
    getSite().setSelectionProvider(this.viewer);
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Text(org.eclipse.swt.widgets.Text) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Image(org.eclipse.swt.graphics.Image) IDockerPortMapping(org.eclipse.linuxtools.docker.core.IDockerPortMapping) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Iterator(java.util.Iterator) EnumDockerStatus(org.eclipse.linuxtools.docker.core.EnumDockerStatus) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 63 with TableViewerColumn

use of org.eclipse.jface.viewers.TableViewerColumn in project linuxtools by eclipse.

the class DockerImagesView method createColumn.

private TableViewerColumn createColumn(final String title) {
    final TableViewerColumn propertyColumn = new TableViewerColumn(viewer, SWT.BORDER);
    propertyColumn.getColumn().setText(title);
    propertyColumn.getColumn().addSelectionListener(onColumnSelected());
    return propertyColumn;
}
Also used : TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 64 with TableViewerColumn

use of org.eclipse.jface.viewers.TableViewerColumn in project yamcs-studio by yamcs.

the class ClientsTableViewer method addFixedColumns.

private void addFixedColumns() {
    TableViewerColumn idColumn = new TableViewerColumn(this, SWT.CENTER);
    idColumn.getColumn().setText(COL_ID);
    idColumn.getColumn().setWidth(30);
    idColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ClientInfo client = (ClientInfo) element;
            return String.valueOf(client.getId());
        }
    });
    TableViewerColumn userColumn = new TableViewerColumn(this, SWT.LEFT);
    userColumn.getColumn().setText(COL_USER);
    userColumn.getColumn().setWidth(100);
    userColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ClientInfo client = (ClientInfo) element;
            return String.valueOf(client.getUsername());
        }
    });
    TableViewerColumn applicationColumn = new TableViewerColumn(this, SWT.LEFT);
    applicationColumn.getColumn().setText(COL_APPLICATION);
    applicationColumn.getColumn().setWidth(100);
    applicationColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ClientInfo client = (ClientInfo) element;
            return client.getApplicationName();
        }
    });
    TableViewerColumn instanceColumn = new TableViewerColumn(this, SWT.LEFT);
    instanceColumn.getColumn().setText(COL_INSTANCE);
    instanceColumn.getColumn().setWidth(100);
    instanceColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ClientInfo client = (ClientInfo) element;
            return client.getInstance();
        }
    });
    TableViewerColumn processorColumn = new TableViewerColumn(this, SWT.LEFT);
    processorColumn.getColumn().setText(COL_PROCESSOR);
    processorColumn.getColumn().setWidth(100);
    processorColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ClientInfo client = (ClientInfo) element;
            return client.getProcessorName();
        }
    });
    // prevent resize to 0
    for (TableColumn column : getTable().getColumns()) {
        column.addControlListener(new ControlListener() {

            @Override
            public void controlMoved(ControlEvent e) {
            }

            @Override
            public void controlResized(ControlEvent e) {
                if (column.getWidth() < 5) {
                    column.setWidth(5);
                }
            }
        });
    }
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ControlListener(org.eclipse.swt.events.ControlListener) ClientInfo(org.yamcs.protobuf.YamcsManagement.ClientInfo) ControlEvent(org.eclipse.swt.events.ControlEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 65 with TableViewerColumn

use of org.eclipse.jface.viewers.TableViewerColumn in project yamcs-studio by yamcs.

the class AddParameterPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    setControl(composite);
    GridLayout gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    gl.numColumns = 2;
    gl.makeColumnsEqualWidth = false;
    composite.setLayout(gl);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite tableWrapper1 = new Composite(composite, SWT.NONE);
    contentProvider = new ParameterContentProvider();
    trcl = new TreeColumnLayout();
    tableWrapper1.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableWrapper1.setLayout(trcl);
    namespaceTable = new TreeViewer(tableWrapper1, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    namespaceTable.getTree().setHeaderVisible(true);
    namespaceTable.getTree().setLinesVisible(true);
    // column container
    TreeViewerColumn pathColumn = new TreeViewerColumn(namespaceTable, SWT.NONE);
    pathColumn.getColumn().setText(COL_NAMESPACE);
    pathColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            String namespace = (String) element;
            return namespace;
        }
    });
    trcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
    namespaceTable.addSelectionChangedListener(evt -> {
        IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
        if (sel.isEmpty()) {
            contentProvider.setNamespace(null);
            return;
        }
        contentProvider.setNamespace((String) sel.getFirstElement());
    });
    namespaceTable.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection sel = new IStructuredSelection() {

                @Override
                public boolean isEmpty() {
                    return false;
                }

                @Override
                public List toList() {
                    return Arrays.asList(contentProvider.getElements(event));
                }

                @Override
                public Object[] toArray() {
                    return contentProvider.getElements(event);
                }

                @Override
                public int size() {
                    return contentProvider.getElements(event).length;
                }

                @Override
                public Iterator iterator() {
                    return Arrays.asList(contentProvider.getElements(event)).iterator();
                }

                @Override
                public Object getFirstElement() {
                    return null;
                }
            };
            parameterTable.setSelection(sel);
        }
    });
    namespaceTable.setContentProvider(new NamespaceContentProvider());
    namespaceTable.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            String n1 = (String) o1;
            String n2 = (String) o2;
            return n1.compareTo(n2);
        }
    });
    Composite tableWrapper2 = new Composite(composite, SWT.NONE);
    tcl = new TableColumnLayout();
    tableWrapper2.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableWrapper2.setLayout(tcl);
    parameterTable = new TableViewer(tableWrapper2, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    parameterTable.getTable().setHeaderVisible(true);
    parameterTable.getTable().setLinesVisible(true);
    TableViewerColumn nameColumn = new TableViewerColumn(parameterTable, SWT.NONE);
    nameColumn.getColumn().setText(COL_NAME);
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ParameterInfo obj = (ParameterInfo) element;
            return obj.getQualifiedName();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
    parameterTable.addSelectionChangedListener(evt -> {
        IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
        if (sel.isEmpty()) {
            setParameter(new ArrayList<>());
            return;
        }
        List<ParameterInfo> parameters = new ArrayList<>();
        for (Object obj : sel.toArray()) {
            parameters.add((ParameterInfo) obj);
        }
        setParameter(parameters);
        setPageComplete(true);
    });
    parameterTable.setContentProvider(contentProvider);
    parameterTable.setInput(contentProvider);
    ParameterCatalogue.getInstance().getMetaParameters().forEach(pmtr -> {
        for (NamedObjectId alias : pmtr.getAliasList()) {
            String namespace = alias.getNamespace();
            if (!namespace.startsWith("/"))
                return;
            if (!parameterInfos.containsKey(namespace)) {
                parameterInfos.put(namespace, new ArrayList<>());
            }
            parameterInfos.get(namespace).add(pmtr);
            String parentns = namespace.substring(0, namespace.lastIndexOf("/"));
            while (!parentns.isEmpty()) {
                if (!parameterInfos.containsKey(parentns)) {
                    parameterInfos.put(parentns, new ArrayList<>());
                }
                parentns = parentns.substring(0, parentns.lastIndexOf("/"));
            }
        }
    });
    namespaceTable.setInput(parameterInfos.keySet());
    parameterTable.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            ParameterInfo n1 = (ParameterInfo) o1;
            ParameterInfo n2 = (ParameterInfo) o2;
            return n1.getQualifiedName().compareTo(n2.getQualifiedName());
        }
    });
}
Also used : TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) GridData(org.eclipse.swt.layout.GridData) NamedObjectId(org.yamcs.protobuf.Yamcs.NamedObjectId) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)134 TableViewer (org.eclipse.jface.viewers.TableViewer)72 Composite (org.eclipse.swt.widgets.Composite)53 GridData (org.eclipse.swt.layout.GridData)52 SelectionEvent (org.eclipse.swt.events.SelectionEvent)45 TableColumn (org.eclipse.swt.widgets.TableColumn)41 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)36 GridLayout (org.eclipse.swt.layout.GridLayout)32 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)28 Table (org.eclipse.swt.widgets.Table)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)19 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)16 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)16 Point (org.eclipse.swt.graphics.Point)15 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)14 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)14 FillLayout (org.eclipse.swt.layout.FillLayout)14 Button (org.eclipse.swt.widgets.Button)14 Image (org.eclipse.swt.graphics.Image)13 Text (org.eclipse.swt.widgets.Text)11