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();
}
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;
}
Aggregations