use of org.springsource.ide.eclipse.commons.frameworks.core.internal.commands.IFrameworkCommandDescriptor in project eclipse-integration-commons by spring-projects.
the class GenericCommandWizard method addCommandDescriptor.
/**
* Add a command descriptor to the wizard. If the wizard already has a
* command of the same type, the wizard will use the existing command. It is
* not possible to override an existing command already present in the
* wizard
*/
public void addCommandDescriptor(IFrameworkCommandDescriptor commandDescriptor) {
// Make sure this always executes in UI thread
final IFrameworkCommandDescriptor commandDesc = commandDescriptor;
Display.getDefault().syncExec(new Runnable() {
public void run() {
if (commandListPage != null && !commandListPage.containsCommandDescriptor(commandDesc)) {
commandListPage.addCommandDescriptor(commandDesc);
}
}
});
}
use of org.springsource.ide.eclipse.commons.frameworks.core.internal.commands.IFrameworkCommandDescriptor 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.core.internal.commands.IFrameworkCommandDescriptor in project eclipse-integration-commons by spring-projects.
the class GenericWizardCommandListPage method setTableColumnAndLayout.
/**
* Sets the main column in the viewer that lists all the commands and adds a
* sorter.
*
* @param tableviewer
*/
protected void setTableColumnAndLayout(final TableViewer tableviewer) {
tableviewer.setSorter(new ViewerSorter() {
public int compare(Viewer viewer, Object command1, Object command2) {
if (viewer instanceof TableViewer) {
Table table = ((TableViewer) viewer).getTable();
if (command1 instanceof IFrameworkCommandDescriptor && command2 instanceof IFrameworkCommandDescriptor) {
int sortDirection = table.getSortDirection();
String commandName1 = ((IFrameworkCommandDescriptor) command1).getName();
String commandName2 = ((IFrameworkCommandDescriptor) command2).getName();
return sortDirection == SWT.UP ? commandName1.compareToIgnoreCase(commandName2) : commandName2.compareToIgnoreCase(commandName1);
}
}
return super.compare(viewer, command1, command2);
}
});
final Table table = tableviewer.getTable();
GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, getMinTableHeight()).applyTo(table);
TableLayout tableLayout = new TableLayout();
tableLayout.addColumnData(new ColumnWeightData(getMinCommandColumnWeight(), true));
TableColumn commandColumn = new TableColumn(table, SWT.NONE);
table.setLayout(tableLayout);
// the command column cannot be null, as the table viewer must have at
// least one column
commandColumn.setText("Commands");
commandColumn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int dir = table.getSortDirection();
dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
table.setSortDirection(dir);
tableviewer.refresh();
}
});
table.setSortColumn(commandColumn);
table.setSortDirection(SWT.UP);
// Hide the header for now. If sorting direction change is required,
// simply set to true:
table.setHeaderVisible(false);
table.layout(true);
tableviewer.refresh();
}
use of org.springsource.ide.eclipse.commons.frameworks.core.internal.commands.IFrameworkCommandDescriptor 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;
}
use of org.springsource.ide.eclipse.commons.frameworks.core.internal.commands.IFrameworkCommandDescriptor in project eclipse-integration-commons by spring-projects.
the class GenericCommandWizard method getStartingPage.
public IWizardPage getStartingPage() {
// If a command instance already exists, open the second page first
if (commandListPage != null && commandInstance != null) {
IFrameworkCommandDescriptor descriptor = commandInstance.getCommandDescriptor();
commandListPage.addCommandDescriptor(descriptor);
commandListPage.selectCommandInViewer(descriptor);
parameterPage = createParameterPage(commandInstance);
return parameterPage;
}
return super.getStartingPage();
}
Aggregations