Search in sources :

Example 86 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project knime-core by knime.

the class PluginSelectionPage method createControl.

/**
 * {@inheritDoc}
 */
@Override
public void createControl(final Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setBounds(0, 0, 600, 200);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    container.setLayout(layout);
    m_table = CheckboxTableViewer.newCheckList(container, SWT.BORDER | SWT.SHADOW_IN);
    m_table.setLabelProvider(new LabelProvider());
    m_table.setContentProvider(new ArrayContentProvider());
    m_table.setSorter(new ViewerSorter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public int compare(final Viewer viewer, final Object e1, final Object e2) {
            String s1 = (String) e1;
            String s2 = (String) e2;
            return s1.compareTo(s2);
        }
    });
    initTable();
    m_table.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            String selection = (String) ((IStructuredSelection) event.getSelection()).getFirstElement();
            m_table.setChecked(selection, !m_table.getChecked(selection));
            updatePageComplete();
        }
    });
    /*
        m_table.addSelectionChangedListener(new ISelectionChangedListener() {

            /**
             *
             * {@inheritDoc}
             *
            public void selectionChanged(final SelectionChangedEvent event) {
                updatePageComplete();
            }

        });
        */
    GridData gridData = new GridData();
    gridData.widthHint = 400;
    m_table.getControl().setLayoutData(gridData);
    Composite buttonCont = new Composite(container, SWT.TOP);
    GridLayout layout2 = new GridLayout();
    layout2.numColumns = 1;
    buttonCont.setLayout(layout2);
    gridData = new GridData();
    buttonCont.setLayoutData(gridData);
    Button selectAll = new Button(buttonCont, SWT.PUSH);
    selectAll.setText("Select all");
    gridData = new GridData();
    gridData.verticalAlignment = SWT.TOP;
    gridData.horizontalAlignment = SWT.RIGHT;
    gridData.widthHint = 80;
    selectAll.setLayoutData(gridData);
    selectAll.addSelectionListener(new SelectionListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            m_table.setAllChecked(true);
            updatePageComplete();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void widgetSelected(final SelectionEvent e) {
            m_table.setAllChecked(true);
            updatePageComplete();
        }
    });
    Button deselectAll = new Button(buttonCont, SWT.PUSH);
    deselectAll.setText("Deselect all");
    gridData = new GridData();
    gridData.verticalAlignment = SWT.TOP;
    gridData.horizontalAlignment = SWT.RIGHT;
    gridData.widthHint = 80;
    deselectAll.setLayoutData(gridData);
    deselectAll.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            m_table.setAllChecked(false);
            updatePageComplete();
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            m_table.setAllChecked(false);
            updatePageComplete();
        }
    });
    setControl(container);
    updatePageComplete();
    setMessage(null);
    setErrorMessage(null);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 87 with ArrayContentProvider

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

the class ColorMapEditDialog method createColorListViewer.

/**
 * Creates and configures a {@link TableViewer}.
 *
 * @param parent
 *            The parent for the table
 * @return The {@link TableViewer}
 */
