Search in sources :

Example 1 with ViewerSearchPart

use of org.springsource.ide.eclipse.commons.frameworks.ui.internal.swt.ViewerSearchPart in project eclipse-integration-commons by spring-projects.

the class GenericWizardCommandListPage method createCommandTableArea.

protected synchronized void createCommandTableArea(Composite parent) {
    Composite tableArea = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(tableArea);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tableArea);
    Label tableLabel = new Label(tableArea, SWT.LEFT);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(tableLabel);
    tableLabel.setText(SELECT_COMMAND_LABEL);
    final ViewerSearchPart part = createSearchControl(tableArea);
    Table table = new Table(tableArea, getViewerConfiguration());
    commandTableViewer = new TableViewer(table);
    part.connectViewer(commandTableViewer);
    setTableColumnAndLayout(commandTableViewer);
    commandTableViewer.setContentProvider(new IStructuredContentProvider() {

        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof Collection<?>) {
                Collection<?> topLevel = (Collection<?>) inputElement;
                return topLevel.toArray();
            }
            return null;
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        // Nothing
        }

        public void dispose() {
        // Nothing
        }
    });
    commandTableViewer.setLabelProvider(new ColumnLabelProvider() {

        public String getText(Object element) {
            if (element instanceof IFrameworkCommandDescriptor) {
                return ((IFrameworkCommandDescriptor) element).getName();
            }
            return null;
        }
    });
    commandTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) commandTableViewer.getSelection();
            if (selection != null) {
                Object selObj = selection.getFirstElement();
                if (selObj instanceof IFrameworkCommandDescriptor) {
                    GenericWizardCommandListPage.this.selectionChanged((IFrameworkCommandDescriptor) selObj);
                }
            }
            checkPageComplete();
        }
    });
    commandTableViewer.getTable().addKeyListener(new KeyListener() {

        public void keyReleased(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
            // arrow pressed
            if (e.keyCode == SWT.ARROW_UP) {
                Object topSelection = commandTableViewer.getElementAt(0);
                IFrameworkCommandDescriptor currentSelection = getSelectedCommandDescriptor();
                if (topSelection == currentSelection) {
                    part.getTextControl().setFocus();
                }
            }
        }
    });
    commandTableViewer.setInput(commandDescriptors);
    Text searchText = part.getTextControl();
    searchText.addKeyListener(new KeyListener() {

        public void keyReleased(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
            // down arrow is pressed
            if (e.keyCode == SWT.ARROW_DOWN) {
                commandTableViewer.getTable().setFocus();
                Object selection = commandTableViewer.getElementAt(0);
                if (selection instanceof IFrameworkCommandDescriptor) {
                    selectCommandInViewer((IFrameworkCommandDescriptor) selection);
                }
            }
        }
    });
    // STS 1251: Add filter listener to automatically select commands based
    // on the pattern that is typed
    searchText.addKeyListener(new KeyListener() {

        public void keyReleased(KeyEvent event) {
            // STS 1251: If one element is left in the table after search is
            // performed, select it to enable
            // the appropriate wizard buttons
            int itemCount = commandTableViewer.getTable().getItemCount();
            if (itemCount == 1) {
                IFrameworkCommandDescriptor remainingDescriptor = (IFrameworkCommandDescriptor) commandTableViewer.getElementAt(0);
                if (remainingDescriptor != null) {
                    GenericWizardCommandListPage.this.selectCommandInViewer(remainingDescriptor);
                }
            } else {
                // else clear the selection nothing is found by search or
                // multiple matches are found
                GenericWizardCommandListPage.this.selectCommandInViewer(null);
            }
        }

        public void keyPressed(KeyEvent event) {
        }
    });
    searchText.setFocus();
    checkPageComplete();
}
Also used : ViewerSearchPart(org.springsource.ide.eclipse.commons.frameworks.ui.internal.swt.ViewerSearchPart) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Text(org.eclipse.swt.widgets.Text) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) KeyEvent(org.eclipse.swt.events.KeyEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Collection(java.util.Collection) KeyListener(org.eclipse.swt.events.KeyListener) TableViewer(org.eclipse.jface.viewers.TableViewer) IFrameworkCommandDescriptor(org.springsource.ide.eclipse.commons.frameworks.core.internal.commands.IFrameworkCommandDescriptor)

Example 2 with ViewerSearchPart

use of org.springsource.ide.eclipse.commons.frameworks.ui.internal.swt.ViewerSearchPart in project eclipse-integration-commons by spring-projects.

the class GenericWizardCommandListPage method createSearchControl.

protected ViewerSearchPart createSearchControl(Composite parent) {
    ViewerSearchPart part = new ViewerSearchPart(parent) {

        protected boolean matches(Object element, Object parentElement, String pattern) {
            if (element instanceof IFrameworkCommandDescriptor) {
                String commandName = ((IFrameworkCommandDescriptor) element).getName();
                String lowerCasePattern = pattern.toLowerCase();
                if (commandName != null) {
                    commandName = commandName.toLowerCase();
                    SearchPattern filter = new SearchPattern();
                    filter.setPattern(lowerCasePattern);
                    return filter.matches(commandName);
                }
            }
            return false;
        }
    };
    return part;
}
Also used : ViewerSearchPart(org.springsource.ide.eclipse.commons.frameworks.ui.internal.swt.ViewerSearchPart) SearchPattern(org.eclipse.ui.dialogs.SearchPattern) IFrameworkCommandDescriptor(org.springsource.ide.eclipse.commons.frameworks.core.internal.commands.IFrameworkCommandDescriptor)

Aggregations

IFrameworkCommandDescriptor (org.springsource.ide.eclipse.commons.frameworks.core.internal.commands.IFrameworkCommandDescriptor)2 ViewerSearchPart (org.springsource.ide.eclipse.commons.frameworks.ui.internal.swt.ViewerSearchPart)2 Collection (java.util.Collection)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Table (org.eclipse.swt.widgets.Table)1 Text (org.eclipse.swt.widgets.Text)1 SearchPattern (org.eclipse.ui.dialogs.SearchPattern)1