Search in sources :

Example 76 with ArrayContentProvider

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

the class JarListWizardPage method createControl.

@Override
public void createControl(final Composite parent) {
    setTitle("Select JARs");
    final Composite composite = new Composite(parent, SWT.NONE);
    Label lblHint = new Label(composite, SWT.WRAP);
    lblHint.setText("Selected files (hint: drag files from an external application into this list):");
    final Table table = new Table(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ClassPathLabelProvider());
    btnAdd = new Button(composite, SWT.PUSH);
    btnAdd.setText("Add");
    btnAddExternal = new Button(composite, SWT.PUSH);
    btnAddExternal.setText("Add External");
    btnRemove = new Button(composite, SWT.PUSH);
    btnRemove.setText("Remove");
    viewer.setInput(paths);
    update();
    // Listeners
    ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {

        @Override
        public void dragEnter(DropTargetEvent event) {
            super.dragEnter(event);
            event.detail = DND.DROP_COPY;
        }

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            return true;
        }

        @Override
        public boolean performDrop(Object data) {
            if (data instanceof String[]) {
                String[] newPaths = (String[]) data;
                List<IPath> added = new ArrayList<IPath>(newPaths.length);
                for (String path : newPaths) {
                    added.add(new Path(path));
                }
                if (!added.isEmpty()) {
                    addToPaths(added);
                    viewer.add(added.toArray());
                    update();
                }
            }
            return true;
        }
    };
    dropAdapter.setFeedbackEnabled(false);
    dropAdapter.setSelectionFeedbackEnabled(false);
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { FileTransfer.getInstance() }, dropAdapter);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            update();
        }
    });
    btnAdd.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // IResource newFile = ResourcesPlugin.getWorkspace().getRoot();
            // if(newFile != null) {
            ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
            dialog.setValidator(new ISelectionStatusValidator() {

                @Override
                public IStatus validate(Object[] selection) {
                    if (selection.length > 0 && selection[0] instanceof IFile) {
                        //$NON-NLS-1$
                        return new Status(IStatus.OK, Plugin.PLUGIN_ID, IStatus.OK, "", null);
                    }
                    //$NON-NLS-1$
                    return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, IStatus.ERROR, "", null);
                }
            });
            dialog.setAllowMultiple(true);
            dialog.setTitle("JAR File Selection");
            dialog.setMessage("Select one or more JAR files.");
            //$NON-NLS-1$
            dialog.addFilter(new FileExtensionFilter("jar"));
            dialog.setInput(ResourcesPlugin.getWorkspace());
            if (dialog.open() == Window.OK) {
                Object[] files = dialog.getResult();
                List<IPath> added = new ArrayList<IPath>(files.length);
                for (Object file : files) {
                    added.add(((IResource) file).getFullPath().makeRelative());
                }
                if (!added.isEmpty()) {
                    addToPaths(added);
                    viewer.add(added.toArray());
                }
            }
            // }
            update();
        }
    });
    btnAddExternal.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.MULTI);
            dialog.setFilterExtensions(new String[] { //$NON-NLS-1$
            "*.jar" });
            String res = dialog.open();
            if (res != null) {
                IPath filterPath = new Path(dialog.getFilterPath());
                String[] fileNames = dialog.getFileNames();
                List<IPath> added = new ArrayList<IPath>(fileNames.length);
                for (String fileName : fileNames) {
                    added.add(filterPath.append(fileName));
                }
                if (!added.isEmpty()) {
                    addToPaths(added);
                    viewer.add(added.toArray());
                }
            }
            update();
        }
    });
    btnRemove.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            removeFromPaths(((IStructuredSelection) viewer.getSelection()).toList());
            viewer.remove(((IStructuredSelection) viewer.getSelection()).toArray());
            update();
        }
    });
    // Layout
    composite.setLayout(new GridLayout(2, false));
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
    btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    btnAddExternal.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    lblHint.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1));
    setControl(composite);
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ClassPathLabelProvider(bndtools.utils.ClassPathLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) TransferData(org.eclipse.swt.dnd.TransferData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileExtensionFilter(bndtools.utils.FileExtensionFilter) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 77 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project eclipse.platform.text by eclipse.

the class LinkedModeConfigurationBlock method createControl.

/**
 * Creates page for hover preferences.
 *
 * @param parent the parent composite
 * @return the control for the preference page
 */
@Override
public Control createControl(Composite parent) {
    OverlayPreferenceStore store = getPreferenceStore();
    store.load();
    store.start();
    initializeDialogUnits(parent);
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    Label label = new Label(composite, SWT.LEFT);
    label.setText(TextEditorMessages.LinkedModeConfigurationBlock_annotationPresentationOptions);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    label.setLayoutData(gd);
    Composite editorComposite = new Composite(composite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    editorComposite.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    editorComposite.setLayoutData(gd);
    fAnnotationTypeViewer = new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
    fAnnotationTypeViewer.setLabelProvider(new ItemLabelProvider());
    fAnnotationTypeViewer.setContentProvider(new ItemContentProvider());
    gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
    gd.heightHint = convertHeightInCharsToPixels(5);
    fAnnotationTypeViewer.getControl().setLayoutData(gd);
    Composite optionsComposite = new Composite(editorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    optionsComposite.setLayout(layout);
    optionsComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
    // we only allow to set either "show in text" or "highlight in text", but not both
    fShowInTextCheckBox = new Button(optionsComposite, SWT.CHECK);
    fShowInTextCheckBox.setText(TextEditorMessages.LinkedModeConfigurationBlock_labels_showIn);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    fShowInTextCheckBox.setLayoutData(gd);
    fDecorationViewer = new ComboViewer(optionsComposite, SWT.READ_ONLY);
    fDecorationViewer.setContentProvider(new ArrayContentProvider());
    fDecorationViewer.setLabelProvider(new ArrayLabelProvider());
    fDecorationViewer.setComparator(new ViewerComparator(Collator.getInstance()));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    fDecorationViewer.getControl().setLayoutData(gd);
    fDecorationViewer.setInput(new Object[] { HIGHLIGHT, SQUIGGLES, BOX, DASHED_BOX, UNDERLINE, IBEAM });
    label = new Label(optionsComposite, SWT.LEFT);
    label.setText(TextEditorMessages.LinkedModeConfigurationBlock_color);
    gd = new GridData();
    gd.horizontalAlignment = GridData.BEGINNING;
    label.setLayoutData(gd);
    fAnnotationForegroundColorEditor = new ColorSelector(optionsComposite);
    Button foregroundColorButton = fAnnotationForegroundColorEditor.getButton();
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    foregroundColorButton.setLayoutData(gd);
    createDependency(fShowInTextCheckBox, new Control[] { label, foregroundColorButton });
    fAnnotationTypeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            handleAnnotationListSelection();
        }
    });
    fShowInTextCheckBox.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // do nothing
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            final boolean value = fShowInTextCheckBox.getSelection();
            if (value) {
                // enable whatever is in the combo
                String[] decoration = (String[]) ((IStructuredSelection) fDecorationViewer.getSelection()).getFirstElement();
                if (HIGHLIGHT.equals(decoration))
                    getPreferenceStore().setValue(item.highlightKey, true);
                else
                    getPreferenceStore().setValue(item.textKey, true);
            } else {
                // disable both
                getPreferenceStore().setValue(item.textKey, false);
                getPreferenceStore().setValue(item.highlightKey, false);
            }
            getPreferenceStore().setValue(item.textKey, value);
            updateDecorationViewer(item, false);
        }
    });
    foregroundColorButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // do nothing
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            PreferenceConverter.setValue(getPreferenceStore(), item.colorKey, fAnnotationForegroundColorEditor.getColorValue());
        }
    });
    fDecorationViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            String[] decoration = (String[]) ((IStructuredSelection) fDecorationViewer.getSelection()).getFirstElement();
            ListItem item = getSelectedItem();
            if (fShowInTextCheckBox.getSelection()) {
                if (HIGHLIGHT.equals(decoration)) {
                    getPreferenceStore().setValue(item.highlightKey, true);
                    getPreferenceStore().setValue(item.textKey, false);
                    getPreferenceStore().setValue(item.textStyleKey, AnnotationPreference.STYLE_NONE);
                } else {
                    getPreferenceStore().setValue(item.highlightKey, false);
                    getPreferenceStore().setValue(item.textKey, true);
                    getPreferenceStore().setValue(item.textStyleKey, decoration[1]);
                }
            }
        }
    });
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColorSelector(org.eclipse.jface.preference.ColorSelector) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 78 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project eclipse.platform.text by eclipse.

