Search in sources :

Example 1 with TableResizeHelper

use of org.springsource.ide.eclipse.commons.quicksearch.util.TableResizeHelper in project eclipse-integration-commons by spring-projects.

the class QuickSearchDialog method createDialogArea.

// /**
// * Creates an extra content area, which will be located above the details.
// *
// * @param parent
// *           parent to create the dialog widgets in
// * @return an extra content area
// */
// protected abstract Control createExtendedContentArea(Composite parent);
/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    dialogArea.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            QuickSearchDialog.this.dispose();
        }
    });
    Composite content = new Composite(dialogArea, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_BOTH);
    content.setLayoutData(gd);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    content.setLayout(layout);
    final Label headerLabel = createHeader(content);
    pattern = new Text(content, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL);
    pattern.getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(AccessibleEvent e) {
            e.result = LegacyActionTools.removeMnemonics(headerLabel.getText());
        }
    });
    gd = new GridData(GridData.FILL_HORIZONTAL);
    pattern.setLayoutData(gd);
    final Label listLabel = createLabels(content);
    sashForm = new SashForm(content, SWT.VERTICAL);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(sashForm);
    list = new TableViewer(sashForm, (multi ? SWT.MULTI : SWT.SINGLE) | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL);
    // ColumnViewerToolTipSupport.enableFor(list, ToolTip.NO_RECREATE);
    list.getTable().setHeaderVisible(true);
    list.getTable().setLinesVisible(true);
    list.getTable().getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(AccessibleEvent e) {
            if (e.childID == ACC.CHILDID_SELF) {
                e.result = LegacyActionTools.removeMnemonics(listLabel.getText());
            }
        }
    });
    list.setContentProvider(contentProvider);
    // new ScrollListener(list.getTable().getVerticalBar());
    // new SelectionChangedListener(list);
    TableViewerColumn col = new TableViewerColumn(list, SWT.RIGHT);
    col.setLabelProvider(LINE_NUMBER_LABEL_PROVIDER);
    col.getColumn().setText("Line");
    col.getColumn().setWidth(40);
    col = new TableViewerColumn(list, SWT.LEFT);
    col.getColumn().setText("Text");
    col.setLabelProvider(LINE_TEXT_LABEL_PROVIDER);
    col.getColumn().setWidth(400);
    col = new TableViewerColumn(list, SWT.LEFT);
    col.getColumn().setText("Path");
    col.setLabelProvider(LINE_FILE_LABEL_PROVIDER);
    col.getColumn().setWidth(150);
    new TableResizeHelper(list).enableResizing();
    // list.setLabelProvider(getItemsListLabelProvider());
    list.setInput(new Object[0]);
    list.setItemCount(contentProvider.getNumberOfElements());
    gd = new GridData(GridData.FILL_BOTH);
    applyDialogFont(list.getTable());
    gd.heightHint = list.getTable().getItemHeight() * 15;
    list.getTable().setLayoutData(gd);
    createPopupMenu();
    pattern.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            applyFilter();
        }
    });
    pattern.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_DOWN) {
                if (list.getTable().getItemCount() > 0) {
                    list.getTable().setFocus();
                    list.getTable().select(0);
                    // programatic selection may not fire selection events so...
                    refreshDetails();
                }
            }
        }
    });
    list.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            handleSelected(selection);
        }
    });
    list.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            handleDoubleClick();
        }
    });
    list.getTable().addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_UP && (e.stateMask & SWT.SHIFT) == 0 && (e.stateMask & SWT.CTRL) == 0) {
                StructuredSelection selection = (StructuredSelection) list.getSelection();
                if (selection.size() == 1) {
                    Object element = selection.getFirstElement();
                    if (element.equals(list.getElementAt(0))) {
                        pattern.setFocus();
                    }
                    list.getTable().notifyListeners(SWT.Selection, new Event());
                }
            }
            if (e.keyCode == SWT.ARROW_DOWN && (e.stateMask & SWT.SHIFT) != 0 && (e.stateMask & SWT.CTRL) != 0) {
                list.getTable().notifyListeners(SWT.Selection, new Event());
            }
        }
    });
    createDetailsArea(sashForm);
    sashForm.setWeights(new int[] { 5, 1 });
    applyDialogFont(content);
    restoreDialog(getDialogSettings());
    if (initialPatternText != null) {
        pattern.setText(initialPatternText);
    }
    switch(selectionMode) {
        case CARET_BEGINNING:
            pattern.setSelection(0, 0);
            break;
        case FULL_SELECTION:
            pattern.setSelection(0, initialPatternText.length());
            break;
    }
    // apply filter even if pattern is empty (display history)
    applyFilter();
    return dialogArea;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) TableResizeHelper(org.springsource.ide.eclipse.commons.quicksearch.util.TableResizeHelper) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 AccessibleAdapter (org.eclipse.swt.accessibility.AccessibleAdapter)1 AccessibleEvent (org.eclipse.swt.accessibility.AccessibleEvent)1 SashForm (org.eclipse.swt.custom.SashForm)1 StyledText (org.eclipse.swt.custom.StyledText)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1