Example usage for org.eclipse.jface.viewers StructuredSelection EMPTY

List of usage examples for org.eclipse.jface.viewers StructuredSelection EMPTY

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection EMPTY.

Prototype

StructuredSelection EMPTY

To view the source code for org.eclipse.jface.viewers StructuredSelection EMPTY.

Click Source Link

Document

The canonical empty selection.

Usage

From source file:net.enilink.komma.edit.ui.commands.AbstractHandler.java

License:Open Source License

/**
 * Retrieves the current structured selection.
 * // w  w  w.  ja  va2s  .co  m
 * @return The current structured selection.
 */
protected IStructuredSelection getStructuredSelection(ExecutionEvent event) {
    ISelection selection = getSelection(event);
    return (selection instanceof StructuredSelection) ? (StructuredSelection) selection
            : StructuredSelection.EMPTY;
}

From source file:net.enilink.komma.edit.ui.dialogs.FilteredList.java

License:Open Source License

/**
 * Refreshes the dialog - has to be called in UI thread.
 *//*from w ww . j a  v a 2s  . c om*/
public void refresh() {
    if (list != null && !list.getTable().isDisposed()) {

        List<?> lastRefreshSelection = ((StructuredSelection) list.getSelection()).toList();

        list.setItemCount(contentProvider.getElements(null).length);
        list.refresh();

        if (list.getTable().getItemCount() > 0) {
            // preserve previous selection
            if (refreshWithLastSelection && lastRefreshSelection != null && lastRefreshSelection.size() > 0) {
                list.setSelection(new StructuredSelection(lastRefreshSelection));
            } else {
                refreshWithLastSelection = true;

                list.getTable().setSelection(0);

                list.getTable().notifyListeners(SWT.Selection, new Event());
            }
        } else {
            list.setSelection(StructuredSelection.EMPTY);
        }

    }

    scheduleProgressMessageRefresh();
}

From source file:net.refractions.udig.catalog.ui.operation.TransformPanel.java

License:Open Source License

