Search in sources :

Example 61 with SelectionChangedEvent

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

the class RunBlacklistPart method createSection.

private void createSection(Section section, FormToolkit tk) {
    section.setText("Run Blacklist");
    section.setDescription("The specified requirements will be excluded from the resolution.");
    // Create toolbar
    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);
    fillToolBar(toolbar);
    // Create main panel
    Composite composite = tk.createComposite(section);
    section.setClient(composite);
    table = tk.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer = new TableViewer(table);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setLabelProvider(new RequirementLabelProvider());
    // Listeners
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            removeTool.setEnabled(!viewer.getSelection().isEmpty());
        }
    });
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemove();
            } else if (e.character == '+') {
                doAddBundle();
            }
        }
    });
    RequirementViewerDropAdapter dropper = new RequirementViewerDropAdapter();
    dropper.install(viewer);
    // Layout
    GridLayout layout;
    GridData gd;
    layout = new GridLayout(2, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 5;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd.widthHint = 50;
    gd.heightHint = 50;
    table.setLayoutData(gd);
    gd = new GridData(SWT.RIGHT, SWT.CENTER, true, false);
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) RequirementLabelProvider(org.bndtools.core.ui.resource.RequirementLabelProvider)

Example 62 with SelectionChangedEvent

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

the class AnnotationsConfigurationBlock method createControl.

@Override
public Control createControl(Composite parent) {
    PixelConverter pixelConverter = new PixelConverter(parent);
    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    Label label = new Label(composite, SWT.LEFT);
    label.setText(TextEditorMessages.AnnotationsConfigurationBlock_annotationPresentationOptions);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 2;
    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(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
    gd.horizontalSpan = 2;
    editorComposite.setLayoutData(gd);
    fAnnotationTypeViewer = new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    fAnnotationTypeViewer.setLabelProvider(new ItemLabelProvider());
    fAnnotationTypeViewer.setContentProvider(new ItemContentProvider());
    gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
    gd.heightHint = pixelConverter.convertHeightInCharsToPixels(20);
    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(GridData.FILL_BOTH));
    label = new Label(optionsComposite, SWT.LEFT);
    label.setText(TextEditorMessages.AnnotationsConfigurationBlock_labels_showIn);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    label.setLayoutData(gd);
    fShowInVerticalRulerCheckBox = new Button(optionsComposite, SWT.CHECK);
    fShowInVerticalRulerCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInVerticalRuler);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    gd.horizontalIndent = 20;
    fShowInVerticalRulerCheckBox.setLayoutData(gd);
    fShowInOverviewRulerCheckBox = new Button(optionsComposite, SWT.CHECK);
    fShowInOverviewRulerCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInOverviewRuler);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    gd.horizontalIndent = 20;
    fShowInOverviewRulerCheckBox.setLayoutData(gd);
    fShowInTextCheckBox = new Button(optionsComposite, SWT.CHECK);
    fShowInTextCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInText);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalIndent = 20;
    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, PROBLEM_UNDERLINE, IBEAM });
    fDecorationViewer.getCombo().setVisibleItemCount(fDecorationViewer.getCombo().getItemCount());
    label = new Label(optionsComposite, SWT.LEFT);
    label.setText(TextEditorMessages.AnnotationsConfigurationBlock_color);
    gd = new GridData();
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalIndent = 20;
    label.setLayoutData(gd);
    fAnnotationForegroundColorEditor = new ColorSelector(optionsComposite);
    Button foregroundColorButton = fAnnotationForegroundColorEditor.getButton();
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    foregroundColorButton.setLayoutData(gd);
    addFiller(optionsComposite);
    fIsNextPreviousTargetCheckBox = new Button(optionsComposite, SWT.CHECK);
    fIsNextPreviousTargetCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_isNavigationTarget);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    gd.horizontalIndent = 0;
    fIsNextPreviousTargetCheckBox.setLayoutData(gd);
    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))
                    fStore.setValue(item.highlightKey, true);
                else
                    fStore.setValue(item.textKey, true);
            } else {
                // disable both
                if (item.textKey != null)
                    fStore.setValue(item.textKey, false);
                if (item.highlightKey != null)
                    fStore.setValue(item.highlightKey, false);
            }
            fStore.setValue(item.textKey, value);
            updateDecorationViewer(item, false);
            fAnnotationTypeViewer.refresh(item);
        }
    });
    fShowInOverviewRulerCheckBox.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            fStore.setValue(item.overviewRulerKey, fShowInOverviewRulerCheckBox.getSelection());
            fAnnotationTypeViewer.refresh(item);
        }
    });
    fShowInVerticalRulerCheckBox.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            fStore.setValue(item.verticalRulerKey, fShowInVerticalRulerCheckBox.getSelection());
            fAnnotationTypeViewer.refresh(item);
        }
    });
    fIsNextPreviousTargetCheckBox.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            fStore.setValue(item.isNextPreviousNavigationKey, fIsNextPreviousTargetCheckBox.getSelection());
            fAnnotationTypeViewer.refresh(item);
        }
    });
    foregroundColorButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            PreferenceConverter.setValue(fStore, item.colorKey, fAnnotationForegroundColorEditor.getColorValue());
            fAnnotationTypeViewer.refresh(item);
        }
    });
    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)) {
                    fStore.setValue(item.highlightKey, true);
                    if (item.textKey != null) {
                        fStore.setValue(item.textKey, false);
                        if (item.textStyleKey != null)
                            fStore.setValue(item.textStyleKey, AnnotationPreference.STYLE_NONE);
                    }
                } else {
                    if (item.highlightKey != null)
                        fStore.setValue(item.highlightKey, false);
                    if (item.textKey != null) {
                        fStore.setValue(item.textKey, true);
                        if (item.textStyleKey != null)
                            fStore.setValue(item.textStyleKey, decoration[1]);
                    }
                }
            }
            fAnnotationTypeViewer.refresh(item);
        }
    });
    composite.layout();
    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) PixelConverter(org.eclipse.jface.layout.PixelConverter) 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 63 with SelectionChangedEvent

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

