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:com.bdaum.zoom.ui.internal.views.DataEntryView.java

License:Open Source License

public void updateField(QueryField qfield, FieldEntry fieldEntry) {
    Object widget = widgetMap.get(qfield);
    Control control = (widget instanceof ComboViewer ? ((ComboViewer) widget).getControl() : (Control) widget);
    if (!fieldEntry.applicable || (!fieldEntry.editable && fieldEntry != FieldEntry.PENDING)) {
        setControlVisible(control, false);
        return;/*from   w ww. j a va2s  . c om*/
    }
    setControlVisible(control, true);
    updateSet.add(qfield);
    try {
        if (fieldEntry == FieldEntry.PENDING) {
            setControlEnabled(control, false);
            ControlDecoration fieldDec = getFieldDecoration(control);
            FieldDecoration deco = FieldDecorationRegistry.getDefault().getFieldDecoration(DEC_PENDING);
            fieldDec.setImage(deco.getImage());
            fieldDec.setDescriptionText(deco.getDescription());
            fieldDec.show();
        } else {
            Object value = fieldEntry.value;
            if (value == QueryField.VALUE_MIXED) {
                setControlEnabled(control,
                        qfield.getCard() == 1 || qfield.getCard() == QueryField.CARD_MODIFIABLEBAG);
                ControlDecoration fieldDec = getFieldDecoration(control);
                FieldDecoration deco = FieldDecorationRegistry.getDefault().getFieldDecoration(DEC_MIXED);
                fieldDec.setImage(deco.getImage());
                fieldDec.setDescriptionText(deco.getDescription());
                fieldDec.show();
                if (control instanceof Combo)
                    ((Combo) control).setText(QueryField.VALUE_MIXED);
                else if (control instanceof Text)
                    ((Text) control).setText(QueryField.VALUE_MIXED);
                else if (control instanceof CheckedText)
                    ((CheckedText) control).setText(QueryField.VALUE_MIXED);
                else if (control instanceof DateComponent)
                    ((DateComponent) control).setSelection(QueryField.VALUE_MIXED);
                else if (control instanceof SpinnerComponent)
                    ((SpinnerComponent) control).setSelection(QueryField.VALUE_MIXED);
            } else {
                setControlEnabled(control, value != QueryField.VALUE_NOTHING);
                String text = qfield.value2text(value, CLICK_TO_VIEW_DETAILS);
                if (text != null && value != QueryField.VALUE_MIXED) {
                    if (!text.isEmpty() && value != QueryField.VALUE_NOTHING
                            && text != Format.MISSINGENTRYSTRING) {
                        if (widget instanceof ComboViewer)
                            ((ComboViewer) widget).setSelection(new StructuredSelection(value));
                        else if (control instanceof Text)
                            ((Text) control).setText(text);
                        else if (control instanceof CheckedText)
                            ((CheckedText) control).setText(text);
                        else if (control instanceof DateComponent)
                            ((DateComponent) control).setSelection(value);
                        else if (control instanceof SpinnerComponent) {
                            if (qfield.getType() == QueryField.T_CURRENCY)
                                ((SpinnerComponent) control).setSelection(
                                        (int) ((Double) value * Math.pow(10, Format.getCurrencyDigits())
                                                + 0.5));
                            else
                                ((SpinnerComponent) control).setSelection(value);
                        }
                    } else {
                        if (widget instanceof ComboViewer)
                            ((ComboViewer) widget).setSelection(StructuredSelection.EMPTY);
                        else if (control instanceof Text)
                            ((Text) control).setText(text);
                        else if (control instanceof CheckedText)
                            ((CheckedText) control).setText(text);
                        else if (control instanceof DateComponent)
                            ((DateComponent) control).setSelection(text);
                        else if (control instanceof SpinnerComponent)
                            ((SpinnerComponent) control).setSelection(text);
                    }
                }
                hideFieldDeco(control);
            }
        }
    } finally {
        updateSet.remove(qfield);
    }

}

From source file:com.bdaum.zoom.ui.internal.views.HistogramView.java

License:Open Source License

public ISelection getSelection() {
    return currentItem != null ? new StructuredSelection(currentItem) : StructuredSelection.EMPTY;
}

From source file:com.bdaum.zoom.ui.internal.views.PreviewView.java

License:Open Source License

public ISelection getSelection() {
    return (currentItem != null) ? new StructuredSelection(currentItem) : StructuredSelection.EMPTY;
}

From source file:com.bdaum.zoom.ui.internal.views.TrashcanView.java

License:Open Source License

@Override
public void selectNone() {
    gallery.setSelection(EMPTYITEMS);
    selection = StructuredSelection.EMPTY;
}

From source file:com.boothen.jsonedit.quickoutline.QuickOutlinePopup.java

License:Open Source License

/**
 * Selects the first element in the tree which matches the current filter pattern.
 *//*from www .ja  v  a  2s  .c om*/
private void selectFirstMatch() {
    final Tree tree = treeViewer.getTree();
    TreeItem element = findElement(tree.getItems());

    if (element != null) {
        tree.setSelection(element);
        tree.showItem(element);
    } else {
        treeViewer.setSelection(StructuredSelection.EMPTY);
    }
}

From source file:com.cloudbees.eclipse.run.ui.contributions.handlers.CBSampleWebAppHandler.java

License:Open Source License