protected Control createExpressionTable(Composite parent) {
    setLayout(new MigLayout("insets 0", "[grow,fill][]", "[][][][][grow,fill][][][][grow,fill][][]"));

    Label label = new Label(this, SWT.LEFT);
    label.setText("Transform");
    label.setLayoutData("cell 0 0 2 1,width pref!,left");

    Button button = new Button(this, SWT.CENTER);
    button.setText("Add");
    button.setLayoutData("cell 1 1 1 1,grow");
    button.addSelectionListener(new SelectionAdapter() {
        @Override/* w w  w  . ja v  a2s.  c  om*/
        public void widgetSelected(SelectionEvent e) {
            int row = table.getTable().getSelectionIndex();
            Definition definition = new Definition();
            definition.name = "";
            definition.expression = Expression.NIL;
            transform.add(row, definition);
            table.refresh();
            table.setSelection(new StructuredSelection(definition));
        }
    });

    button = new Button(this, SWT.CENTER);
    button.setText("Up");
    button.setLayoutData("cell 1 2 1 1,grow");
    button.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int row = table.getTable().getSelectionIndex();
            if (row == 0 || row == -1) {
                return;
            }
            row--;
            Definition definition = selectedDefinition();
            transform.remove(definition);
            transform.add(row, definition);
            table.refresh();
            table.setSelection(new StructuredSelection(definition));
        }
    });

    button = new Button(this, SWT.CENTER);
    button.setText("Down");
    button.setLayoutData("cell 1 3 1 1,grow");
    button.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int row = table.getTable().getSelectionIndex();
            if (row == transform.size() - 1 || row == -1) {
                return;
            }
            row++;
            Definition definition = selectedDefinition();
            transform.remove(definition);
            transform.add(row, definition);
            table.refresh();
            table.setSelection(new StructuredSelection(definition));
        }
    });

    button = new Button(this, SWT.CENTER);
    button.setText("Remove");
    button.setLayoutData("cell 1 5 1 1,grow");
    button.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int row = table.getTable().getSelectionIndex();
            if (row == -1) {
                return;
            }
            if (row > 0) {
                row = row - 1;
            }
            Definition definition = selectedDefinition();
            transform.remove(definition);
            table.refresh();

            if (row < transform.size()) {
                table.getTable().setSelection(row);
            } else {
                table.getTable().deselectAll();
            }
        }
    });

    table = new TableViewer(this, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    table.setContentProvider(ArrayContentProvider.getInstance());
    table.getControl().setLayoutData("cell 0 1 1 5, grow, height 200:50%:70%,width 300:pref:100%");

    TableViewerColumn column = new TableViewerColumn(table, SWT.NONE);
    column.getColumn().setWidth(100);
    column.getColumn().setMoveable(false);
    column.getColumn().setResizable(true);
    column.getColumn().setText("Attribute");
    column.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            Definition definition = (Definition) element;
            return definition.name;
        }
    });
    column = new TableViewerColumn(table, SWT.NONE);
    column.getColumn().setWidth(60);
    column.getColumn().setMoveable(false);
    column.getColumn().setResizable(true);
    column.getColumn().setText("Type");
    column.getColumn().setAlignment(SWT.CENTER);
    column.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            Definition definition = (Definition) element;
            return definition.binding == null ? NO_CONTENT : definition.binding.getSimpleName();
        }
    });
    column = new TableViewerColumn(table, SWT.NONE);
    column.getColumn().setWidth(140);
    column.getColumn().setMoveable(false);
    column.getColumn().setResizable(true);
    column.getColumn().setText("Expression");
    column.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            Definition definition = (Definition) element;
            return definition.expression == null ? NO_CONTENT : ECQL.toCQL(definition.expression);
        }
    });
    table.getTable().setHeaderVisible(true);
    table.getTable().setLinesVisible(true);
    table.addSelectionChangedListener(tableListener);

    Transfer[] types = new Transfer[] { UDigByteAndLocalTransfer.getInstance() };
    table.addDragSupport(DND.DROP_MOVE | DND.DROP_DEFAULT, types, new DragSourceAdapter() {
        @Override
        public void dragSetData(DragSourceEvent event) {
            IStructuredSelection selection = (IStructuredSelection) table.getSelection();

            if (UDigByteAndLocalTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = selection.getFirstElement();
            }
        }
    });

    // drag drop order support
    table.addDropSupport(DND.DROP_MOVE | DND.DROP_DEFAULT, types, new ViewerDropAdapter(table) {

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            if (target instanceof Definition) {
                return true;
            } else {
                return false;
            }
        }

        @Override
        public boolean performDrop(Object data) {
            if (data instanceof Definition) {
                listen(false);

                int index = transform.indexOf(getCurrentTarget());

                // if (location == LOCATION_BEFORE)
                // index--;

                Definition definition = (Definition) data;
                transform.remove(definition);
                transform.add(index, definition);
                table.refresh();
                table.setSelection(new StructuredSelection(definition));

                listen(true);
                return true;
            }
            return false;
        }
    });

    definitionLabel = new Label(this, SWT.LEFT);
    definitionLabel.setText("Definition");
    definitionLabel.setLayoutData("cell 0 6 2 1, width pref!,left");

    feedbackDecorator = new ControlDecoration(definitionLabel, SWT.RIGHT | SWT.TOP);

    name = new Text(this, SWT.SINGLE | SWT.BORDER);
    name.setEditable(true);
    name.setText("");
    name.setLayoutData("cell 0 7 2 1");

    expression = new ExpressionViewer(this, SWT.MULTI);
    // expression.setInput(expressionInput);
    expression.getControl().setLayoutData("cell 0 8 2 1,height 200:50%:50%,width 300:pref:100%");
    expression.addSelectionChangedListener(expressionListener);

    // start up with nothing selected
    table.setSelection(StructuredSelection.EMPTY);
    enable(false);
    return this;
}

From source file:net.refractions.udig.core.SelectionProviderForwarder.java

License:Open Source License

@Override
public ISelection getSelection() {
    ISelection selection = provider.getSelection();
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        IStructuredSelection sel = (IStructuredSelection) selection;
        Object element = sel.getFirstElement();

        if (forwardType.isInstance(element)) {
            return selection;
        }/*  ww w .j  a v  a2s . c o m*/
        // check IAdaptable incase ILayer or another selection wants to play
        if (element instanceof IAdaptable) {
            IAdaptable adaptable = (IAdaptable) element;

            Object value = adaptable.getAdapter(forwardType);
            if (value != null) {
                return new StructuredSelection(value);
            }
        }
    }
    return StructuredSelection.EMPTY; // no dice!
}