the class AbstractTextSearchViewPage method createViewer.

private void createViewer(Composite parent, int layout) {
    if ((layout & FLAG_LAYOUT_FLAT) != 0) {
        TableViewer viewer = createTableViewer(parent);
        fViewer = viewer;
        configureTableViewer(viewer);
    } else if ((layout & FLAG_LAYOUT_TREE) != 0) {
        TreeViewer viewer = createTreeViewer(parent);
        fViewer = viewer;
        configureTreeViewer(viewer);
        fCollapseAllAction.setViewer(viewer);
        fExpandAllAction.setViewer(viewer);
    }
    fCopyToClipboardAction.setViewer(fViewer);
    fSelectAllAction.setViewer(fViewer);
    IToolBarManager tbm = getSite().getActionBars().getToolBarManager();
    tbm.removeAll();
    SearchView.createToolBarGroups(tbm);
    fillToolbar(tbm);
    tbm.update(false);
    new OpenAndLinkWithEditorHelper(fViewer) {

        @Override
        protected void activate(ISelection selection) {
            final int currentMode = OpenStrategy.getOpenMethod();
            try {
                OpenStrategy.setOpenMethod(OpenStrategy.DOUBLE_CLICK);
                handleOpen(new OpenEvent(fViewer, selection));
            } finally {
                OpenStrategy.setOpenMethod(currentMode);
            }
        }

        @Override
        protected void linkToEditor(ISelection selection) {
        // not supported by this part
        }

        @Override
        protected void open(ISelection selection, boolean activate) {
            handleOpen(new OpenEvent(fViewer, selection));
        }
    };
    fViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            fCurrentMatchIndex = -1;
            fRemoveSelectedMatches.setEnabled(canRemoveMatchesWith(event.getSelection()));
        }
    });
    fViewer.addSelectionChangedListener(fViewerAdapter);
    Menu menu = fMenu.createContextMenu(fViewer.getControl());
    fViewer.getControl().setMenu(menu);
    updateLayoutActions();
    getViewPart().updateLabel();
}
Also used : OpenAndLinkWithEditorHelper(org.eclipse.ui.OpenAndLinkWithEditorHelper) IToolBarManager(org.eclipse.jface.action.IToolBarManager) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Menu(org.eclipse.swt.widgets.Menu) TableViewer(org.eclipse.jface.viewers.TableViewer) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 64 with SelectionChangedEvent

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

