Search in sources :

Example 66 with IDoubleClickListener

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

the class WidgetsSelectDialog method createWidgetsViewer.

private TableViewer createWidgetsViewer(Composite parent) {
    final TableViewer viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.SINGLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new WidgetsListLableProvider());
    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            selectedWidget = (String) ((StructuredSelection) viewer.getSelection()).getFirstElement();
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            okPressed();
        }
    });
    return viewer;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 67 with IDoubleClickListener

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

the class ResourceSelectionGroup method createTreeViewer.

/**
 * Returns a new drill down viewer for this dialog.
 *
 * @param fileExtensions
 *            The file extensions of files to include in the tree.
 * @param heightHint
 *            height hint for the drill down composite
 */
protected void createTreeViewer(final String[] fileExtensions, final int heightHint) {
    // Create drill down.
    DrillDownComposite drillDown = new DrillDownComposite(this, SWT.BORDER);
    GridData spec = new GridData(SWT.FILL, SWT.FILL, true, true);
    spec.widthHint = SIZING_SELECTION_PANE_WIDTH;
    spec.heightHint = heightHint;
    drillDown.setLayoutData(spec);
    // Create tree viewer inside drill down.
    _treeViewer = new TreeViewer(drillDown, SWT.NONE);
    drillDown.setChildTree(_treeViewer);
    WorkspaceResourceContentProvider cp = new WorkspaceResourceContentProvider(fileExtensions);
    cp.showClosedProjects(_showClosedProjects);
    _treeViewer.setContentProvider(cp);
    _treeViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
    _treeViewer.setSorter(new ViewerSorter());
    _treeViewer.setUseHashlookup(true);
    _treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(final SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            containerSelectionChanged((IResource) selection.getFirstElement());
            if (_newFolderAction != null) {
                _newFolderAction.setEnabled(selection != null);
            }
        }
    });
    _treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(final DoubleClickEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                Object item = ((IStructuredSelection) selection).getFirstElement();
                if (item == null) {
                    return;
                }
                if (_treeViewer.getExpandedState(item)) {
                    _treeViewer.collapseToLevel(item, 1);
                } else if (_treeViewer.isExpandable(item)) {
                    _treeViewer.expandToLevel(item, 1);
                } else if (!(item instanceof IContainer))
                    itemDoubleClicked((IResource) item);
            }
        }
    });
    // This has to be done after the viewer has been laid out
    _treeViewer.setInput(ResourcesPlugin.getWorkspace());
    this.addNewContainerActions(drillDown.getToolBarManager());
    this.addPopupMenu(_treeViewer);
    this.setDefaultSelection(_treeViewer);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)67 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)67 GridData (org.eclipse.swt.layout.GridData)40 TableViewer (org.eclipse.jface.viewers.TableViewer)37 Composite (org.eclipse.swt.widgets.Composite)33 SelectionEvent (org.eclipse.swt.events.SelectionEvent)32 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)28 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)25 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)25 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)23 GridLayout (org.eclipse.swt.layout.GridLayout)21 Table (org.eclipse.swt.widgets.Table)16 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)15 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)13 Button (org.eclipse.swt.widgets.Button)13 Label (org.eclipse.swt.widgets.Label)13 TableColumn (org.eclipse.swt.widgets.TableColumn)13 ISelection (org.eclipse.jface.viewers.ISelection)11 TreeViewer (org.eclipse.jface.viewers.TreeViewer)11 FillLayout (org.eclipse.swt.layout.FillLayout)10