Search in sources :

Example 31 with ColumnLabelProvider

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

the class BasePropertySection method createTableTreeViewer.

private TreeViewer createTableTreeViewer(final Composite container) {
    final TreeViewer treeViewer = new TreeViewer(container, SWT.V_SCROLL | SWT.H_SCROLL);
    final Tree tree = treeViewer.getTree();
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    final TreeViewerColumn propertyColumn = new TreeViewerColumn(treeViewer, SWT.BORDER);
    propertyColumn.getColumn().setWidth(150);
    propertyColumn.getColumn().setText("Property");
    propertyColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof Object[]) {
                final Object property = ((Object[]) element)[0];
                return property.toString();
            }
            return super.getText(element);
        }
    });
    final TreeViewerColumn valueColumn = new TreeViewerColumn(treeViewer, SWT.BORDER);
    valueColumn.getColumn().setWidth(500);
    valueColumn.getColumn().setText("Value");
    valueColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof Object[]) {
                final Object value = ((Object[]) element)[1];
                // do not show values of a collection. There will be nested elements in the treeview for them.
                if (value instanceof Collection) {
                    return "";
                } else if (value instanceof String || value instanceof Boolean || value instanceof Integer) {
                    return value.toString();
                }
                return "";
            }
            return super.getText(element);
        }
    });
    return treeViewer;
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Tree(org.eclipse.swt.widgets.Tree) Collection(java.util.Collection) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn)

Example 32 with ColumnLabelProvider

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

the class DockerContainersComparator method compareByColumn.

private int compareByColumn(final IDockerContainer container1, final IDockerContainer container2) {
    final ColumnLabelProvider sortColumnLabelProvider = (ColumnLabelProvider) this.tableViewer.getLabelProvider(sortColumnIndex);
    final String container1ColumnValue = sortColumnLabelProvider.getText(container1);
    final String container2ColumnValue = sortColumnLabelProvider.getText(container2);
    if (this.sortDirection == SWT.UP) {
        return container1ColumnValue.compareToIgnoreCase(container2ColumnValue);
    } else {
        return container1ColumnValue.compareToIgnoreCase(container2ColumnValue) * -1;
    }
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider)

Example 33 with ColumnLabelProvider

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

the class DockerImagesComparator method compareByColumn.

private int compareByColumn(final IDockerImage image1, final IDockerImage image2) {
    final ColumnLabelProvider sortColumnLabelProvider = (ColumnLabelProvider) this.tableViewer.getLabelProvider(sortColumnIndex);
    final String image1ColumnValue;
    final String image2ColumnValue;
    // Special columns will provide a special value to use in comparing
    if (sortColumnLabelProvider instanceof SpecialColumnLabelProvider) {
        image1ColumnValue = ((SpecialColumnLabelProvider) sortColumnLabelProvider).getCompareText(image1);
        image2ColumnValue = ((SpecialColumnLabelProvider) sortColumnLabelProvider).getCompareText(image2);
    } else {
        image1ColumnValue = sortColumnLabelProvider.getText(image1);
        image2ColumnValue = sortColumnLabelProvider.getText(image2);
    }
    if (this.sortDirection == SWT.UP) {
        return image1ColumnValue.compareToIgnoreCase(image2ColumnValue);
    } else {
        return image1ColumnValue.compareToIgnoreCase(image2ColumnValue) * -1;
    }
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider)

Example 34 with ColumnLabelProvider

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

the class DockerImagesView method createTableViewer.

private void createTableViewer(final Composite container) {
    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 DockerImagesContentProvider());
    final Table table = 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);
    // 'Image' column
    final TableViewerColumn idColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
    "ID"));
    setLayout(idColumn, tableLayout, 150);
    idColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerImage) {
                // for image id, remove any sha256 digest prefix
                // and truncate to max of 12 characters
                String imageId = ((IDockerImage) element).id();
                if (// $NON-NLS-1$
                imageId.startsWith("sha256:"))
                    imageId = imageId.substring(7);
                if (imageId.length() > 12) {
                    return imageId.substring(0, 12);
                }
                return imageId;
            }
            return super.getText(element);
        }
    });
    // 'Repo/Tags' column
    final TableViewerColumn tagsColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
    "TAGS"));
    setLayout(tagsColumn, tableLayout, 150);
    tagsColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerImage) {
                final IDockerImage image = (IDockerImage) element;
                final StringBuilder messageBuilder = new StringBuilder();
                for (Iterator<String> iterator = image.repoTags().iterator(); iterator.hasNext(); ) {
                    final String repoTag = iterator.next();
                    messageBuilder.append(repoTag);
                    if (iterator.hasNext()) {
                        messageBuilder.append('\n');
                    }
                }
                return messageBuilder.toString();
            }
            return super.getText(element);
        }
    });
    // 'Creation Date' column
    final TableViewerColumn creationDateColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
    "CREATED"));
    setLayout(creationDateColumn, tableLayout, 150);
    creationDateColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerImage) {
                return LabelProviderUtils.toCreatedDate(Long.parseLong(((IDockerImage) element).created()));
            }
            return super.getText(element);
        }
    });
    // 'Virtual Size' column
    final TableViewerColumn virtsizeColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
    "VIRTSIZE"));
    setLayout(virtsizeColumn, tableLayout, 150);
    virtsizeColumn.setLabelProvider(new SpecialColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerImage) {
                Long size = ((IDockerImage) element).virtualSize();
                if (size <= 0)
                    // $NON-NLS-1$
                    return "0";
                final String[] units = new String[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "B", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "kB", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "MB", "GB", // $NON-NLS-1$ //$NON-NLS-2$
                "TB" };
                int digitGroups = (int) (Math.log10(size) / Math.log10(1000));
                return new DecimalFormat("#,##0.#").format(// $NON-NLS-1$
                size / Math.pow(1000, digitGroups)) + " " + units[digitGroups];
            }
            return super.getText(element);
        }

        @Override
        public String getCompareText(final Object element) {
            // and not the shortened value with units appended.
            if (element instanceof IDockerImage) {
                return // $NON-NLS-1$
                new DecimalFormat("000000000000000000000000").format((((IDockerImage) element).virtualSize()));
            }
            return super.getText(element);
        }
    });
    // comparator
    final DockerImagesComparator comparator = new DockerImagesComparator(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());
    viewer.setComparator(comparator);
    // apply search filter
    this.viewer.addFilter(getImagesFilter());
    setConnection(CommandUtils.getCurrentConnection(null));
    // get the current selection in the tableviewer
    getSite().setSelectionProvider(viewer);
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) DecimalFormat(java.text.DecimalFormat) Text(org.eclipse.swt.widgets.Text) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Iterator(java.util.Iterator) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 35 with ColumnLabelProvider

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