the class MatchFilterSelectionDialog method createMatchFilterControls.

private void createMatchFilterControls(Composite parent) {
    // Create list viewer
    Label l = new Label(parent, SWT.NONE);
    l.setFont(parent.getFont());
    l.setText(SearchMessages.MatchFilterSelectionDialog_filter_description);
    Table table = new Table(parent, SWT.CHECK | SWT.BORDER);
    table.setFont(parent.getFont());
    fListViewer = new CheckboxTableViewer(table);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.minimumHeight = convertHeightInCharsToPixels(8);
    table.setLayoutData(data);
    class ListenerAndLabelProvider extends LabelProvider implements ISelectionChangedListener, ICheckStateListener {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            performFilterListSelectionChanged();
        }

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            performFilterListCheckStateChanged();
        }

        @Override
        public String getText(Object element) {
            return ((MatchFilter) element).getName();
        }
    }
    ListenerAndLabelProvider listenerAndLP = new ListenerAndLabelProvider();
    fListViewer.setLabelProvider(listenerAndLP);
    fListViewer.setContentProvider(new ArrayContentProvider());
    fListViewer.addSelectionChangedListener(listenerAndLP);
    fListViewer.addCheckStateListener(listenerAndLP);
    fListViewer.setInput(fAllFilters);
    fListViewer.setCheckedElements(fEnabledFilters);
    l = new Label(parent, SWT.NONE);
    l.setFont(parent.getFont());
    l.setText(SearchMessages.MatchFilterSelectionDialog_description_label);
    fDescription = new Text(parent, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL);
    fDescription.setFont(parent.getFont());
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = convertHeightInCharsToPixels(3);
    fDescription.setLayoutData(data);
}
Also used : Table(org.eclipse.swt.widgets.Table) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Text(org.eclipse.swt.widgets.Text) MatchFilter(org.eclipse.search.ui.text.MatchFilter) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 65 with SelectionChangedEvent

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

the class AbstractTextEditor method getSelectionChangedListener.

/**
 * Returns this editor's selection changed listener to be installed
 * on the editor's source viewer.
 *
 * @return the listener
 */
protected final ISelectionChangedListener getSelectionChangedListener() {
    if (fSelectionChangedListener == null) {
        fSelectionChangedListener = new ISelectionChangedListener() {

            private Runnable fRunnable = new Runnable() {

                @Override
                public void run() {
                    // check whether editor has not been disposed yet
                    if (fSourceViewer != null && fSourceViewer.getDocument() != null) {
                        handleCursorPositionChanged();
                        updateSelectionDependentActions();
                    }
                }
            };

            private Display fDisplay;

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                if (fDisplay == null)
                    fDisplay = getSite().getShell().getDisplay();
                if (Display.getCurrent() == fDisplay)
                    fRunnable.run();
                else
                    fDisplay.asyncExec(fRunnable);
            }
        };
    }
    return fSelectionChangedListener;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SafeRunnable(org.eclipse.jface.util.SafeRunnable) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Display(org.eclipse.swt.widgets.Display)

Aggregations

SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)168 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)161 GridData (org.eclipse.swt.layout.GridData)95 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)82 Composite (org.eclipse.swt.widgets.Composite)74 GridLayout (org.eclipse.swt.layout.GridLayout)65 TableViewer (org.eclipse.jface.viewers.TableViewer)60 SelectionEvent (org.eclipse.swt.events.SelectionEvent)55 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)46 Label (org.eclipse.swt.widgets.Label)42 ISelection (org.eclipse.jface.viewers.ISelection)41 Table (org.eclipse.swt.widgets.Table)41 TreeViewer (org.eclipse.jface.viewers.TreeViewer)36 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)31 Button (org.eclipse.swt.widgets.Button)31 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)25 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)25 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)18 ArrayList (java.util.ArrayList)17 ComboViewer (org.eclipse.jface.viewers.ComboViewer)17