the class SearchHistorySelectionDialog method createDialogArea.

/*
	 * Overrides method from Dialog
	 */
@Override
protected Control createDialogArea(Composite container) {
    Composite ancestor = (Composite) super.createDialogArea(container);
    createMessageArea(ancestor);
    Composite parent = new Composite(ancestor, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);
    parent.setLayoutData(new GridData(GridData.FILL_BOTH));
    fViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    fViewer.setContentProvider(new ArrayContentProvider());
    final Table table = fViewer.getTable();
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            okPressed();
        }
    });
    fViewer.setLabelProvider(new SearchesLabelProvider());
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = convertHeightInCharsToPixels(15);
    gd.widthHint = convertWidthInCharsToPixels(WIDTH_IN_CHARACTERS);
    table.setLayoutData(gd);
    fRemoveButton = new Button(parent, SWT.PUSH);
    fRemoveButton.setText(SearchMessages.SearchesDialog_remove_label);
    fRemoveButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            buttonPressed(REMOVE_ID);
        }
    });
    fRemoveButton.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
    SWTUtil.setButtonDimensionHint(fRemoveButton);
    fViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            validateDialogState();
        }
    });
    fLink = new Link(parent, SWT.NONE);
    configureHistoryLink();
    fLink.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            HistoryConfigurationDialog dialog = new HistoryConfigurationDialog(getShell(), fInput, fRemovedEntries);
            if (dialog.open() == Window.OK) {
                fViewer.refresh();
                configureHistoryLink();
            }
        }
    });
    fLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    applyDialogFont(ancestor);
    // set input & selections last, so all the widgets are created.
    fViewer.setInput(fInput);
    fViewer.getTable().setFocus();
    return ancestor;
}
Also used : Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) Link(org.eclipse.swt.widgets.Link)