the class JavaImageTab method createControl.

@Override
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    Label connLbl = new Label(composite, SWT.NONE);
    connLbl.setText(Messages.ImageSelectionDialog_connection_label);
    connCmb = new ComboViewer(composite, SWT.READ_ONLY);
    connCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    connCmb.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            for (IDockerConnection conn : DockerConnectionManager.getInstance().getAllConnections()) {
                try {
                    ((DockerConnection) conn).open(false);
                } catch (DockerException e) {
                }
            }
            return DockerConnectionManager.getInstance().getAllConnections().stream().filter(c -> c.isOpen()).toArray(size -> new IDockerConnection[size]);
        }
    });
    // $NON-NLS-1$
    connCmb.setInput("place_holder");
    Label imageLbl = new Label(composite, SWT.NONE);
    imageLbl.setText(Messages.ImageSelectionDialog_image_label);
    imageCmb = new ComboViewer(composite, SWT.READ_ONLY);
    imageCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    imageCmb.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            IDockerConnection conn = (IDockerConnection) inputElement;
            if (conn == null || conn.getImages() == null) {
                return new Object[0];
            } else {
                return conn.getImages().stream().filter(// $NON-NLS-1$
                i -> !i.repoTags().get(0).equals("<none>:<none>")).toArray(size -> new IDockerImage[size]);
            }
        }
    });
    imageCmb.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            IDockerImage img = (IDockerImage) element;
            return img.repoTags().get(0);
        }
    });
    imageCmb.setInput(null);
    connCmb.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = event.getStructuredSelection();
            IDockerConnection conn = (IDockerConnection) sel.getFirstElement();
            selectedConnection = conn;
            imageCmb.setInput(conn);
            updateLaunchConfigurationDialog();
        }
    });
    imageCmb.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = event.getStructuredSelection();
            IDockerImage img = (IDockerImage) sel.getFirstElement();
            selectedImage = img;
            updateLaunchConfigurationDialog();
        }
    });
    Group dirGroup = new Group(composite, SWT.NONE);
    dirGroup.setText(Messages.JavaImageTab_additional_dirs);
    dirGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    dirGroup.setLayout(new GridLayout(2, false));
    directoryList = new List(dirGroup, SWT.SINGLE | SWT.V_SCROLL);
    directoryList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
    directoryList.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            removeButton.setEnabled(true);
        }
    });
    addButton = createPushButton(dirGroup, Messages.JavaImageTab_button_add, null);
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dialog = new DirectoryDialog(getShell());
            String directory = dialog.open();
            if (directory != null && !listContains(directoryList, directory)) {
                directoryList.add(directory);
                updateLaunchConfigurationDialog();
            }
        }
    });
    removeButton = createPushButton(dirGroup, Messages.JavaImageTab_button_remove, null);
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true));
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int i = directoryList.getSelectionIndex();
            if (i >= 0) {
                directoryList.remove(i);
                updateLaunchConfigurationDialog();
            }
            if (directoryList.getItemCount() == 0) {
                removeButton.setEnabled(false);
            }
        }
    });
    removeButton.setEnabled(false);
    setControl(composite);
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Arrays(java.util.Arrays) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) CoreException(org.eclipse.core.runtime.CoreException) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) AbstractLaunchConfigurationTab(org.eclipse.debug.ui.AbstractLaunchConfigurationTab) Composite(org.eclipse.swt.widgets.Composite) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) DockerException(org.eclipse.linuxtools.docker.core.DockerException) GridData(org.eclipse.swt.layout.GridData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Button(org.eclipse.swt.widgets.Button) DockerConnectionManager(org.eclipse.linuxtools.docker.core.DockerConnectionManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Group(org.eclipse.swt.widgets.Group) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) List(org.eclipse.swt.widgets.List) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Aggregations

ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)41 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)28 Composite (org.eclipse.swt.widgets.Composite)16 Image (org.eclipse.swt.graphics.Image)13 TableViewer (org.eclipse.jface.viewers.TableViewer)11 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)10 GridData (org.eclipse.swt.layout.GridData)10 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)9 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)8 ArrayList (java.util.ArrayList)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)7 GridLayout (org.eclipse.swt.layout.GridLayout)7 Table (org.eclipse.swt.widgets.Table)7 Text (org.eclipse.swt.widgets.Text)6 ControlEvent (org.eclipse.swt.events.ControlEvent)5 ControlListener (org.eclipse.swt.events.ControlListener)5 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)4 Viewer (org.eclipse.jface.viewers.Viewer)4