Search in sources :

Example 6 with ITableLabelProvider

use of org.eclipse.jface.viewers.ITableLabelProvider in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsPreferencePage method createApplicationInsightsResourceTable.

public void createApplicationInsightsResourceTable(Composite parent) {
    table = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    GridData gridData = new GridData();
    gridData.heightHint = 360;
    gridData.verticalIndent = 15;
    gridData.horizontalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = false;
    table.setLayoutData(gridData);
    TableColumn strNameCol = new TableColumn(table, SWT.FILL);
    strNameCol.setText(Messages.resrcName);
    strNameCol.setWidth(150);
    TableColumn strUrlDisCol = new TableColumn(table, SWT.FILL);
    strUrlDisCol.setText(Messages.instrKey);
    strUrlDisCol.setWidth(190);
    tableViewer = new TableViewer(table);
    tableViewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object obj, Object obj1) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object obj) {
            return getTableContent();
        }
    });
    tableViewer.setLabelProvider(new ITableLabelProvider() {

        @Override
        public void removeListener(ILabelProviderListener ilabelproviderlistener) {
        }

        @Override
        public boolean isLabelProperty(Object element, String s) {
            return false;
        }

        @Override
        public void dispose() {
        }

        @Override
        public void addListener(ILabelProviderListener ilabelproviderlistener) {
        }

        @Override
        public String getColumnText(Object element, int i) {
            ApplicationInsightsPageTableElement rowElement = (ApplicationInsightsPageTableElement) element;
            String result = "";
            switch(i) {
                case 0:
                    result = rowElement.getResourceName();
                    break;
                case 1:
                    result = rowElement.getInstrumentationKey();
                    break;
                default:
                    break;
            }
            return result;
        }

        @Override
        public Image getColumnImage(Object element, int i) {
            return null;
        }
    });
    tableViewer.setInput(getTableContent());
    Composite containerButtons = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.END;
    gridData.verticalAlignment = GridData.BEGINNING;
    gridData.verticalIndent = 15;
    containerButtons.setLayout(gridLayout);
    containerButtons.setLayoutData(gridData);
    btnNew = new Button(containerButtons, SWT.PUSH);
    btnNew.setText(Messages.btnNewLbl);
    gridData = new GridData();
    gridData.widthHint = 70;
    btnNew.setLayoutData(gridData);
    btnNew.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            newButtonListener();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    btnAdd = new Button(containerButtons, SWT.PUSH);
    btnAdd.setText(Messages.btnAddLbl);
    gridData = new GridData();
    gridData.widthHint = 70;
    btnAdd.setLayoutData(gridData);
    btnAdd.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            addButtonListener();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    btnDetails = new Button(containerButtons, SWT.PUSH);
    btnDetails.setEnabled(false);
    btnDetails.setText(Messages.btnDtlsLbl);
    gridData = new GridData();
    gridData.widthHint = 70;
    btnDetails.setLayoutData(gridData);
    btnDetails.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            detailsButtonListener();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    btnRemove = new Button(containerButtons, SWT.PUSH);
    btnRemove.setEnabled(false);
    btnRemove.setText(Messages.btnRmvLbl);
    gridData = new GridData();
    gridData.widthHint = 70;
    btnRemove.setLayoutData(gridData);
    btnRemove.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            removeButtonListener();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    table.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            selIndex = tableViewer.getTable().getSelectionIndex();
            btnDetails.setEnabled(true);
            btnRemove.setEnabled(true);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
        }
    });
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent selectionchangedevent) {
            if (selectionchangedevent.getSelection().isEmpty()) {
                btnDetails.setEnabled(false);
                btnRemove.setEnabled(false);
            }
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) TableColumn(org.eclipse.swt.widgets.TableColumn) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 7 with ITableLabelProvider

use of org.eclipse.jface.viewers.ITableLabelProvider in project tdi-studio-se by Talend.

