Search in sources :

Example 1 with IFrameworkCommandDescriptor

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);
            }
        }
    });
}
Also used : IFrameworkCommandDescriptor(org.springsource.ide.eclipse.commons.frameworks.core.internal.commands.IFrameworkCommandDescriptor)

Example 2 with IFrameworkCommandDescriptor

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();
}
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 3 with IFrameworkCommandDescriptor

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();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) IFrameworkCommandDescriptor(org.springsource.ide.eclipse.commons.frameworks.core.internal.commands.IFrameworkCommandDescriptor)

Example 4 with IFrameworkCommandDescriptor

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

Example 5 with IFrameworkCommandDescriptor

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();
}
Also used : IFrameworkCommandDescriptor(org.springsource.ide.eclipse.commons.frameworks.core.internal.commands.IFrameworkCommandDescriptor)

Aggregations

IFrameworkCommandDescriptor (org.springsource.ide.eclipse.commons.frameworks.core.internal.commands.IFrameworkCommandDescriptor)5 TableViewer (org.eclipse.jface.viewers.TableViewer)2 Viewer (org.eclipse.jface.viewers.Viewer)2 Table (org.eclipse.swt.widgets.Table)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 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)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 TableLayout (org.eclipse.jface.viewers.TableLayout)1 ViewerSorter (org.eclipse.jface.viewers.ViewerSorter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1