From source file:net.refractions.udig.ui.filter.IExpressionViewer.java

License:Open Source License

/**
 * Returns the current selection for this provider.
 * /*from  w  w  w .j a  v a  2s  .c  om*/
 * @return Current expression from {@link #getExpression()} or {@link StructuredSelection#EMPTY} if not defined
 */
public ISelection getSelection() {
    if (expression != null) {
        return new StructuredSelection(expression);
    }
    return StructuredSelection.EMPTY;
}

From source file:net.refractions.udig.ui.filter.IExpressionViewer.java

License:Open Source License

/**
 * Used internally to update the expression and issue a {@link SelectionChangedEvent}.
 * //  w w  w .ja v a 2s  .c om
 * @param newExpression Expression used to update {@link #getExpression()} and the user interface components
 */
protected void internalUpdate(Expression newExpression) {
    if (this.expression == newExpression) {
        return;
    }
    String before = expression != null ? ECQL.toCQL(expression) : "(empty)";
    String after = newExpression != null ? ECQL.toCQL(newExpression) : "(empty)";
    if (!Utilities.equals(before, after)) {
        this.expression = newExpression;
        feedback(); // clear any outstanding feedback as our value matches our display now

        StructuredSelection selection = newExpression != null ? new StructuredSelection(newExpression)
                : StructuredSelection.EMPTY;
        fireSelectionChanged(new SelectionChangedEvent(this, selection));
    }
}

From source file:net.refractions.udig.ui.filter.IFilterViewer.java

License:Open Source License

/**
 * Returns the current selection for this provider.
 * /*from ww  w  .j a  v  a 2  s . c  o  m*/
 * @return Current filter from {@link #getFilter()} or {@link StructuredSelection#EMPTY} if not defined
 */
public ISelection getSelection() {
    if (filter != null) {
        return new StructuredSelection(filter);
    }
    return StructuredSelection.EMPTY;
}

From source file:net.refractions.udig.ui.filter.IFilterViewer.java

License:Open Source License

/**
 * Used internally to update the filter and issue a {@link SelectionChangedEvent}.
 * /*from   w ww.  ja  v a 2s  . co m*/
 * @param newFilter
 */
protected void internalUpdate(Filter newFilter) {
    if (this.filter == newFilter) {
        return;
    }
    String before = filter != null ? ECQL.toCQL(filter) : "(empty)";
    String after = newFilter != null ? ECQL.toCQL(newFilter) : "(empty)";
    if (!Utilities.equals(before, after)) {
        this.filter = newFilter;
        StructuredSelection selection = newFilter != null ? new StructuredSelection(newFilter)
                : StructuredSelection.EMPTY;
        SelectionChangedEvent selectionEvent = new SelectionChangedEvent(this, selection);
        fireSelectionChanged(selectionEvent);
    }
}

From source file:net.rim.ejde.internal.menu.DebugConfigurationsCommandHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);
    if (selection != null && !selection.isEmpty()) {
        AbstractLaunchShortcut ls = new FledgeLaunchShortcut();
        ls.openLaunchConfiguration(selection, "debug");
    } else {//  w  w  w  .  jav  a 2  s  .com
        DebugUITools.openLaunchConfigurationDialog(Display.getDefault().getShells()[0],
                StructuredSelection.EMPTY, "debug");
    }
    return null;
}

From source file:net.rim.ejde.internal.menu.NewProjectCommandHandler.java

License:Open Source License

private void doIt() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    BlackBerryProjectWizard bbProjWiz = new BlackBerryProjectWizard();
    bbProjWiz.init(workbench, StructuredSelection.EMPTY);
    WizardDialog dialog = new WizardDialog(Display.getDefault().getShells()[0], bbProjWiz);
    dialog.create();/*from  w ww  .ja  v a2 s.c  o  m*/

    // Open wizard.
    dialog.open();
}