private TableViewer createColorListViewer(final Composite parent) {
    final TableViewer viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    final TableViewerColumn tvColumn = new TableViewerColumn(viewer, SWT.NONE);
    tvColumn.getColumn().setText("Value");
    tvColumn.getColumn().setMoveable(false);
    tvColumn.getColumn().setWidth(100);
    tvColumn.setEditingSupport(new ValueColumnEditingSupport(viewer, viewer.getTable()));
    tvColumn.getColumn().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Table table = viewer.getTable();
            int dir = table.getSortDirection();
            dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
            viewer.getTable().setSortDirection(dir);
            Object[] colorTupleArray = colorList.toArray();
            Arrays.sort(colorTupleArray);
            colorList.clear();
            int i = 0;
            ColorTuple[] array = new ColorTuple[colorTupleArray.length];
            for (Object o : colorTupleArray) {
                if (dir == SWT.UP)
                    array[i++] = (ColorTuple) o;
                else
                    array[colorTupleArray.length - 1 - i++] = (ColorTuple) o;
            }
            colorList.addAll(Arrays.asList(array));
            viewer.refresh();
        }
    });
    final TableViewerColumn colorColumn = new TableViewerColumn(viewer, SWT.NONE);
    colorColumn.getColumn().setText("Color");
    colorColumn.getColumn().setMoveable(false);
    colorColumn.getColumn().setWidth(100);
    colorColumn.setEditingSupport(new ColorColumnEditingSupport(viewer, viewer.getTable()));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ColorListLabelProvider());
    viewer.getTable().setSortColumn(tvColumn.getColumn());
    viewer.getTable().setSortDirection(SWT.UP);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            refreshToolbarOnSelection();
        }
    });
    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    return viewer;
}
Also used : Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 88 with ArrayContentProvider

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

the class ConnectionsDialog method createServerPanel.

private Composite createServerPanel(Composite parent, ResourceManager resourceManager) {
    Composite serverPanel = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_BOTH);
    serverPanel.setLayoutData(gd);
    TableColumnLayout tcl = new TableColumnLayout();
    serverPanel.setLayout(tcl);
    Image serverImage = resourceManager.createImage(RCPUtils.getImageDescriptor(ConnectionsDialog.class, "icons/obj16/server.gif"));
    connViewer = new TableViewer(serverPanel, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    connViewer.getTable().setHeaderVisible(true);
    connViewer.getTable().setLinesVisible(false);
    TableViewerColumn nameColumn = new TableViewerColumn(connViewer, SWT.NONE);
    nameColumn.getColumn().setText("Connection Name");
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            return serverImage;
        }

        @Override
        public String getText(Object element) {
            YamcsConfiguration conf = (YamcsConfiguration) element;
            return conf.getName();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(400));
    connViewer.setContentProvider(new ArrayContentProvider());
    connViewer.addSelectionChangedListener(evt -> {
        IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
        if (sel.getFirstElement() != null) {
            YamcsConfiguration conf = (YamcsConfiguration) sel.getFirstElement();
            yamcsInstanceText.setText(forceString(conf.getInstance()));
            yamcsUserText.setText(forceString(conf.getUser()));
            yamcsPasswordText.setText(forceString(conf.getPassword()));
            savePasswordButton.setSelection(conf.isSavePassword());
            yamcsPrimaryHostText.setText(forceString(conf.getPrimaryHost()));
            yamcsPrimaryPortText.setText(forceString(conf.getPrimaryPort()));
            yamcsFailoverHostText.setText(forceString(conf.getFailoverHost()));
            yamcsFailoverPortText.setText(forceString(conf.getFailoverPort()));
            nameText.setText(forceString(conf.getName()));
            updateState();
        }
    });
    connViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            YamcsConfiguration c1 = (YamcsConfiguration) o1;
            YamcsConfiguration c2 = (YamcsConfiguration) o2;
            if (c1.getName() != null && c2.getName() != null)
                return c1.getName().compareTo(c2.getName());
            else
                return 0;
        }
    });
    return serverPanel;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TextUtils.forceString(org.yamcs.studio.core.ui.utils.TextUtils.forceString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 89 with ArrayContentProvider

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

the class PVTupleTableEditor method createPVTupleListTableViewer.

/**
 * Creates and configures a {@link TableViewer}.
 *
 * @param parent
 *            The parent for the table
 * @return The {@link TableViewer}
 */
private TableViewer createPVTupleListTableViewer(final Composite parent) {
    final TableViewer viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    final TableViewerColumn numColumn = new TableViewerColumn(viewer, SWT.NONE);
    numColumn.getColumn().setText("#");
    numColumn.getColumn().setMoveable(false);
    numColumn.getColumn().setWidth(50);
    final TableViewerColumn pvColumn = new TableViewerColumn(viewer, SWT.NONE);
    pvColumn.getColumn().setText("PV Name");
    pvColumn.getColumn().setMoveable(false);
    pvColumn.getColumn().setWidth(220);
    pvColumn.setEditingSupport(new PVColumnEditingSupport(viewer, viewer.getTable()));
    final TableViewerColumn TrigColumn = new TableViewerColumn(viewer, SWT.NONE);
    TrigColumn.getColumn().setText("Trigger");
    TrigColumn.getColumn().setMoveable(false);
    TrigColumn.getColumn().pack();
    TrigColumn.setEditingSupport(new TriggerColumnEditingSupport(viewer, viewer.getTable()));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new PVTupleLabelProvider(pvTupleList));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(final SelectionChangedEvent event) {
            refreshToolbarOnSelection();
        }
    });
    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    DropTarget target = new DropTarget(viewer.getControl(), DND.DROP_MOVE | DND.DROP_COPY);
    target.setTransfer(new Transfer[] { TextTransfer.getInstance() });
    target.addDropListener(new DropTargetListener() {

        @Override
        public void dragEnter(DropTargetEvent event) {
        }

        @Override
        public void dragLeave(DropTargetEvent event) {
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
        }

        @Override
        public void dragOver(DropTargetEvent event) {
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (event == null || !(event.data instanceof String))
                return;
            String txt = (String) event.data;
            String[] names = txt.split("[\r\n]+");
            PVTuple[] tuples = new PVTuple[names.length];
            int i = 0;
            for (String name : names) {
                tuples[i] = new PVTuple(name, true);
                pvTupleList.add(tuples[i]);
                i++;
            }
            refreshTableViewerFromAction(tuples);
        }

        @Override
        public void dropAccept(DropTargetEvent event) {
        }
    });
    return viewer;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PVTuple(org.csstudio.opibuilder.script.PVTuple) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) DropTarget(org.eclipse.swt.dnd.DropTarget) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 90 with ArrayContentProvider

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