private IStructuredSelection getCurrentSelection() {
    IWorkbenchWindow window = JavaPlugin.getActiveWorkbenchWindow();
    if (window != null) {
        ISelection selection = window.getSelectionService().getSelection();
        if (selection instanceof IStructuredSelection) {
            return (IStructuredSelection) selection;
        }/*www  .  j a  v  a  2  s  . c om*/
    }
    return StructuredSelection.EMPTY;
}

From source file:com.cloudbees.eclipse.ui.wizard.CBWizardSupport.java

License:Open Source License

public static IStructuredSelection getCurrentSelection() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        ISelection selection = window.getSelectionService().getSelection();
        if (selection instanceof IStructuredSelection) {
            return (IStructuredSelection) selection;
        }//from  w w  w  . jav a  2s. co  m
    }
    return StructuredSelection.EMPTY;
}

From source file:com.codeaffine.home.control.admin.ui.util.viewer.property.PropertySheetViewer.java

License:Open Source License

/**
 * The <code>PropertySheetViewer</code> implementation of this
 * <code>ISelectionProvider</code> method returns the result as a
 * <code>StructuredSelection</code>.
 * <p>/*from   w w w . java  2  s  . c  om*/
 * Note that this method only includes <code>IPropertySheetEntry</code> in
 * the selection (no categories).
 * </p>
 */
@Override
public ISelection getSelection() {
    if (tree.getSelectionCount() == 0) {
        return StructuredSelection.EMPTY;
    }
    TreeItem[] sel = tree.getSelection();
    List entries = new ArrayList(sel.length);
    for (TreeItem ti : sel) {
        Object data = ti.getData();
        if (data instanceof IPropertySheetEntry) {
            entries.add(data);
        }
    }
    return new StructuredSelection(entries);
}

From source file:com.diffplug.common.swt.jface.ViewerMisc.java

License:Apache License

/** Returns a thread-safe `RxBox<Optional>` for manipulating the selection of a {@link StructuredViewer} created with {@link SWT#SINGLE}. */
public static <T> void singleSelection(StructuredViewer viewer, RxBox<Optional<T>> box) {
    Preconditions.checkArgument(SwtMisc.flagIsSet(SWT.SINGLE, viewer.getControl()),
            "Control style does not have SWT.SINGLE set.");
    // set the box when the selection changes
    viewer.addSelectionChangedListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        @SuppressWarnings("unchecked")
        T selected = (T) selection.getFirstElement();
        box.set(Optional.ofNullable(selected));
    });/*from  w ww . jav  a2 s.c o  m*/
    // set the selection when the box changes
    SwtExec.immediate().guardOn(viewer.getControl()).subscribe(box.asObservable(), optional -> {
        if (optional.isPresent()) {
            viewer.setSelection(new StructuredSelection(optional.get()));
        } else {
            viewer.setSelection(StructuredSelection.EMPTY);
        }
    });
}

From source file:com.drgarbage.bytecodevisualizer.editors.ToggleBytecodeBreakpointAdapter.java

License:Apache License

protected ISelection translateToMembers(IWorkbenchPart part, ISelection selection) throws CoreException {

    if (!(part instanceof BytecodeEditor)) {
        BytecodeVisualizerPlugin.log(new IllegalStateException("part not an instance of BytecodeEditor"));
        return StructuredSelection.EMPTY;
    } else {//from  www .j  av  a2 s.  co m

        BytecodeEditor bytecodeEditor = (BytecodeEditor) part;

        if (!(selection instanceof ITextSelection)) {
            BytecodeVisualizerPlugin
                    .log(new IllegalStateException("selection not an instance of ITextSelection"));
            return StructuredSelection.EMPTY;
        } else {
            ITextSelection textSelection = (ITextSelection) selection;

            IType primaryType = getPrimaryType(bytecodeEditor.getBytecodeEditorInput());
            BytecodeDocumentProvider documentProvider = (BytecodeDocumentProvider) bytecodeEditor
                    .getDocumentProvider();

            if (primaryType == null) {
                primaryType = getPrimaryType(bytecodeEditor);
            }

            if (primaryType == null) {
                primaryType = getPrimaryType(documentProvider);
            }

            if (primaryType != null) {

                IClassFileDocument doc = documentProvider.getClassFileDocument();

                int line = textSelection.getStartLine();
                if (line == doc.getClassSignatureDocumentLine()) {
                    return new StructuredSelection(primaryType);
                }

                if (doc.isLineInMethod(line)) {
                    IMethodSection ms = doc.findMethodSection(line);
                    if (ms != null) {
                        IMethod m = ClassFileDocumentsUtils.findMethod(primaryType, ms.getName(),
                                ms.getDescriptor());
                        if (m != null) {
                            return new StructuredSelection(m);
                        } else {
                            /* probably an implicit constructor */
                            primaryType = getPrimaryType(documentProvider);
                            if (primaryType != null) {
                                m = ClassFileDocumentsUtils.findMethod(primaryType, ms.getName(),
                                        ms.getDescriptor());
                                if (m != null) {
                                    return new StructuredSelection(m);
                                }
                            }
                        }
                    }
                    return StructuredSelection.EMPTY;
                }

                if (doc.isLineInField(line)) {
                    IFieldSection fs = doc.findFieldSection(line);
                    if (fs != null) {
                        IField f = primaryType.getField(fs.getName());
                        if (f != null) {
                            return new StructuredSelection(f);
                        }
                    }
                    return StructuredSelection.EMPTY;
                }

            }
            return StructuredSelection.EMPTY;
        }

    }

}