Example 79 with ArrayContentProvider

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

the class BuildDockerImageLaunchConfigurationMainTab method createControl.

@Override
public void createControl(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(container);
    GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(container);
    setControl(container);
    // connection selection
    final Group connectionGroup = new Group(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(connectionGroup);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(connectionGroup);
    connectionGroup.setText(LaunchMessages.getString(CONNECTION_LABEL));
    connectionGroup.setToolTipText(LaunchMessages.getString(CONNECTION_TOOLTIP));
    final Combo connectionSelectionCombo = new Combo(connectionGroup, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(connectionSelectionCombo);
    this.connectionSelectionComboViewer = new ComboViewer(connectionSelectionCombo);
    this.connectionSelectionComboViewer.setContentProvider(new ArrayContentProvider());
    this.connectionSelectionComboViewer.setInput(DockerConnectionManager.getInstance().getConnectionNames());
    connectionSelectionCombo.addSelectionListener(new LaunchConfigurationChangeListener());
    // build context path
    createBuildContextPathGroup(container);
    // repository name
    createRepoNameGroup(container);
    // dockerfile path
    // createDockerfilePathGroup(container);
    // build options
    createBuildOptionsGroup(container);
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Combo(org.eclipse.swt.widgets.Combo)

Example 80 with ArrayContentProvider

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

the class DockerComposeUpLaunchConfigurationMainTab method createControl.

@Override
public void createControl(final Composite parent) {
    final Composite container = new Composite(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(container);
    GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(container);
    setControl(container);
    // connection selection
    final Group connectionGroup = new Group(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(connectionGroup);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(connectionGroup);
    connectionGroup.setText(LaunchMessages.getString(// $NON-NLS-1$
    "DockerComposeUpLaunchConfigurationMainTab.connection.group.label"));
    connectionGroup.setToolTipText(LaunchMessages.getString(// $NON-NLS-1$
    "DockerComposeUpLaunchConfigurationMainTab.connection.group.tooltip"));
    final Combo connectionSelectionCombo = new Combo(connectionGroup, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(connectionSelectionCombo);
    this.connectionSelectionComboViewer = new ComboViewer(connectionSelectionCombo);
    this.connectionSelectionComboViewer.setContentProvider(new ArrayContentProvider());
    this.connectionSelectionComboViewer.setInput(DockerConnectionManager.getInstance().getConnectionNames());
    connectionSelectionCombo.addSelectionListener(new LaunchConfigurationChangeListener());
    // docker compose config file
    createDockerComposeWorkingDirLocationGroup(container);
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Combo(org.eclipse.swt.widgets.Combo)

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