the class PropertiesEditDialog method createPropertiesViewer.

private TableViewer createPropertiesViewer(Composite parent) {
    TableViewer viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    TableViewerColumn tvColumn = new TableViewerColumn(viewer, SWT.NONE);
    tvColumn.getColumn().setText("Property");
    tvColumn.getColumn().setMoveable(false);
    tvColumn.getColumn().setWidth(150);
    tvColumn = new TableViewerColumn(viewer, SWT.NONE);
    tvColumn.getColumn().setText("Value");
    tvColumn.getColumn().setMoveable(false);
    tvColumn.getColumn().setWidth(150);
    EditingSupport editingSupport = new PropertyDataEditingSupport(viewer, viewer.getTable());
    tvColumn.setEditingSupport(editingSupport);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new PropertyDataLabelProvider());
    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    return viewer;
}
Also used : ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) EditingSupport(org.eclipse.jface.viewers.EditingSupport) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)92 GridData (org.eclipse.swt.layout.GridData)67 Composite (org.eclipse.swt.widgets.Composite)59 TableViewer (org.eclipse.jface.viewers.TableViewer)56 SelectionEvent (org.eclipse.swt.events.SelectionEvent)45 Table (org.eclipse.swt.widgets.Table)43 GridLayout (org.eclipse.swt.layout.GridLayout)41 Button (org.eclipse.swt.widgets.Button)37 Label (org.eclipse.swt.widgets.Label)36 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)32 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)32 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)30 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)30 Group (org.eclipse.swt.widgets.Group)23 ComboViewer (org.eclipse.jface.viewers.ComboViewer)21 TableColumn (org.eclipse.swt.widgets.TableColumn)21 LabelProvider (org.eclipse.jface.viewers.LabelProvider)19 Combo (org.eclipse.swt.widgets.Combo)19 Text (org.eclipse.swt.widgets.Text)19 Point (org.eclipse.swt.graphics.Point)18