the class ItemsVersionConfirmDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    TableViewer viewer = new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.minimumHeight = 200;
    data.heightHint = 200;
    data.minimumWidth = 350;
    data.widthHint = 350;
    viewer.getControl().setLayoutData(data);
    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn column = new TableColumn(table, SWT.NONE);
    //$NON-NLS-1$
    column.setText(Messages.getString("VersionManagementDialog.Items"));
    column.setWidth(140);
    column = new TableColumn(table, SWT.NONE);
    //$NON-NLS-1$
    column.setText(Messages.getString("ItemsVersionChangedDialog.OriginalVersion"));
    column.setWidth(120);
    column = new TableColumn(table, SWT.NONE);
    //$NON-NLS-1$
    column.setText(Messages.getString("VersionManagementDialog.NewVersion"));
    column.setWidth(90);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setLabelProvider(new ITableLabelProvider() {

        public Image getColumnImage(Object element, int columnIndex) {
            ItemVersionObject object = (ItemVersionObject) element;
            if (columnIndex == 0) {
                return ImageProvider.getImage(CoreImageProvider.getIcon(object.getItem()));
            }
            return null;
        }

        public String getColumnText(Object element, int columnIndex) {
            ItemVersionObject object = (ItemVersionObject) element;
            switch(columnIndex) {
                case 0:
                    return object.getItem().getProperty().getLabel();
                case 1:
                    return object.getOldVersion();
                case 2:
                    if (object.getOldVersion().equals(object.getNewVersion())) {
                        //$NON-NLS-1$
                        return "-";
                    }
                    return object.getNewVersion();
                default:
            }
            return null;
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void removeListener(ILabelProviderListener listener) {
        }
    });
    viewer.setInput(modifiedVersionItems);
    for (TableItem item : table.getItems()) {
        ItemVersionObject object = (ItemVersionObject) item.getData();
        if (!object.getOldVersion().equals(object.getNewVersion())) {
            item.setForeground(2, Display.getDefault().getSystemColor(SWT.COLOR_RED));
        }
    }
    return composite;
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TableItem(org.eclipse.swt.widgets.TableItem) Image(org.eclipse.swt.graphics.Image) TableColumn(org.eclipse.swt.widgets.TableColumn) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) GridData(org.eclipse.swt.layout.GridData) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 8 with ITableLabelProvider

use of org.eclipse.jface.viewers.ITableLabelProvider in project tdi-studio-se by Talend.

the class SchemaDetailsViewerSorter method compare.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object,
     * java.lang.Object)
     */
@SuppressWarnings("unchecked")
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    if (sortViewer != null) {
        ITableLabelProvider labelProvider = (ITableLabelProvider) sortViewer.getLabelProvider();
        final String text1 = labelProvider.getColumnText(e1, index);
        final String text2 = labelProvider.getColumnText(e2, index);
        //$NON-NLS-1$ //$NON-NLS-2$
        return getComparator().compare((text1 != null ? text1 : ""), (text2 != null ? text2 : "")) * direction;
    }
    return 0;
}
Also used : ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider)

Aggregations

ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)8 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)7 TableViewer (org.eclipse.jface.viewers.TableViewer)6 Image (org.eclipse.swt.graphics.Image)6 TableColumn (org.eclipse.swt.widgets.TableColumn)6 Viewer (org.eclipse.jface.viewers.Viewer)5 GridData (org.eclipse.swt.layout.GridData)5 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)4 Composite (org.eclipse.swt.widgets.Composite)4 Table (org.eclipse.swt.widgets.Table)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 List (java.util.List)2 IMenuListener (org.eclipse.jface.action.IMenuListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 ViewerSorter (org.eclipse.jface.viewers.ViewerSorter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 FormAttachment (org.eclipse.swt.layout.FormAttachment)2 FormData (org.eclipse.swt.layout.FormData)2 Event (org.eclipse.swt.widgets.Event)2