Search in sources :

Example 36 with ArrayContentProvider

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

the class MassifViewPart method createPartControl.

@Override
public void createPartControl(Composite parent) {
    chartInputs = new ArrayList<>();
    top = new Composite(parent, SWT.NONE);
    stackLayout = new StackLayout();
    top.setLayout(stackLayout);
    top.setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer = new TableViewer(top, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    Table table = viewer.getTable();
    table.setLayoutData(new GridData(GridData.FILL_BOTH));
    String[] columnTitles = { TITLE_NUMBER, TITLE_TIME, TITLE_TOTAL, TITLE_USEFUL, TITLE_EXTRA, TITLE_STACKS };
    for (int i = 0; i < columnTitles.length; i++) {
        TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
        column.getColumn().setText(columnTitles[i]);
        column.getColumn().setWidth(COLUMN_SIZE);
        column.getColumn().setResizable(true);
        column.getColumn().addSelectionListener(getHeaderListener());
    }
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new MassifLabelProvider());
    treeViewer = new MassifTreeViewer(top);
    treeViewer.getViewer().getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer.addDoubleClickListener(event -> {
        MassifSnapshot snapshot = (MassifSnapshot) ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (snapshot.getType() != SnapshotType.EMPTY) {
            treeAction.setChecked(true);
            setTopControl(treeViewer.getViewer().getControl());
            treeViewer.getViewer().setSelection(new StructuredSelection(snapshot.getRoot()), true);
            treeViewer.getViewer().expandToLevel(snapshot.getRoot(), AbstractTreeViewer.ALL_LEVELS);
        }
    });
    stackLayout.topControl = viewer.getControl();
    top.layout();
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StackLayout(org.eclipse.swt.custom.StackLayout) 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 37 with ArrayContentProvider

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

the class ContainerDataVolumeDialog method createDialogArea.

@Override
protected Control createDialogArea(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    final int COLUMNS = 3;
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, true).applyTo(container);
    GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(COLUMNS).applyTo(container);
    // Container path
    final Label containerPathLabel = new Label(container, SWT.NONE);
    containerPathLabel.setText(WizardMessages.getString(// $NON-NLS-1$
    "ContainerDataVolumeDialog.containerPathLabel"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(containerPathLabel);
    final Text containerPathText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(containerPathText);
    final IObservableValue containerPathObservable = BeanProperties.value(DataVolumeModel.class, DataVolumeModel.CONTAINER_PATH).observe(model);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(containerPathText), containerPathObservable);
    // mount type
    final Label explanationLabel = new Label(container, SWT.NONE);
    explanationLabel.setText(WizardMessages.getString(// $NON-NLS-1$
    "ContainerDataVolumeDialog.explanationLabel"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(true, false).applyTo(explanationLabel);
    final int INDENT = 20;
    // No mount
    final Button noMountButton = new Button(container, SWT.RADIO);
    noMountButton.setText(WizardMessages.getString(// $NON-NLS-1$
    "ContainerDataVolumeDialog.noMountButton"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(INDENT, 0).span(COLUMNS, 1).grab(true, false).applyTo(noMountButton);
    bindButton(noMountButton, MountType.NONE);
    // File System mount
    final Button fileSystemMountButton = new Button(container, SWT.RADIO);
    fileSystemMountButton.setText(WizardMessages.getString(// $NON-NLS-1$
    "ContainerDataVolumeDialog.fileSystemMountButton"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(INDENT, 0).span(COLUMNS, 1).grab(true, false).applyTo(fileSystemMountButton);
    final Label hostPathLabel = new Label(container, SWT.NONE);
    hostPathLabel.setText(WizardMessages.getString(// $NON-NLS-1$
    "ContainerDataVolumeDialog.hostPathLabel"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(2 * INDENT, SWT.DEFAULT).grab(false, false).applyTo(hostPathLabel);
    final Text hostPathText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(hostPathText);
    final IObservableValue hostPathObservable = BeanProperties.value(DataVolumeModel.class, DataVolumeModel.HOST_PATH_MOUNT).observe(model);
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(hostPathText), hostPathObservable);
    // browse for directory
    final Button hostPathDirectoryButton = new Button(container, SWT.NONE);
    hostPathDirectoryButton.setText(WizardMessages.getString(// $NON-NLS-1$
    "ContainerDataVolumeDialog.directoryButton"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(hostPathDirectoryButton);
    hostPathDirectoryButton.addSelectionListener(onHostDirectoryPath());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(new Label(container, SWT.NONE));
    // optional read-only access
    final Button readOnlyButton = new Button(container, SWT.CHECK);
    readOnlyButton.setText(WizardMessages.getString(// $NON-NLS-1$
    "ContainerDataVolumeDialog.readOnlyButton"));
    readOnlyButton.setToolTipText(WizardMessages.getString(// $NON-NLS-1$
    "ContainerDataVolumeDialog.readOnlyButtonTooltip"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS - 2, 1).grab(true, false).applyTo(readOnlyButton);
    final ISWTObservableValue readOnlyButtonObservable = WidgetProperties.selection().observe(readOnlyButton);
    dbc.bindValue(readOnlyButtonObservable, BeanProperties.value(DataVolumeModel.class, DataVolumeModel.READ_ONLY_VOLUME).observe(model));
    // browse for file
    final Button hostPathFileButton = new Button(container, SWT.NONE);
    hostPathFileButton.setText(WizardMessages.getString(// $NON-NLS-1$
    "ContainerDataVolumeDialog.fileButton"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(hostPathFileButton);
    hostPathFileButton.addSelectionListener(onHostFilePath());
    bindButton(fileSystemMountButton, MountType.HOST_FILE_SYSTEM, hostPathText, hostPathDirectoryButton, hostPathFileButton, readOnlyButton);
    // Container mount
    final Button containerMountButton = new Button(container, SWT.RADIO);
    containerMountButton.setText(WizardMessages.getString(// $NON-NLS-1$
    "ContainerDataVolumeDialog.containerMountButton"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(INDENT, 0).span(COLUMNS, 1).grab(true, false).applyTo(containerMountButton);
    final Label containerSelectionLabel = new Label(container, SWT.NONE);
    containerSelectionLabel.setText(WizardMessages.getString(// $NON-NLS-1$
    "ContainerDataVolumeDialog.containerSelectionLabel"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(2 * INDENT, SWT.DEFAULT).applyTo(containerSelectionLabel);
    final Combo containerSelectionCombo = new Combo(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(containerSelectionCombo);
    new ControlDecoration(containerSelectionCombo, SWT.TOP | SWT.LEFT);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(new Label(container, SWT.NONE));
    bindButton(containerMountButton, MountType.CONTAINER, containerSelectionCombo);
    final ComboViewer containerSelectionComboViewer = new ComboViewer(containerSelectionCombo);
    containerSelectionComboViewer.setContentProvider(new ArrayContentProvider());
    containerSelectionComboViewer.setInput(this.containerNames);
    final IObservableValue selectedContainerObservable = BeanProperties.value(DataVolumeModel.class, DataVolumeModel.CONTAINER_MOUNT).observe(model);
    dbc.bindValue(WidgetProperties.selection().observe(containerSelectionCombo), selectedContainerObservable);
    new ContentProposalAdapter(containerSelectionCombo, new ComboContentAdapter() {

        @Override
        public void insertControlContents(Control control, String text, int cursorPosition) {
            final Combo combo = (Combo) control;
            final Point selection = combo.getSelection();
            combo.setText(text);
            selection.x = text.length();
            selection.y = selection.x;
            combo.setSelection(selection);
        }
    }, getContainerNameContentProposalProvider(containerSelectionCombo), null, null);
    // error message
    final Composite errorContainer = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(COLUMNS, 1).grab(true, true).applyTo(errorContainer);
    GridLayoutFactory.fillDefaults().margins(6, 6).numColumns(2).applyTo(errorContainer);
    final Label errorMessageIcon = new Label(errorContainer, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(20, SWT.DEFAULT).applyTo(errorMessageIcon);
    final Label errorMessageLabel = new Label(errorContainer, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(errorMessageLabel);
    setupValidationSupport(errorMessageIcon, errorMessageLabel);
    return container;
}
Also used : ComboContentAdapter(org.eclipse.jface.fieldassist.ComboContentAdapter) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Example 38 with ArrayContentProvider

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

the class DockerComposeUpDialog method createDialogArea.

@SuppressWarnings("unchecked")
@Override
protected Control createDialogArea(final Composite parent) {
    final int COLUMNS = 2;
    final Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(COLUMNS, 1).grab(true, false).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(10, 10).applyTo(container);
    final Label explanationLabel = new Label(container, SWT.NONE);
    explanationLabel.setText(WizardMessages.getString(// $NON-NLS-1$
    "DockerComposeUpDialog.explanationLabel"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(false, false).applyTo(explanationLabel);
    final Label containerLabel = new Label(container, SWT.NONE);
    containerLabel.setText(WizardMessages.getString(// $NON-NLS-1$
    "DockerComposeUpDialog.connectionLabel"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(containerLabel);
    final Combo containerSelectionCombo = new Combo(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(containerSelectionCombo);
    final ComboViewer connectionSelectionComboViewer = new ComboViewer(containerSelectionCombo);
    connectionSelectionComboViewer.setContentProvider(new ArrayContentProvider());
    final List<String> connectionNames = model.getConnectionNames();
    connectionSelectionComboViewer.setInput(connectionNames);
    new ContentProposalAdapter(containerSelectionCombo, new ComboContentAdapter() {

        @Override
        public void insertControlContents(Control control, String text, int cursorPosition) {
            final Combo combo = (Combo) control;
            final Point selection = combo.getSelection();
            combo.setText(text);
            selection.x = text.length();
            selection.y = selection.x;
            combo.setSelection(selection);
        }
    }, getConnectionNameContentProposalProvider(containerSelectionCombo), null, null);
    final ISWTObservableValue connnectionNameObservable = WidgetProperties.selection().observe(connectionSelectionComboViewer.getCombo());
    // pre-select with first connection
    if (!connectionNames.isEmpty()) {
        model.setConnectionName(connectionNames.get(0));
    }
    // error message
    final Composite errorContainer = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(COLUMNS, 1).grab(true, true).applyTo(errorContainer);
    GridLayoutFactory.fillDefaults().margins(6, 6).numColumns(2).applyTo(errorContainer);
    final Label errorMessageIcon = new Label(errorContainer, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(20, SWT.DEFAULT).applyTo(errorMessageIcon);
    final Label errorMessageLabel = new Label(errorContainer, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(errorMessageLabel);
    dbc.bindValue(connnectionNameObservable, BeanProperties.value(DockerComposeUpModel.class, DockerComposeUpModel.CONNECTION_NAME).observe(model));
    // must be called after bindings were set
    setupValidationSupport(errorMessageIcon, errorMessageLabel);
    return container;
}
Also used : ComboContentAdapter(org.eclipse.jface.fieldassist.ComboContentAdapter) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) Control(org.eclipse.swt.widgets.Control) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue)

Example 39 with ArrayContentProvider

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

the class ImagePushPage method createImageSelectionControls.

@SuppressWarnings("unchecked")
private IObservableValue<String> createImageSelectionControls(final Composite container) {
    final Label nameLabel = new Label(container, SWT.NULL);
    nameLabel.setText(// $NON-NLS-1$
    WizardMessages.getString("ImagePullPushPage.name.label"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(nameLabel);
    final Combo imageNameCombo = new Combo(container, SWT.DROP_DOWN);
    imageNameCombo.setToolTipText(// $NON-NLS-1$
    WizardMessages.getString("ImagePushName.toolTip"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(imageNameCombo);
    final ComboViewer imageNameComboViewer = new ComboViewer(imageNameCombo);
    imageNameComboViewer.setContentProvider(new ArrayContentProvider());
    imageNameComboViewer.setInput(getModel().getImage().repoTags());
    // binding must take place after the input is set, so that default
    // repo/name can be selected.
    final IObservableValue<String> imageNameObservable = BeanProperties.value(ImagePushPageModel.class, ImagePullPushPageModel.SELECTED_IMAGE_NAME).observe(getModel());
    dbc.bindValue(WidgetProperties.selection().observe(imageNameCombo), imageNameObservable);
    // filler for the last column
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(new Label(container, SWT.NONE));
    return imageNameObservable;
}
Also used : ComboViewer(org.eclipse.jface.viewers.ComboViewer) Label(org.eclipse.swt.widgets.Label) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Combo(org.eclipse.swt.widgets.Combo)

Example 40 with ArrayContentProvider

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

the class RuleDataEditDialog method createExpressionsTableViewer.

/**
 * Creates and configures a {@link TableViewer}.
 *
 * @param parent
 *            The parent for the table
 * @return The {@link TableViewer}
 */
private TableViewer createExpressionsTableViewer(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);
    TableViewerColumn expressionColumn = new TableViewerColumn(viewer, SWT.NONE);
    expressionColumn.getColumn().setText("Boolean Expression");
    expressionColumn.getColumn().setMoveable(false);
    expressionColumn.getColumn().setWidth(200);
    expressionColumn.setEditingSupport(new EditingSupport(viewer) {

        @Override
        protected void setValue(Object element, Object value) {
            if (element instanceof Expression)
                ((Expression) element).setBooleanExpression(value.toString());
            viewer.refresh();
        }

        @Override
        protected Object getValue(Object element) {
            if (element instanceof Expression)
                return ((Expression) element).getBooleanExpression();
            return null;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new TextCellEditor(viewer.getTable());
        }

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }
    });
    valueColumn = new TableViewerColumn(viewer, SWT.NONE);
    valueColumn.getColumn().setText(ruleData.isOutputExpValue() ? "Output Expression" : "Output Value");
    valueColumn.getColumn().setMoveable(false);
    valueColumn.getColumn().setWidth(200);
    EditingSupport editingSupport = new EditingSupport(viewer) {

        @Override
        protected void setValue(Object element, Object value) {
            if (element instanceof Expression) {
                ((Expression) element).setValue(value);
            }
            viewer.refresh();
        }

        @Override
        protected Object getValue(Object element) {
            if (element instanceof Expression) {
                if (((Expression) element).getValue() == null)
                    // $NON-NLS-1$
                    return "";
                return ((Expression) element).getValue();
            }
            return null;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            if (element instanceof Expression) {
                if (ruleData.isOutputExpValue() || ruleData.getProperty().getPropertyDescriptor() == null)
                    return new TextCellEditor(viewer.getTable());
                else
                    return ruleData.getProperty().getPropertyDescriptor().createPropertyEditor(viewer.getTable());
            }
            return null;
        }

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }
    };
    valueColumn.setEditingSupport(editingSupport);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ExpressionLabelProvider());
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    viewer.getTable().setLayoutData(gd);
    return viewer;
}
Also used : Expression(org.csstudio.opibuilder.script.Expression) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) EditingSupport(org.eclipse.jface.viewers.EditingSupport) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) 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